summaryrefslogtreecommitdiff
path: root/sys/src
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-02-25 03:42:38 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2018-02-25 03:42:38 +0100
commitf0a314605f1a6d56da34ac07bb4effe2dcff8c37 (patch)
tree64c8bc5158c161202cbed0ea454c2146b08cc937 /sys/src
parent5560efb3dbe76bfab78d0d7f97969d7589a3f171 (diff)
devether: remove (unimplemented) detach, allow device creation on attach
we allow devether to create ethernet cards on attach. this is useull for virtual cards like the sink driver, so we can create a sink by simply: bind -a '#l2:sink ea=112233445566' /net the detach routine was never called, so remove it from the few drivers that attempted to implement it.
Diffstat (limited to 'sys/src')
-rw-r--r--sys/src/9/pc/etherm10g.c1
-rw-r--r--sys/src/9/pc/wavelan.c1
-rw-r--r--sys/src/9/port/devether.c73
-rw-r--r--sys/src/9/port/etherif.h1
-rw-r--r--sys/src/9/port/netif.c2
-rw-r--r--sys/src/9/xen/etherxen.c1
-rw-r--r--sys/src/9/zynq/dat.h3
7 files changed, 48 insertions, 34 deletions
diff --git a/sys/src/9/pc/etherm10g.c b/sys/src/9/pc/etherm10g.c
index fe55f3bc9..941808b63 100644
--- a/sys/src/9/pc/etherm10g.c
+++ b/sys/src/9/pc/etherm10g.c
@@ -1614,7 +1614,6 @@ m10gpnp(Ether *e)
memmove(e->ea, c->ra, Eaddrlen);
e->attach = m10gattach;
- e->detach = m10gshutdown;
e->transmit = m10gtransmit;
e->interrupt = m10ginterrupt;
e->ifstat = m10gifstat;
diff --git a/sys/src/9/pc/wavelan.c b/sys/src/9/pc/wavelan.c
index e2df7acd0..5e3c87a16 100644
--- a/sys/src/9/pc/wavelan.c
+++ b/sys/src/9/pc/wavelan.c
@@ -1234,7 +1234,6 @@ wavelanreset(Ether* ether, Ctlr *ctlr)
ether->ctlr = ctlr;
ether->mbps = 10;
ether->attach = w_attach;
- ether->detach = w_detach;
ether->transmit = w_transmit;
ether->ifstat = w_ifstat;
ether->ctl = w_ctl;
diff --git a/sys/src/9/port/devether.c b/sys/src/9/port/devether.c
index 766242e01..abc56f325 100644
--- a/sys/src/9/port/devether.c
+++ b/sys/src/9/port/devether.c
@@ -14,23 +14,35 @@ extern int eipfmt(Fmt*);
extern ushort ipcsum(uchar *);
static Ether *etherxx[MaxEther];
+static Ether *etherprobe(int cardno, int ctlrno, char *conf);
Chan*
etherattach(char* spec)
{
ulong ctlrno;
- char *p;
+ char *conf;
Chan *chan;
ctlrno = 0;
- if(spec && *spec){
- ctlrno = strtoul(spec, &p, 0);
- if((ctlrno == 0 && p == spec) || *p || (ctlrno >= MaxEther))
- error(Ebadarg);
+ if(*spec){
+ ctlrno = strtoul(spec, &conf, 0);
+ if(ctlrno >= MaxEther)
+ error(Enodev);
+ if(conf == spec)
+ error(Ebadspec);
+ if(*conf){
+ if(*conf != ':')
+ error(Ebadspec);
+ *conf++ = 0;
+ if(!iseve())
+ error(Enoattach);
+ if(etherxx[ctlrno] != nil)
+ error(Einuse);
+ etherxx[ctlrno] = etherprobe(-1, ctlrno, conf);
+ }
}
- if(etherxx[ctlrno] == 0)
+ if(etherxx[ctlrno] == nil)
error(Enodev);
-
chan = devattach('l', spec);
if(waserror()){
chanfree(chan);
@@ -350,7 +362,7 @@ addethercard(char* t, int (*r)(Ether*))
}
static Ether*
-etherprobe(int cardno, int ctlrno)
+etherprobe(int cardno, int ctlrno, char *conf)
{
int i, lg;
ulong mb, bsz;
@@ -370,36 +382,41 @@ etherprobe(int cardno, int ctlrno)
ether->maxmtu = ETHERMAXTU;
if(cardno < 0){
- if(isaconfig("ether", ctlrno, ether) == 0){
- free(ether);
- return nil;
- }
- for(cardno = 0; cards[cardno].type; cardno++){
- if(cistrcmp(cards[cardno].type, ether->type))
- continue;
- for(i = 0; i < ether->nopt; i++){
- if(strncmp(ether->opt[i], "ea=", 3))
- continue;
+ if(conf != nil){
+ kstrdup(&ether->type, conf);
+ ether->nopt = tokenize(ether->type, ether->opt, nelem(ether->opt));
+ if(ether->nopt < 1)
+ goto Nope;
+ memmove(&ether->opt[0], &ether->opt[1], --ether->nopt*sizeof(ether->opt[0]));
+ } else if(isaconfig("ether", ctlrno, ether) == 0)
+ goto Nope;
+
+ for(cardno = 0; cards[cardno].type != nil; cardno++)
+ if(cistrcmp(cards[cardno].type, ether->type) == 0)
+ break;
+ if(cards[cardno].type == nil)
+ goto Nope;
+
+ for(i = 0; i < ether->nopt; i++){
+ if(strncmp(ether->opt[i], "ea=", 3) == 0){
if(parseether(ether->ea, &ether->opt[i][3]))
memset(ether->ea, 0, Eaddrlen);
}
- break;
}
}
-
- if(cardno >= MaxEther || cards[cardno].type == nil){
- free(ether);
- return nil;
- }
+ if(cardno >= MaxEther || cards[cardno].type == nil)
+ goto Nope;
snprint(ether->name, sizeof(ether->name), "ether%d", ctlrno);
if(cards[cardno].reset(ether) < 0){
+Nope:
+ if(conf != nil) free(ether->type); /* see kstrdup() above */
free(ether);
return nil;
}
+ ether->type = cards[cardno].type;
print("#l%d: %s: %dMbps port 0x%luX irq %d ea %E\n",
- ctlrno, cards[cardno].type,
- ether->mbps, ether->port, ether->irq, ether->ea);
+ ctlrno, ether->type, ether->mbps, ether->port, ether->irq, ether->ea);
/* compute log10(ether->mbps) into lg */
for(lg = 0, mb = ether->mbps; mb >= 10; lg++)
@@ -439,7 +456,7 @@ etherreset(void)
fmtinstall('E', eipfmt);
for(ctlrno = 0; ctlrno < MaxEther; ctlrno++){
- if((ether = etherprobe(-1, ctlrno)) == nil)
+ if((ether = etherprobe(-1, ctlrno, nil)) == nil)
continue;
etherxx[ctlrno] = ether;
}
@@ -451,7 +468,7 @@ etherreset(void)
ctlrno++;
continue;
}
- if((ether = etherprobe(cardno, ctlrno)) == nil){
+ if((ether = etherprobe(cardno, ctlrno, nil)) == nil){
cardno++;
continue;
}
diff --git a/sys/src/9/port/etherif.h b/sys/src/9/port/etherif.h
index d846eb582..5ce7ce786 100644
--- a/sys/src/9/port/etherif.h
+++ b/sys/src/9/port/etherif.h
@@ -20,7 +20,6 @@ struct Ether {
int maxmtu;
void (*attach)(Ether*); /* filled in by reset routine */
- void (*detach)(Ether*);
void (*transmit)(Ether*);
long (*ifstat)(Ether*, void*, long, ulong);
long (*ctl)(Ether*, void*, long); /* custom ctl messages */
diff --git a/sys/src/9/port/netif.c b/sys/src/9/port/netif.c
index 4b818938e..48bcdd405 100644
--- a/sys/src/9/port/netif.c
+++ b/sys/src/9/port/netif.c
@@ -80,7 +80,7 @@ netifgen(Chan *c, char*, Dirtab *vp, int, int i, Dir *dp)
break;
case 1:
q.path = Naddrqid;
- devdir(c, q, "addr", 0, eve, 0666, dp);
+ devdir(c, q, "addr", 0, eve, 0444, dp);
break;
case 2:
q.path = Nstatqid;
diff --git a/sys/src/9/xen/etherxen.c b/sys/src/9/xen/etherxen.c
index 8d3fc4c26..fa13a16e6 100644
--- a/sys/src/9/xen/etherxen.c
+++ b/sys/src/9/xen/etherxen.c
@@ -474,7 +474,6 @@ pnp(Ether* ether)
memmove(ether->ea, ea, sizeof ether->ea);
ether->mbps = 100; // XXX what speed?
ether->attach = etherxenattach;
- ether->detach = nil;
ether->transmit = etherxentransmit;
ether->irq = -1;
ether->tbdf = BUSUNKNOWN;
diff --git a/sys/src/9/zynq/dat.h b/sys/src/9/zynq/dat.h
index 811b23407..b18a5551d 100644
--- a/sys/src/9/zynq/dat.h
+++ b/sys/src/9/zynq/dat.h
@@ -159,13 +159,14 @@ struct Mach
int stack[1];
};
+#define NISAOPT 8
struct ISAConf
{
char *type;
ulong port;
int irq;
int nopt;
- char *opt[1];
+ char *opt[NISAOPT];
};
#define BUSUNKNOWN -1