Only in sys/netgraph7/bluetooth/drivers/h4: Makefile
diff -ur /home/s/reference/FreeBSD/src/sys/netgraph/bluetooth/drivers/h4/TODO sys/netgraph7/bluetooth/drivers/h4/TODO
--- /home/s/reference/FreeBSD/src/sys/netgraph/bluetooth/drivers/h4/TODO	2013-09-02 20:18:16.000000000 +0200
+++ sys/netgraph7/bluetooth/drivers/h4/TODO	2014-07-15 10:11:06.056950000 +0200
@@ -1,5 +1,5 @@
 $Id: TODO,v 1.2 2004/08/23 18:08:15 max Exp $
-$FreeBSD: head/sys/netgraph/bluetooth/drivers/h4/TODO 171818 2007-08-13 17:19:28Z emax $
+$FreeBSD: src/sys/netgraph/bluetooth/drivers/h4/TODO,v 1.3 2007/08/13 17:19:28 emax Exp $
 
 FIXME/TODO list
 
diff -ur /home/s/reference/FreeBSD/src/sys/netgraph/bluetooth/drivers/h4/ng_h4.c sys/netgraph7/bluetooth/drivers/h4/ng_h4.c
--- /home/s/reference/FreeBSD/src/sys/netgraph/bluetooth/drivers/h4/ng_h4.c	2013-09-02 20:18:16.000000000 +0200
+++ sys/netgraph7/bluetooth/drivers/h4/ng_h4.c	2014-07-15 10:11:06.056950000 +0200
@@ -1,11 +1,11 @@
-/*
- * ng_h4.c
- */
-
 /*-
+ * (MPSAFE)
+ *
  * Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
  * All rights reserved.
  *
+ * ng_h4.c
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -45,7 +45,6 @@
 #include <sys/endian.h>
 #include <sys/errno.h>
 #include <sys/fcntl.h>
-#include <sys/ioccom.h>
 #include <sys/malloc.h>
 #include <sys/mbuf.h>
 #include <sys/priv.h>
@@ -54,14 +53,14 @@
 #include <sys/ttycom.h>
 #include <net/if.h>
 #include <net/if_var.h>
-#include <netgraph/ng_message.h>
-#include <netgraph/netgraph.h>
-#include <netgraph/ng_parse.h>
-#include <netgraph/bluetooth/include/ng_bluetooth.h>
-#include <netgraph/bluetooth/include/ng_hci.h>
-#include <netgraph/bluetooth/include/ng_h4.h>
-#include <netgraph/bluetooth/drivers/h4/ng_h4_var.h>
-#include <netgraph/bluetooth/drivers/h4/ng_h4_prse.h>
+#include <netgraph7/ng_message.h>
+#include <netgraph7/netgraph.h>
+#include <netgraph7/ng_parse.h>
+#include <netgraph7/bluetooth/include/ng_bluetooth.h>
+#include <netgraph7/bluetooth/include/ng_hci.h>
+#include <netgraph7/bluetooth/include/ng_h4.h>
+#include <netgraph7/bluetooth/drivers/h4/ng_h4_var.h>
+#include <netgraph7/bluetooth/drivers/h4/ng_h4_prse.h>
 
 /*****************************************************************************
  *****************************************************************************
@@ -91,7 +90,7 @@
 static int	ng_h4_input	(int, struct tty *);
 static int	ng_h4_start	(struct tty *);
 static int	ng_h4_ioctl	(struct tty *, u_long, caddr_t, 
-					int, struct thread *);
+					int, struct ucred *);
 
 /* Line discipline descriptor */
 static struct linesw		ng_h4_disc = {
@@ -161,10 +160,11 @@
 		return (error);
 
 	/* Initialize private struct */
-	sc = malloc(sizeof(*sc), M_NETGRAPH_H4, M_NOWAIT|M_ZERO);
+	sc = kmalloc(sizeof(*sc), M_NETGRAPH_H4, M_WAITOK | M_NULLOK | M_ZERO);
 	if (sc == NULL)
 		return (ENOMEM);
 
+	lwkt_gettoken(&tty_token);
 	sc->tp = tp;
 	sc->debug = NG_H4_WARN_LEVEL;
 
@@ -172,8 +172,7 @@
 	sc->want = 1;
 	sc->got = 0;
 
-	mtx_init(&sc->outq.ifq_mtx, "ng_h4 node+queue", NULL, MTX_DEF);
-	IFQ_SET_MAXLEN(&sc->outq, NG_H4_DEFAULTQLEN);
+	sc->outq.ifq_maxlen = NG_H4_DEFAULTQLEN;
 	ng_callout_init(&sc->timo);
 
 	NG_H4_LOCK(sc);
@@ -185,10 +184,10 @@
 
 		printf("%s: Unable to create new node!\n", __func__);
 
-		mtx_destroy(&sc->outq.ifq_mtx);
 		bzero(sc, sizeof(*sc));
-		free(sc, M_NETGRAPH_H4);
+		kfree(sc, M_NETGRAPH_H4);
 
+		lwkt_reltoken(&tty_token);
 		return (error);
 	}
 
@@ -202,16 +201,16 @@
 		printf("%s: %s - node name exists?\n", __func__, name);
 
 		NG_NODE_UNREF(sc->node);
-		mtx_destroy(&sc->outq.ifq_mtx);
 		bzero(sc, sizeof(*sc));
-		free(sc, M_NETGRAPH_H4);
+		kfree(sc, M_NETGRAPH_H4);
 
+		lwkt_reltoken(&tty_token);
 		return (error);
 	}
 
 	/* Set back pointers */
 	NG_NODE_SET_PRIVATE(sc->node, sc);
-	tp->t_lsc = (caddr_t) sc;
+	tp->t_sc = (caddr_t) sc;
 
 	/* The node has to be a WRITER because data can change node status */
 	NG_NODE_FORCE_WRITER(sc->node);
@@ -229,6 +228,7 @@
 
 	NG_H4_UNLOCK(sc);
 
+	lwkt_reltoken(&tty_token);
 	return (error);
 } /* ng_h4_open */
 
@@ -240,8 +240,9 @@
 static int
 ng_h4_close(struct tty *tp, int flag)
 {
-	ng_h4_info_p	sc = (ng_h4_info_p) tp->t_lsc;
+	ng_h4_info_p	sc = (ng_h4_info_p) tp->t_sc;
 
+	lwkt_gettoken(&tty_token);
 	ttyflush(tp, FREAD | FWRITE);
 	clist_free_cblocks(&tp->t_outq);
 
@@ -251,7 +252,7 @@
 		if (callout_pending(&sc->timo))
 			ng_uncallout(&sc->timo, sc->node);
 
-		tp->t_lsc = NULL;
+		tp->t_sc = NULL;
 		sc->dying = 1;
 
 		NG_H4_UNLOCK(sc);
@@ -259,6 +260,7 @@
 		ng_rmnode_self(sc->node);
 	}
 
+	lwkt_reltoken(&tty_token);
 	return (0);
 } /* ng_h4_close */
 
@@ -288,14 +290,15 @@
 
 static int
 ng_h4_ioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
-		struct thread *td)
+    struct ucred *cred)
 {
-	ng_h4_info_p	sc = (ng_h4_info_p) tp->t_lsc;
+	ng_h4_info_p	sc = (ng_h4_info_p) tp->t_sc;
 	int		error = 0;
 
 	if (sc == NULL)
 		return (ENXIO);
 
+	lwkt_gettoken(&tty_token);
 	NG_H4_LOCK(sc);
 
 	switch (cmd) {
@@ -323,6 +326,7 @@
 
 	NG_H4_UNLOCK(sc);
 
+	lwkt_reltoken(&tty_token);
 	return (error);
 } /* ng_h4_ioctl */
 
@@ -334,11 +338,14 @@
 static int
 ng_h4_input(int c, struct tty *tp)
 {
-	ng_h4_info_p	sc = (ng_h4_info_p) tp->t_lsc;
+	ng_h4_info_p	sc = (ng_h4_info_p) tp->t_sc;
 
+	lwkt_gettoken(&tty_token);
 	if (sc == NULL || tp != sc->tp ||
-	    sc->node == NULL || NG_NODE_NOT_VALID(sc->node))
+	    sc->node == NULL || NG_NODE_NOT_VALID(sc->node)) {
+		lwkt_reltoken(&tty_token);
 		return (0);
+	}
 
 	NG_H4_LOCK(sc);
 
@@ -353,6 +360,7 @@
 
 		NG_H4_UNLOCK(sc);
 
+		lwkt_reltoken(&tty_token);
 		return (0); /* XXX Loss of synchronization here! */
 	}
 
@@ -370,6 +378,7 @@
 
 		NG_H4_UNLOCK(sc);
 
+		lwkt_reltoken(&tty_token);
 		return (0); /* XXX Loss of synchronization here! */
 	}
 
@@ -389,6 +398,7 @@
 
 		NG_H4_UNLOCK(sc);
 
+		lwkt_reltoken(&tty_token);
 		return (0); /* XXX Loss of synchronization here! */
 	}
 
@@ -400,6 +410,7 @@
 	if (sc->got < sc->want) {
 		NG_H4_UNLOCK(sc);
 
+		lwkt_reltoken(&tty_token);
 		return (0); /* Wait for more */
 	}
 
@@ -462,7 +473,7 @@
 			break;
 
 		default:
-			KASSERT((0), ("Invalid packet type=%#x\n",
+			KASSERT((0), ("Invalid packet type=%#x",
 				sc->ibuf[0]));
 			break;
 		}
@@ -525,7 +536,7 @@
 		if (sc->hook != NULL && NG_HOOK_IS_VALID(sc->hook)) {
 			struct mbuf	*m = NULL;
 
-			MGETHDR(m, M_NOWAIT, MT_DATA);
+			MGETHDR(m, MB_DONTWAIT, MT_DATA);
 			if (m != NULL) {
 				m->m_pkthdr.len = 0;
 
@@ -556,6 +567,7 @@
 
 	NG_H4_UNLOCK(sc);
 
+	lwkt_reltoken(&tty_token);
 	return (0);
 } /* ng_h4_input */
 
@@ -567,13 +579,16 @@
 static int
 ng_h4_start(struct tty *tp)
 {
-	ng_h4_info_p	 sc = (ng_h4_info_p) tp->t_lsc;
+	ng_h4_info_p	 sc = (ng_h4_info_p) tp->t_sc;
 	struct mbuf	*m = NULL;
 	int		 size;
 
+	lwkt_gettoken(&tty_token);
 	if (sc == NULL || tp != sc->tp || 
-	    sc->node == NULL || NG_NODE_NOT_VALID(sc->node))
+	    sc->node == NULL || NG_NODE_NOT_VALID(sc->node)) {
+		lwkt_reltoken(&tty_token);
 		return (0);
+	}
 
 #if 0
 	while (tp->t_outq.c_cc < NG_H4_HIWATER) { /* XXX 2.2 specific ? */
@@ -619,7 +634,8 @@
 	 * being called in lieu of ttstart and must do what it would.
 	 */
 
-	tt_oproc(sc->tp);
+	if (tp->t_oproc != NULL)
+		(*tp->t_oproc) (tp);
 
 	/*
 	 * This timeout is needed for operation on a pseudo-tty, because the
@@ -628,12 +644,13 @@
 
 	NG_H4_LOCK(sc);
 
-	if (!IFQ_IS_EMPTY(&sc->outq) && !callout_pending(&sc->timo))
+	if (!IF_QEMPTY(&sc->outq) && !callout_pending(&sc->timo))
 		ng_callout(&sc->timo, sc->node, NULL, 1,
 			ng_h4_process_timeout, NULL, 0);
 
 	NG_H4_UNLOCK(sc);
 
+	lwkt_reltoken(&tty_token);
 	return (0);
 } /* ng_h4_start */
 
@@ -690,7 +707,7 @@
 	ng_h4_info_p	sc = (ng_h4_info_p) NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
 
 	if (hook != sc->hook)
-		panic("%s: hook != sc->hook\n", __func__);
+		panic("%s: hook != sc->hook", __func__);
 
 	NG_HOOK_FORCE_QUEUE(NG_HOOK_PEER(hook));
 	NG_HOOK_FORCE_QUEUE(hook);
@@ -714,7 +731,7 @@
 
 	if (sc != NULL) {
 		if (hook != sc->hook)
-			panic("%s: hook != sc->hook\n", __func__);
+			panic("%s: hook != sc->hook", __func__);
 
 		NG_H4_LOCK(sc);
 
@@ -722,7 +739,7 @@
 		if (callout_pending(&sc->timo))
 			ng_uncallout(&sc->timo, sc->node);
 
-		_IF_DRAIN(&sc->outq); 
+		IF_DRAIN(&sc->outq); 
 
 		sc->state = NG_H4_W4_PKT_IND;
 		sc->want = 1;
@@ -760,12 +777,11 @@
 
 	NG_NODE_SET_PRIVATE(node, NULL);
 
-	_IF_DRAIN(&sc->outq);
+	IF_DRAIN(&sc->outq);
 
 	NG_NODE_UNREF(node);
-	mtx_destroy(&sc->outq.ifq_mtx);
 	bzero(sc, sizeof(*sc));
-	free(sc, M_NETGRAPH_H4);
+	kfree(sc, M_NETGRAPH_H4);
 
 	return (0);
 } /* ng_h4_shutdown */
@@ -786,19 +802,19 @@
 		return (EHOSTDOWN);
 
 	if (hook != sc->hook)
-		panic("%s: hook != sc->hook\n", __func__);
+		panic("%s: hook != sc->hook", __func__);
 
 	NGI_GET_M(item, m);
 	NG_FREE_ITEM(item);
 
 	NG_H4_LOCK(sc);
 
-	if (_IF_QFULL(&sc->outq)) {
+	if (IF_QFULL(&sc->outq)) {
 		NG_H4_ERR("%s: %s - dropping mbuf, len=%d\n", __func__,
 			NG_NODE_NAME(sc->node), m->m_pkthdr.len);
 
 		NG_H4_STAT_OERROR(sc->stat);
-		_IF_DROP(&sc->outq);
+		IF_DROP(&sc->outq);
 
 		NG_H4_UNLOCK(sc);
 
@@ -810,8 +826,8 @@
 	NG_H4_INFO("%s: %s - queue mbuf, len=%d\n", __func__,
 		NG_NODE_NAME(sc->node), m->m_pkthdr.len);
 
-	_IF_ENQUEUE(&sc->outq, m);
-	qlen = _IF_QLEN(&sc->outq);
+	IF_ENQUEUE(&sc->outq, m);
+	qlen = IF_QLEN(&sc->outq);
 
 	NG_H4_UNLOCK(sc);
 
@@ -819,11 +835,8 @@
 	 * If qlen > 1, then we should already have a scheduled callout
 	 */
 
-	if (qlen == 1) {
-		mtx_lock(&Giant);
+	if (qlen == 1)
 		ng_h4_start(sc->tp);
-		mtx_unlock(&Giant);
-	}
 
 	return (0);
 } /* ng_h4_rcvdata */
@@ -849,7 +862,7 @@
 	case NGM_GENERIC_COOKIE:
 		switch (msg->header.cmd) {
 		case NGM_TEXT_STATUS:
-			NG_MKRESPONSE(resp, msg, NG_TEXTRESPONSE, M_NOWAIT);
+			NG_MKRESPONSE(resp, msg, NG_TEXTRESPONSE, M_WAITOK | M_NULLOK);
 			if (resp == NULL)
 				error = ENOMEM;
 			else
@@ -862,7 +875,7 @@
 					(sc->hook != NULL)? NG_H4_HOOK : "",
 					sc->debug,
 					sc->state,
-					_IF_QLEN(&sc->outq),
+					IF_QLEN(&sc->outq),
 					sc->outq.ifq_maxlen,
 					sc->got,
 					sc->want);
@@ -877,7 +890,7 @@
 	case NGM_H4_COOKIE:
 		switch (msg->header.cmd) {
 		case NGM_H4_NODE_RESET:
-			_IF_DRAIN(&sc->outq); 
+			IF_DRAIN(&sc->outq); 
 			sc->state = NG_H4_W4_PKT_IND;
 			sc->want = 1;
 			sc->got = 0;
@@ -885,7 +898,7 @@
 
 		case NGM_H4_NODE_GET_STATE:
 			NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_state_ep),
-				M_NOWAIT);
+				M_WAITOK | M_NULLOK);
 			if (resp == NULL)
 				error = ENOMEM;
 			else
@@ -895,7 +908,7 @@
 
 		case NGM_H4_NODE_GET_DEBUG:
 			NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_debug_ep),
-				M_NOWAIT);
+				M_WAITOK | M_NULLOK);
 			if (resp == NULL)
 				error = ENOMEM;
 			else
@@ -913,7 +926,7 @@
 
 		case NGM_H4_NODE_GET_QLEN:
 			NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_qlen_ep),
-				M_NOWAIT);
+				M_WAITOK | M_NULLOK);
 			if (resp == NULL)
 				error = ENOMEM;
 			else
@@ -927,13 +940,13 @@
 			else if (*((ng_h4_node_qlen_ep *)(msg->data)) <= 0)
 				error = EINVAL;
 			else
-				IFQ_SET_MAXLEN(&sc->outq,
-					*((ng_h4_node_qlen_ep *)(msg->data)));
+				sc->outq.ifq_maxlen =
+					*((ng_h4_node_qlen_ep *)(msg->data));
 			break;
 
 		case NGM_H4_NODE_GET_STAT:
 			NG_MKRESPONSE(resp, msg, sizeof(ng_h4_node_stat_ep),
-				M_NOWAIT);
+				M_WAITOK | M_NULLOK);
 			if (resp == NULL)
 				error = ENOMEM;
 			else
@@ -974,9 +987,7 @@
 {
 	ng_h4_info_p	sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
 
-	mtx_lock(&Giant);
 	ng_h4_start(sc->tp);
-	mtx_unlock(&Giant);
 } /* ng_h4_process_timeout */
 
 /*
@@ -992,9 +1003,9 @@
 	switch (event) {
 	case MOD_LOAD:
 		/* Register line discipline */
-		mtx_lock(&Giant);
-		ng_h4_ldisc = ldisc_register(H4DISC, &ng_h4_disc);
-		mtx_unlock(&Giant);
+		crit_enter();
+		ng_h4_ldisc = ldisc_register(BTUARTDISC, &ng_h4_disc);
+		crit_exit();
 
 		if (ng_h4_ldisc < 0) {
 			printf("%s: can't register H4 line discipline\n",
@@ -1005,9 +1016,9 @@
 
 	case MOD_UNLOAD:
 		/* Unregister line discipline */
-		mtx_lock(&Giant);
+		crit_enter();
 		ldisc_deregister(ng_h4_ldisc);
-		mtx_unlock(&Giant);
+		crit_exit();
 		break;
 
 	default:
diff -ur /home/s/reference/FreeBSD/src/sys/netgraph/bluetooth/drivers/h4/ng_h4_var.h sys/netgraph7/bluetooth/drivers/h4/ng_h4_var.h
--- /home/s/reference/FreeBSD/src/sys/netgraph/bluetooth/drivers/h4/ng_h4_var.h	2013-09-02 20:18:16.000000000 +0200
+++ sys/netgraph7/bluetooth/drivers/h4/ng_h4_var.h	2014-07-15 10:11:06.056950000 +0200
@@ -83,8 +83,8 @@
 
 	struct ifqueue		outq;	/* Queue of outgoing mbuf's */
 #define NG_H4_DEFAULTQLEN	 12     /* XXX max number of mbuf's in outq */
-#define	NG_H4_LOCK(sc)		IF_LOCK(&sc->outq)
-#define	NG_H4_UNLOCK(sc)	IF_UNLOCK(&sc->outq)
+#define	NG_H4_LOCK(sc)		crit_enter();
+#define	NG_H4_UNLOCK(sc)	crit_exit();
 
 #define NG_H4_IBUF_SIZE		1024	/* XXX must be big enough to hold full 
 					   frame */
