ether82557.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  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 0x1064: /* Intel 82562 PRO/100 VE */
  807. case 0x2449: /* Intel 82562ET */
  808. nop = 1;
  809. /*FALLTHROUGH*/
  810. case 0x1209: /* Intel 82559ER */
  811. case 0x1229: /* Intel 8255[789] */
  812. case 0x1030: /* Intel 82559 InBusiness 10/100 */
  813. break;
  814. }
  815. if(pcigetpms(p) > 0){
  816. pcisetpms(p, 0);
  817. for(i = 0; i < 6; i++)
  818. pcicfgw32(p, PciBAR0+i*4, p->mem[i].bar);
  819. pcicfgw8(p, PciINTL, p->intl);
  820. pcicfgw8(p, PciLTR, p->ltr);
  821. pcicfgw8(p, PciCLS, p->cls);
  822. pcicfgw16(p, PciPCR, p->pcr);
  823. }
  824. /*
  825. * bar[0] is the memory-mapped register address (4KB),
  826. * bar[1] is the I/O port register address (32 bytes) and
  827. * bar[2] is for the flash ROM (1MB).
  828. */
  829. port = p->mem[1].bar & ~0x01;
  830. if(ioalloc(port, p->mem[1].size, 0, "i82557") < 0){
  831. print("i82557: port %#ux in use\n", port);
  832. continue;
  833. }
  834. ctlr = malloc(sizeof(Ctlr));
  835. ctlr->port = port;
  836. ctlr->pcidev = p;
  837. ctlr->nop = nop;
  838. if(ctlrhead != nil)
  839. ctlrtail->next = ctlr;
  840. else
  841. ctlrhead = ctlr;
  842. ctlrtail = ctlr;
  843. pcisetbme(p);
  844. }
  845. }
  846. static char* mediatable[9] = {
  847. "10BASE-T", /* TP */
  848. "10BASE-2", /* BNC */
  849. "10BASE-5", /* AUI */
  850. "100BASE-TX",
  851. "10BASE-TFD",
  852. "100BASE-TXFD",
  853. "100BASE-T4",
  854. "100BASE-FX",
  855. "100BASE-FXFD",
  856. };
  857. static int
  858. scanphy(Ctlr* ctlr)
  859. {
  860. int i, oui, x;
  861. for(i = 0; i < 32; i++){
  862. if((oui = miir(ctlr, i, 2)) == -1 || oui == 0 || oui == 0xFFFF)
  863. continue;
  864. oui <<= 6;
  865. x = miir(ctlr, i, 3);
  866. oui |= x>>10;
  867. //print("phy%d: oui %#ux reg1 %#ux\n", i, oui, miir(ctlr, i, 1));
  868. ctlr->eeprom[6] = i;
  869. if(oui == 0xAA00)
  870. ctlr->eeprom[6] |= 0x07<<8;
  871. else if(oui == 0x80017){
  872. if(x & 0x01)
  873. ctlr->eeprom[6] |= 0x0A<<8;
  874. else
  875. ctlr->eeprom[6] |= 0x04<<8;
  876. }
  877. return i;
  878. }
  879. return -1;
  880. }
  881. static void
  882. shutdown(Ether* ether)
  883. {
  884. Ctlr *ctlr = ether->ctlr;
  885. print("ether82557 shutting down\n");
  886. csr32w(ctlr, Port, 0);
  887. delay(1);
  888. csr8w(ctlr, Interrupt, InterruptM);
  889. }
  890. static int
  891. reset(Ether* ether)
  892. {
  893. int anar, anlpar, bmcr, bmsr, i, k, medium, phyaddr, x;
  894. unsigned short sum;
  895. uchar ea[Eaddrlen];
  896. Ctlr *ctlr;
  897. if(ctlrhead == nil)
  898. i82557pci();
  899. /*
  900. * Any adapter matches if no ether->port is supplied,
  901. * otherwise the ports must match.
  902. */
  903. for(ctlr = ctlrhead; ctlr != nil; ctlr = ctlr->next){
  904. if(ctlr->active)
  905. continue;
  906. if(ether->port == 0 || ether->port == ctlr->port){
  907. ctlr->active = 1;
  908. break;
  909. }
  910. }
  911. if(ctlr == nil)
  912. return -1;
  913. /*
  914. * Initialise the Ctlr structure.
  915. * Perform a software reset after which should ensure busmastering
  916. * is still enabled. The EtherExpress PRO/100B appears to leave
  917. * the PCI configuration alone (see the 'To do' list above) so punt
  918. * for now.
  919. * Load the RUB and CUB registers for linear addressing (0).
  920. */
  921. ether->ctlr = ctlr;
  922. ether->port = ctlr->port;
  923. ether->irq = ctlr->pcidev->intl;
  924. ether->tbdf = ctlr->pcidev->tbdf;
  925. ilock(&ctlr->rlock);
  926. csr32w(ctlr, Port, 0);
  927. delay(1);
  928. csr8w(ctlr, Interrupt, InterruptM);
  929. iunlock(&ctlr->rlock);
  930. command(ctlr, LoadRUB, 0);
  931. command(ctlr, LoadCUB, 0);
  932. command(ctlr, LoadDCA, PADDR(ctlr->dump));
  933. /*
  934. * Initialise the receive frame, transmit ring and configuration areas.
  935. */
  936. ctlr->ncb = Ncb;
  937. ctlrinit(ctlr);
  938. /*
  939. * Read the EEPROM.
  940. * Do a dummy read first to get the size
  941. * and allocate ctlr->eeprom.
  942. */
  943. hy93c46r(ctlr, 0);
  944. sum = 0;
  945. for(i = 0; i < (1<<ctlr->eepromsz); i++){
  946. x = hy93c46r(ctlr, i);
  947. ctlr->eeprom[i] = x;
  948. sum += x;
  949. }
  950. if(sum != 0xBABA)
  951. print("#l%d: EEPROM checksum - %#4.4ux\n", ether->ctlrno, sum);
  952. /*
  953. * Eeprom[6] indicates whether there is a PHY and whether
  954. * it's not 10Mb-only, in which case use the given PHY address
  955. * to set any PHY specific options and determine the speed.
  956. * Unfortunately, sometimes the EEPROM is blank except for
  957. * the ether address and checksum; in this case look at the
  958. * controller type and if it's am 82558 or 82559 it has an
  959. * embedded PHY so scan for that.
  960. * If no PHY, assume 82503 (serial) operation.
  961. */
  962. if((ctlr->eeprom[6] & 0x1F00) && !(ctlr->eeprom[6] & 0x8000))
  963. phyaddr = ctlr->eeprom[6] & 0x00FF;
  964. else
  965. switch(ctlr->pcidev->rid){
  966. case 0x01: /* 82557 A-step */
  967. case 0x02: /* 82557 B-step */
  968. case 0x03: /* 82557 C-step */
  969. default:
  970. phyaddr = -1;
  971. break;
  972. case 0x04: /* 82558 A-step */
  973. case 0x05: /* 82558 B-step */
  974. case 0x06: /* 82559 A-step */
  975. case 0x07: /* 82559 B-step */
  976. case 0x08: /* 82559 C-step */
  977. case 0x09: /* 82559ER A-step */
  978. phyaddr = scanphy(ctlr);
  979. break;
  980. }
  981. if(phyaddr >= 0){
  982. /*
  983. * Resolve the highest common ability of the two
  984. * link partners. In descending order:
  985. * 0x0100 100BASE-TX Full Duplex
  986. * 0x0200 100BASE-T4
  987. * 0x0080 100BASE-TX
  988. * 0x0040 10BASE-T Full Duplex
  989. * 0x0020 10BASE-T
  990. */
  991. anar = miir(ctlr, phyaddr, 0x04);
  992. anlpar = miir(ctlr, phyaddr, 0x05) & 0x03E0;
  993. anar &= anlpar;
  994. bmcr = 0;
  995. if(anar & 0x380)
  996. bmcr = 0x2000;
  997. if(anar & 0x0140)
  998. bmcr |= 0x0100;
  999. switch((ctlr->eeprom[6]>>8) & 0x001F){
  1000. case 0x04: /* DP83840 */
  1001. case 0x0A: /* DP83840A */
  1002. /*
  1003. * The DP83840[A] requires some tweaking for
  1004. * reliable operation.
  1005. * The manual says bit 10 should be unconditionally
  1006. * set although it supposedly only affects full-duplex
  1007. * operation (an & 0x0140).
  1008. */
  1009. x = miir(ctlr, phyaddr, 0x17) & ~0x0520;
  1010. x |= 0x0420;
  1011. for(i = 0; i < ether->nopt; i++){
  1012. if(cistrcmp(ether->opt[i], "congestioncontrol"))
  1013. continue;
  1014. x |= 0x0100;
  1015. break;
  1016. }
  1017. miiw(ctlr, phyaddr, 0x17, x);
  1018. /*
  1019. * If the link partner can't autonegotiate, determine
  1020. * the speed from elsewhere.
  1021. */
  1022. if(anlpar == 0){
  1023. miir(ctlr, phyaddr, 0x01);
  1024. bmsr = miir(ctlr, phyaddr, 0x01);
  1025. x = miir(ctlr, phyaddr, 0x19);
  1026. if((bmsr & 0x0004) && !(x & 0x0040))
  1027. bmcr = 0x2000;
  1028. }
  1029. break;
  1030. case 0x07: /* Intel 82555 */
  1031. /*
  1032. * Auto-negotiation may fail if the other end is
  1033. * a DP83840A and the cable is short.
  1034. */
  1035. miir(ctlr, phyaddr, 0x01);
  1036. bmsr = miir(ctlr, phyaddr, 0x01);
  1037. if((miir(ctlr, phyaddr, 0) & 0x1000) && !(bmsr & 0x0020)){
  1038. miiw(ctlr, phyaddr, 0x1A, 0x2010);
  1039. x = miir(ctlr, phyaddr, 0);
  1040. miiw(ctlr, phyaddr, 0, 0x0200|x);
  1041. for(i = 0; i < 3000; i++){
  1042. delay(1);
  1043. if(miir(ctlr, phyaddr, 0x01) & 0x0020)
  1044. break;
  1045. }
  1046. miiw(ctlr, phyaddr, 0x1A, 0x2000);
  1047. anar = miir(ctlr, phyaddr, 0x04);
  1048. anlpar = miir(ctlr, phyaddr, 0x05) & 0x03E0;
  1049. anar &= anlpar;
  1050. bmcr = 0;
  1051. if(anar & 0x380)
  1052. bmcr = 0x2000;
  1053. if(anar & 0x0140)
  1054. bmcr |= 0x0100;
  1055. }
  1056. break;
  1057. }
  1058. /*
  1059. * Force speed and duplex if no auto-negotiation.
  1060. */
  1061. if(anlpar == 0){
  1062. medium = -1;
  1063. for(i = 0; i < ether->nopt; i++){
  1064. for(k = 0; k < nelem(mediatable); k++){
  1065. if(cistrcmp(mediatable[k], ether->opt[i]))
  1066. continue;
  1067. medium = k;
  1068. break;
  1069. }
  1070. switch(medium){
  1071. default:
  1072. break;
  1073. case 0x00: /* 10BASE-T */
  1074. case 0x01: /* 10BASE-2 */
  1075. case 0x02: /* 10BASE-5 */
  1076. bmcr &= ~(0x2000|0x0100);
  1077. ctlr->configdata[19] &= ~0x40;
  1078. break;
  1079. case 0x03: /* 100BASE-TX */
  1080. case 0x06: /* 100BASE-T4 */
  1081. case 0x07: /* 100BASE-FX */
  1082. ctlr->configdata[19] &= ~0x40;
  1083. bmcr |= 0x2000;
  1084. break;
  1085. case 0x04: /* 10BASE-TFD */
  1086. bmcr = (bmcr & ~0x2000)|0x0100;
  1087. ctlr->configdata[19] |= 0x40;
  1088. break;
  1089. case 0x05: /* 100BASE-TXFD */
  1090. case 0x08: /* 100BASE-FXFD */
  1091. bmcr |= 0x2000|0x0100;
  1092. ctlr->configdata[19] |= 0x40;
  1093. break;
  1094. }
  1095. }
  1096. if(medium != -1)
  1097. miiw(ctlr, phyaddr, 0x00, bmcr);
  1098. }
  1099. if(bmcr & 0x2000)
  1100. ether->mbps = 100;
  1101. ctlr->configdata[8] = 1;
  1102. ctlr->configdata[15] &= ~0x80;
  1103. }
  1104. else{
  1105. ctlr->configdata[8] = 0;
  1106. ctlr->configdata[15] |= 0x80;
  1107. }
  1108. /*
  1109. * Workaround for some broken HUB chips when connected at 10Mb/s
  1110. * half-duplex.
  1111. * This is a band-aid, but as there's no dynamic auto-negotiation
  1112. * code at the moment, only deactivate the workaround code in txstart
  1113. * if the link is 100Mb/s.
  1114. */
  1115. if(ether->mbps != 10)
  1116. ctlr->nop = 0;
  1117. /*
  1118. * Load the chip configuration and start it off.
  1119. */
  1120. if(ether->oq == 0)
  1121. ether->oq = qopen(256*1024, Qmsg, 0, 0);
  1122. configure(ether, 0);
  1123. command(ctlr, CUstart, PADDR(&ctlr->cbr->status));
  1124. /*
  1125. * Check if the adapter's station address is to be overridden.
  1126. * If not, read it from the EEPROM and set in ether->ea prior to loading
  1127. * the station address with the Individual Address Setup command.
  1128. */
  1129. memset(ea, 0, Eaddrlen);
  1130. if(memcmp(ea, ether->ea, Eaddrlen) == 0){
  1131. for(i = 0; i < Eaddrlen/2; i++){
  1132. x = ctlr->eeprom[i];
  1133. ether->ea[2*i] = x;
  1134. ether->ea[2*i+1] = x>>8;
  1135. }
  1136. }
  1137. ilock(&ctlr->cblock);
  1138. ctlr->action = CbIAS;
  1139. txstart(ether);
  1140. iunlock(&ctlr->cblock);
  1141. /*
  1142. * Linkage to the generic ethernet driver.
  1143. */
  1144. ether->attach = attach;
  1145. ether->transmit = transmit;
  1146. ether->interrupt = interrupt;
  1147. ether->ifstat = ifstat;
  1148. ether->shutdown = shutdown;
  1149. ether->promiscuous = promiscuous;
  1150. ether->multicast = multicast;
  1151. ether->arg = ether;
  1152. return 0;
  1153. }
  1154. void
  1155. ether82557link(void)
  1156. {
  1157. addethercard("i82557", reset);
  1158. }