Deleted Added
full compact
30,31c30,31
< * $Id: ng_h4.c,v 1.7 2004/08/23 18:08:15 max Exp $
< * $FreeBSD: head/sys/netgraph/bluetooth/drivers/h4/ng_h4.c 171345 2007-07-10 16:38:43Z emax $
---
> * $Id: ng_h4.c,v 1.10 2005/10/31 17:57:43 max Exp $
> * $FreeBSD: head/sys/netgraph/bluetooth/drivers/h4/ng_h4.c 171818 2007-08-13 17:19:28Z emax $
51a52
> #include <sys/socket.h>
53a55,56
> #include <net/if.h>
> #include <net/if_var.h>
76,77d78
< #error "NET_NEEDS_GIANT"
<
92d92
< static void ng_h4_start2 (node_p, hook_p, void *, int);
118,119d117
< static void ng_h4_timeout (node_p);
< static void ng_h4_untimeout (node_p);
154a153
> struct thread *td = curthread;
157c156
< int s, error;
---
> int error;
160c159
< error = priv_check(curthread, PRIV_NETGRAPH_TTY); /* XXX */
---
> error = priv_check(td, PRIV_NETGRAPH_TTY); /* XXX */
164,166d162
< s = splnet(); /* XXX */
< spltty(); /* XXX */
<
169,172c165,166
< if (sc == NULL) {
< error = ENOMEM;
< goto out;
< }
---
> if (sc == NULL)
> return (ENOMEM);
181c175,176
< NG_BT_MBUFQ_INIT(&sc->outq, NG_H4_DEFAULTQLEN);
---
> mtx_init(&sc->outq.ifq_mtx, "ng_h4 node+queue", NULL, MTX_DEF);
> IFQ_SET_MAXLEN(&sc->outq, NG_H4_DEFAULTQLEN);
183a179,180
> NG_H4_LOCK(sc);
>
186a184,188
> NG_H4_UNLOCK(sc);
>
> printf("%s: Unable to create new node!\n", __func__);
>
> mtx_destroy(&sc->outq.ifq_mtx);
189c191,192
< goto out;
---
>
> return (error);
197c200,203
< NG_H4_ALERT("%s: %s - node name exists?\n", __func__, name);
---
> NG_H4_UNLOCK(sc);
>
> printf("%s: %s - node name exists?\n", __func__, name);
>
198a205
> mtx_destroy(&sc->outq.ifq_mtx);
201c208,209
< goto out;
---
>
> return (error);
221,222d228
< out:
< splx(s); /* XXX */
223a230,231
> NG_H4_UNLOCK(sc);
>
236d243
< int s;
238,239d244
< s = spltty(); /* XXX */
<
241a247
>
243c249
< tp->t_lsc = NULL;
---
> NG_H4_LOCK(sc);
245,247c251,252
< if (sc->node != NULL) {
< if (sc->flags & NG_H4_TIMEOUT)
< ng_h4_untimeout(sc->node);
---
> if (callout_pending(&sc->timo))
> ng_uncallout(&sc->timo, sc->node);
249,252c254,255
< NG_NODE_SET_PRIVATE(sc->node, NULL);
< ng_rmnode_self(sc->node);
< sc->node = NULL;
< }
---
> tp->t_lsc = NULL;
> sc->dying = 1;
254,256c257,259
< NG_BT_MBUFQ_DESTROY(&sc->outq);
< bzero(sc, sizeof(*sc));
< FREE(sc, M_NETGRAPH_H4);
---
> NG_H4_UNLOCK(sc);
>
> ng_rmnode_self(sc->node);
259,260d261
< splx(s); /* XXX */
<
293c294
< int s, error = 0;
---
> int error = 0;
295c296,297
< s = spltty(); /* XXX */
---
> if (sc == NULL)
> return (ENXIO);
296a299,300
> NG_H4_LOCK(sc);
>
320c324
< splx(s); /* XXX */
---
> NG_H4_UNLOCK(sc);
338a343,344
> NG_H4_LOCK(sc);
>
340c346
< if ((sc->tp->t_state & TS_CONNECTED) == 0) {
---
> if ((tp->t_state & TS_CONNECTED) == 0) {
347a354,355
> NG_H4_UNLOCK(sc);
>
362a371,372
> NG_H4_UNLOCK(sc);
>
379a390,391
> NG_H4_UNLOCK(sc);
>
388c400,402
< if (sc->got < sc->want)
---
> if (sc->got < sc->want) {
> NG_H4_UNLOCK(sc);
>
389a404
> }
541a557,558
> NG_H4_UNLOCK(sc);
>
553c570,572
< ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
---
> ng_h4_info_p sc = (ng_h4_info_p) tp->t_lsc;
> struct mbuf *m = NULL;
> int size;
559,576d577
< return (ng_send_fn(sc->node, NULL, ng_h4_start2, NULL, 0));
< } /* ng_h4_start */
<
< /*
< * Device driver is ready for more output. Part 2. Called (via ng_send_fn)
< * ng_h4_start() and from ng_h4_rcvdata() when a new mbuf is available for
< * output.
< */
<
< static void
< ng_h4_start2(node_p node, hook_p hook, void *arg1, int arg2)
< {
< ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
< struct mbuf *m = NULL;
< int s, size;
<
< s = spltty(); /* XXX */
<
578c579
< while (sc->tp->t_outq.c_cc < NG_H4_HIWATER) { /* XXX 2.2 specific ? */
---
> while (tp->t_outq.c_cc < NG_H4_HIWATER) { /* XXX 2.2 specific ? */
583c584
< NG_BT_MBUFQ_DEQUEUE(&sc->outq, m);
---
> IF_DEQUEUE(&sc->outq, m);
590c591
< m->m_len, &sc->tp->t_outq);
---
> m->m_len, &tp->t_outq);
591a593
> NG_H4_LOCK(sc);
592a595
> NG_H4_UNLOCK(sc);
604c607
< NG_BT_MBUFQ_PREPEND(&sc->outq, m);
---
> IF_PREPEND(&sc->outq, m);
608a612
> NG_H4_LOCK(sc);
609a614
> NG_H4_UNLOCK(sc);
624,625c629
< if (NG_BT_MBUFQ_LEN(&sc->outq) > 0 && (sc->flags & NG_H4_TIMEOUT) == 0)
< ng_h4_timeout(node);
---
> NG_H4_LOCK(sc);
627,628c631,633
< splx(s); /* XXX */
< } /* ng_h4_start2 */
---
> if (!IFQ_IS_EMPTY(&sc->outq) && !callout_pending(&sc->timo))
> ng_callout(&sc->timo, sc->node, NULL, 1,
> ng_h4_process_timeout, NULL, 0);
629a635,639
> NG_H4_UNLOCK(sc);
>
> return (0);
> } /* ng_h4_start */
>
660,661c670
< if (sc->hook != NULL)
< return (EISCONN);
---
> NG_H4_LOCK(sc);
662a672,675
> if (sc->hook != NULL) {
> NG_H4_UNLOCK(sc);
> return (EISCONN);
> }
664a678,679
> NG_H4_UNLOCK(sc);
>
677,680c692,693
< if (hook != sc->hook) {
< sc->hook = NULL;
< return (EINVAL);
< }
---
> if (hook != sc->hook)
> panic("%s: hook != sc->hook\n", __func__);
682a696
> NG_HOOK_FORCE_QUEUE(hook);
698c712
< * ng_h4_clsoe() via ng_rmnode_self()
---
> * ng_h4_close() via ng_rmnode_self()
703c717
< return (EINVAL);
---
> panic("%s: hook != sc->hook\n", __func__);
704a719,720
> NG_H4_LOCK(sc);
>
706,707c722,723
< if (sc->flags & NG_H4_TIMEOUT)
< ng_h4_untimeout(NG_HOOK_NODE(hook));
---
> if (callout_pending(&sc->timo))
> ng_uncallout(&sc->timo, sc->node);
709c725,726
< NG_BT_MBUFQ_DRAIN(&sc->outq);
---
> _IF_DRAIN(&sc->outq);
>
714a732,733
>
> NG_H4_UNLOCK(sc);
729d747
< char name[NG_NODESIZ];
731,733c749
< /* Let old node go */
< NG_NODE_SET_PRIVATE(node, NULL);
< NG_NODE_UNREF(node);
---
> NG_H4_LOCK(sc);
735,737c751,752
< /* Check if device was closed */
< if (sc == NULL)
< goto out;
---
> if (!sc->dying) {
> NG_H4_UNLOCK(sc);
739,743c754,756
< /* Setup new netgraph node */
< if (ng_make_node_common(&typestruct, &sc->node) != 0) {
< printf("%s: Unable to create new node!\n", __func__);
< sc->node = NULL;
< goto out;
---
> NG_NODE_REVIVE(node); /* we will persist */
>
> return (EOPNOTSUPP);
746,747c759
< /* Assign node its name */
< snprintf(name, sizeof(name), "%s%d", typestruct.name, ng_h4_node ++);
---
> NG_H4_UNLOCK(sc);
749,754c761
< if (ng_name_node(sc->node, name) != 0) {
< printf("%s: %s - node name exists?\n", __func__, name);
< NG_NODE_UNREF(sc->node);
< sc->node = NULL;
< goto out;
< }
---
> NG_NODE_SET_PRIVATE(node, NULL);
756,759c763,769
< /* The node has to be a WRITER because data can change node status */
< NG_NODE_FORCE_WRITER(sc->node);
< NG_NODE_SET_PRIVATE(sc->node, sc);
< out:
---
> _IF_DRAIN(&sc->outq);
>
> NG_NODE_UNREF(node);
> mtx_destroy(&sc->outq.ifq_mtx);
> bzero(sc, sizeof(*sc));
> FREE(sc, M_NETGRAPH_H4);
>
772d781
< int error = 0;
773a783
> int qlen;
775,778c785,786
< if (sc == NULL) {
< error = EHOSTDOWN;
< goto out;
< }
---
> if (sc == NULL)
> return (EHOSTDOWN);
780,783c788,789
< if (hook != sc->hook) {
< error = EINVAL;
< goto out;
< }
---
> if (hook != sc->hook)
> panic("%s: hook != sc->hook\n", __func__);
785a792
> NG_FREE_ITEM(item);
787c794,796
< if (NG_BT_MBUFQ_FULL(&sc->outq)) {
---
> NG_H4_LOCK(sc);
>
> if (_IF_QFULL(&sc->outq)) {
791d799
< NG_BT_MBUFQ_DROP(&sc->outq);
792a801
> _IF_DROP(&sc->outq);
793a803,804
> NG_H4_UNLOCK(sc);
>
795,798d805
< error = ENOBUFS;
< } else {
< NG_H4_INFO("%s: %s - queue mbuf, len=%d\n", __func__,
< NG_NODE_NAME(sc->node), m->m_pkthdr.len);
800c807,808
< NG_BT_MBUFQ_ENQUEUE(&sc->outq, m);
---
> return (ENOBUFS);
> }
802,805c810,811
< /*
< * We have lock on the node, so we can call ng_h4_start2()
< * directly
< */
---
> NG_H4_INFO("%s: %s - queue mbuf, len=%d\n", __func__,
> NG_NODE_NAME(sc->node), m->m_pkthdr.len);
807c813,825
< ng_h4_start2(sc->node, NULL, NULL, 0);
---
> _IF_ENQUEUE(&sc->outq, m);
> qlen = _IF_QLEN(&sc->outq);
>
> NG_H4_UNLOCK(sc);
>
> /*
> * If qlen > 1, then we should already have a scheduled callout
> */
>
> if (qlen == 1) {
> mtx_lock(&Giant);
> ng_h4_start(sc->tp);
> mtx_unlock(&Giant);
809,810d826
< out:
< NG_FREE_ITEM(item);
812c828
< return (error);
---
> return (0);
826,829c842,843
< if (sc == NULL) {
< error = EHOSTDOWN;
< goto out;
< }
---
> if (sc == NULL)
> return (EHOSTDOWN);
831a846
> NG_H4_LOCK(sc);
843d857
< "Flags: %#x\n" \
849d862
< sc->flags,
852,853c865,866
< NG_BT_MBUFQ_LEN(&sc->outq),
< sc->outq.maxlen,
---
> _IF_QLEN(&sc->outq),
> sc->outq.ifq_maxlen,
867c880
< NG_BT_MBUFQ_DRAIN(&sc->outq);
---
> _IF_DRAIN(&sc->outq);
908c921
< sc->outq.maxlen;
---
> sc->outq.ifq_maxlen;
917,918c930,931
< sc->outq.maxlen =
< *((ng_h4_node_qlen_ep *)(msg->data));
---
> IFQ_SET_MAXLEN(&sc->outq,
> *((ng_h4_node_qlen_ep *)(msg->data)));
945c958,960
< out:
---
>
> NG_H4_UNLOCK(sc);
>
953,978d967
< * Set timeout
< */
<
< static void
< ng_h4_timeout(node_p node)
< {
< ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
<
< ng_callout(&sc->timo, node, NULL, 1, ng_h4_process_timeout, NULL, 0);
< sc->flags |= NG_H4_TIMEOUT;
< } /* ng_h4_timeout */
<
< /*
< * Unset timeout
< */
<
< static void
< ng_h4_untimeout(node_p node)
< {
< ng_h4_info_p sc = (ng_h4_info_p) NG_NODE_PRIVATE(node);
<
< sc->flags &= ~NG_H4_TIMEOUT;
< ng_uncallout(&sc->timo, node);
< } /* ng_h4_untimeout */
<
< /*
988,995c977,979
< sc->flags &= ~NG_H4_TIMEOUT;
<
< /*
< * We can call ng_h4_start2() directly here because we have lock
< * on the node.
< */
<
< ng_h4_start2(node, NULL, NULL, 0);
---
> mtx_lock(&Giant);
> ng_h4_start(sc->tp);
> mtx_unlock(&Giant);
1006c990
< int s, error = 0;
---
> int error = 0;
1008,1009d991
< s = spltty(); /* XXX */
<
1012a995
> mtx_lock(&Giant);
1013a997,998
> mtx_unlock(&Giant);
>
1022a1008
> mtx_lock(&Giant);
1023a1010
> mtx_unlock(&Giant);
1031,1032d1017
< splx(s); /* XXX */
<