mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
devether: provide ethersetspeed() function to adjust queue sizes
When the link-speed changes, we want to adjust not only the output queue limit (done by some drivers) but also the input queue limit per netif file. Now, instead of setting Ether->mbps directly, drivers should call ethersetspeed(ether, mbps).
This commit is contained in:
parent
3b5e83f164
commit
11ac75e789
23 changed files with 133 additions and 110 deletions
|
@ -768,7 +768,7 @@ linkproc(void *arg)
|
||||||
REG(ctlr->regs[ExtRgmiiOobCtrl]) = (REG(ctlr->regs[ExtRgmiiOobCtrl]) & ~OobDisable) | RgmiiLink;
|
REG(ctlr->regs[ExtRgmiiOobCtrl]) = (REG(ctlr->regs[ExtRgmiiOobCtrl]) & ~OobDisable) | RgmiiLink;
|
||||||
umaccmd(ctlr, cmd, CmdSpeedMask|CmdHdEn|CmdRxPauseIgn|CmdTxPauseIgn);
|
umaccmd(ctlr, cmd, CmdSpeedMask|CmdHdEn|CmdRxPauseIgn|CmdTxPauseIgn);
|
||||||
|
|
||||||
edev->mbps = phy->speed;
|
ethersetspeed(edev, phy->speed);
|
||||||
}
|
}
|
||||||
edev->link = link;
|
edev->link = link;
|
||||||
// print("#l%d: link %d speed %d\n", edev->ctlrno, edev->link, edev->mbps);
|
// print("#l%d: link %d speed %d\n", edev->ctlrno, edev->link, edev->mbps);
|
||||||
|
|
|
@ -127,20 +127,19 @@ ethproc(void *ved)
|
||||||
}
|
}
|
||||||
v = mdread(c, MDPHYCTRL);
|
v = mdread(c, MDPHYCTRL);
|
||||||
if((v & 0x40) != 0){
|
if((v & 0x40) != 0){
|
||||||
sp = "1000BASE-T";
|
|
||||||
while((mdread(c, MDGSTATUS) & RECVOK) != RECVOK)
|
while((mdread(c, MDGSTATUS) & RECVOK) != RECVOK)
|
||||||
;
|
;
|
||||||
edev->mbps = 1000;
|
|
||||||
c->r[MAC_CONFIG] &= ~(1<<15);
|
c->r[MAC_CONFIG] &= ~(1<<15);
|
||||||
|
ethersetspeed(edev, 1000);
|
||||||
|
sp = "1000BASE-T";
|
||||||
}else if((v & 0x20) != 0){
|
}else if((v & 0x20) != 0){
|
||||||
sp = "100BASE-TX";
|
|
||||||
edev->mbps = 100;
|
|
||||||
c->r[MAC_CONFIG] = c->r[MAC_CONFIG] | (1<<15|1<<14);
|
c->r[MAC_CONFIG] = c->r[MAC_CONFIG] | (1<<15|1<<14);
|
||||||
|
ethersetspeed(edev, 100);
|
||||||
|
sp = "100BASE-TX";
|
||||||
}else if((v & 0x10) != 0){
|
}else if((v & 0x10) != 0){
|
||||||
sp = "10BASE-T";
|
|
||||||
edev->mbps = 10;
|
|
||||||
c->r[MAC_CONFIG] = c->r[MAC_CONFIG] & ~(1<<14) | 1<<15;
|
c->r[MAC_CONFIG] = c->r[MAC_CONFIG] & ~(1<<14) | 1<<15;
|
||||||
|
ethersetspeed(edev, 10);
|
||||||
|
sp = "10BASE-T";
|
||||||
}else
|
}else
|
||||||
sp = "???";
|
sp = "???";
|
||||||
if((v & 0x08) != 0){
|
if((v & 0x08) != 0){
|
||||||
|
|
|
@ -515,7 +515,7 @@ linkproc(void *arg)
|
||||||
wr(ctlr, ENET_RCR, rcr);
|
wr(ctlr, ENET_RCR, rcr);
|
||||||
wr(ctlr, ENET_TCR, tcr);
|
wr(ctlr, ENET_TCR, tcr);
|
||||||
|
|
||||||
edev->mbps = phy->speed;
|
ethersetspeed(edev, phy->speed);
|
||||||
|
|
||||||
wr(ctlr, ENET_RDAR, RDAR_ACTIVE);
|
wr(ctlr, ENET_RDAR, RDAR_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1281,7 +1281,7 @@ kirkwoodmii(Ether *ether)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ether->mbps = phy->speed;
|
ethersetspeed(ether, phy->speed);
|
||||||
MIIDBG("#l%d: kirkwoodmii: fd %d speed %d tfc %d rfc %d\n",
|
MIIDBG("#l%d: kirkwoodmii: fd %d speed %d tfc %d rfc %d\n",
|
||||||
ctlr->port, phy->fd, phy->speed, phy->tfc, phy->rfc);
|
ctlr->port, phy->fd, phy->speed, phy->tfc, phy->rfc);
|
||||||
MIIDBG("mii done\n");
|
MIIDBG("mii done\n");
|
||||||
|
|
|
@ -646,14 +646,10 @@ rtl8139interrupt(Ureg*, void* arg)
|
||||||
*/
|
*/
|
||||||
msr = csr8r(ctlr, Msr);
|
msr = csr8r(ctlr, Msr);
|
||||||
if(!(msr & Linkb)){
|
if(!(msr & Linkb)){
|
||||||
if(!(msr & Speed10) && edev->mbps != 100){
|
if(msr & Speed10)
|
||||||
edev->mbps = 100;
|
ethersetspeed(edev, 10);
|
||||||
qsetlimit(edev->oq, 256*1024);
|
else
|
||||||
}
|
ethersetspeed(edev, 100);
|
||||||
else if((msr & Speed10) && edev->mbps != 10){
|
|
||||||
edev->mbps = 10;
|
|
||||||
qsetlimit(edev->oq, 65*1024);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
isr &= ~(Clc|PunLc);
|
isr &= ~(Clc|PunLc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -876,7 +876,6 @@ static void
|
||||||
rtl8169link(Ether* edev)
|
rtl8169link(Ether* edev)
|
||||||
{
|
{
|
||||||
uint r;
|
uint r;
|
||||||
int limit;
|
|
||||||
Ctlr *ctlr;
|
Ctlr *ctlr;
|
||||||
|
|
||||||
ctlr = edev->ctlr;
|
ctlr = edev->ctlr;
|
||||||
|
@ -887,18 +886,14 @@ rtl8169link(Ether* edev)
|
||||||
* Could stall transmits if no link, maybe?
|
* Could stall transmits if no link, maybe?
|
||||||
*/
|
*/
|
||||||
edev->link = (r & Linksts) != 0;
|
edev->link = (r & Linksts) != 0;
|
||||||
|
if(edev->link){
|
||||||
limit = 256*1024;
|
if(r & Speed10)
|
||||||
if(r & Speed10){
|
ethersetspeed(edev, 10);
|
||||||
edev->mbps = 10;
|
else if(r & Speed100)
|
||||||
limit = 65*1024;
|
ethersetspeed(edev, 100);
|
||||||
} else if(r & Speed100)
|
else if(r & Speed1000)
|
||||||
edev->mbps = 100;
|
ethersetspeed(edev, 1000);
|
||||||
else if(r & Speed1000)
|
}
|
||||||
edev->mbps = 1000;
|
|
||||||
|
|
||||||
if(edev->oq != nil)
|
|
||||||
qsetlimit(edev->oq, limit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -1222,10 +1222,11 @@ phyl79proc(void *v)
|
||||||
}
|
}
|
||||||
i = (phy>>8) & 3;
|
i = (phy>>8) & 3;
|
||||||
e->link = i != 3 && (phy & Link) != 0;
|
e->link = i != 3 && (phy & Link) != 0;
|
||||||
if(e->link == 0)
|
if(e->link)
|
||||||
|
ethersetspeed(e, speedtab[i]);
|
||||||
|
else
|
||||||
i = 3;
|
i = 3;
|
||||||
c->speeds[i]++;
|
c->speeds[i]++;
|
||||||
e->mbps = speedtab[i];
|
|
||||||
lsleep(c, Lsc);
|
lsleep(c, Lsc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1278,10 +1279,11 @@ phylproc(void *v)
|
||||||
phywrite(c, phyno, Phyctl, phyread(c, phyno, Phyctl) | Ran | Ean);
|
phywrite(c, phyno, Phyctl, phyread(c, phyno, Phyctl) | Ran | Ean);
|
||||||
next:
|
next:
|
||||||
e->link = (phy & Rtlink) != 0;
|
e->link = (phy & Rtlink) != 0;
|
||||||
if(e->link == 0)
|
if(e->link)
|
||||||
|
ethersetspeed(e, speedtab[i]);
|
||||||
|
else
|
||||||
i = 3;
|
i = 3;
|
||||||
c->speeds[i]++;
|
c->speeds[i]++;
|
||||||
e->mbps = speedtab[i];
|
|
||||||
if(c->type == i82563)
|
if(c->type == i82563)
|
||||||
phyerrata(e, c, phyno);
|
phyerrata(e, c, phyno);
|
||||||
lsleep(c, Lsc);
|
lsleep(c, Lsc);
|
||||||
|
@ -1306,12 +1308,12 @@ pcslproc(void *v)
|
||||||
phy = csr32r(c, Pcsstat);
|
phy = csr32r(c, Pcsstat);
|
||||||
e->link = phy & Linkok;
|
e->link = phy & Linkok;
|
||||||
i = 3;
|
i = 3;
|
||||||
if(e->link)
|
if(e->link){
|
||||||
i = (phy & 6) >> 1;
|
i = (phy & 6) >> 1;
|
||||||
else if(phy & Anbad)
|
ethersetspeed(e, speedtab[i]);
|
||||||
|
}else if(phy & Anbad)
|
||||||
csr32w(c, Pcsctl, csr32r(c, Pcsctl) | Pan | Prestart);
|
csr32w(c, Pcsctl, csr32r(c, Pcsctl) | Pan | Prestart);
|
||||||
c->speeds[i]++;
|
c->speeds[i]++;
|
||||||
e->mbps = speedtab[i];
|
|
||||||
lsleep(c, Lsc | Omed);
|
lsleep(c, Lsc | Omed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1334,10 +1336,11 @@ serdeslproc(void *v)
|
||||||
e->link = (rx & 1<<31) != 0;
|
e->link = (rx & 1<<31) != 0;
|
||||||
// e->link = (csr32r(c, Status) & Lu) != 0;
|
// e->link = (csr32r(c, Status) & Lu) != 0;
|
||||||
i = 3;
|
i = 3;
|
||||||
if(e->link)
|
if(e->link){
|
||||||
i = 2;
|
i = 2;
|
||||||
|
ethersetspeed(e, speedtab[i]);
|
||||||
|
}
|
||||||
c->speeds[i]++;
|
c->speeds[i]++;
|
||||||
e->mbps = speedtab[i];
|
|
||||||
lsleep(c, Lsc);
|
lsleep(c, Lsc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -386,10 +386,11 @@ lproc(void *v)
|
||||||
r = c->reg[Links];
|
r = c->reg[Links];
|
||||||
e->link = (r & Lnkup) != 0;
|
e->link = (r & Lnkup) != 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
if(e->link)
|
if(e->link){
|
||||||
i = 1 + ((r & Lnkspd) != 0);
|
i = 1 + ((r & Lnkspd) != 0);
|
||||||
|
ethersetspeed(e, speedtab[i]);
|
||||||
|
}
|
||||||
c->speeds[i]++;
|
c->speeds[i]++;
|
||||||
e->mbps = speedtab[i];
|
|
||||||
c->lim = 0;
|
c->lim = 0;
|
||||||
im(c, Lsc);
|
im(c, Lsc);
|
||||||
sleep(&c->lrendez, lim, c);
|
sleep(&c->lrendez, lim, c);
|
||||||
|
|
|
@ -331,12 +331,12 @@ checklink(Ether *edev)
|
||||||
{
|
{
|
||||||
Ctlr *ctlr;
|
Ctlr *ctlr;
|
||||||
ulong i;
|
ulong i;
|
||||||
|
int mbps;
|
||||||
|
|
||||||
ctlr = edev->ctlr;
|
ctlr = edev->ctlr;
|
||||||
miir(ctlr, PhyStatus); /* dummy read necessary */
|
miir(ctlr, PhyStatus); /* dummy read necessary */
|
||||||
if(!(miir(ctlr, PhyStatus) & PhyLinkStatus)) {
|
if(!(miir(ctlr, PhyStatus) & PhyLinkStatus)) {
|
||||||
edev->link = 0;
|
edev->link = 0;
|
||||||
edev->mbps = 1000;
|
|
||||||
ctlr->duplex = 1;
|
ctlr->duplex = 1;
|
||||||
print("bcm: no link\n");
|
print("bcm: no link\n");
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -345,26 +345,26 @@ checklink(Ether *edev)
|
||||||
while((miir(ctlr, PhyStatus) & PhyAutoNegComplete) == 0);
|
while((miir(ctlr, PhyStatus) & PhyAutoNegComplete) == 0);
|
||||||
i = miir(ctlr, PhyGbitStatus);
|
i = miir(ctlr, PhyGbitStatus);
|
||||||
if(i & (Phy1000FD | Phy1000HD)) {
|
if(i & (Phy1000FD | Phy1000HD)) {
|
||||||
edev->mbps = 1000;
|
mbps = 1000;
|
||||||
ctlr->duplex = (i & Phy1000FD) != 0;
|
ctlr->duplex = (i & Phy1000FD) != 0;
|
||||||
} else if(i = miir(ctlr, PhyPartnerStatus), i & (Phy100FD | Phy100HD)) {
|
} else if(i = miir(ctlr, PhyPartnerStatus), i & (Phy100FD | Phy100HD)) {
|
||||||
edev->mbps = 100;
|
mbps = 100;
|
||||||
ctlr->duplex = (i & Phy100FD) != 0;
|
ctlr->duplex = (i & Phy100FD) != 0;
|
||||||
} else if(i & (Phy10FD | Phy10HD)) {
|
} else if(i & (Phy10FD | Phy10HD)) {
|
||||||
edev->mbps = 10;
|
mbps = 10;
|
||||||
ctlr->duplex = (i & Phy10FD) != 0;
|
ctlr->duplex = (i & Phy10FD) != 0;
|
||||||
} else {
|
} else {
|
||||||
edev->link = 0;
|
edev->link = 0;
|
||||||
edev->mbps = 1000;
|
|
||||||
ctlr->duplex = 1;
|
ctlr->duplex = 1;
|
||||||
print("bcm: link partner supports neither 10/100/1000 Mbps\n");
|
print("bcm: link partner supports neither 10/100/1000 Mbps\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
print("bcm: %d Mbps link, %s duplex\n", edev->mbps, ctlr->duplex ? "full" : "half");
|
print("bcm: %d Mbps link, %s duplex\n", mbps, ctlr->duplex ? "full" : "half");
|
||||||
|
ethersetspeed(edev, mbps);
|
||||||
out:
|
out:
|
||||||
if(ctlr->duplex) csr32(ctlr, MACMode) &= ~MACHalfDuplex;
|
if(ctlr->duplex) csr32(ctlr, MACMode) &= ~MACHalfDuplex;
|
||||||
else csr32(ctlr, MACMode) |= MACHalfDuplex;
|
else csr32(ctlr, MACMode) |= MACHalfDuplex;
|
||||||
if(edev->mbps >= 1000)
|
if(mbps >= 1000)
|
||||||
csr32(ctlr, MACMode) = (csr32(ctlr, MACMode) & MACPortMask) | MACPortGMII;
|
csr32(ctlr, MACMode) = (csr32(ctlr, MACMode) & MACPortMask) | MACPortGMII;
|
||||||
else
|
else
|
||||||
csr32(ctlr, MACMode) = (csr32(ctlr, MACMode) & MACPortMask) | MACPortMII;
|
csr32(ctlr, MACMode) = (csr32(ctlr, MACMode) & MACPortMask) | MACPortMII;
|
||||||
|
|
|
@ -1972,14 +1972,14 @@ etherelnk3reset(Ether* ether)
|
||||||
}
|
}
|
||||||
XCVRDEBUG("mii anar: %uX\n", anar);
|
XCVRDEBUG("mii anar: %uX\n", anar);
|
||||||
if(anar & 0x0100){ /* 100BASE-TXFD */
|
if(anar & 0x0100){ /* 100BASE-TXFD */
|
||||||
ether->mbps = 100;
|
ethersetspeed(ether, 100);
|
||||||
setfullduplex(port);
|
setfullduplex(port);
|
||||||
}
|
}
|
||||||
else if(anar & 0x0200){ /* 100BASE-T4 */
|
else if(anar & 0x0200){ /* 100BASE-T4 */
|
||||||
/* nothing to do */
|
/* nothing to do */
|
||||||
}
|
}
|
||||||
else if(anar & 0x0080) /* 100BASE-TX */
|
else if(anar & 0x0080) /* 100BASE-TX */
|
||||||
ether->mbps = 100;
|
ethersetspeed(ether, 100);
|
||||||
else if(anar & 0x0040) /* 10BASE-TFD */
|
else if(anar & 0x0040) /* 10BASE-TFD */
|
||||||
setfullduplex(port);
|
setfullduplex(port);
|
||||||
else{ /* 10BASE-T */
|
else{ /* 10BASE-T */
|
||||||
|
@ -1998,7 +1998,7 @@ etherelnk3reset(Ether* ether)
|
||||||
outs(port+MediaStatus, x);
|
outs(port+MediaStatus, x);
|
||||||
|
|
||||||
if(x & dataRate100)
|
if(x & dataRate100)
|
||||||
ether->mbps = 100;
|
ethersetspeed(ether, 100);
|
||||||
break;
|
break;
|
||||||
case xcvr10BaseT:
|
case xcvr10BaseT:
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -581,13 +581,14 @@ ga620event(Ether *edev, int eci, int epi)
|
||||||
case 0x06: /* link state changed */
|
case 0x06: /* link state changed */
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 1:
|
case 1:
|
||||||
edev->mbps = 1000;
|
ethersetspeed(edev, 1000);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
print("#l%d: link down\n", edev->ctlrno);
|
print("#l%d: link down\n", edev->ctlrno);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
edev->mbps = 100; /* it's 10 or 100 */
|
/* it's 10 or 100 */
|
||||||
|
ethersetspeed(edev, 100);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (code != 2)
|
if (code != 2)
|
||||||
|
|
|
@ -1586,8 +1586,6 @@ wpiattach(Ether *edev)
|
||||||
error("wifi disabled by switch");
|
error("wifi disabled by switch");
|
||||||
|
|
||||||
if(ctlr->wifi == nil){
|
if(ctlr->wifi == nil){
|
||||||
qsetlimit(edev->oq, MaxQueue);
|
|
||||||
|
|
||||||
ctlr->wifi = wifiattach(edev, transmit);
|
ctlr->wifi = wifiattach(edev, transmit);
|
||||||
ctlr->wifi->rates = wpirates;
|
ctlr->wifi->rates = wpirates;
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,10 +348,11 @@ lproc(void *v)
|
||||||
r = c->reg[Links];
|
r = c->reg[Links];
|
||||||
e->link = (r & Lnkup) != 0;
|
e->link = (r & Lnkup) != 0;
|
||||||
i = 0;
|
i = 0;
|
||||||
if(e->link)
|
if(e->link){
|
||||||
i = 1 + ((r & Lnkspd) != 0);
|
i = 1 + ((r & Lnkspd) != 0);
|
||||||
|
ethersetspeed(e, speedtab[i]);
|
||||||
|
}
|
||||||
c->speeds[i]++;
|
c->speeds[i]++;
|
||||||
e->mbps = speedtab[i];
|
|
||||||
c->lim = 0;
|
c->lim = 0;
|
||||||
im(c, Lsc);
|
im(c, Lsc);
|
||||||
sleep(&c->lrendez, lim, c);
|
sleep(&c->lrendez, lim, c);
|
||||||
|
|
|
@ -1358,23 +1358,16 @@ static int spdtab[4] = {
|
||||||
static void
|
static void
|
||||||
link(Ether *e)
|
link(Ether *e)
|
||||||
{
|
{
|
||||||
uint i, s, spd;
|
uint i, s;
|
||||||
Ctlr *c;
|
Ctlr *c;
|
||||||
|
|
||||||
c = e->ctlr;
|
c = e->ctlr;
|
||||||
i = phyread(c, Phyint);
|
i = phyread(c, Phyint);
|
||||||
s = phyread(c, Phylstat);
|
s = phyread(c, Phylstat);
|
||||||
dprint("#l%d: yuk: link %.8ux %.8ux\n", e->ctlrno, i, s);
|
dprint("#l%d: yuk: link %.8ux %.8ux\n", e->ctlrno, i, s);
|
||||||
spd = 0;
|
|
||||||
e->link = (s & Plink) != 0;
|
e->link = (s & Plink) != 0;
|
||||||
if(e->link && c->feat&Ffiber)
|
if(e->link)
|
||||||
spd = 1000;
|
ethersetspeed(e, (c->feat&Ffiber)? 1000: spdtab[(s & Physpd) >> 14]);
|
||||||
else if(e->link){
|
|
||||||
spd = s & Physpd;
|
|
||||||
spd >>= 14;
|
|
||||||
spd = spdtab[spd];
|
|
||||||
}
|
|
||||||
e->mbps = spd;
|
|
||||||
dprint("#l%d: yuk: link %d spd %d\n", e->ctlrno, e->link, e->mbps);
|
dprint("#l%d: yuk: link %d spd %d\n", e->ctlrno, e->link, e->mbps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -373,11 +373,31 @@ addethercard(char* t, int (*r)(Ether*))
|
||||||
ncard++;
|
ncard++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
etherqueuesize(Ether *ether)
|
||||||
|
{
|
||||||
|
int lg, mb;
|
||||||
|
ulong bsz;
|
||||||
|
|
||||||
|
/* compute log10(mbps) into lg */
|
||||||
|
for(lg = 0, mb = ether->mbps; mb >= 10; lg++)
|
||||||
|
mb /= 10;
|
||||||
|
if (lg > 0)
|
||||||
|
lg--;
|
||||||
|
if (lg > 14) /* 2^(14+17) = 2³¹ */
|
||||||
|
lg = 14;
|
||||||
|
/* allocate larger output queues for higher-speed interfaces */
|
||||||
|
bsz = 1UL << (lg + 17); /* 2¹⁷ = 128K, bsz = 2ⁿ × 128K */
|
||||||
|
while (bsz > mainmem->maxsize / 8 && bsz > 128*1024)
|
||||||
|
bsz /= 2;
|
||||||
|
if(0) print("#l%d: %d Mbps -> queue size %lud\n", ether->ctlrno, ether->mbps, bsz);
|
||||||
|
return (int)bsz;
|
||||||
|
}
|
||||||
|
|
||||||
static Ether*
|
static Ether*
|
||||||
etherprobe(int cardno, int ctlrno, char *conf)
|
etherprobe(int cardno, int ctlrno, char *conf)
|
||||||
{
|
{
|
||||||
int i, lg;
|
int i;
|
||||||
ulong mb, bsz;
|
|
||||||
Ether *ether;
|
Ether *ether;
|
||||||
|
|
||||||
ether = malloc(sizeof(Ether));
|
ether = malloc(sizeof(Ether));
|
||||||
|
@ -430,26 +450,14 @@ Nope:
|
||||||
print("#l%d: %s: %dMbps port 0x%lluX irq %d ea %E\n",
|
print("#l%d: %s: %dMbps port 0x%lluX irq %d ea %E\n",
|
||||||
ctlrno, ether->type, ether->mbps, (uvlong)ether->port, ether->irq, ether->ea);
|
ctlrno, ether->type, ether->mbps, (uvlong)ether->port, ether->irq, ether->ea);
|
||||||
|
|
||||||
/* compute log10(ether->mbps) into lg */
|
netifinit(ether, ether->name, Ntypes, etherqueuesize(ether));
|
||||||
for(lg = 0, mb = ether->mbps; mb >= 10; lg++)
|
if(ether->oq == nil){
|
||||||
mb /= 10;
|
ether->oq = qopen(ether->limit, Qmsg, 0, 0);
|
||||||
if (lg > 0)
|
if(ether->oq == nil)
|
||||||
lg--;
|
panic("etherreset %s: can't allocate output queue", ether->name);
|
||||||
if (lg > 14) /* 2^(14+17) = 2³¹ */
|
} else {
|
||||||
lg = 14;
|
qsetlimit(ether->oq, ether->limit);
|
||||||
/* allocate larger output queues for higher-speed interfaces */
|
|
||||||
bsz = 1UL << (lg + 17); /* 2¹⁷ = 128K, bsz = 2ⁿ × 128K */
|
|
||||||
while (bsz > mainmem->maxsize / 8 && bsz > 128*1024)
|
|
||||||
bsz /= 2;
|
|
||||||
|
|
||||||
netifinit(ether, ether->name, Ntypes, bsz);
|
|
||||||
if(ether->oq == nil) {
|
|
||||||
ether->oq = qopen(bsz, Qmsg, 0, 0);
|
|
||||||
ether->limit = bsz;
|
|
||||||
}
|
}
|
||||||
if(ether->oq == nil)
|
|
||||||
panic("etherreset %s: can't allocate output queue of %ld bytes", ether->name, bsz);
|
|
||||||
|
|
||||||
ether->alen = Eaddrlen;
|
ether->alen = Eaddrlen;
|
||||||
memmove(ether->addr, ether->ea, Eaddrlen);
|
memmove(ether->addr, ether->ea, Eaddrlen);
|
||||||
memset(ether->bcast, 0xFF, Eaddrlen);
|
memset(ether->bcast, 0xFF, Eaddrlen);
|
||||||
|
@ -457,6 +465,18 @@ Nope:
|
||||||
return ether;
|
return ether;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ethersetspeed(Ether *ether, int mbps)
|
||||||
|
{
|
||||||
|
if(ether->mbps == mbps)
|
||||||
|
return;
|
||||||
|
ether->mbps = mbps;
|
||||||
|
if(mbps <= 0 || ether->oq == nil)
|
||||||
|
return;
|
||||||
|
netifsetlimit(ether, etherqueuesize(ether));
|
||||||
|
qsetlimit(ether->oq, ether->limit);
|
||||||
|
}
|
||||||
|
|
||||||
static void netconsole(int);
|
static void netconsole(int);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -51,6 +51,7 @@ struct Ether {
|
||||||
DMAT* dmat;
|
DMAT* dmat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern void ethersetspeed(Ether*, int);
|
||||||
extern void etheriq(Ether*, Block*);
|
extern void etheriq(Ether*, Block*);
|
||||||
extern void addethercard(char*, int(*)(Ether*));
|
extern void addethercard(char*, int(*)(Ether*));
|
||||||
extern ulong ethercrc(uchar*, int);
|
extern ulong ethercrc(uchar*, int);
|
||||||
|
|
|
@ -4103,8 +4103,6 @@ iwlattach(Ether *edev)
|
||||||
error(err);
|
error(err);
|
||||||
|
|
||||||
if(ctlr->wifi == nil){
|
if(ctlr->wifi == nil){
|
||||||
qsetlimit(edev->oq, MaxQueue);
|
|
||||||
|
|
||||||
ctlr->wifi = wifiattach(edev, transmit);
|
ctlr->wifi = wifiattach(edev, transmit);
|
||||||
/* tested with 2230, it has transmit issues using higher bit rates */
|
/* tested with 2230, it has transmit issues using higher bit rates */
|
||||||
if(ctlr->family >= 7000 || ctlr->type != Type2030)
|
if(ctlr->family >= 7000 || ctlr->type != Type2030)
|
||||||
|
|
|
@ -16,7 +16,7 @@ static int parseaddr(uchar*, char*, int);
|
||||||
* set up a new network interface
|
* set up a new network interface
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
netifinit(Netif *nif, char *name, int nfile, ulong limit)
|
netifinit(Netif *nif, char *name, int nfile, int limit)
|
||||||
{
|
{
|
||||||
if(strlen(name) >= sizeof nif->name)
|
if(strlen(name) >= sizeof nif->name)
|
||||||
panic("netifinit: name too long: %s", name);
|
panic("netifinit: name too long: %s", name);
|
||||||
|
@ -29,6 +29,28 @@ netifinit(Netif *nif, char *name, int nfile, ulong limit)
|
||||||
nif->limit = limit;
|
nif->limit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* adjust input queue sizes for all files
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
netifsetlimit(Netif *nif, int limit)
|
||||||
|
{
|
||||||
|
Netfile *f;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
qlock(nif);
|
||||||
|
nif->limit = limit;
|
||||||
|
for(i = 0; i < nif->nfile; i++){
|
||||||
|
f = nif->f[i];
|
||||||
|
if(f == nil)
|
||||||
|
continue;
|
||||||
|
qlock(f);
|
||||||
|
qsetlimit(f->in, nif->limit);
|
||||||
|
qunlock(f);
|
||||||
|
}
|
||||||
|
qunlock(nif);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* generate a 3 level directory
|
* generate a 3 level directory
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -108,7 +108,8 @@ struct Netif
|
||||||
char* (*ifstat)(void*, char*, char*);
|
char* (*ifstat)(void*, char*, char*);
|
||||||
};
|
};
|
||||||
|
|
||||||
void netifinit(Netif*, char*, int, ulong);
|
void netifinit(Netif*, char*, int, int);
|
||||||
|
void netifsetlimit(Netif *, int);
|
||||||
Walkqid* netifwalk(Netif*, Chan*, Chan*, char **, int);
|
Walkqid* netifwalk(Netif*, Chan*, Chan*, char **, int);
|
||||||
Chan* netifopen(Netif*, Chan*, int);
|
Chan* netifopen(Netif*, Chan*, int);
|
||||||
void netifclose(Netif*, Chan*);
|
void netifclose(Netif*, Chan*);
|
||||||
|
|
|
@ -817,7 +817,7 @@ Scan:
|
||||||
while((wn = wifi->bss) != nil){
|
while((wn = wifi->bss) != nil){
|
||||||
ether->link = (wn->status == Sassoc) || (wn->status == Sblocked);
|
ether->link = (wn->status == Sassoc) || (wn->status == Sblocked);
|
||||||
if(ether->link && (rate = wn->actrate) != nil)
|
if(ether->link && (rate = wn->actrate) != nil)
|
||||||
ether->mbps = ((*rate & 0x7f)+3)/4;
|
ethersetspeed(ether, ((*rate & 0x7f)+3)/4);
|
||||||
now = MACHP(0)->ticks;
|
now = MACHP(0)->ticks;
|
||||||
if(wn->status != Sneedauth && TK2SEC(now - wn->lastseen) > 20 || goodbss(wifi, wn) == 0){
|
if(wn->status != Sneedauth && TK2SEC(now - wn->lastseen) > 20 || goodbss(wifi, wn) == 0){
|
||||||
wifideauth(wifi, wn);
|
wifideauth(wifi, wn);
|
||||||
|
|
|
@ -870,7 +870,7 @@ fccltimer(Ureg*, Timer *t)
|
||||||
print("link lost\n");
|
print("link lost\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ether->mbps = phy->speed;
|
ethersetspeed(ether, phy->speed);
|
||||||
|
|
||||||
if(phy->fd != ctlr->duplex)
|
if(phy->fd != ctlr->duplex)
|
||||||
print("set duplex\n");
|
print("set duplex\n");
|
||||||
|
|
|
@ -1275,7 +1275,6 @@ static void
|
||||||
rtl8169link(Ether* edev)
|
rtl8169link(Ether* edev)
|
||||||
{
|
{
|
||||||
uint r;
|
uint r;
|
||||||
int limit;
|
|
||||||
Ctlr *ctlr;
|
Ctlr *ctlr;
|
||||||
|
|
||||||
ctlr = edev->ctlr;
|
ctlr = edev->ctlr;
|
||||||
|
@ -1288,22 +1287,17 @@ rtl8169link(Ether* edev)
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (edev->link == 0) {
|
if(edev->link == 0) {
|
||||||
edev->link = 1;
|
edev->link = 1;
|
||||||
csr8w(ctlr, Cr, Te|Re);
|
csr8w(ctlr, Cr, Te|Re);
|
||||||
iprint("#l%d: link up\n", edev->ctlrno);
|
iprint("#l%d: link up\n", edev->ctlrno);
|
||||||
}
|
}
|
||||||
limit = 256*1024;
|
if(r & Speed10)
|
||||||
if(r & Speed10){
|
ethersetspeed(edev, 10);
|
||||||
edev->mbps = 10;
|
else if(r & Speed100)
|
||||||
limit = 65*1024;
|
ethersetspeed(edev, 100);
|
||||||
} else if(r & Speed100)
|
|
||||||
edev->mbps = 100;
|
|
||||||
else if(r & Speed1000)
|
else if(r & Speed1000)
|
||||||
edev->mbps = 1000;
|
ethersetspeed(edev, 1000);
|
||||||
|
|
||||||
if(edev->oq != nil)
|
|
||||||
qsetlimit(edev->oq, limit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -159,19 +159,19 @@ ethproc(void *ved)
|
||||||
sp = "1000BASE-T";
|
sp = "1000BASE-T";
|
||||||
while((mdread(c, MDGSTATUS) & RECVOK) != RECVOK)
|
while((mdread(c, MDGSTATUS) & RECVOK) != RECVOK)
|
||||||
;
|
;
|
||||||
edev->mbps = 1000;
|
|
||||||
c->r[NET_CFG] |= GIGE_EN;
|
c->r[NET_CFG] |= GIGE_EN;
|
||||||
slcr[GEM0_CLK_CTRL] = 1 << 20 | 8 << 8 | 1;
|
slcr[GEM0_CLK_CTRL] = 1 << 20 | 8 << 8 | 1;
|
||||||
|
ethersetspeed(edev, 1000);
|
||||||
}else if((v & 0x20) != 0){
|
}else if((v & 0x20) != 0){
|
||||||
sp = "100BASE-TX";
|
sp = "100BASE-TX";
|
||||||
edev->mbps = 100;
|
|
||||||
c->r[NET_CFG] = c->r[NET_CFG] & ~GIGE_EN | SPEED;
|
c->r[NET_CFG] = c->r[NET_CFG] & ~GIGE_EN | SPEED;
|
||||||
slcr[GEM0_CLK_CTRL] = 5 << 20 | 8 << 8 | 1;
|
slcr[GEM0_CLK_CTRL] = 5 << 20 | 8 << 8 | 1;
|
||||||
|
ethersetspeed(edev, 100);
|
||||||
}else if((v & 0x10) != 0){
|
}else if((v & 0x10) != 0){
|
||||||
sp = "10BASE-T";
|
sp = "10BASE-T";
|
||||||
edev->mbps = 10;
|
|
||||||
c->r[NET_CFG] = c->r[NET_CFG] & ~(GIGE_EN | SPEED);
|
c->r[NET_CFG] = c->r[NET_CFG] & ~(GIGE_EN | SPEED);
|
||||||
slcr[GEM0_CLK_CTRL] = 20 << 20 | 20 << 8 | 1;
|
slcr[GEM0_CLK_CTRL] = 20 << 20 | 20 << 8 | 1;
|
||||||
|
ethersetspeed(edev, 10);
|
||||||
}else
|
}else
|
||||||
sp = "???";
|
sp = "???";
|
||||||
if((v & 0x08) != 0){
|
if((v & 0x08) != 0){
|
||||||
|
|
Loading…
Reference in a new issue