ether82557.c 30 KB

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