ether82557.c 30 KB

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