diff options
author | julian <julian@FreeBSD.org> | 2001-01-06 00:46:47 +0000 |
---|---|---|
committer | julian <julian@FreeBSD.org> | 2001-01-06 00:46:47 +0000 |
commit | f0c46a9d00fc9fe4644cef5784e76b360f5036c7 (patch) | |
tree | 561902279f2f361f3e137f7fc029ce2714981289 /sys/dev | |
parent | e06f071f56cf6badae9215f8a14ccc66a3fc0f5a (diff) | |
download | FreeBSD-src-f0c46a9d00fc9fe4644cef5784e76b360f5036c7.zip FreeBSD-src-f0c46a9d00fc9fe4644cef5784e76b360f5036c7.tar.gz |
Rewrite of netgraph to start getting ready for SMP.
This version is functional and is aproaching solid..
notice I said APROACHING. There are many node types I cannot test
I have tested: echo hole ppp socket vjc iface tee bpf async tty
The rest compile and "Look" right. More changes to follow.
DEBUGGING is enabled in this code to help if people have problems.
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/ar/if_ar.c | 62 | ||||
-rw-r--r-- | sys/dev/ar/if_ar_isa.c | 62 | ||||
-rw-r--r-- | sys/dev/lmc/if_lmc.c | 70 | ||||
-rw-r--r-- | sys/dev/musycc/musycc.c | 42 | ||||
-rw-r--r-- | sys/dev/sr/if_sr.c | 59 | ||||
-rw-r--r-- | sys/dev/sr/if_sr_isa.c | 59 | ||||
-rw-r--r-- | sys/dev/usb/udbp.c | 71 |
7 files changed, 258 insertions, 167 deletions
diff --git a/sys/dev/ar/if_ar.c b/sys/dev/ar/if_ar.c index fe9abeb..722a133 100644 --- a/sys/dev/ar/if_ar.c +++ b/sys/dev/ar/if_ar.c @@ -267,7 +267,7 @@ static void ngar_init(void* ignored); static ng_constructor_t ngar_constructor; static ng_rcvmsg_t ngar_rcvmsg; -static ng_shutdown_t ngar_rmnode; +static ng_shutdown_t ngar_shutdown; static ng_newhook_t ngar_newhook; /*static ng_findhook_t ngar_findhook; */ static ng_connect_t ngar_connect; @@ -280,7 +280,7 @@ static struct ng_type typestruct = { NULL, ngar_constructor, ngar_rcvmsg, - ngar_rmnode, + ngar_shutdown, ngar_newhook, NULL, ngar_connect, @@ -509,18 +509,17 @@ arattach(struct ar_hardc *hc) if (ngar_done_init == 0) ngar_init(NULL); if (ng_make_node_common(&typestruct, &sc->node) != 0) return (0); + sprintf(sc->nodename, "%s%d", NG_AR_NODE_TYPE, sc->unit); + if (ng_name_node(sc->node, sc->nodename)) { + ng_unref(sc->node); /* drop it again */ + return (0); + } sc->node->private = sc; callout_handle_init(&sc->handle); sc->xmitq.ifq_maxlen = IFQ_MAXLEN; sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN; mtx_init(&sc->xmitq.ifq_mtx, "ar_xmitq", MTX_DEF); mtx_init(&sc->xmitq_hipri.ifq_mtx, "ar_xmitq_hipri", MTX_DEF); - sprintf(sc->nodename, "%s%d", NG_AR_NODE_TYPE, sc->unit); - if (ng_name_node(sc->node, sc->nodename)) { - ng_rmnode(sc->node); - ng_unref(sc->node); - return (0); - } sc->running = 0; #endif /* NETGRAPH */ } @@ -2173,7 +2172,7 @@ ngar_watchdog_frame(void * arg) * If the hardware exists, it will already have created it. */ static int -ngar_constructor(node_p *nodep) +ngar_constructor(node_p node) { return (EINVAL); } @@ -2216,13 +2215,14 @@ ngar_newhook(node_p node, hook_p hook, const char *name) * Just respond to the generic TEXT_STATUS message */ static int -ngar_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, - struct ng_mesg **rptr, hook_p lasthook) +ngar_rcvmsg(node_p node, item_p item, hook_p lasthook) { struct ar_softc * sc; struct ng_mesg *resp = NULL; int error = 0; + struct ng_mesg *msg; + NGI_GET_MSG(item, msg); sc = node->private; switch (msg->header.typecookie) { case NG_AR_COOKIE: @@ -2268,13 +2268,8 @@ ngar_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, break; } /* Take care of synchronous response, if any */ - if (rptr) - *rptr = resp; - else if (resp) - /* Should send the hard way */ - FREE(resp, M_NETGRAPH); - - free(msg, M_NETGRAPH); + NG_RESPOND_MSG(error, node, item, resp); + NG_FREE_MSG(msg); return (error); } @@ -2282,14 +2277,18 @@ ngar_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, * get data from another node and transmit it to the correct channel */ static int -ngar_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, - struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp) +ngar_rcvdata(hook_p hook, item_p item) { int s; int error = 0; struct ar_softc * sc = hook->node->private; struct ifqueue *xmitq_p; + struct mbuf *m; + meta_p meta; + NGI_GET_M(item, m); + NGI_GET_META(item, meta); + NG_FREE_ITEM(item); /* * data doesn't come in from just anywhere (e.g control hook) */ @@ -2326,7 +2325,8 @@ bad: * It was an error case. * check if we need to free the mbuf, and then return the error */ - NG_FREE_DATA(m, meta); + NG_FREE_M(m); + NG_FREE_META(meta); return (error); } @@ -2336,13 +2336,27 @@ bad: * don't unref the node, or remove our name. just clear our links up. */ static int -ngar_rmnode(node_p node) +ngar_shutdown(node_p node) { struct ar_softc * sc = node->private; ar_down(sc); - ng_cutlinks(node); - node->flags &= ~NG_INVALID; /* bounce back to life */ + ng_unref(node); + /* XXX need to drain the output queues! */ + + /* The node is dead, long live the node! */ + /* stolen from the attach routine */ + if (ng_make_node_common(&typestruct, &sc->node) != 0) + return (0); + sprintf(sc->nodename, "%s%d", NG_AR_NODE_TYPE, sc->unit); + if (ng_name_node(sc->node, sc->nodename)) { + sc->node = NULL; + printf("node naming failed\n"); + ng_unref(sc->node); /* node dissappears */ + return (0); + } + sc->node->private = sc; + sc->running = 0; return (0); } diff --git a/sys/dev/ar/if_ar_isa.c b/sys/dev/ar/if_ar_isa.c index fe9abeb..722a133 100644 --- a/sys/dev/ar/if_ar_isa.c +++ b/sys/dev/ar/if_ar_isa.c @@ -267,7 +267,7 @@ static void ngar_init(void* ignored); static ng_constructor_t ngar_constructor; static ng_rcvmsg_t ngar_rcvmsg; -static ng_shutdown_t ngar_rmnode; +static ng_shutdown_t ngar_shutdown; static ng_newhook_t ngar_newhook; /*static ng_findhook_t ngar_findhook; */ static ng_connect_t ngar_connect; @@ -280,7 +280,7 @@ static struct ng_type typestruct = { NULL, ngar_constructor, ngar_rcvmsg, - ngar_rmnode, + ngar_shutdown, ngar_newhook, NULL, ngar_connect, @@ -509,18 +509,17 @@ arattach(struct ar_hardc *hc) if (ngar_done_init == 0) ngar_init(NULL); if (ng_make_node_common(&typestruct, &sc->node) != 0) return (0); + sprintf(sc->nodename, "%s%d", NG_AR_NODE_TYPE, sc->unit); + if (ng_name_node(sc->node, sc->nodename)) { + ng_unref(sc->node); /* drop it again */ + return (0); + } sc->node->private = sc; callout_handle_init(&sc->handle); sc->xmitq.ifq_maxlen = IFQ_MAXLEN; sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN; mtx_init(&sc->xmitq.ifq_mtx, "ar_xmitq", MTX_DEF); mtx_init(&sc->xmitq_hipri.ifq_mtx, "ar_xmitq_hipri", MTX_DEF); - sprintf(sc->nodename, "%s%d", NG_AR_NODE_TYPE, sc->unit); - if (ng_name_node(sc->node, sc->nodename)) { - ng_rmnode(sc->node); - ng_unref(sc->node); - return (0); - } sc->running = 0; #endif /* NETGRAPH */ } @@ -2173,7 +2172,7 @@ ngar_watchdog_frame(void * arg) * If the hardware exists, it will already have created it. */ static int -ngar_constructor(node_p *nodep) +ngar_constructor(node_p node) { return (EINVAL); } @@ -2216,13 +2215,14 @@ ngar_newhook(node_p node, hook_p hook, const char *name) * Just respond to the generic TEXT_STATUS message */ static int -ngar_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, - struct ng_mesg **rptr, hook_p lasthook) +ngar_rcvmsg(node_p node, item_p item, hook_p lasthook) { struct ar_softc * sc; struct ng_mesg *resp = NULL; int error = 0; + struct ng_mesg *msg; + NGI_GET_MSG(item, msg); sc = node->private; switch (msg->header.typecookie) { case NG_AR_COOKIE: @@ -2268,13 +2268,8 @@ ngar_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, break; } /* Take care of synchronous response, if any */ - if (rptr) - *rptr = resp; - else if (resp) - /* Should send the hard way */ - FREE(resp, M_NETGRAPH); - - free(msg, M_NETGRAPH); + NG_RESPOND_MSG(error, node, item, resp); + NG_FREE_MSG(msg); return (error); } @@ -2282,14 +2277,18 @@ ngar_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, * get data from another node and transmit it to the correct channel */ static int -ngar_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, - struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp) +ngar_rcvdata(hook_p hook, item_p item) { int s; int error = 0; struct ar_softc * sc = hook->node->private; struct ifqueue *xmitq_p; + struct mbuf *m; + meta_p meta; + NGI_GET_M(item, m); + NGI_GET_META(item, meta); + NG_FREE_ITEM(item); /* * data doesn't come in from just anywhere (e.g control hook) */ @@ -2326,7 +2325,8 @@ bad: * It was an error case. * check if we need to free the mbuf, and then return the error */ - NG_FREE_DATA(m, meta); + NG_FREE_M(m); + NG_FREE_META(meta); return (error); } @@ -2336,13 +2336,27 @@ bad: * don't unref the node, or remove our name. just clear our links up. */ static int -ngar_rmnode(node_p node) +ngar_shutdown(node_p node) { struct ar_softc * sc = node->private; ar_down(sc); - ng_cutlinks(node); - node->flags &= ~NG_INVALID; /* bounce back to life */ + ng_unref(node); + /* XXX need to drain the output queues! */ + + /* The node is dead, long live the node! */ + /* stolen from the attach routine */ + if (ng_make_node_common(&typestruct, &sc->node) != 0) + return (0); + sprintf(sc->nodename, "%s%d", NG_AR_NODE_TYPE, sc->unit); + if (ng_name_node(sc->node, sc->nodename)) { + sc->node = NULL; + printf("node naming failed\n"); + ng_unref(sc->node); /* node dissappears */ + return (0); + } + sc->node->private = sc; + sc->running = 0; return (0); } diff --git a/sys/dev/lmc/if_lmc.c b/sys/dev/lmc/if_lmc.c index 0aa6ea6..bec558d 100644 --- a/sys/dev/lmc/if_lmc.c +++ b/sys/dev/lmc/if_lmc.c @@ -1130,18 +1130,17 @@ lmc_attach(lmc_softc_t * const sc) if (ng_lmc_done_init == 0) ng_lmc_init(NULL); if (ng_make_node_common(&typestruct, &sc->lmc_node) != 0) return (0); + sprintf(sc->lmc_nodename, "%s%d", NG_LMC_NODE_TYPE, sc->lmc_unit); + if (ng_name_node(sc->lmc_node, sc->lmc_nodename)) { + ng_unref(sc->lmc_node); /* make it go away again */ + return (0); + } sc->lmc_node->private = sc; callout_handle_init(&sc->lmc_handle); sc->lmc_xmitq.ifq_maxlen = IFQ_MAXLEN; sc->lmc_xmitq_hipri.ifq_maxlen = IFQ_MAXLEN; mtx_init(&sc->lmc_xmitq.ifq_mtx, "lmc_xmitq", MTX_DEF); mtx_init(&sc->lmc_xmitq_hipri.ifq_mtx, "lmc_xmitq_hipri", MTX_DEF); - sprintf(sc->lmc_nodename, "%s%d", NG_LMC_NODE_TYPE, sc->lmc_unit); - if (ng_name_node(sc->lmc_node, sc->lmc_nodename)) { - ng_rmnode(sc->lmc_node); - ng_unref(sc->lmc_node); - return (0); - } sc->lmc_running = 0; /* @@ -1251,7 +1250,7 @@ ng_lmc_watchdog_frame(void *arg) * If the hardware exists, it will already have created it. */ static int -ng_lmc_constructor(node_p *nodep) +ng_lmc_constructor(node_p node) { return (EINVAL); } @@ -1295,13 +1294,14 @@ ng_lmc_newhook(node_p node, hook_p hook, const char *name) * Just respond to the generic TEXT_STATUS message */ static int -ng_lmc_rcvmsg(node_p node, struct ng_mesg *msg, - const char *retaddr, struct ng_mesg **rptr, hook_p lasthook) +ng_lmc_rcvmsg(node_p node, item_p item, hook_p lasthook) { lmc_softc_t *sc = (lmc_softc_t *) node->private; struct ng_mesg *resp = NULL; int error = 0; + struct ng_mesg *msg; + NGI_GET_MSG(item, msg); switch (msg->header.typecookie) { case NG_LMC_COOKIE: switch (msg->header.cmd) { @@ -1377,12 +1377,8 @@ ng_lmc_rcvmsg(node_p node, struct ng_mesg *msg, } /* Take care of synchronous response, if any */ - if (rptr) - *rptr = resp; - else if (resp) - FREE(resp, M_NETGRAPH); - - free(msg, M_NETGRAPH); + NG_RESPOND_MSG(error, node, item, resp); + NG_FREE_MSG(msg); return (error); } @@ -1390,13 +1386,19 @@ ng_lmc_rcvmsg(node_p node, struct ng_mesg *msg, * get data from another node and transmit it to the line */ static int -ng_lmc_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, - struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp) +ng_lmc_rcvdata(hook_p hook, item_p item) { int s; int error = 0; lmc_softc_t * sc = (lmc_softc_t *) hook->node->private; struct ifqueue *xmitq_p; + struct mbuf *m; + meta_p meta; + + /* Unpack all the data components */ + NGI_GET_M(item, m); + NGI_GET_META(item, meta); + NG_FREE_ITEM(item); /* * data doesn't come in from just anywhere (e.g control hook) @@ -1434,7 +1436,8 @@ bad: * It was an error case. * check if we need to free the mbuf, and then return the error */ - NG_FREE_DATA(m, meta); + NG_FREE_M(m); + NG_FREE_META(meta); return (error); } @@ -1449,8 +1452,35 @@ ng_lmc_rmnode(node_p node) lmc_softc_t * sc = (lmc_softc_t *) node->private; lmc_ifdown(sc); - ng_cutlinks(node); - node->flags &= ~NG_INVALID; /* bounce back to life */ + + /* + * Get rid of the old node. + */ + node->flags |= NG_INVALID; + node->private = NULL; + ng_unref(node); + + /* + * Create a new node. This is basically what a device + * driver would do in the attach routine. So let's just do that.. + * The node is dead, long live the node! + */ + if (ng_make_node_common(&typestruct, &sc->lmc_node) != 0) + return (0); + sprintf(sc->lmc_nodename, "%s%d", NG_LMC_NODE_TYPE, sc->lmc_unit); + if (ng_name_node(sc->lmc_node, sc->lmc_nodename)) { + sc->lmc_node = NULL; /* to be sure */ + ng_unref(sc->lmc_node); /* make it go away */ + return (0); + } + sc->lmc_node->private = sc; + callout_handle_init(&sc->lmc_handle); + sc->lmc_running = 0; + /* + * turn off those LEDs... + */ + sc->lmc_miireg16 |= LMC_MII16_LED_ALL; + lmc_led_on(sc, LMC_MII16_LED0); return (0); } /* already linked */ diff --git a/sys/dev/musycc/musycc.c b/sys/dev/musycc/musycc.c index 98d5334..e1817fa 100644 --- a/sys/dev/musycc/musycc.c +++ b/sys/dev/musycc/musycc.c @@ -834,7 +834,7 @@ musycc_intr1(void *arg) */ static int -musycc_constructor(node_p *nodep) +musycc_constructor(node_p node) { return (EINVAL); @@ -929,21 +929,19 @@ barf: /* * Handle status and config enquiries. * Respond with a synchronous response. - * [JRE] -this would be easier to read with the usual 'switch' structure- */ static int -musycc_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, - struct ng_mesg **rptr, hook_p lasthook) +musycc_rcvmsg(node_p node, item_p item, hook_p lasthook) { struct softc *sc; struct ng_mesg *resp = NULL; char *s, *r; int error = 0; + struct ng_mesg *msg; + + NGI_GET_MSG(item, msg); sc = node->private; - if (rptr) - *rptr = NULL; /* default answer in case of errors */ - if (msg->header.typecookie != NGM_GENERIC_COOKIE) goto out; @@ -957,7 +955,7 @@ musycc_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, s = (char *)resp->data; status_8370(sc, s); resp->header.arglen = strlen(s) + 1; - FREE(msg, M_NETGRAPH); + NG_FREE_MSG(msg); } else if (msg->header.cmd == NGM_TEXT_CONFIG) { if (msg->header.arglen) { @@ -976,19 +974,15 @@ musycc_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, *r = '\0'; musycc_config(node, s, r); resp->header.arglen = strlen(r) + 1; - FREE(msg, M_NETGRAPH); + NG_FREE_MSG(msg); } else { error = EINVAL; } out: /* Take care of synchronous response, if any */ - if (rptr) - *rptr = resp; - else if (resp) - FREE(resp, M_NETGRAPH); /* eventually 'send' the response */ - - FREE(msg, M_NETGRAPH); + NG_RESPOND_MSG(error, node, item, resp); + NG_FREE_MSG(msg); return (error); } @@ -1044,8 +1038,7 @@ musycc_newhook(node_p node, hook_p hook, const char *name) } static int -musycc_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, - struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp) +musycc_rcvdata(hook_p hook, item_p item) { struct softc *sc; @@ -1054,6 +1047,7 @@ musycc_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, struct mdesc *md; u_int32_t ch, u, len; struct mbuf *m2; + struct mbuf *m; sch = hook->private; sc = sch->sc; @@ -1062,24 +1056,26 @@ musycc_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, if (csc->state != C_RUNNING) { printf("csc->state = %d\n", csc->state); - NG_FREE_DATA(m, meta); + NG_FREE_ITEM(item); return (0); } - NG_FREE_META(meta); - meta = NULL; if (sch->state != UP) { printf("sch->state = %d\n", sch->state); - NG_FREE_DATA(m, meta); + NG_FREE_ITEM(item); return (0); } + NGI_GET_M(item, m); + NG_FREE_ITEM(item); if (sch->tx_pending + m->m_pkthdr.len > sch->tx_limit * maxlatency) { - printf("pend %ld len %d lim %ld\n", sch->tx_pending, m->m_pkthdr.len, sch->tx_limit * maxlatency); - NG_FREE_DATA(m, meta); + printf("pend %ld len %d lim %ld\n", sch->tx_pending, + m->m_pkthdr.len, sch->tx_limit * maxlatency); + NG_FREE_M(m); return (0); } + m2 = m; len = m->m_pkthdr.len; while (len) { diff --git a/sys/dev/sr/if_sr.c b/sys/dev/sr/if_sr.c index 9ca41d4..a7ba8e9 100644 --- a/sys/dev/sr/if_sr.c +++ b/sys/dev/sr/if_sr.c @@ -367,7 +367,7 @@ static void ngsr_init(void* ignored); static ng_constructor_t ngsr_constructor; static ng_rcvmsg_t ngsr_rcvmsg; -static ng_shutdown_t ngsr_rmnode; +static ng_shutdown_t ngsr_shutdown; static ng_newhook_t ngsr_newhook; /*static ng_findhook_t ngsr_findhook; */ static ng_connect_t ngsr_connect; @@ -380,7 +380,7 @@ static struct ng_type typestruct = { NULL, ngsr_constructor, ngsr_rcvmsg, - ngsr_rmnode, + ngsr_shutdown, ngsr_newhook, NULL, ngsr_connect, @@ -934,18 +934,17 @@ srattach(struct sr_hardc *hc) if (ngsr_done_init == 0) ngsr_init(NULL); if (ng_make_node_common(&typestruct, &sc->node) != 0) return (0); + sprintf(sc->nodename, "%s%d", NG_SR_NODE_TYPE, sc->unit); + if (ng_name_node(sc->node, sc->nodename)) { + ng_unref(sc->node); /* make it go away again */ + return (0); + } sc->node->private = sc; callout_handle_init(&sc->handle); sc->xmitq.ifq_maxlen = IFQ_MAXLEN; sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN; mtx_init(&sc->xmitq.ifq_mtx, "sr_xmitq", MTX_DEF); mtx_init(&sc->xmitq_hipri.ifq_mtx, "sr_xmitq_hipri", MTX_DEF); - sprintf(sc->nodename, "%s%d", NG_SR_NODE_TYPE, sc->unit); - if (ng_name_node(sc->node, sc->nodename)) { - ng_rmnode(sc->node); - ng_unref(sc->node); - return (0); - } sc->running = 0; #endif /* NETGRAPH */ } @@ -3126,7 +3125,7 @@ ngsr_watchdog_frame(void * arg) * If the hardware exists, it will already have created it. */ static int -ngsr_constructor(node_p *nodep) +ngsr_constructor(node_p node) { return (EINVAL); } @@ -3169,13 +3168,14 @@ ngsr_newhook(node_p node, hook_p hook, const char *name) * Just respond to the generic TEXT_STATUS message */ static int -ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, - struct ng_mesg **rptr, hook_p lasthook) +ngsr_rcvmsg(node_p node, item_p item, hook_p lasthook) { struct sr_softc * sc; struct ng_mesg *resp = NULL; int error = 0; + struct ng_mesg *msg; + NGI_GET_MSG(item,msg); sc = node->private; switch (msg->header.typecookie) { case NG_SR_COOKIE: @@ -3223,12 +3223,8 @@ ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, break; } /* Take care of synchronous response, if any */ - if (rptr) - *rptr = resp; - else if (resp) - FREE(resp, M_NETGRAPH); - - free(msg, M_NETGRAPH); + NG_RESPOND_MSG(error, node, item, resp); + NG_FREE_MSG(msg); return (error); } @@ -3236,14 +3232,18 @@ ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, * get data from another node and transmit it to the correct channel */ static int -ngsr_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, - struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp) +ngsr_rcvdata(hook_p hook, item_p item) { int s; int error = 0; struct sr_softc * sc = hook->node->private; struct ifqueue *xmitq_p; + struct mbuf *m; + meta_p meta; + NGI_GET_M(item, m); + NGI_GET_META(item, meta); + NG_FREE_ITEM(item); /* * data doesn't come in from just anywhere (e.g control hook) */ @@ -3280,7 +3280,8 @@ bad: * It was an error case. * check if we need to free the mbuf, and then return the error */ - NG_FREE_DATA(m, meta); + NG_FREE_M(m); + NG_FREE_META(meta); return (error); } @@ -3290,13 +3291,25 @@ bad: * don't unref the node, or remove our name. just clear our links up. */ static int -ngsr_rmnode(node_p node) +ngsr_shutdown(node_p node) { struct sr_softc * sc = node->private; sr_down(sc); - ng_cutlinks(node); - node->flags &= ~NG_INVALID; /* bounce back to life */ + ng_unref(node); +/* XXX should drain queues! */ + if (ng_make_node_common(&typestruct, &sc->node) != 0) + return (0); + sprintf(sc->nodename, "%s%d", NG_SR_NODE_TYPE, sc->unit); + if (ng_name_node(sc->node, sc->nodename)) { + printf("node naming failed\n"); + sc->node = NULL; + ng_unref(sc->node); /* drop it again */ + return (0); + } + sc->node->private = sc; + callout_handle_init(&sc->handle); /* should kill timeout */ + sc->running = 0; return (0); } diff --git a/sys/dev/sr/if_sr_isa.c b/sys/dev/sr/if_sr_isa.c index 9ca41d4..a7ba8e9 100644 --- a/sys/dev/sr/if_sr_isa.c +++ b/sys/dev/sr/if_sr_isa.c @@ -367,7 +367,7 @@ static void ngsr_init(void* ignored); static ng_constructor_t ngsr_constructor; static ng_rcvmsg_t ngsr_rcvmsg; -static ng_shutdown_t ngsr_rmnode; +static ng_shutdown_t ngsr_shutdown; static ng_newhook_t ngsr_newhook; /*static ng_findhook_t ngsr_findhook; */ static ng_connect_t ngsr_connect; @@ -380,7 +380,7 @@ static struct ng_type typestruct = { NULL, ngsr_constructor, ngsr_rcvmsg, - ngsr_rmnode, + ngsr_shutdown, ngsr_newhook, NULL, ngsr_connect, @@ -934,18 +934,17 @@ srattach(struct sr_hardc *hc) if (ngsr_done_init == 0) ngsr_init(NULL); if (ng_make_node_common(&typestruct, &sc->node) != 0) return (0); + sprintf(sc->nodename, "%s%d", NG_SR_NODE_TYPE, sc->unit); + if (ng_name_node(sc->node, sc->nodename)) { + ng_unref(sc->node); /* make it go away again */ + return (0); + } sc->node->private = sc; callout_handle_init(&sc->handle); sc->xmitq.ifq_maxlen = IFQ_MAXLEN; sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN; mtx_init(&sc->xmitq.ifq_mtx, "sr_xmitq", MTX_DEF); mtx_init(&sc->xmitq_hipri.ifq_mtx, "sr_xmitq_hipri", MTX_DEF); - sprintf(sc->nodename, "%s%d", NG_SR_NODE_TYPE, sc->unit); - if (ng_name_node(sc->node, sc->nodename)) { - ng_rmnode(sc->node); - ng_unref(sc->node); - return (0); - } sc->running = 0; #endif /* NETGRAPH */ } @@ -3126,7 +3125,7 @@ ngsr_watchdog_frame(void * arg) * If the hardware exists, it will already have created it. */ static int -ngsr_constructor(node_p *nodep) +ngsr_constructor(node_p node) { return (EINVAL); } @@ -3169,13 +3168,14 @@ ngsr_newhook(node_p node, hook_p hook, const char *name) * Just respond to the generic TEXT_STATUS message */ static int -ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, - struct ng_mesg **rptr, hook_p lasthook) +ngsr_rcvmsg(node_p node, item_p item, hook_p lasthook) { struct sr_softc * sc; struct ng_mesg *resp = NULL; int error = 0; + struct ng_mesg *msg; + NGI_GET_MSG(item,msg); sc = node->private; switch (msg->header.typecookie) { case NG_SR_COOKIE: @@ -3223,12 +3223,8 @@ ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, break; } /* Take care of synchronous response, if any */ - if (rptr) - *rptr = resp; - else if (resp) - FREE(resp, M_NETGRAPH); - - free(msg, M_NETGRAPH); + NG_RESPOND_MSG(error, node, item, resp); + NG_FREE_MSG(msg); return (error); } @@ -3236,14 +3232,18 @@ ngsr_rcvmsg(node_p node, struct ng_mesg *msg, const char *retaddr, * get data from another node and transmit it to the correct channel */ static int -ngsr_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, - struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp) +ngsr_rcvdata(hook_p hook, item_p item) { int s; int error = 0; struct sr_softc * sc = hook->node->private; struct ifqueue *xmitq_p; + struct mbuf *m; + meta_p meta; + NGI_GET_M(item, m); + NGI_GET_META(item, meta); + NG_FREE_ITEM(item); /* * data doesn't come in from just anywhere (e.g control hook) */ @@ -3280,7 +3280,8 @@ bad: * It was an error case. * check if we need to free the mbuf, and then return the error */ - NG_FREE_DATA(m, meta); + NG_FREE_M(m); + NG_FREE_META(meta); return (error); } @@ -3290,13 +3291,25 @@ bad: * don't unref the node, or remove our name. just clear our links up. */ static int -ngsr_rmnode(node_p node) +ngsr_shutdown(node_p node) { struct sr_softc * sc = node->private; sr_down(sc); - ng_cutlinks(node); - node->flags &= ~NG_INVALID; /* bounce back to life */ + ng_unref(node); +/* XXX should drain queues! */ + if (ng_make_node_common(&typestruct, &sc->node) != 0) + return (0); + sprintf(sc->nodename, "%s%d", NG_SR_NODE_TYPE, sc->unit); + if (ng_name_node(sc->node, sc->nodename)) { + printf("node naming failed\n"); + sc->node = NULL; + ng_unref(sc->node); /* drop it again */ + return (0); + } + sc->node->private = sc; + callout_handle_init(&sc->handle); /* should kill timeout */ + sc->running = 0; return (0); } diff --git a/sys/dev/usb/udbp.c b/sys/dev/usb/udbp.c index 29e203e..125558b 100644 --- a/sys/dev/usb/udbp.c +++ b/sys/dev/usb/udbp.c @@ -355,22 +355,20 @@ USB_ATTACH(udbp) if ((err = ng_make_node_common(&ng_udbp_typestruct, &sc->node)) == 0) { char nodename[128]; - sc->node->private = sc; - sc->xmitq.ifq_maxlen = IFQ_MAXLEN; - sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN; - mtx_init(&sc->xmitq.ifq_mtx, "usb_xmitq", MTX_DEF); - mtx_init(&sc->xmitq_hipri.ifq_mtx, "usb_xmitq_hipri", MTX_DEF); sprintf(nodename, "%s", USBDEVNAME(sc->sc_dev)); if ((err = ng_name_node(sc->node, nodename))) { - ng_rmnode(sc->node); ng_unref(sc->node); + sc->node = NULL; + goto bad; } else { - /* something to note it's done */ + sc->node->private = sc; + sc->xmitq.ifq_maxlen = IFQ_MAXLEN; + sc->xmitq_hipri.ifq_maxlen = IFQ_MAXLEN; + mtx_init(&sc->xmitq.ifq_mtx, "usb_xmitq", MTX_DEF); + mtx_init(&sc->xmitq_hipri.ifq_mtx, + "usb_xmitq_hipri", MTX_DEF); } } - if (err) { - goto bad; - } sc->flags = NETGRAPH_INITIALISED; /* sc->flags &= ~DISCONNECTED; */ /* XXX */ @@ -612,7 +610,7 @@ DRIVER_MODULE(udbp, uhub, udbp_driver, udbp_devclass, usbd_driver_load, 0); * to create nodes that depend on hardware (unless you can add the hardware :) */ Static int -ng_udbp_constructor(node_p *nodep) +ng_udbp_constructor(node_p node) { return (EINVAL); } @@ -641,7 +639,6 @@ ng_udbp_newhook(node_p node, hook_p hook, const char *name) #endif if (strcmp(name, NG_UDBP_HOOK_NAME) == 0) { - /* do something specific to a debug connection */ sc->hook = hook; hook->private = NULL; } else { @@ -662,14 +659,14 @@ ng_udbp_newhook(node_p node, hook_p hook, const char *name) * (so that old userland programs could continue to work). */ Static int -ng_udbp_rcvmsg(node_p node, - struct ng_mesg *msg, const char *retaddr, struct ng_mesg **rptr, - hook_p lasthook) +ng_udbp_rcvmsg(node_p node, item_p item, hook_p lasthook) { const udbp_p sc = node->private; struct ng_mesg *resp = NULL; int error = 0; + struct ng_mesg *msg; + NGI_GET_MSG(item, msg); /* Deal with message according to cookie and command */ switch (msg->header.typecookie) { case NGM_UDBP_COOKIE: @@ -706,13 +703,8 @@ ng_udbp_rcvmsg(node_p node, } /* Take care of synchronous response, if any */ - if (rptr) - *rptr = resp; - else if (resp) - FREE(resp, M_NETGRAPH); - - /* Free the message and return */ - FREE(msg, M_NETGRAPH); + NG_RESPOND_MSG(error, node, item, resp); + NG_FREE_MSG(msg); return(error); } @@ -720,14 +712,18 @@ ng_udbp_rcvmsg(node_p node, * Accept data from the hook and queue it for output. */ Static int -ng_udbp_rcvdata(hook_p hook, struct mbuf *m, meta_p meta, - struct mbuf **ret_m, meta_p *ret_meta, struct ng_mesg **resp) +ng_udbp_rcvdata(hook_p hook, item_p item) { const udbp_p sc = hook->node->private; int error; struct ifqueue *xmitq_p; int s; + struct mbuf *m; + meta_p meta; + NGI_GET_M(item, m); + NGI_GET_META(item, meta); + NG_FREE_ITEM(item); /* * Now queue the data for when it can be sent */ @@ -756,7 +752,8 @@ bad: /* * It was an error case. * check if we need to free the mbuf, and then return the error */ - NG_FREE_DATA(m, meta); + NG_FREE_M(m); + NG_FREE_META(meta); return (error); } @@ -769,9 +766,9 @@ Static int ng_udbp_rmnode(node_p node) { const udbp_p sc = node->private; + int err; node->flags |= NG_INVALID; - ng_cutlinks(node); /* Drain the queues */ IF_DRAIN(&sc->xmitq_hipri); @@ -779,8 +776,21 @@ ng_udbp_rmnode(node_p node) sc->packets_in = 0; /* reset stats */ sc->packets_out = 0; - node->flags &= ~NG_INVALID; /* reset invalid flag */ - return (0); + ng_unref(node); /* forget it ever existed */ + + /* stolen from attach routine */ + if ((err = ng_make_node_common(&ng_udbp_typestruct, &sc->node)) == 0) { + char nodename[128]; + sprintf(nodename, "%s", USBDEVNAME(sc->sc_dev)); + if ((err = ng_name_node(sc->node, nodename))) { + ng_unref(sc->node); /* out damned spot! */ + sc->flags &= ~NETGRAPH_INITIALISED; + sc->node = NULL; + } else { + sc->node->private = sc; + } + } + return (err); } /* @@ -807,8 +817,9 @@ ng_udbp_disconnect(hook_p hook) const udbp_p sc = hook->node->private; sc->hook = NULL; - if (hook->node->numhooks == 0) - ng_rmnode(hook->node); + if ((hook->node->numhooks == 0) + && ((hook->node->flags & NG_INVALID) == 0)) + ng_rmnode_self(hook->node); return (0); } |