summaryrefslogtreecommitdiffstats
path: root/sys/dev/sr
diff options
context:
space:
mode:
authorjulian <julian@FreeBSD.org>2001-01-06 00:46:47 +0000
committerjulian <julian@FreeBSD.org>2001-01-06 00:46:47 +0000
commitf0c46a9d00fc9fe4644cef5784e76b360f5036c7 (patch)
tree561902279f2f361f3e137f7fc029ce2714981289 /sys/dev/sr
parente06f071f56cf6badae9215f8a14ccc66a3fc0f5a (diff)
downloadFreeBSD-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/sr')
-rw-r--r--sys/dev/sr/if_sr.c59
-rw-r--r--sys/dev/sr/if_sr_isa.c59
2 files changed, 72 insertions, 46 deletions
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);
}
OpenPOWER on IntegriCloud