ether82557.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. /*
  2. * Intel 82557 Fast Ethernet PCI Bus LAN Controller
  3. * as found on the Intel EtherExpress PRO/100B. This chip is full
  4. * of smarts, unfortunately they're not all in the right place.
  5. * To do:
  6. * the PCI scanning code could be made common to other adapters;
  7. * auto-negotiation, full-duplex;
  8. * optionally use memory-mapped registers;
  9. * detach for PCI reset problems (also towards loadable drivers).
  10. */
  11. #include "u.h"
  12. #include "../port/lib.h"
  13. #include "mem.h"
  14. #include "dat.h"
  15. #include "fns.h"
  16. #include "io.h"
  17. #include "../port/error.h"
  18. #include "../port/netif.h"
  19. #include "etherif.h"
  20. enum {
  21. Nrfd = 64, /* receive frame area */
  22. Ncb = 64, /* maximum control blocks queued */
  23. NullPointer = 0xFFFFFFFF, /* 82557 NULL pointer */
  24. };
  25. enum { /* CSR */
  26. Status = 0x00, /* byte or word (word includes Ack) */
  27. Ack = 0x01, /* byte */
  28. CommandR = 0x02, /* byte or word (word includes Interrupt) */
  29. Interrupt = 0x03, /* byte */
  30. General = 0x04, /* dword */
  31. Port = 0x08, /* dword */
  32. Fcr = 0x0C, /* Flash control register */
  33. Ecr = 0x0E, /* EEPROM control register */
  34. Mcr = 0x10, /* MDI control register */
  35. Gstatus = 0x1D, /* General status register */
  36. };
  37. enum { /* Status */
  38. RUidle = 0x0000,
  39. RUsuspended = 0x0004,
  40. RUnoresources = 0x0008,
  41. RUready = 0x0010,
  42. RUrbd = 0x0020, /* bit */
  43. RUstatus = 0x003F, /* mask */
  44. CUidle = 0x0000,
  45. CUsuspended = 0x0040,
  46. CUactive = 0x0080,
  47. CUstatus = 0x00C0, /* mask */
  48. StatSWI = 0x0400, /* SoftWare generated Interrupt */
  49. StatMDI = 0x0800, /* MDI r/w done */
  50. StatRNR = 0x1000, /* Receive unit Not Ready */
  51. StatCNA = 0x2000, /* Command unit Not Active (Active->Idle) */
  52. StatFR = 0x4000, /* Finished Receiving */
  53. StatCX = 0x8000, /* Command eXecuted */
  54. StatTNO = 0x8000, /* Transmit NOT OK */
  55. };
  56. enum { /* Command (byte) */
  57. CUnop = 0x00,
  58. CUstart = 0x10,
  59. CUresume = 0x20,
  60. LoadDCA = 0x40, /* Load Dump Counters Address */
  61. DumpSC = 0x50, /* Dump Statistical Counters */
  62. LoadCUB = 0x60, /* Load CU Base */
  63. ResetSA = 0x70, /* Dump and Reset Statistical Counters */
  64. RUstart = 0x01,
  65. RUresume = 0x02,
  66. RUabort = 0x04,
  67. LoadHDS = 0x05, /* Load Header Data Size */
  68. LoadRUB = 0x06, /* Load RU Base */
  69. RBDresume = 0x07, /* Resume frame reception */
  70. };
  71. enum { /* Interrupt (byte) */
  72. InterruptM = 0x01, /* interrupt Mask */
  73. InterruptSI = 0x02, /* Software generated Interrupt */
  74. };
  75. enum { /* Ecr */
  76. EEsk = 0x01, /* serial clock */
  77. EEcs = 0x02, /* chip select */
  78. EEdi = 0x04, /* serial data in */
  79. EEdo = 0x08, /* serial data out */
  80. EEstart = 0x04, /* start bit */
  81. EEread = 0x02, /* read opcode */
  82. };
  83. enum { /* Mcr */
  84. MDIread = 0x08000000, /* read opcode */
  85. MDIwrite = 0x04000000, /* write opcode */
  86. MDIready = 0x10000000, /* ready bit */
  87. MDIie = 0x20000000, /* interrupt enable */
  88. };
  89. typedef struct Rfd {
  90. int field;
  91. ulong link;
  92. ulong rbd;
  93. ushort count;
  94. ushort size;
  95. uchar data[1700];
  96. } Rfd;
  97. enum { /* field */
  98. RfdCollision = 0x00000001,
  99. RfdIA = 0x00000002, /* IA match */
  100. RfdRxerr = 0x00000010, /* PHY character error */
  101. RfdType = 0x00000020, /* Type frame */
  102. RfdRunt = 0x00000080,
  103. RfdOverrun = 0x00000100,
  104. RfdBuffer = 0x00000200,
  105. RfdAlignment = 0x00000400,
  106. RfdCRC = 0x00000800,
  107. RfdOK = 0x00002000, /* frame received OK */
  108. RfdC = 0x00008000, /* reception Complete */
  109. RfdSF = 0x00080000, /* Simplified or Flexible (1) Rfd */
  110. RfdH = 0x00100000, /* Header RFD */
  111. RfdI = 0x20000000, /* Interrupt after completion */
  112. RfdS = 0x40000000, /* Suspend after completion */
  113. RfdEL = 0x80000000, /* End of List */
  114. };
  115. enum { /* count */
  116. RfdF = 0x4000,
  117. RfdEOF = 0x8000,
  118. };
  119. typedef struct Cb Cb;
  120. typedef struct Cb {
  121. ushort status;
  122. ushort command;
  123. ulong link;
  124. union {
  125. uchar data[24]; /* CbIAS + CbConfigure */
  126. struct {
  127. ulong tbd;
  128. ushort count;
  129. uchar threshold;
  130. uchar number;
  131. ulong tba;
  132. ushort tbasz;
  133. ushort pad;
  134. };
  135. };
  136. Block* bp;
  137. Cb* next;
  138. } Cb;
  139. enum { /* action command */
  140. CbU = 0x1000, /* transmit underrun */
  141. CbOK = 0x2000, /* DMA completed OK */
  142. CbC = 0x8000, /* execution Complete */
  143. CbNOP = 0x0000,
  144. CbIAS = 0x0001, /* Individual Address Setup */
  145. CbConfigure = 0x0002,
  146. CbMAS = 0x0003, /* Multicast Address Setup */
  147. CbTransmit = 0x0004,
  148. CbDump = 0x0006,
  149. CbDiagnose = 0x0007,
  150. CbCommand = 0x0007, /* mask */
  151. CbSF = 0x0008, /* Flexible-mode CbTransmit */
  152. CbI = 0x2000, /* Interrupt after completion */
  153. CbS = 0x4000, /* Suspend after completion */
  154. CbEL = 0x8000, /* End of List */
  155. };
  156. enum { /* CbTransmit count */
  157. CbEOF = 0x8000,
  158. };
  159. typedef struct Ctlr Ctlr;
  160. typedef struct Ctlr {
  161. Lock slock; /* attach */
  162. int state;
  163. int port;
  164. Pcidev* pcidev;
  165. Ctlr* next;
  166. int active;
  167. int eepromsz; /* address size in bits */
  168. ushort* eeprom;
  169. Lock miilock;
  170. int tick;
  171. Lock rlock; /* registers */
  172. int command; /* last command issued */
  173. Block* rfdhead; /* receive side */
  174. Block* rfdtail;
  175. int nrfd;
  176. Lock cblock; /* transmit side */
  177. int action;
  178. int nop;
  179. uchar configdata[24];
  180. int threshold;
  181. int ncb;
  182. Cb* cbr;
  183. Cb* cbhead;
  184. Cb* cbtail;
  185. int cbq;
  186. int cbqmax;
  187. int cbqmaxhw;
  188. Lock dlock; /* dump statistical counters */
  189. ulong dump[17];
  190. } Ctlr;
  191. static Ctlr* ctlrhead;
  192. static Ctlr* ctlrtail;
  193. static uchar configdata[24] = {
  194. 0x16, /* byte count */
  195. 0x08, /* Rx/Tx FIFO limit */
  196. 0x00, /* adaptive IFS */
  197. 0x00,
  198. 0x00, /* Rx DMA maximum byte count */
  199. // 0x80, /* Tx DMA maximum byte count */
  200. 0x00, /* Tx DMA maximum byte count */
  201. 0x32, /* !late SCB, CNA interrupts */
  202. 0x03, /* discard short Rx frames */
  203. 0x00, /* 503/MII */
  204. 0x00,
  205. 0x2E, /* normal operation, NSAI */
  206. 0x00, /* linear priority */
  207. 0x60, /* inter-frame spacing */
  208. 0x00,
  209. 0xF2,
  210. 0xC8, /* 503, promiscuous mode off */
  211. 0x00,
  212. 0x40,
  213. 0xF3, /* transmit padding enable */
  214. 0x80, /* full duplex pin enable */
  215. 0x3F, /* no Multi IA */
  216. 0x05, /* no Multi Cast ALL */
  217. };
  218. #define csr8r(c, r) (inb((c)->port+(r)))
  219. #define csr16r(c, r) (ins((c)->port+(r)))
  220. #define csr32r(c, r) (inl((c)->port+(r)))
  221. #define csr8w(c, r, b) (outb((c)->port+(r), (int)(b)))
  222. #define csr16w(c, r, w) (outs((c)->port+(r), (ushort)(w)))
  223. #define csr32w(c, r, l) (outl((c)->port+(r), (ulong)(l)))
  224. static void
  225. command(Ctlr* ctlr, int c, int v)
  226. {
  227. int timeo;
  228. ilock(&ctlr->rlock);
  229. /*
  230. * Only back-to-back CUresume can be done
  231. * without waiting for any previous command to complete.
  232. * This should be the common case.
  233. * Unfortunately there's a chip errata where back-to-back
  234. * CUresumes can be lost, the fix is to always wait.
  235. if(c == CUresume && ctlr->command == CUresume){
  236. csr8w(ctlr, CommandR, c);
  237. iunlock(&ctlr->rlock);
  238. return;
  239. }
  240. */
  241. for(timeo = 0; timeo < 100; timeo++){
  242. if(!csr8r(ctlr, CommandR))
  243. break;
  244. microdelay(1);
  245. }
  246. if(timeo >= 100){
  247. ctlr->command = -1;
  248. iunlock(&ctlr->rlock);
  249. iprint("i82557: command %#ux %#ux timeout\n", c, v);
  250. return;
  251. }
  252. switch(c){
  253. case CUstart:
  254. case LoadDCA:
  255. case LoadCUB:
  256. case RUstart:
  257. case LoadHDS:
  258. case LoadRUB:
  259. csr32w(ctlr, General, v);
  260. break;
  261. /*
  262. case CUnop:
  263. case CUresume:
  264. case DumpSC:
  265. case ResetSA:
  266. case RUresume:
  267. case RUabort:
  268. */
  269. default:
  270. break;
  271. }
  272. csr8w(ctlr, CommandR, c);
  273. ctlr->command = c;
  274. iunlock(&ctlr->rlock);
  275. }
  276. static Block*
  277. rfdalloc(ulong link)
  278. {
  279. Block *bp;
  280. Rfd *rfd;
  281. if(bp = iallocb(sizeof(Rfd))){
  282. rfd = (Rfd*)bp->rp;
  283. rfd->field = 0;
  284. rfd->link = link;
  285. rfd->rbd = NullPointer;
  286. rfd->count = 0;
  287. rfd->size = sizeof(Etherpkt);
  288. }
  289. return bp;
  290. }
  291. static void
  292. watchdog(void* arg)
  293. {
  294. Ether *ether;
  295. Ctlr *ctlr;
  296. static void txstart(Ether*);
  297. ether = arg;
  298. for(;;){
  299. tsleep(&up->sleep, return0, 0, 4000);
  300. /*
  301. * Hmmm. This doesn't seem right. Currently
  302. * the device can't be disabled but it may be in
  303. * the future.
  304. */
  305. ctlr = ether->ctlr;
  306. if(ctlr == nil || ctlr->state == 0){
  307. print("%s: exiting\n", up->text);
  308. pexit("disabled", 0);
  309. }
  310. ilock(&ctlr->cblock);
  311. if(ctlr->tick++){
  312. ctlr->action = CbMAS;
  313. txstart(ether);
  314. }
  315. iunlock(&ctlr->cblock);
  316. }
  317. }
  318. static void
  319. attach(Ether* ether)
  320. {
  321. Ctlr *ctlr;
  322. char name[KNAMELEN];
  323. ctlr = ether->ctlr;
  324. lock(&ctlr->slock);
  325. if(ctlr->state == 0){
  326. ilock(&ctlr->rlock);
  327. csr8w(ctlr, Interrupt, 0);
  328. iunlock(&ctlr->rlock);
  329. command(ctlr, RUstart, PADDR(ctlr->rfdhead->rp));
  330. ctlr->state = 1;
  331. /*
  332. * Start the watchdog timer for the receive lockup errata
  333. * unless the EEPROM compatibility word indicates it may be
  334. * omitted.
  335. */
  336. if((ctlr->eeprom[0x03] & 0x0003) != 0x0003){
  337. snprint(name, KNAMELEN, "#l%dwatchdog", ether->ctlrno);
  338. kproc(name, watchdog, ether);
  339. }
  340. }
  341. unlock(&ctlr->slock);
  342. }
  343. static long
  344. ifstat(Ether* ether, void* a, long n, ulong offset)
  345. {
  346. char *p;
  347. int i, len, phyaddr;
  348. Ctlr *ctlr;
  349. ulong dump[17];
  350. ctlr = ether->ctlr;
  351. lock(&ctlr->dlock);
  352. /*
  353. * Start the command then
  354. * wait for completion status,
  355. * should be 0xA005.
  356. */
  357. ctlr->dump[16] = 0;
  358. command(ctlr, DumpSC, 0);
  359. while(ctlr->dump[16] == 0)
  360. ;
  361. ether->oerrs = ctlr->dump[1]+ctlr->dump[2]+ctlr->dump[3];
  362. ether->crcs = ctlr->dump[10];
  363. ether->frames = ctlr->dump[11];
  364. ether->buffs = ctlr->dump[12]+ctlr->dump[15];
  365. ether->overflows = ctlr->dump[13];
  366. if(n == 0){
  367. unlock(&ctlr->dlock);
  368. return 0;
  369. }
  370. memmove(dump, ctlr->dump, sizeof(dump));
  371. unlock(&ctlr->dlock);
  372. p = malloc(READSTR);
  373. len = snprint(p, READSTR, "transmit good frames: %lud\n", dump[0]);
  374. len += snprint(p+len, READSTR-len, "transmit maximum collisions errors: %lud\n", dump[1]);
  375. len += snprint(p+len, READSTR-len, "transmit late collisions errors: %lud\n", dump[2]);
  376. len += snprint(p+len, READSTR-len, "transmit underrun errors: %lud\n", dump[3]);
  377. len += snprint(p+len, READSTR-len, "transmit lost carrier sense: %lud\n", dump[4]);
  378. len += snprint(p+len, READSTR-len, "transmit deferred: %lud\n", dump[5]);
  379. len += snprint(p+len, READSTR-len, "transmit single collisions: %lud\n", dump[6]);
  380. len += snprint(p+len, READSTR-len, "transmit multiple collisions: %lud\n", dump[7]);
  381. len += snprint(p+len, READSTR-len, "transmit total collisions: %lud\n", dump[8]);
  382. len += snprint(p+len, READSTR-len, "receive good frames: %lud\n", dump[9]);
  383. len += snprint(p+len, READSTR-len, "receive CRC errors: %lud\n", dump[10]);
  384. len += snprint(p+len, READSTR-len, "receive alignment errors: %lud\n", dump[11]);
  385. len += snprint(p+len, READSTR-len, "receive resource errors: %lud\n", dump[12]);
  386. len += snprint(p+len, READSTR-len, "receive overrun errors: %lud\n", dump[13]);
  387. len += snprint(p+len, READSTR-len, "receive collision detect errors: %lud\n", dump[14]);
  388. len += snprint(p+len, READSTR-len, "receive short frame errors: %lud\n", dump[15]);
  389. len += snprint(p+len, READSTR-len, "nop: %d\n", ctlr->nop);
  390. if(ctlr->cbqmax > ctlr->cbqmaxhw)
  391. ctlr->cbqmaxhw = ctlr->cbqmax;
  392. len += snprint(p+len, READSTR-len, "cbqmax: %d\n", ctlr->cbqmax);
  393. ctlr->cbqmax = 0;
  394. len += snprint(p+len, READSTR-len, "threshold: %d\n", ctlr->threshold);
  395. len += snprint(p+len, READSTR-len, "eeprom:");
  396. for(i = 0; i < (1<<ctlr->eepromsz); i++){
  397. if(i && ((i & 0x07) == 0))
  398. len += snprint(p+len, READSTR-len, "\n ");
  399. len += snprint(p+len, READSTR-len, " %4.4ux", ctlr->eeprom[i]);
  400. }
  401. if((ctlr->eeprom[6] & 0x1F00) && !(ctlr->eeprom[6] & 0x8000)){
  402. phyaddr = ctlr->eeprom[6] & 0x00FF;
  403. len += snprint(p+len, READSTR-len, "\nphy %2d:", phyaddr);
  404. for(i = 0; i < 6; i++){
  405. static int miir(Ctlr*, int, int);
  406. len += snprint(p+len, READSTR-len, " %4.4ux",
  407. miir(ctlr, phyaddr, i));
  408. }
  409. }
  410. snprint(p+len, READSTR-len, "\n");
  411. n = readstr(offset, a, n, p);
  412. free(p);
  413. return n;
  414. }
  415. static void
  416. txstart(Ether* ether)
  417. {
  418. Ctlr *ctlr;
  419. Block *bp;
  420. Cb *cb;
  421. ctlr = ether->ctlr;
  422. while(ctlr->cbq < (ctlr->ncb-1)){
  423. cb = ctlr->cbhead->next;
  424. if(ctlr->action == 0){
  425. bp = qget(ether->oq);
  426. if(bp == nil)
  427. break;
  428. cb->command = CbS|CbSF|CbTransmit;
  429. cb->tbd = PADDR(&cb->tba);
  430. cb->count = 0;
  431. cb->threshold = ctlr->threshold;
  432. cb->number = 1;
  433. cb->tba = PADDR(bp->rp);
  434. cb->bp = bp;
  435. cb->tbasz = BLEN(bp);
  436. }
  437. else if(ctlr->action == CbConfigure){
  438. cb->command = CbS|CbConfigure;
  439. memmove(cb->data, ctlr->configdata, sizeof(ctlr->configdata));
  440. ctlr->action = 0;
  441. }
  442. else if(ctlr->action == CbIAS){
  443. cb->command = CbS|CbIAS;
  444. memmove(cb->data, ether->ea, Eaddrlen);
  445. ctlr->action = 0;
  446. }
  447. else if(ctlr->action == CbMAS){
  448. cb->command = CbS|CbMAS;
  449. memset(cb->data, 0, sizeof(cb->data));
  450. ctlr->action = 0;
  451. }
  452. else{
  453. print("#l%d: action %#ux\n", ether->ctlrno, ctlr->action);
  454. ctlr->action = 0;
  455. break;
  456. }
  457. cb->status = 0;
  458. coherence();
  459. ctlr->cbhead->command &= ~CbS;
  460. ctlr->cbhead = cb;
  461. ctlr->cbq++;
  462. }
  463. /*
  464. * Workaround for some broken HUB chips
  465. * when connected at 10Mb/s half-duplex.
  466. */
  467. if(ctlr->nop){
  468. command(ctlr, CUnop, 0);
  469. microdelay(1);
  470. }
  471. command(ctlr, CUresume, 0);
  472. if(ctlr->cbq > ctlr->cbqmax)
  473. ctlr->cbqmax = ctlr->cbq;
  474. }
  475. static void
  476. configure(Ether* ether, int promiscuous)
  477. {
  478. Ctlr *ctlr;
  479. ctlr = ether->ctlr;
  480. ilock(&ctlr->cblock);
  481. if(promiscuous){
  482. ctlr->configdata[6] |= 0x80; /* Save Bad Frames */
  483. //ctlr->configdata[6] &= ~0x40; /* !Discard Overrun Rx Frames */
  484. ctlr->configdata[7] &= ~0x01; /* !Discard Short Rx Frames */
  485. ctlr->configdata[15] |= 0x01; /* Promiscuous mode */
  486. ctlr->configdata[18] &= ~0x01; /* (!Padding enable?), !stripping enable */
  487. ctlr->configdata[21] |= 0x08; /* Multi Cast ALL */
  488. }
  489. else{
  490. ctlr->configdata[6] &= ~0x80;
  491. //ctlr->configdata[6] |= 0x40;
  492. ctlr->configdata[7] |= 0x01;
  493. ctlr->configdata[15] &= ~0x01;
  494. ctlr->configdata[18] |= 0x01; /* 0x03? */
  495. ctlr->configdata[21] &= ~0x08;
  496. }
  497. ctlr->action = CbConfigure;
  498. txstart(ether);
  499. iunlock(&ctlr->cblock);
  500. }
  501. static void
  502. promiscuous(void* arg, int on)
  503. {
  504. configure(arg, on);
  505. }
  506. static void
  507. multicast(void* arg, uchar *addr, int on)
  508. {
  509. USED(addr, on);
  510. configure(arg, 1);
  511. }
  512. static void
  513. transmit(Ether* ether)
  514. {
  515. Ctlr *ctlr;
  516. ctlr = ether->ctlr;
  517. ilock(&ctlr->cblock);
  518. txstart(ether);
  519. iunlock(&ctlr->cblock);
  520. }
  521. static void
  522. receive(Ether* ether)
  523. {
  524. Rfd *rfd;
  525. Ctlr *ctlr;
  526. int count;
  527. Block *bp, *pbp, *xbp;
  528. ctlr = ether->ctlr;
  529. bp = ctlr->rfdhead;
  530. for(rfd = (Rfd*)bp->rp; rfd->field & RfdC; rfd = (Rfd*)bp->rp){
  531. /*
  532. * If it's an OK receive frame
  533. * 1) save the count
  534. * 2) if it's small, try to allocate a block and copy
  535. * the data, then adjust the necessary fields for reuse;
  536. * 3) if it's big, try to allocate a new Rfd and if
  537. * successful
  538. * adjust the received buffer pointers for the
  539. * actual data received;
  540. * initialise the replacement buffer to point to
  541. * the next in the ring;
  542. * initialise bp to point to the replacement;
  543. * 4) if there's a good packet, pass it on for disposal.
  544. */
  545. if(rfd->field & RfdOK){
  546. pbp = nil;
  547. count = rfd->count & 0x3FFF;
  548. if((count < ETHERMAXTU/4) && (pbp = iallocb(count))){
  549. memmove(pbp->rp, bp->rp+offsetof(Rfd, data[0]), count);
  550. pbp->wp = pbp->rp + count;
  551. rfd->count = 0;
  552. rfd->field = 0;
  553. }
  554. else if(xbp = rfdalloc(rfd->link)){
  555. bp->rp += offsetof(Rfd, data[0]);
  556. bp->wp = bp->rp + count;
  557. xbp->next = bp->next;
  558. bp->next = 0;
  559. pbp = bp;
  560. bp = xbp;
  561. }
  562. if(pbp != nil)
  563. etheriq(ether, pbp, 1);
  564. }
  565. else{
  566. rfd->count = 0;
  567. rfd->field = 0;
  568. }
  569. /*
  570. * The ring tail pointer follows the head with with one
  571. * unused buffer in between to defeat hardware prefetch;
  572. * once the tail pointer has been bumped on to the next
  573. * and the new tail has the Suspend bit set, it can be
  574. * removed from the old tail buffer.
  575. * As a replacement for the current head buffer may have
  576. * been allocated above, ensure that the new tail points
  577. * to it (next and link).
  578. */
  579. rfd = (Rfd*)ctlr->rfdtail->rp;
  580. ctlr->rfdtail = ctlr->rfdtail->next;
  581. ctlr->rfdtail->next = bp;
  582. ((Rfd*)ctlr->rfdtail->rp)->link = PADDR(bp->rp);
  583. ((Rfd*)ctlr->rfdtail->rp)->field |= RfdS;
  584. coherence();
  585. rfd->field &= ~RfdS;
  586. /*
  587. * Finally done with the current (possibly replaced)
  588. * head, move on to the next and maintain the sentinel
  589. * between tail and head.
  590. */
  591. ctlr->rfdhead = bp->next;
  592. bp = ctlr->rfdhead;
  593. }
  594. }
  595. static void
  596. interrupt(Ureg*, void* arg)
  597. {
  598. Cb* cb;
  599. Ctlr *ctlr;
  600. Ether *ether;
  601. int status;
  602. ether = arg;
  603. ctlr = ether->ctlr;
  604. for(;;){
  605. ilock(&ctlr->rlock);
  606. status = csr16r(ctlr, Status);
  607. csr8w(ctlr, Ack, (status>>8) & 0xFF);
  608. iunlock(&ctlr->rlock);
  609. if(!(status & (StatCX|StatFR|StatCNA|StatRNR|StatMDI|StatSWI)))
  610. break;
  611. /*
  612. * If the watchdog timer for the receiver lockup errata is running,
  613. * let it know the receiver is active.
  614. */
  615. if(status & (StatFR|StatRNR)){
  616. ilock(&ctlr->cblock);
  617. ctlr->tick = 0;
  618. iunlock(&ctlr->cblock);
  619. }
  620. if(status & StatFR){
  621. receive(ether);
  622. status &= ~StatFR;
  623. }
  624. if(status & StatRNR){
  625. command(ctlr, RUresume, 0);
  626. status &= ~StatRNR;
  627. }
  628. if(status & StatCNA){
  629. ilock(&ctlr->cblock);
  630. cb = ctlr->cbtail;
  631. while(ctlr->cbq){
  632. if(!(cb->status & CbC))
  633. break;
  634. if(cb->bp){
  635. freeb(cb->bp);
  636. cb->bp = nil;
  637. }
  638. if((cb->status & CbU) && ctlr->threshold < 0xE0)
  639. ctlr->threshold++;
  640. ctlr->cbq--;
  641. cb = cb->next;
  642. }
  643. ctlr->cbtail = cb;
  644. txstart(ether);
  645. iunlock(&ctlr->cblock);
  646. status &= ~StatCNA;
  647. }
  648. if(status & (StatCX|StatFR|StatCNA|StatRNR|StatMDI|StatSWI))
  649. panic("#l%d: status %#ux\n", ether->ctlrno, status);
  650. }
  651. }
  652. static void
  653. ctlrinit(Ctlr* ctlr)
  654. {
  655. int i;
  656. Block *bp;
  657. Rfd *rfd;
  658. ulong link;
  659. /*
  660. * Create the Receive Frame Area (RFA) as a ring of allocated
  661. * buffers.
  662. * A sentinel buffer is maintained between the last buffer in
  663. * the ring (marked with RfdS) and the head buffer to defeat the
  664. * hardware prefetch of the next RFD and allow dynamic buffer
  665. * allocation.
  666. */
  667. link = NullPointer;
  668. for(i = 0; i < Nrfd; i++){
  669. bp = rfdalloc(link);
  670. if(ctlr->rfdhead == nil)
  671. ctlr->rfdtail = bp;
  672. bp->next = ctlr->rfdhead;
  673. ctlr->rfdhead = bp;
  674. link = PADDR(bp->rp);
  675. }
  676. ctlr->rfdtail->next = ctlr->rfdhead;
  677. rfd = (Rfd*)ctlr->rfdtail->rp;
  678. rfd->link = PADDR(ctlr->rfdhead->rp);
  679. rfd->field |= RfdS;
  680. ctlr->rfdhead = ctlr->rfdhead->next;
  681. /*
  682. * Create a ring of control blocks for the
  683. * transmit side.
  684. */
  685. ilock(&ctlr->cblock);
  686. ctlr->cbr = malloc(ctlr->ncb*sizeof(Cb));
  687. for(i = 0; i < ctlr->ncb; i++){
  688. ctlr->cbr[i].status = CbC|CbOK;
  689. ctlr->cbr[i].command = CbS|CbNOP;
  690. ctlr->cbr[i].link = PADDR(&ctlr->cbr[NEXT(i, ctlr->ncb)].status);
  691. ctlr->cbr[i].next = &ctlr->cbr[NEXT(i, ctlr->ncb)];
  692. }
  693. ctlr->cbhead = ctlr->cbr;
  694. ctlr->cbtail = ctlr->cbr;
  695. ctlr->cbq = 0;
  696. memmove(ctlr->configdata, configdata, sizeof(configdata));
  697. ctlr->threshold = 80;
  698. ctlr->tick = 0;
  699. iunlock(&ctlr->cblock);
  700. }
  701. static int
  702. miir(Ctlr* ctlr, int phyadd, int regadd)
  703. {
  704. int mcr, timo;
  705. lock(&ctlr->miilock);
  706. csr32w(ctlr, Mcr, MDIread|(phyadd<<21)|(regadd<<16));
  707. mcr = 0;
  708. for(timo = 64; timo; timo--){
  709. mcr = csr32r(ctlr, Mcr);
  710. if(mcr & MDIready)
  711. break;
  712. microdelay(1);
  713. }
  714. unlock(&ctlr->miilock);
  715. if(mcr & MDIready)
  716. return mcr & 0xFFFF;
  717. return -1;
  718. }
  719. static int
  720. miiw(Ctlr* ctlr, int phyadd, int regadd, int data)
  721. {
  722. int mcr, timo;
  723. lock(&ctlr->miilock);
  724. csr32w(ctlr, Mcr, MDIwrite|(phyadd<<21)|(regadd<<16)|(data & 0xFFFF));
  725. mcr = 0;
  726. for(timo = 64; timo; timo--){
  727. mcr = csr32r(ctlr, Mcr);
  728. if(mcr & MDIready)
  729. break;
  730. microdelay(1);
  731. }
  732. unlock(&ctlr->miilock);
  733. if(mcr & MDIready)
  734. return 0;
  735. return -1;
  736. }
  737. static int
  738. hy93c46r(Ctlr* ctlr, int r)
  739. {
  740. int data, i, op, size;
  741. /*
  742. * Hyundai HY93C46 or equivalent serial EEPROM.
  743. * This sequence for reading a 16-bit register 'r'
  744. * in the EEPROM is taken straight from Section
  745. * 3.3.4.2 of the Intel 82557 User's Guide.
  746. */
  747. reread:
  748. csr16w(ctlr, Ecr, EEcs);
  749. op = EEstart|EEread;
  750. for(i = 2; i >= 0; i--){
  751. data = (((op>>i) & 0x01)<<2)|EEcs;
  752. csr16w(ctlr, Ecr, data);
  753. csr16w(ctlr, Ecr, data|EEsk);
  754. microdelay(1);
  755. csr16w(ctlr, Ecr, data);
  756. microdelay(1);
  757. }
  758. /*
  759. * First time through must work out the EEPROM size.
  760. */
  761. if((size = ctlr->eepromsz) == 0)
  762. size = 8;
  763. for(size = size-1; size >= 0; size--){
  764. data = (((r>>size) & 0x01)<<2)|EEcs;
  765. csr16w(ctlr, Ecr, data);
  766. csr16w(ctlr, Ecr, data|EEsk);
  767. delay(1);
  768. csr16w(ctlr, Ecr, data);
  769. microdelay(1);
  770. if(!(csr16r(ctlr, Ecr) & EEdo))
  771. break;
  772. }
  773. data = 0;
  774. for(i = 15; i >= 0; i--){
  775. csr16w(ctlr, Ecr, EEcs|EEsk);
  776. microdelay(1);
  777. if(csr16r(ctlr, Ecr) & EEdo)
  778. data |= (1<<i);
  779. csr16w(ctlr, Ecr, EEcs);
  780. microdelay(1);
  781. }
  782. csr16w(ctlr, Ecr, 0);
  783. if(ctlr->eepromsz == 0){
  784. ctlr->eepromsz = 8-size;
  785. ctlr->eeprom = malloc((1<<ctlr->eepromsz)*sizeof(ushort));
  786. goto reread;
  787. }
  788. return data;
  789. }
  790. static void
  791. i82557pci(void)
  792. {
  793. Pcidev *p;
  794. Ctlr *ctlr;
  795. int i, nop, port;
  796. p = nil;
  797. nop = 0;
  798. while(p = pcimatch(p, 0x8086, 0)){
  799. switch(p->did){
  800. default:
  801. continue;
  802. case 0x1031: /* Intel 82562EM */
  803. case 0x1050: /* Intel 82562EZ */
  804. case 0x1039: /* Intel 82801BD PRO/100 VE */
  805. case 0x103A: /* Intel 82562 PRO/100 VE */
  806. case 0x103D: /* Intel 82562 PRO/100 VE */
  807. case 0x1064: /* Intel 82562 PRO/100 VE */
  808. case 0x2449: /* Intel 82562ET */
  809. nop = 1;
  810. /*FALLTHROUGH*/
  811. case 0x1209: /* Intel 82559ER */
  812. case 0x1229: /* Intel 8255[789] */
  813. case 0x1030: /* Intel 82559 InBusiness 10/100 */
  814. break;
  815. }
  816. if(pcigetpms(p) > 0){
  817. pcisetpms(p, 0);
  818. for(i = 0; i < 6; i++)
  819. pcicfgw32(p, PciBAR0+i*4, p->mem[i].bar);
  820. pcicfgw8(p, PciINTL, p->intl);
  821. pcicfgw8(p, PciLTR, p->ltr);
  822. pcicfgw8(p, PciCLS, p->cls);
  823. pcicfgw16(p, PciPCR, p->pcr);
  824. }
  825. /*
  826. * bar[0] is the memory-mapped register address (4KB),
  827. * bar[1] is the I/O port register address (32 bytes) and
  828. * bar[2] is for the flash ROM (1MB).
  829. */
  830. port = p->mem[1].bar & ~0x01;
  831. if(ioalloc(port, p->mem[1].size, 0, "i82557") < 0){
  832. print("i82557: port %#ux in use\n", port);
  833. continue;
  834. }
  835. ctlr = malloc(sizeof(Ctlr));
  836. ctlr->port = port;
  837. ctlr->pcidev = p;
  838. ctlr->nop = nop;
  839. if(ctlrhead != nil)
  840. ctlrtail->next = ctlr;
  841. else
  842. ctlrhead = ctlr;
  843. ctlrtail = ctlr;
  844. pcisetbme(p);
  845. }
  846. }
  847. static char* mediatable[9] = {
  848. "10BASE-T", /* TP */
  849. "10BASE-2", /* BNC */
  850. "10BASE-5", /* AUI */
  851. "100BASE-TX",
  852. "10BASE-TFD",
  853. "100BASE-TXFD",
  854. "100BASE-T4",
  855. "100BASE-FX",
  856. "100BASE-FXFD",
  857. };
  858. static int
  859. scanphy(Ctlr* ctlr)
  860. {
  861. int i, oui, x;
  862. for(i = 0; i < 32; i++){
  863. if((oui = miir(ctlr, i, 2)) == -1 || oui == 0 || oui == 0xFFFF)
  864. continue;
  865. oui <<= 6;
  866. x = miir(ctlr, i, 3);
  867. oui |= x>>10;
  868. //print("phy%d: oui %#ux reg1 %#ux\n", i, oui, miir(ctlr, i, 1));
  869. ctlr->eeprom[6] = i;
  870. if(oui == 0xAA00)
  871. ctlr->eeprom[6] |= 0x07<<8;
  872. else if(oui == 0x80017){
  873. if(x & 0x01)
  874. ctlr->eeprom[6] |= 0x0A<<8;
  875. else
  876. ctlr->eeprom[6] |= 0x04<<8;
  877. }
  878. return i;
  879. }
  880. return -1;
  881. }
  882. static void
  883. shutdown(Ether* ether)
  884. {
  885. Ctlr *ctlr = ether->ctlr;
  886. print("ether82557 shutting down\n");
  887. csr32w(ctlr, Port, 0);
  888. delay(1);
  889. csr8w(ctlr, Interrupt, InterruptM);
  890. }
  891. static int
  892. reset(Ether* ether)
  893. {
  894. int anar, anlpar, bmcr, bmsr, i, k, medium, phyaddr, x;
  895. unsigned short sum;
  896. uchar ea[Eaddrlen];
  897. Ctlr *ctlr;
  898. if(ctlrhead == nil)
  899. i82557pci();
  900. /*
  901. * Any adapter matches if no ether->port is supplied,
  902. * otherwise the ports must match.
  903. */
  904. for(ctlr = ctlrhead; ctlr != nil; ctlr = ctlr->next){
  905. if(ctlr->active)
  906. continue;
  907. if(ether->port == 0 || ether->port == ctlr->port){
  908. ctlr->active = 1;
  909. break;
  910. }
  911. }
  912. if(ctlr == nil)
  913. return -1;
  914. /*
  915. * Initialise the Ctlr structure.
  916. * Perform a software reset after which should ensure busmastering
  917. * is still enabled. The EtherExpress PRO/100B appears to leave
  918. * the PCI configuration alone (see the 'To do' list above) so punt
  919. * for now.
  920. * Load the RUB and CUB registers for linear addressing (0).
  921. */
  922. ether->ctlr = ctlr;
  923. ether->port = ctlr->port;
  924. ether->irq = ctlr->pcidev->intl;
  925. ether->tbdf = ctlr->pcidev->tbdf;
  926. ilock(&ctlr->rlock);
  927. csr32w(ctlr, Port, 0);
  928. delay(1);
  929. csr8w(ctlr, Interrupt, InterruptM);
  930. iunlock(&ctlr->rlock);
  931. command(ctlr, LoadRUB, 0);
  932. command(ctlr, LoadCUB, 0);
  933. command(ctlr, LoadDCA, PADDR(ctlr->dump));
  934. /*
  935. * Initialise the receive frame, transmit ring and configuration areas.
  936. */
  937. ctlr->ncb = Ncb;
  938. ctlrinit(ctlr);
  939. /*
  940. * Read the EEPROM.
  941. * Do a dummy read first to get the size
  942. * and allocate ctlr->eeprom.
  943. */
  944. hy93c46r(ctlr, 0);
  945. sum = 0;
  946. for(i = 0; i < (1<<ctlr->eepromsz); i++){
  947. x = hy93c46r(ctlr, i);
  948. ctlr->eeprom[i] = x;
  949. sum += x;
  950. }
  951. if(sum != 0xBABA)
  952. print("#l%d: EEPROM checksum - %#4.4ux\n", ether->ctlrno, sum);
  953. /*
  954. * Eeprom[6] indicates whether there is a PHY and whether
  955. * it's not 10Mb-only, in which case use the given PHY address
  956. * to set any PHY specific options and determine the speed.
  957. * Unfortunately, sometimes the EEPROM is blank except for
  958. * the ether address and checksum; in this case look at the
  959. * controller type and if it's am 82558 or 82559 it has an
  960. * embedded PHY so scan for that.
  961. * If no PHY, assume 82503 (serial) operation.
  962. */
  963. if((ctlr->eeprom[6] & 0x1F00) && !(ctlr->eeprom[6] & 0x8000))
  964. phyaddr = ctlr->eeprom[6] & 0x00FF;
  965. else
  966. switch(ctlr->pcidev->rid){
  967. case 0x01: /* 82557 A-step */
  968. case 0x02: /* 82557 B-step */
  969. case 0x03: /* 82557 C-step */
  970. default:
  971. phyaddr = -1;
  972. break;
  973. case 0x04: /* 82558 A-step */
  974. case 0x05: /* 82558 B-step */
  975. case 0x06: /* 82559 A-step */
  976. case 0x07: /* 82559 B-step */
  977. case 0x08: /* 82559 C-step */
  978. case 0x09: /* 82559ER A-step */
  979. phyaddr = scanphy(ctlr);
  980. break;
  981. }
  982. if(phyaddr >= 0){
  983. /*
  984. * Resolve the highest common ability of the two
  985. * link partners. In descending order:
  986. * 0x0100 100BASE-TX Full Duplex
  987. * 0x0200 100BASE-T4
  988. * 0x0080 100BASE-TX
  989. * 0x0040 10BASE-T Full Duplex
  990. * 0x0020 10BASE-T
  991. */
  992. anar = miir(ctlr, phyaddr, 0x04);
  993. anlpar = miir(ctlr, phyaddr, 0x05) & 0x03E0;
  994. anar &= anlpar;
  995. bmcr = 0;
  996. if(anar & 0x380)
  997. bmcr = 0x2000;
  998. if(anar & 0x0140)
  999. bmcr |= 0x0100;
  1000. switch((ctlr->eeprom[6]>>8) & 0x001F){
  1001. case 0x04: /* DP83840 */
  1002. case 0x0A: /* DP83840A */
  1003. /*
  1004. * The DP83840[A] requires some tweaking for
  1005. * reliable operation.
  1006. * The manual says bit 10 should be unconditionally
  1007. * set although it supposedly only affects full-duplex
  1008. * operation (an & 0x0140).
  1009. */
  1010. x = miir(ctlr, phyaddr, 0x17) & ~0x0520;
  1011. x |= 0x0420;
  1012. for(i = 0; i < ether->nopt; i++){
  1013. if(cistrcmp(ether->opt[i], "congestioncontrol"))
  1014. continue;
  1015. x |= 0x0100;
  1016. break;
  1017. }
  1018. miiw(ctlr, phyaddr, 0x17, x);
  1019. /*
  1020. * If the link partner can't autonegotiate, determine
  1021. * the speed from elsewhere.
  1022. */
  1023. if(anlpar == 0){
  1024. miir(ctlr, phyaddr, 0x01);
  1025. bmsr = miir(ctlr, phyaddr, 0x01);
  1026. x = miir(ctlr, phyaddr, 0x19);
  1027. if((bmsr & 0x0004) && !(x & 0x0040))
  1028. bmcr = 0x2000;
  1029. }
  1030. break;
  1031. case 0x07: /* Intel 82555 */
  1032. /*
  1033. * Auto-negotiation may fail if the other end is
  1034. * a DP83840A and the cable is short.
  1035. */
  1036. miir(ctlr, phyaddr, 0x01);
  1037. bmsr = miir(ctlr, phyaddr, 0x01);
  1038. if((miir(ctlr, phyaddr, 0) & 0x1000) && !(bmsr & 0x0020)){
  1039. miiw(ctlr, phyaddr, 0x1A, 0x2010);
  1040. x = miir(ctlr, phyaddr, 0);
  1041. miiw(ctlr, phyaddr, 0, 0x0200|x);
  1042. for(i = 0; i < 3000; i++){
  1043. delay(1);
  1044. if(miir(ctlr, phyaddr, 0x01) & 0x0020)
  1045. break;
  1046. }
  1047. miiw(ctlr, phyaddr, 0x1A, 0x2000);
  1048. anar = miir(ctlr, phyaddr, 0x04);
  1049. anlpar = miir(ctlr, phyaddr, 0x05) & 0x03E0;
  1050. anar &= anlpar;
  1051. bmcr = 0;
  1052. if(anar & 0x380)
  1053. bmcr = 0x2000;
  1054. if(anar & 0x0140)
  1055. bmcr |= 0x0100;
  1056. }
  1057. break;
  1058. }
  1059. /*
  1060. * Force speed and duplex if no auto-negotiation.
  1061. */
  1062. if(anlpar == 0){
  1063. medium = -1;
  1064. for(i = 0; i < ether->nopt; i++){
  1065. for(k = 0; k < nelem(mediatable); k++){
  1066. if(cistrcmp(mediatable[k], ether->opt[i]))
  1067. continue;
  1068. medium = k;
  1069. break;
  1070. }
  1071. switch(medium){
  1072. default:
  1073. break;
  1074. case 0x00: /* 10BASE-T */
  1075. case 0x01: /* 10BASE-2 */
  1076. case 0x02: /* 10BASE-5 */
  1077. bmcr &= ~(0x2000|0x0100);
  1078. ctlr->configdata[19] &= ~0x40;
  1079. break;
  1080. case 0x03: /* 100BASE-TX */
  1081. case 0x06: /* 100BASE-T4 */
  1082. case 0x07: /* 100BASE-FX */
  1083. ctlr->configdata[19] &= ~0x40;
  1084. bmcr |= 0x2000;
  1085. break;
  1086. case 0x04: /* 10BASE-TFD */
  1087. bmcr = (bmcr & ~0x2000)|0x0100;
  1088. ctlr->configdata[19] |= 0x40;
  1089. break;
  1090. case 0x05: /* 100BASE-TXFD */
  1091. case 0x08: /* 100BASE-FXFD */
  1092. bmcr |= 0x2000|0x0100;
  1093. ctlr->configdata[19] |= 0x40;
  1094. break;
  1095. }
  1096. }
  1097. if(medium != -1)
  1098. miiw(ctlr, phyaddr, 0x00, bmcr);
  1099. }
  1100. if(bmcr & 0x2000)
  1101. ether->mbps = 100;
  1102. ctlr->configdata[8] = 1;
  1103. ctlr->configdata[15] &= ~0x80;
  1104. }
  1105. else{
  1106. ctlr->configdata[8] = 0;
  1107. ctlr->configdata[15] |= 0x80;
  1108. }
  1109. /*
  1110. * Workaround for some broken HUB chips when connected at 10Mb/s
  1111. * half-duplex.
  1112. * This is a band-aid, but as there's no dynamic auto-negotiation
  1113. * code at the moment, only deactivate the workaround code in txstart
  1114. * if the link is 100Mb/s.
  1115. */
  1116. if(ether->mbps != 10)
  1117. ctlr->nop = 0;
  1118. /*
  1119. * Load the chip configuration and start it off.
  1120. */
  1121. if(ether->oq == 0)
  1122. ether->oq = qopen(256*1024, Qmsg, 0, 0);
  1123. configure(ether, 0);
  1124. command(ctlr, CUstart, PADDR(&ctlr->cbr->status));
  1125. /*
  1126. * Check if the adapter's station address is to be overridden.
  1127. * If not, read it from the EEPROM and set in ether->ea prior to loading
  1128. * the station address with the Individual Address Setup command.
  1129. */
  1130. memset(ea, 0, Eaddrlen);
  1131. if(memcmp(ea, ether->ea, Eaddrlen) == 0){
  1132. for(i = 0; i < Eaddrlen/2; i++){
  1133. x = ctlr->eeprom[i];
  1134. ether->ea[2*i] = x;
  1135. ether->ea[2*i+1] = x>>8;
  1136. }
  1137. }
  1138. ilock(&ctlr->cblock);
  1139. ctlr->action = CbIAS;
  1140. txstart(ether);
  1141. iunlock(&ctlr->cblock);
  1142. /*
  1143. * Linkage to the generic ethernet driver.
  1144. */
  1145. ether->attach = attach;
  1146. ether->transmit = transmit;
  1147. ether->interrupt = interrupt;
  1148. ether->ifstat = ifstat;
  1149. ether->shutdown = shutdown;
  1150. ether->promiscuous = promiscuous;
  1151. ether->multicast = multicast;
  1152. ether->arg = ether;
  1153. return 0;
  1154. }
  1155. void
  1156. ether82557link(void)
  1157. {
  1158. addethercard("i82557", reset);
  1159. }