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.
This commit is contained in:
cinap_lenrek 2018-02-25 03:42:38 +01:00
parent 5560efb3db
commit f0a314605f
7 changed files with 48 additions and 34 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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 */

View file

@ -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;

View file

@ -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;

View file

@ -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