bcm64: work in progress genet ethernet driver for raspberry pi 4

This commit is contained in:
cinap_lenrek 2019-07-25 09:11:53 +02:00
parent 2a4c767c41
commit 3bc4e5a6d5
3 changed files with 1113 additions and 5 deletions

1075
sys/src/9/bcm64/ethergenet.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,8 @@ int
mii(Mii* mii, int mask)
{
MiiPhy *miiphy;
int bit, oui, phyno, r, rmask;
int bit, oui, phyno, rmask;
u32int id;
/*
* Probe through mii for PHYs in mask;
@ -33,10 +34,9 @@ mii(Mii* mii, int mask)
}
if(mii->mir(mii, phyno, Bmsr) == -1)
continue;
r = mii->mir(mii, phyno, Phyidr1);
oui = (r & 0x3FFF)<<6;
r = mii->mir(mii, phyno, Phyidr2);
oui |= r>>10;
id = mii->mir(mii, phyno, Phyidr1) << 16;
id |= mii->mir(mii, phyno, Phyidr2);
oui = (id & 0x3FFFFC00)>>10;
if(oui == 0xFFFFF || oui == 0)
continue;
@ -44,6 +44,7 @@ mii(Mii* mii, int mask)
continue;
miiphy->mii = mii;
miiphy->id = id;
miiphy->oui = oui;
miiphy->phyno = phyno;
@ -233,3 +234,29 @@ miistatus(Mii* mii)
return 0;
}
int
miimmdr(Mii* mii, int a, int r)
{
a &= 0x1F;
if(miimiw(mii, Mmdctrl, a) == -1)
return -1;
if(miimiw(mii, Mmddata, r) == -1)
return -1;
if(miimiw(mii, Mmdctrl, a | 0x4000) == -1)
return -1;
return miimir(mii, Mmddata);
}
int
miimmdw(Mii* mii, int a, int r, int data)
{
a &= 0x1F;
if(miimiw(mii, Mmdctrl, a) == -1)
return -1;
if(miimiw(mii, Mmddata, r) == -1)
return -1;
if(miimiw(mii, Mmdctrl, a | 0x4000) == -1)
return -1;
return miimiw(mii, Mmddata, data);
}

View file

@ -13,6 +13,8 @@ enum { /* registers */
Annprr = 0x08, /* AN Next Page RX */
Mscr = 0x09, /* MASTER-SLAVE Control */
Mssr = 0x0A, /* MASTER-SLAVE Status */
Mmdctrl = 0x0D, /* MMD Access Control */
Mmddata = 0x0E, /* MMD Access Data Register */
Esr = 0x0F, /* Extended Status */
NMiiPhyr = 32,
@ -94,6 +96,7 @@ typedef struct Mii {
typedef struct MiiPhy {
Mii* mii;
u32int id;
int oui;
int phyno;
@ -114,3 +117,6 @@ extern int miimir(Mii*, int);
extern int miimiw(Mii*, int, int);
extern int miireset(Mii*);
extern int miistatus(Mii*);
extern int miimmdr(Mii*, int, int);
extern int miimmdw(Mii*, int, int, int);