From: Aidan K. Wiggins <akw@oneiri.one>
To: 9front@9front.org
Subject: [9front] [PATCH] nusb/ether: add support for AX88179A
Date: Thu, 13 Mar 2025 17:55:52 -0700 [thread overview]
Message-ID: <FF9CE2CC9E796089AAB21BFB95F894BC@oneiri.one> (raw)
One more on the pile, this is a USB-C adapter sporting an 88179A. Both
the 88179 and 88179A share USB did/vids, so we have to tell them apart
by their usb revision.
My adapter works well enough for rcpu and the basics (I'm sending this
over rcpu), but it's noticeably slower than the 88179; not sure if
this is related to this driver, the controllers for these USB-C ports,
or this specific adapter.
Aidan
diff 5dcb8d92ff849359a164b7c0d7ecae64594d6db6 uncommitted
--- a/sys/src/cmd/nusb/ether/asix.c
+++ b/sys/src/cmd/nusb/ether/asix.c
@@ -29,16 +29,15 @@
Munk = 0x8000,
Mall772 = Mfd|Mrfc|Mtfc|Mps|Mac|Mre,
Mall178 = Mps|Mfd|Mac|Mrfc|Mtfc|Mjfe|Mre,
- Mall179 = Mgm|Mfd|Mmhz|Mrfc|Mtfc|Mjfe|Munk|Mre,
- Rxctldce = 0x0100, /* drop crcerr */
- Rxctlso = 0x80, /* start operation */
- Rxctlam = 0x10,
- Rxctlab = 0x08,
- Rxctlsep = 0x04,
- Rxctlamall = 0x02, /* all multicast */
- Rxctlprom = 0x01, /* promiscuous */
- Rxall179 = Rxctldce|Rxctlso|Rxctlab|Rxctlamall,
+ Rxctldce = 0x100, /* drop crcerr */
+ Rxctlso = 0x080, /* start operation */
+ Rxctlam = 0x010,
+ Rxctlab = 0x008,
+ Rxctlsep = 0x004,
+ Rxctlamall = 0x002, /* all multicast */
+ Rxctlprom = 0x001, /* promiscuous */
+ Rxall179 = Rxctldce|Rxctlso|Rxctlab|Rxctlam,
/* MII */
Miibmcr = 0x00, /* basic mode ctrl reg. */
@@ -422,17 +421,17 @@
Nid = 0x10,
Aphy = 0x02,
- Physts = 0x02,
+ Phyusb = 0x02,
Phyid = 0x03,
- Phyfd = 0x11,
+ Physr = 0x11,
/* Control */
+ Cfwmd = 0x08, /* firmware mode */
+ Fwmd179 = 0x00,
+ Fwmd179a = 0x01,
Crxctl = 0x0b,
Cmed = 0x22, /* medium status register */
- Cmmsr = 0x24, /* control monitor */
- Mrwmp = 0x04,
- Mpmepol = 0x20,
- Mpmetyp = 0x40,
+ Cmmsr = 0x24, /* control monitor */
Cphy = 0x26, /* control phy */
Cphybz = 0x0010,
@@ -447,15 +446,22 @@
Cpwtrh = 0x55,
Capo = 0x91, /* auto-power off phy */
- /* USB/Link conn. */
+ /* USB device release numbers */
+ Dno179 = 0x100,
+ Dno179a = 0x200,
+
+ /* Phy link */
+ Linkup = 0x0400,
+ Linkfd = 0x2000,
+ Link10 = 0x0000,
+ Link100 = 0x4000,
+ Link1000 = 0x8000,
+ Linkmask = Link100 | Link1000,
+
+ /* USB conn. */
Usbfs = 0x01,
Usbhs = 0x02,
Usbss = 0x04,
- Link10 = 0x10,
- Link100 = 0x20,
- Link1000 = 0x40,
-
- Linkfd = 0x2000,
};
static int
@@ -537,7 +543,7 @@
{
Block *b;
uchar *hdr;
- uint pktlen, npkt;
+ ushort npkt, pktlen;
int n;
b = allocb(a179bufsz);
@@ -546,16 +552,19 @@
return -1;
}
b->wp += n;
- npkt = GET2(b->wp-4);
- hdr = b->base + GET2(b->wp-2);
+
+ hdr = b->base + GET2(b->wp - 2);
+ npkt = GET2(b->wp - 4);
b->wp -= 4;
while(npkt-- > 0){
pktlen = GET2(hdr+2) & 0x1FFF;
+ hdr += 4;
+ if(pktlen == 0)
+ continue;
if(pktlen < ETHERHDRSIZE || pktlen > BLEN(b))
break;
- etheriq(copyblock(b, pktlen-4));
- b->rp += (pktlen+7) & 0xFFF8;
- hdr += 4;
+ etheriq(copyblock(b, pktlen));
+ b->rp += (pktlen + 7) & ~7;
}
freeb(b);
return 0;
@@ -580,9 +589,8 @@
static int
a179getrxctl(Dev *d)
{
- uchar buf[2];
+ uchar buf[2] = { 0 };
- memset(buf, 0, sizeof(buf));
if(a179get(d, Amac, Crxctl, 2, buf, 2) < 0)
return -1;
return GET2(buf);
@@ -596,8 +604,8 @@
timeout = 5000;
do{
- link = a179miiread(d, Miibmsr);
- if(link & Bmsrlink)
+ link = a179miiread(d, Physr);
+ if(link & Linkup)
return 0;
sleep(50);
}while(timeout -= 50);
@@ -632,18 +640,22 @@
return a179set2(d, Crxctl, rxctl);
}
+
static int
a179linkspeed(Dev *d)
{
- uchar link;
+ int link;
- a179get(d, Amac, Physts, 1, &link, 1);
- if(link & Link1000)
+ if((link = a179miiread(d, Physr)) < 0)
+ return -1;
+ switch(link & Linkmask){
+ case Link1000:
return 1000;
- if(link & Link100)
+ case Link100:
return 100;
- if(link & Link10)
+ case Link10:
return 10;
+ }
return 0;
}
@@ -656,9 +668,10 @@
{0x07, 0xae, 0x07, 0x04, 0xff},
{0x07, 0xcc, 0x4c, 0x04, 0x08}
};
- ushort mode, fd;
- uchar link;
+ ushort mode;
+ uchar usbspd;
int spd;
+ int link;
a179set2(d, Cphy, 0);
a179set2(d, Cphy, Cphyiprl);
@@ -665,6 +678,14 @@
sleep(200);
a179set1(d, Csclk, Sclkacs|Sclkbcs);
sleep(100);
+
+ /*
+ * 88179 & 88179a differ by release number
+ */
+ if(d->usb->dno & Dno179a)
+ /* Make 88179a use 88179 firmware compat. */
+ a179set1(d, Cfwmd, Fwmd179);
+
a179set1(d, Cpwtrl, 0x34);
a179set1(d, Cpwtrh, 0x52);
if(setmac){
@@ -674,8 +695,9 @@
return -1;
if(a179set2(d, Crxctl, Rxall179) < 0)
return -1;
- if(a179set1(d, Cmmsr, Mpmetyp|Mpmepol|Mrwmp) < 0)
+ if(a179set1(d, Cmmsr, 0) < 0)
return -1;
+
if(a179set(d, Capo, 0, 0, nil, 0) < 0)
return -1;
@@ -683,25 +705,31 @@
return -1;
spd = 3; /* default bulkinq */
- mode = Mtfc | Mrfc | Mre;
- a179get(d, Amac, Physts, 1, &link, 1);
- if(link & Link1000){
+ mode = Mtfc|Mrfc|Mre;
+ if(a179get(d, Amac, Phyusb, 1, &usbspd, 1) < 0)
+ return -1;
+ if((link = a179miiread(d, Physr)) < 0)
+ return -1;
+ switch(link & Linkmask){
+ case Link1000:
mode |= Mgm|Mmhz|Mjfe|Munk;
- if(link & Usbss)
+ if(usbspd & Usbss)
spd = 0;
- else if(link & Usbhs)
+ else if(usbspd & Usbhs)
spd = 1;
- }else if(link & Link100){
+ break;
+ case Link100:
mode |= Mps;
- if(link & (Usbss|Usbhs))
+ if(usbspd & (Usbss|Usbhs))
spd = 2;
- } /* Link10 */
+ case Link10:
+ break;
+ }
a179set(d, Amac, Cblkinq, 5, qctrl[spd], 5);
a179bufsz = 1024*(qctrl[spd][3]+2);
- fd = a179miiread(d, Phyfd);
- if(fd & Linkfd)
- mode |= Mfd;
+ if(link & Linkfd)
+ mode |= Mfd;
if(a179set2(d, Cmed, mode) < 0)
return -1;
reply other threads:[~2025-03-14 1:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=FF9CE2CC9E796089AAB21BFB95F894BC@oneiri.one \
--to=akw@oneiri.one \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).