ether82557.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  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. if(p == nil)
  374. error(Enomem);
  375. len = snprint(p, READSTR, "transmit good frames: %lud\n", dump[0]);
  376. len += snprint(p+len, READSTR-len, "transmit maximum collisions errors: %lud\n", dump[1]);
  377. len += snprint(p+len, READSTR-len, "transmit late collisions errors: %lud\n", dump[2]);
  378. len += snprint(p+len, READSTR-len, "transmit underrun errors: %lud\n", dump[3]);
  379. len += snprint(p+len, READSTR-len, "transmit lost carrier sense: %lud\n", dump[4]);
  380. len += snprint(p+len, READSTR-len, "transmit deferred: %lud\n", dump[5]);
  381. len += snprint(p+len, READSTR-len, "transmit single collisions: %lud\n", dump[6]);
  382. len += snprint(p+len, READSTR-len, "transmit multiple collisions: %lud\n", dump[7]);
  383. len += snprint(p+len, READSTR-len, "transmit total collisions: %lud\n", dump[8]);
  384. len += snprint(p+len, READSTR-len, "receive good frames: %lud\n", dump[9]);
  385. len += snprint(p+len, READSTR-len, "receive CRC errors: %lud\n", dump[10]);
  386. len += snprint(p+len, READSTR-len, "receive alignment errors: %lud\n", dump[11]);
  387. len += snprint(p+len, READSTR-len, "receive resource errors: %lud\n", dump[12]);
  388. len += snprint(p+len, READSTR-len, "receive overrun errors: %lud\n", dump[13]);
  389. len += snprint(p+len, READSTR-len, "receive collision detect errors: %lud\n", dump[14]);
  390. len += snprint(p+len, READSTR-len, "receive short frame errors: %lud\n", dump[15]);
  391. len += snprint(p+len, READSTR-len, "nop: %d\n", ctlr->nop);
  392. if(ctlr->cbqmax > ctlr->cbqmaxhw)
  393. ctlr->cbqmaxhw = ctlr->cbqmax;
  394. len += snprint(p+len, READSTR-len, "cbqmax: %d\n", ctlr->cbqmax);
  395. ctlr->cbqmax = 0;
  396. len += snprint(p+len, READSTR-len, "threshold: %d\n", ctlr->threshold);
  397. len += snprint(p+len, READSTR-len, "eeprom:");
  398. for(i = 0; i < (1<<ctlr->eepromsz); i++){
  399. if(i && ((i & 0x07) == 0))
  400. len += snprint(p+len, READSTR-len, "\n ");
  401. len += snprint(p+len, READSTR-len, " %4.4ux", ctlr->eeprom[i]);
  402. }
  403. if((ctlr->eeprom[6] & 0x1F00) && !(ctlr->eeprom[6] & 0x8000)){
  404. phyaddr = ctlr->eeprom[6] & 0x00FF;
  405. len += snprint(p+len, READSTR-len, "\nphy %2d:", phyaddr);
  406. for(i = 0; i < 6; i++){
  407. static int miir(Ctlr*, int, int);
  408. len += snprint(p+len, READSTR-len, " %4.4ux",
  409. miir(ctlr, phyaddr, i));
  410. }
  411. }
  412. snprint(p+len, READSTR-len, "\n");
  413. n = readstr(offset, a, n, p);
  414. free(p);
  415. return n;
  416. }
  417. static void
  418. txstart(Ether* ether)
  419. {
  420. Ctlr *ctlr;
  421. Block *bp;
  422. Cb *cb;
  423. ctlr = ether->ctlr;
  424. while(ctlr->cbq < (ctlr->ncb-1)){
  425. cb = ctlr->cbhead->next;
  426. if(ctlr->action == 0){
  427. bp = qget(ether->oq);
  428. if(bp == nil)
  429. break;
  430. cb->command = CbS|CbSF|CbTransmit;
  431. cb->tbd = PADDR(&cb->tba);
  432. cb->count = 0;
  433. cb->threshold = ctlr->threshold;
  434. cb->number = 1;
  435. cb->tba = PADDR(bp->rp);
  436. cb->bp = bp;
  437. cb->tbasz = BLEN(bp);
  438. }
  439. else if(ctlr->action == CbConfigure){
  440. cb->command = CbS|CbConfigure;
  441. memmove(cb->data, ctlr->configdata, sizeof(ctlr->configdata));
  442. ctlr->action = 0;
  443. }
  444. else if(ctlr->action == CbIAS){
  445. cb->command = CbS|CbIAS;
  446. memmove(cb->data, ether->ea, Eaddrlen);
  447. ctlr->action = 0;
  448. }
  449. else if(ctlr->action == CbMAS){
  450. cb->command = CbS|CbMAS;
  451. memset(cb->data, 0, sizeof(cb->data));
  452. ctlr->action = 0;
  453. }
  454. else{
  455. print("#l%d: action %#ux\n", ether->ctlrno, ctlr->action);
  456. ctlr->action = 0;
  457. break;
  458. }
  459. cb->status = 0;
  460. coherence();
  461. ctlr->cbhead->command &= ~CbS;
  462. ctlr->cbhead = cb;
  463. ctlr->cbq++;
  464. }
  465. /*
  466. * Workaround for some broken HUB chips
  467. * when connected at 10Mb/s half-duplex.
  468. */
  469. if(ctlr->nop){
  470. command(ctlr, CUnop, 0);
  471. microdelay(1);
  472. }
  473. command(ctlr, CUresume, 0);
  474. if(ctlr->cbq > ctlr->cbqmax)
  475. ctlr->cbqmax = ctlr->cbq;
  476. }
  477. static void
  478. configure(Ether* ether, int promiscuous)
  479. {
  480. Ctlr *ctlr;
  481. ctlr = ether->ctlr;
  482. ilock(&ctlr->cblock);
  483. if(promiscuous){
  484. ctlr->configdata[6] |= 0x80; /* Save Bad Frames */
  485. //ctlr->configdata[6] &= ~0x40; /* !Discard Overrun Rx Frames */
  486. ctlr->configdata[7] &= ~0x01; /* !Discard Short Rx Frames */
  487. ctlr->configdata[15] |= 0x01; /* Promiscuous mode */
  488. ctlr->configdata[18] &= ~0x01; /* (!Padding enable?), !stripping enable */
  489. ctlr->configdata[21] |= 0x08; /* Multi Cast ALL */
  490. }
  491. else{
  492. ctlr->configdata[6] &= ~0x80;
  493. //ctlr->configdata[6] |= 0x40;
  494. ctlr->configdata[7] |= 0x01;
  495. ctlr->configdata[15] &= ~0x01;
  496. ctlr->configdata[18] |= 0x01; /* 0x03? */
  497. ctlr->configdata[21] &= ~0x08;
  498. }
  499. ctlr->action = CbConfigure;
  500. txstart(ether);
  501. iunlock(&ctlr->cblock);
  502. }
  503. static void
  504. promiscuous(void* arg, int on)
  505. {
  506. configure(arg, on);
  507. }
  508. static void
  509. multicast(void* ether, uchar *addr, int add)
  510. {
  511. USED(addr);
  512. /*
  513. * TODO: if (add) add addr to list of mcast addrs in controller
  514. * else remove addr from list of mcast addrs in controller
  515. * enable multicast input (see CbMAS) instead of promiscuous mode.
  516. */
  517. if (add)
  518. configure(ether, 1);
  519. }
  520. static void
  521. transmit(Ether* ether)
  522. {
  523. Ctlr *ctlr;
  524. ctlr = ether->ctlr;
  525. ilock(&ctlr->cblock);
  526. txstart(ether);
  527. iunlock(&ctlr->cblock);
  528. }
  529. static void
  530. receive(Ether* ether)
  531. {
  532. Rfd *rfd;
  533. Ctlr *ctlr;
  534. int count;
  535. Block *bp, *pbp, *xbp;
  536. ctlr = ether->ctlr;
  537. bp = ctlr->rfdhead;
  538. for(rfd = (Rfd*)bp->rp; rfd->field & RfdC; rfd = (Rfd*)bp->rp){
  539. /*
  540. * If it's an OK receive frame
  541. * 1) save the count
  542. * 2) if it's small, try to allocate a block and copy
  543. * the data, then adjust the necessary fields for reuse;
  544. * 3) if it's big, try to allocate a new Rfd and if
  545. * successful
  546. * adjust the received buffer pointers for the
  547. * actual data received;
  548. * initialise the replacement buffer to point to
  549. * the next in the ring;
  550. * initialise bp to point to the replacement;
  551. * 4) if there's a good packet, pass it on for disposal.
  552. */
  553. if(rfd->field & RfdOK){
  554. pbp = nil;
  555. count = rfd->count & 0x3FFF;
  556. if((count < ETHERMAXTU/4) && (pbp = iallocb(count))){
  557. memmove(pbp->rp, bp->rp+offsetof(Rfd, data[0]), count);
  558. pbp->wp = pbp->rp + count;
  559. rfd->count = 0;
  560. rfd->field = 0;
  561. }
  562. else if(xbp = rfdalloc(rfd->link)){
  563. bp->rp += offsetof(Rfd, data[0]);
  564. bp->wp = bp->rp + count;
  565. xbp->next = bp->next;
  566. bp->next = 0;
  567. pbp = bp;
  568. bp = xbp;
  569. }
  570. if(pbp != nil)
  571. etheriq(ether, pbp, 1);
  572. }
  573. else{
  574. rfd->count = 0;
  575. rfd->field = 0;
  576. }
  577. /*
  578. * The ring tail pointer follows the head with with one
  579. * unused buffer in between to defeat hardware prefetch;
  580. * once the tail pointer has been bumped on to the next
  581. * and the new tail has the Suspend bit set, it can be
  582. * removed from the old tail buffer.
  583. * As a replacement for the current head buffer may have
  584. * been allocated above, ensure that the new tail points
  585. * to it (next and link).
  586. */
  587. rfd = (Rfd*)ctlr->rfdtail->rp;
  588. ctlr->rfdtail = ctlr->rfdtail->next;
  589. ctlr->rfdtail->next = bp;
  590. ((Rfd*)ctlr->rfdtail->rp)->link = PADDR(bp->rp);
  591. ((Rfd*)ctlr->rfdtail->rp)->field |= RfdS;
  592. coherence();
  593. rfd->field &= ~RfdS;
  594. /*
  595. * Finally done with the current (possibly replaced)
  596. * head, move on to the next and maintain the sentinel
  597. * between tail and head.
  598. */
  599. ctlr->rfdhead = bp->next;
  600. bp = ctlr->rfdhead;
  601. }
  602. }
  603. static void
  604. interrupt(Ureg*, void* arg)
  605. {
  606. Cb* cb;
  607. Ctlr *ctlr;
  608. Ether *ether;
  609. int status;
  610. ether = arg;
  611. ctlr = ether->ctlr;
  612. for(;;){
  613. ilock(&ctlr->rlock);
  614. status = csr16r(ctlr, Status);
  615. csr8w(ctlr, Ack, (status>>8) & 0xFF);
  616. iunlock(&ctlr->rlock);
  617. if(!(status & (StatCX|StatFR|StatCNA|StatRNR|StatMDI|StatSWI)))
  618. break;
  619. /*
  620. * If the watchdog timer for the receiver lockup errata is running,
  621. * let it know the receiver is active.
  622. */
  623. if(status & (StatFR|StatRNR)){
  624. ilock(&ctlr->cblock);
  625. ctlr->tick = 0;
  626. iunlock(&ctlr->cblock);
  627. }
  628. if(status & StatFR){
  629. receive(ether);
  630. status &= ~StatFR;
  631. }
  632. if(status & StatRNR){
  633. command(ctlr, RUresume, 0);
  634. status &= ~StatRNR;
  635. }
  636. if(status & StatCNA){
  637. ilock(&ctlr->cblock);
  638. cb = ctlr->cbtail;
  639. while(ctlr->cbq){
  640. if(!(cb->status & CbC))
  641. break;
  642. if(cb->bp){
  643. freeb(cb->bp);
  644. cb->bp = nil;
  645. }
  646. if((cb->status & CbU) && ctlr->threshold < 0xE0)
  647. ctlr->threshold++;
  648. ctlr->cbq--;
  649. cb = cb->next;
  650. }
  651. ctlr->cbtail = cb;
  652. txstart(ether);
  653. iunlock(&ctlr->cblock);
  654. status &= ~StatCNA;
  655. }
  656. if(status & (StatCX|StatFR|StatCNA|StatRNR|StatMDI|StatSWI))
  657. panic("#l%d: status %#ux\n", ether->ctlrno, status);
  658. }
  659. }
  660. static void
  661. ctlrinit(Ctlr* ctlr)
  662. {
  663. int i;
  664. Block *bp;
  665. Rfd *rfd;
  666. ulong link;
  667. /*
  668. * Create the Receive Frame Area (RFA) as a ring of allocated
  669. * buffers.
  670. * A sentinel buffer is maintained between the last buffer in
  671. * the ring (marked with RfdS) and the head buffer to defeat the
  672. * hardware prefetch of the next RFD and allow dynamic buffer
  673. * allocation.
  674. */
  675. link = NullPointer;
  676. for(i = 0; i < Nrfd; i++){
  677. bp = rfdalloc(link);
  678. if(ctlr->rfdhead == nil)
  679. ctlr->rfdtail = bp;
  680. bp->next = ctlr->rfdhead;
  681. ctlr->rfdhead = bp;
  682. link = PADDR(bp->rp);
  683. }
  684. ctlr->rfdtail->next = ctlr->rfdhead;
  685. rfd = (Rfd*)ctlr->rfdtail->rp;
  686. rfd->link = PADDR(ctlr->rfdhead->rp);
  687. rfd->field |= RfdS;
  688. ctlr->rfdhead = ctlr->rfdhead->next;
  689. /*
  690. * Create a ring of control blocks for the
  691. * transmit side.
  692. */
  693. ilock(&ctlr->cblock);
  694. ctlr->cbr = malloc(ctlr->ncb*sizeof(Cb));
  695. if(ctlr->cbr == nil) {
  696. iunlock(&ctlr->cblock);
  697. error(Enomem);
  698. }
  699. for(i = 0; i < ctlr->ncb; i++){
  700. ctlr->cbr[i].status = CbC|CbOK;
  701. ctlr->cbr[i].command = CbS|CbNOP;
  702. ctlr->cbr[i].link = PADDR(&ctlr->cbr[NEXT(i, ctlr->ncb)].status);
  703. ctlr->cbr[i].next = &ctlr->cbr[NEXT(i, ctlr->ncb)];
  704. }
  705. ctlr->cbhead = ctlr->cbr;
  706. ctlr->cbtail = ctlr->cbr;
  707. ctlr->cbq = 0;
  708. memmove(ctlr->configdata, configdata, sizeof(configdata));
  709. ctlr->threshold = 80;
  710. ctlr->tick = 0;
  711. iunlock(&ctlr->cblock);
  712. }
  713. static int
  714. miir(Ctlr* ctlr, int phyadd, int regadd)
  715. {
  716. int mcr, timo;
  717. lock(&ctlr->miilock);
  718. csr32w(ctlr, Mcr, MDIread|(phyadd<<21)|(regadd<<16));
  719. mcr = 0;
  720. for(timo = 64; timo; timo--){
  721. mcr = csr32r(ctlr, Mcr);
  722. if(mcr & MDIready)
  723. break;
  724. microdelay(1);
  725. }
  726. unlock(&ctlr->miilock);
  727. if(mcr & MDIready)
  728. return mcr & 0xFFFF;
  729. return -1;
  730. }
  731. static int
  732. miiw(Ctlr* ctlr, int phyadd, int regadd, int data)
  733. {
  734. int mcr, timo;
  735. lock(&ctlr->miilock);
  736. csr32w(ctlr, Mcr, MDIwrite|(phyadd<<21)|(regadd<<16)|(data & 0xFFFF));
  737. mcr = 0;
  738. for(timo = 64; timo; timo--){
  739. mcr = csr32r(ctlr, Mcr);
  740. if(mcr & MDIready)
  741. break;
  742. microdelay(1);
  743. }
  744. unlock(&ctlr->miilock);
  745. if(mcr & MDIready)
  746. return 0;
  747. return -1;
  748. }
  749. static int
  750. hy93c46r(Ctlr* ctlr, int r)
  751. {
  752. int data, i, op, size;
  753. /*
  754. * Hyundai HY93C46 or equivalent serial EEPROM.
  755. * This sequence for reading a 16-bit register 'r'
  756. * in the EEPROM is taken straight from Section
  757. * 3.3.4.2 of the Intel 82557 User's Guide.
  758. */
  759. reread:
  760. csr16w(ctlr, Ecr, EEcs);
  761. op = EEstart|EEread;
  762. for(i = 2; i >= 0; i--){
  763. data = (((op>>i) & 0x01)<<2)|EEcs;
  764. csr16w(ctlr, Ecr, data);
  765. csr16w(ctlr, Ecr, data|EEsk);
  766. microdelay(1);
  767. csr16w(ctlr, Ecr, data);
  768. microdelay(1);
  769. }
  770. /*
  771. * First time through must work out the EEPROM size.
  772. */
  773. if((size = ctlr->eepromsz) == 0)
  774. size = 8;
  775. for(size = size-1; size >= 0; size--){
  776. data = (((r>>size) & 0x01)<<2)|EEcs;
  777. csr16w(ctlr, Ecr, data);
  778. csr16w(ctlr, Ecr, data|EEsk);
  779. delay(1);
  780. csr16w(ctlr, Ecr, data);
  781. microdelay(1);
  782. if(!(csr16r(ctlr, Ecr) & EEdo))
  783. break;
  784. }
  785. data = 0;
  786. for(i = 15; i >= 0; i--){
  787. csr16w(ctlr, Ecr, EEcs|EEsk);
  788. microdelay(1);
  789. if(csr16r(ctlr, Ecr) & EEdo)
  790. data |= (1<<i);
  791. csr16w(ctlr, Ecr, EEcs);
  792. microdelay(1);
  793. }
  794. csr16w(ctlr, Ecr, 0);
  795. if(ctlr->eepromsz == 0){
  796. ctlr->eepromsz = 8-size;
  797. ctlr->eeprom = malloc((1<<ctlr->eepromsz)*sizeof(ushort));
  798. if(ctlr->eeprom == nil)
  799. error(Enomem);
  800. goto reread;
  801. }
  802. return data;
  803. }
  804. static void
  805. i82557pci(void)
  806. {
  807. Pcidev *p;
  808. Ctlr *ctlr;
  809. int i, nop, port;
  810. p = nil;
  811. nop = 0;
  812. while(p = pcimatch(p, 0x8086, 0)){
  813. switch(p->did){
  814. default:
  815. continue;
  816. case 0x1031: /* Intel 82562EM */
  817. case 0x103B: /* Intel 82562EM */
  818. case 0x103C: /* Intel 82562EM */
  819. case 0x1050: /* Intel 82562EZ */
  820. case 0x1039: /* Intel 82801BD PRO/100 VE */
  821. case 0x103A: /* Intel 82562 PRO/100 VE */
  822. case 0x103D: /* Intel 82562 PRO/100 VE */
  823. case 0x1064: /* Intel 82562 PRO/100 VE */
  824. case 0x2449: /* Intel 82562ET */
  825. case 0x27DC: /* Intel 82801G PRO/100 VE */
  826. nop = 1;
  827. /*FALLTHROUGH*/
  828. case 0x1209: /* Intel 82559ER */
  829. case 0x1229: /* Intel 8255[789] */
  830. case 0x1030: /* Intel 82559 InBusiness 10/100 */
  831. break;
  832. }
  833. if(pcigetpms(p) > 0){
  834. pcisetpms(p, 0);
  835. for(i = 0; i < 6; i++)
  836. pcicfgw32(p, PciBAR0+i*4, p->mem[i].bar);
  837. pcicfgw8(p, PciINTL, p->intl);
  838. pcicfgw8(p, PciLTR, p->ltr);
  839. pcicfgw8(p, PciCLS, p->cls);
  840. pcicfgw16(p, PciPCR, p->pcr);
  841. }
  842. /*
  843. * bar[0] is the memory-mapped register address (4KB),
  844. * bar[1] is the I/O port register address (32 bytes) and
  845. * bar[2] is for the flash ROM (1MB).
  846. */
  847. port = p->mem[1].bar & ~0x01;
  848. if(ioalloc(port, p->mem[1].size, 0, "i82557") < 0){
  849. print("i82557: port %#ux in use\n", port);
  850. continue;
  851. }
  852. ctlr = malloc(sizeof(Ctlr));
  853. if(ctlr == nil)
  854. error(Enomem);
  855. ctlr->port = port;
  856. ctlr->pcidev = p;
  857. ctlr->nop = nop;
  858. if(ctlrhead != nil)
  859. ctlrtail->next = ctlr;
  860. else
  861. ctlrhead = ctlr;
  862. ctlrtail = ctlr;
  863. pcisetbme(p);
  864. }
  865. }
  866. static char* mediatable[9] = {
  867. "10BASE-T", /* TP */
  868. "10BASE-2", /* BNC */
  869. "10BASE-5", /* AUI */
  870. "100BASE-TX",
  871. "10BASE-TFD",
  872. "100BASE-TXFD",
  873. "100BASE-T4",
  874. "100BASE-FX",
  875. "100BASE-FXFD",
  876. };
  877. static int
  878. scanphy(Ctlr* ctlr)
  879. {
  880. int i, oui, x;
  881. for(i = 0; i < 32; i++){
  882. if((oui = miir(ctlr, i, 2)) == -1 || oui == 0 || oui == 0xFFFF)
  883. continue;
  884. oui <<= 6;
  885. x = miir(ctlr, i, 3);
  886. oui |= x>>10;
  887. //print("phy%d: oui %#ux reg1 %#ux\n", i, oui, miir(ctlr, i, 1));
  888. ctlr->eeprom[6] = i;
  889. if(oui == 0xAA00)
  890. ctlr->eeprom[6] |= 0x07<<8;
  891. else if(oui == 0x80017){
  892. if(x & 0x01)
  893. ctlr->eeprom[6] |= 0x0A<<8;
  894. else
  895. ctlr->eeprom[6] |= 0x04<<8;
  896. }
  897. return i;
  898. }
  899. return -1;
  900. }
  901. static void
  902. shutdown(Ether* ether)
  903. {
  904. Ctlr *ctlr = ether->ctlr;
  905. print("ether82557 shutting down\n");
  906. csr32w(ctlr, Port, 0);
  907. delay(1);
  908. csr8w(ctlr, Interrupt, InterruptM);
  909. }
  910. static int
  911. reset(Ether* ether)
  912. {
  913. int anar, anlpar, bmcr, bmsr, i, k, medium, phyaddr, x;
  914. unsigned short sum;
  915. uchar ea[Eaddrlen];
  916. Ctlr *ctlr;
  917. if(ctlrhead == nil)
  918. i82557pci();
  919. /*
  920. * Any adapter matches if no ether->port is supplied,
  921. * otherwise the ports must match.
  922. */
  923. for(ctlr = ctlrhead; ctlr != nil; ctlr = ctlr->next){
  924. if(ctlr->active)
  925. continue;
  926. if(ether->port == 0 || ether->port == ctlr->port){
  927. ctlr->active = 1;
  928. break;
  929. }
  930. }
  931. if(ctlr == nil)
  932. return -1;
  933. /*
  934. * Initialise the Ctlr structure.
  935. * Perform a software reset after which should ensure busmastering
  936. * is still enabled. The EtherExpress PRO/100B appears to leave
  937. * the PCI configuration alone (see the 'To do' list above) so punt
  938. * for now.
  939. * Load the RUB and CUB registers for linear addressing (0).
  940. */
  941. ether->ctlr = ctlr;
  942. ether->port = ctlr->port;
  943. ether->irq = ctlr->pcidev->intl;
  944. ether->tbdf = ctlr->pcidev->tbdf;
  945. ilock(&ctlr->rlock);
  946. csr32w(ctlr, Port, 0);
  947. delay(1);
  948. csr8w(ctlr, Interrupt, InterruptM);
  949. iunlock(&ctlr->rlock);
  950. command(ctlr, LoadRUB, 0);
  951. command(ctlr, LoadCUB, 0);
  952. command(ctlr, LoadDCA, PADDR(ctlr->dump));
  953. /*
  954. * Initialise the receive frame, transmit ring and configuration areas.
  955. */
  956. ctlr->ncb = Ncb;
  957. ctlrinit(ctlr);
  958. /*
  959. * Read the EEPROM.
  960. * Do a dummy read first to get the size
  961. * and allocate ctlr->eeprom.
  962. */
  963. hy93c46r(ctlr, 0);
  964. sum = 0;
  965. for(i = 0; i < (1<<ctlr->eepromsz); i++){
  966. x = hy93c46r(ctlr, i);
  967. ctlr->eeprom[i] = x;
  968. sum += x;
  969. }
  970. if(sum != 0xBABA)
  971. print("#l%d: EEPROM checksum - %#4.4ux\n", ether->ctlrno, sum);
  972. /*
  973. * Eeprom[6] indicates whether there is a PHY and whether
  974. * it's not 10Mb-only, in which case use the given PHY address
  975. * to set any PHY specific options and determine the speed.
  976. * Unfortunately, sometimes the EEPROM is blank except for
  977. * the ether address and checksum; in this case look at the
  978. * controller type and if it's am 82558 or 82559 it has an
  979. * embedded PHY so scan for that.
  980. * If no PHY, assume 82503 (serial) operation.
  981. */
  982. if((ctlr->eeprom[6] & 0x1F00) && !(ctlr->eeprom[6] & 0x8000))
  983. phyaddr = ctlr->eeprom[6] & 0x00FF;
  984. else
  985. switch(ctlr->pcidev->rid){
  986. case 0x01: /* 82557 A-step */
  987. case 0x02: /* 82557 B-step */
  988. case 0x03: /* 82557 C-step */
  989. default:
  990. phyaddr = -1;
  991. break;
  992. case 0x04: /* 82558 A-step */
  993. case 0x05: /* 82558 B-step */
  994. case 0x06: /* 82559 A-step */
  995. case 0x07: /* 82559 B-step */
  996. case 0x08: /* 82559 C-step */
  997. case 0x09: /* 82559ER A-step */
  998. phyaddr = scanphy(ctlr);
  999. break;
  1000. }
  1001. if(phyaddr >= 0){
  1002. /*
  1003. * Resolve the highest common ability of the two
  1004. * link partners. In descending order:
  1005. * 0x0100 100BASE-TX Full Duplex
  1006. * 0x0200 100BASE-T4
  1007. * 0x0080 100BASE-TX
  1008. * 0x0040 10BASE-T Full Duplex
  1009. * 0x0020 10BASE-T
  1010. */
  1011. anar = miir(ctlr, phyaddr, 0x04);
  1012. anlpar = miir(ctlr, phyaddr, 0x05) & 0x03E0;
  1013. anar &= anlpar;
  1014. bmcr = 0;
  1015. if(anar & 0x380)
  1016. bmcr = 0x2000;
  1017. if(anar & 0x0140)
  1018. bmcr |= 0x0100;
  1019. switch((ctlr->eeprom[6]>>8) & 0x001F){
  1020. case 0x04: /* DP83840 */
  1021. case 0x0A: /* DP83840A */
  1022. /*
  1023. * The DP83840[A] requires some tweaking for
  1024. * reliable operation.
  1025. * The manual says bit 10 should be unconditionally
  1026. * set although it supposedly only affects full-duplex
  1027. * operation (an & 0x0140).
  1028. */
  1029. x = miir(ctlr, phyaddr, 0x17) & ~0x0520;
  1030. x |= 0x0420;
  1031. for(i = 0; i < ether->nopt; i++){
  1032. if(cistrcmp(ether->opt[i], "congestioncontrol"))
  1033. continue;
  1034. x |= 0x0100;
  1035. break;
  1036. }
  1037. miiw(ctlr, phyaddr, 0x17, x);
  1038. /*
  1039. * If the link partner can't autonegotiate, determine
  1040. * the speed from elsewhere.
  1041. */
  1042. if(anlpar == 0){
  1043. miir(ctlr, phyaddr, 0x01);
  1044. bmsr = miir(ctlr, phyaddr, 0x01);
  1045. x = miir(ctlr, phyaddr, 0x19);
  1046. if((bmsr & 0x0004) && !(x & 0x0040))
  1047. bmcr = 0x2000;
  1048. }
  1049. break;
  1050. case 0x07: /* Intel 82555 */
  1051. /*
  1052. * Auto-negotiation may fail if the other end is
  1053. * a DP83840A and the cable is short.
  1054. */
  1055. miir(ctlr, phyaddr, 0x01);
  1056. bmsr = miir(ctlr, phyaddr, 0x01);
  1057. if((miir(ctlr, phyaddr, 0) & 0x1000) && !(bmsr & 0x0020)){
  1058. miiw(ctlr, phyaddr, 0x1A, 0x2010);
  1059. x = miir(ctlr, phyaddr, 0);
  1060. miiw(ctlr, phyaddr, 0, 0x0200|x);
  1061. for(i = 0; i < 3000; i++){
  1062. delay(1);
  1063. if(miir(ctlr, phyaddr, 0x01) & 0x0020)
  1064. break;
  1065. }
  1066. miiw(ctlr, phyaddr, 0x1A, 0x2000);
  1067. anar = miir(ctlr, phyaddr, 0x04);
  1068. anlpar = miir(ctlr, phyaddr, 0x05) & 0x03E0;
  1069. anar &= anlpar;
  1070. bmcr = 0;
  1071. if(anar & 0x380)
  1072. bmcr = 0x2000;
  1073. if(anar & 0x0140)
  1074. bmcr |= 0x0100;
  1075. }
  1076. break;
  1077. }
  1078. /*
  1079. * Force speed and duplex if no auto-negotiation.
  1080. */
  1081. if(anlpar == 0){
  1082. medium = -1;
  1083. for(i = 0; i < ether->nopt; i++){
  1084. for(k = 0; k < nelem(mediatable); k++){
  1085. if(cistrcmp(mediatable[k], ether->opt[i]))
  1086. continue;
  1087. medium = k;
  1088. break;
  1089. }
  1090. switch(medium){
  1091. default:
  1092. break;
  1093. case 0x00: /* 10BASE-T */
  1094. case 0x01: /* 10BASE-2 */
  1095. case 0x02: /* 10BASE-5 */
  1096. bmcr &= ~(0x2000|0x0100);
  1097. ctlr->configdata[19] &= ~0x40;
  1098. break;
  1099. case 0x03: /* 100BASE-TX */
  1100. case 0x06: /* 100BASE-T4 */
  1101. case 0x07: /* 100BASE-FX */
  1102. ctlr->configdata[19] &= ~0x40;
  1103. bmcr |= 0x2000;
  1104. break;
  1105. case 0x04: /* 10BASE-TFD */
  1106. bmcr = (bmcr & ~0x2000)|0x0100;
  1107. ctlr->configdata[19] |= 0x40;
  1108. break;
  1109. case 0x05: /* 100BASE-TXFD */
  1110. case 0x08: /* 100BASE-FXFD */
  1111. bmcr |= 0x2000|0x0100;
  1112. ctlr->configdata[19] |= 0x40;
  1113. break;
  1114. }
  1115. }
  1116. if(medium != -1)
  1117. miiw(ctlr, phyaddr, 0x00, bmcr);
  1118. }
  1119. if(bmcr & 0x2000)
  1120. ether->mbps = 100;
  1121. ctlr->configdata[8] = 1;
  1122. ctlr->configdata[15] &= ~0x80;
  1123. }
  1124. else{
  1125. ctlr->configdata[8] = 0;
  1126. ctlr->configdata[15] |= 0x80;
  1127. }
  1128. /*
  1129. * Workaround for some broken HUB chips when connected at 10Mb/s
  1130. * half-duplex.
  1131. * This is a band-aid, but as there's no dynamic auto-negotiation
  1132. * code at the moment, only deactivate the workaround code in txstart
  1133. * if the link is 100Mb/s.
  1134. */
  1135. if(ether->mbps != 10)
  1136. ctlr->nop = 0;
  1137. /*
  1138. * Load the chip configuration and start it off.
  1139. */
  1140. if(ether->oq == 0)
  1141. ether->oq = qopen(64*1024, Qmsg, 0, 0);
  1142. configure(ether, 0);
  1143. command(ctlr, CUstart, PADDR(&ctlr->cbr->status));
  1144. /*
  1145. * Check if the adapter's station address is to be overridden.
  1146. * If not, read it from the EEPROM and set in ether->ea prior to loading
  1147. * the station address with the Individual Address Setup command.
  1148. */
  1149. memset(ea, 0, Eaddrlen);
  1150. if(memcmp(ea, ether->ea, Eaddrlen) == 0){
  1151. for(i = 0; i < Eaddrlen/2; i++){
  1152. x = ctlr->eeprom[i];
  1153. ether->ea[2*i] = x;
  1154. ether->ea[2*i+1] = x>>8;
  1155. }
  1156. }
  1157. ilock(&ctlr->cblock);
  1158. ctlr->action = CbIAS;
  1159. txstart(ether);
  1160. iunlock(&ctlr->cblock);
  1161. /*
  1162. * Linkage to the generic ethernet driver.
  1163. */
  1164. ether->attach = attach;
  1165. ether->transmit = transmit;
  1166. ether->interrupt = interrupt;
  1167. ether->ifstat = ifstat;
  1168. ether->shutdown = shutdown;
  1169. ether->promiscuous = promiscuous;
  1170. ether->multicast = multicast;
  1171. ether->arg = ether;
  1172. return 0;
  1173. }
  1174. void
  1175. ether82557link(void)
  1176. {
  1177. addethercard("i82557", reset);
  1178. }