etherrhine.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. Via Rhine driver, written for VT6102.
  3. Uses the ethermii to control PHY.
  4. Currently always copies on both, tx and rx.
  5. rx side could be copy-free, and tx-side might be made
  6. (almost) copy-free by using (possibly) two descriptors (if it allows
  7. arbitrary tx lengths, which it should..): first for alignment and
  8. second for rest of the frame. Rx-part should be worth doing.
  9. */
  10. #include "u.h"
  11. #include "lib.h"
  12. #include "mem.h"
  13. #include "dat.h"
  14. #include "fns.h"
  15. #include "io.h"
  16. #define iprint print
  17. #include "etherif.h"
  18. #include "ethermii.h"
  19. enum {
  20. Ntxd = 16,
  21. Nrxd = 32,
  22. Nwait = 50,
  23. };
  24. typedef struct Desc Desc;
  25. typedef struct Ctlr Ctlr;
  26. struct Desc {
  27. ulong stat;
  28. ulong size;
  29. ulong addr;
  30. ulong next;
  31. char *buf;
  32. ulong pad[3];
  33. };
  34. struct Ctlr {
  35. Pcidev *pci;
  36. int attached;
  37. int txused;
  38. int txhead;
  39. int txtail;
  40. int rxtail;
  41. ulong port;
  42. Mii mii;
  43. Desc *txd; /* wants to be aligned on 16-byte boundary */
  44. Desc *rxd;
  45. // QLock attachlck;
  46. Lock tlock;
  47. };
  48. #define ior8(c, r) (inb((c)->port+(r)))
  49. #define iow8(c, r, b) (outb((c)->port+(r), (int)(b)))
  50. #define ior16(c, r) (ins((c)->port+(r)))
  51. #define ior32(c, r) (inl((c)->port+(r)))
  52. #define iow16(c, r, w) (outs((c)->port+(r), (ushort)(w)))
  53. #define iow32(c, r, l) (outl((c)->port+(r), (ulong)(l)))
  54. /* names used everywhere else */
  55. #define csr8r ior8
  56. #define csr8w iow8
  57. #define csr16r ior16
  58. #define csr16w iow16
  59. #define csr32r ior32
  60. #define csr32w iow32
  61. enum Regs {
  62. Eaddr = 0x0,
  63. Rcr = 0x6,
  64. Tcr = 0x7,
  65. Cr = 0x8,
  66. Isr = 0xc,
  67. Imr = 0xe,
  68. Mcfilt0 = 0x10, /* Multicast Filter 0 */
  69. Mcfilt1 = 0x14, /* Multicast Filter 1 */
  70. RxdAddr = 0x18,
  71. TxdAddr = 0x1C,
  72. Bcr0 = 0x6E, /* Bus Control */
  73. Bcr1 = 0x6F,
  74. RhineMiiPhy = 0x6C,
  75. RhineMiiSr = 0x6D,
  76. RhineMiiCr = 0x70,
  77. RhineMiiAddr = 0x71,
  78. RhineMiiData = 0x72,
  79. Eecsr = 0x74,
  80. ConfigB = 0x79,
  81. ConfigD = 0x7B,
  82. MiscCr = 0x80,
  83. Stickhw = 0x83, /* Sticky Hardware Control */
  84. MiscIsr = 0x84,
  85. MiscImr = 0x86,
  86. WolCrSet = 0xA0,
  87. WolCfgSet = 0xA1,
  88. WolCgSet = 0xA3,
  89. Wolcrclr = 0xA4,
  90. PwrCfgClr = 0xA5,
  91. Wolcgclr = 0xA7,
  92. Pwrcsrclr = 0xAC,
  93. };
  94. enum { /* Rcr */
  95. Sep = 0x01, /* Accept Error Packets */
  96. Ar = 0x02, /* Accept Small Packets */
  97. Am = 0x04, /* Accept Multicast */
  98. Ab = 0x08, /* Accept Broadcast */
  99. RxBcast = Ab,
  100. Prom = 0x10, /* Accept Physical Address Packets */
  101. RxProm = Prom,
  102. RrftMASK = 0xE0, /* Receive FIFO Threshold */
  103. RrftSHIFT = 5,
  104. Rrft64 = 0<<RrftSHIFT,
  105. Rrft32 = 1<<RrftSHIFT,
  106. Rrft128 = 2<<RrftSHIFT,
  107. Rrft256 = 3<<RrftSHIFT,
  108. Rrft512 = 4<<RrftSHIFT,
  109. Rrft768 = 5<<RrftSHIFT,
  110. Rrft1024 = 6<<RrftSHIFT,
  111. RrftSAF = 7<<RrftSHIFT,
  112. };
  113. enum { /* Tcr */
  114. Lb0 = 0x02, /* Loopback Mode */
  115. Lb1 = 0x04,
  116. Ofset = 0x08, /* Back-off Priority Selection */
  117. RtsfMASK = 0xE0, /* Transmit FIFO Threshold */
  118. RtsfSHIFT = 5,
  119. Rtsf128 = 0<<RtsfSHIFT,
  120. Rtsf256 = 1<<RtsfSHIFT,
  121. Rtsf512 = 2<<RtsfSHIFT,
  122. Rtsf1024 = 3<<RtsfSHIFT,
  123. RtsfSAF = 7<<RtsfSHIFT,
  124. };
  125. enum Crbits {
  126. Init = 1<<0,
  127. Start = 1<<1,
  128. Stop = 1<<2,
  129. RxOn = 1<<3,
  130. TxOn = 1<<4,
  131. Tdmd = 1<<5,
  132. Rdmd = 1<<6,
  133. EarlyRx = 1<<8,
  134. Reserved0 = 1<<9,
  135. FullDuplex = 1<<10,
  136. NoAutoPoll = 1<<11,
  137. Reserved1 = 1<<12,
  138. Tdmd1 = 1<<13,
  139. Rdmd1 = 1<<14,
  140. Reset = 1<<15,
  141. };
  142. enum Isrbits {
  143. RxOk = 1<<0,
  144. TxOk = 1<<1,
  145. RxErr = 1<<2,
  146. TxErr = 1<<3,
  147. TxBufUdf = 1<<4,
  148. RxBufLinkErr = 1<<5,
  149. BusErr = 1<<6,
  150. CrcOvf = 1<<7,
  151. EarlyRxInt = 1<<8,
  152. TxFifoUdf = 1<<9,
  153. RxFifoOvf = 1<<10,
  154. TxPktRace = 1<<11,
  155. NoRxbuf = 1<<12,
  156. TxCollision = 1<<13,
  157. PortCh = 1<<14,
  158. GPInt = 1<<15,
  159. };
  160. enum { /* Bcr0 */
  161. DmaMASK = 0x07, /* DMA Length */
  162. DmaSHIFT = 0,
  163. Dma32 = 0<<DmaSHIFT,
  164. Dma64 = 1<<DmaSHIFT,
  165. Dma128 = 2<<DmaSHIFT,
  166. Dma256 = 3<<DmaSHIFT,
  167. Dma512 = 4<<DmaSHIFT,
  168. Dma1024 = 5<<DmaSHIFT,
  169. DmaSAF = 7<<DmaSHIFT,
  170. CrftMASK = 0x38, /* Rx FIFO Threshold */
  171. CrftSHIFT = 3,
  172. Crft64 = 1<<CrftSHIFT,
  173. Crft128 = 2<<CrftSHIFT,
  174. Crft256 = 3<<CrftSHIFT,
  175. Crft512 = 4<<CrftSHIFT,
  176. Crft1024 = 5<<CrftSHIFT,
  177. CrftSAF = 7<<CrftSHIFT,
  178. Extled = 0x40, /* Extra LED Support Control */
  179. Med2 = 0x80, /* Medium Select Control */
  180. };
  181. enum { /* Bcr1 */
  182. PotMASK = 0x07, /* Polling Timer Interval */
  183. PotSHIFT = 0,
  184. CtftMASK = 0x38, /* Tx FIFO Threshold */
  185. CtftSHIFT = 3,
  186. Ctft64 = 1<<CtftSHIFT,
  187. Ctft128 = 2<<CtftSHIFT,
  188. Ctft256 = 3<<CtftSHIFT,
  189. Ctft512 = 4<<CtftSHIFT,
  190. Ctft1024 = 5<<CtftSHIFT,
  191. CtftSAF = 7<<CtftSHIFT,
  192. };
  193. enum Eecsrbits {
  194. EeAutoLoad = 1<<5,
  195. };
  196. enum Descbits {
  197. OwnNic = 1<<31, /* stat */
  198. TxAbort = 1<<8, /* stat */
  199. TxError = 1<<15, /* stat */
  200. RxChainbuf = 1<<10, /* stat */
  201. RxChainStart = 1<<9, /* stat */
  202. RxChainEnd = 1<<8, /* stat */
  203. Chainbuf = 1<<15, /* size rx & tx*/
  204. TxDisableCrc = 1<<16, /* size */
  205. TxChainStart = 1<<21, /* size */
  206. TxChainEnd = 1<<22, /* size */
  207. TxInt = 1<<23, /* size */
  208. };
  209. enum RhineMiiCrbits {
  210. Mdc = 1<<0,
  211. Mdi = 1<<1,
  212. Mdo = 1<<2,
  213. Mdout = 1<<3,
  214. Mdpm = 1<<4,
  215. Wcmd = 1<<5,
  216. Rcmd = 1<<6,
  217. Mauto = 1<<7,
  218. };
  219. static void
  220. attach(Ether *edev)
  221. {
  222. Ctlr *ctlr;
  223. Desc *txd, *rxd, *td, *rd;
  224. Mii *mi;
  225. MiiPhy *phy;
  226. int s;
  227. uint i;
  228. ctlr = edev->ctlr;
  229. // qlock(&ctlr->attachlck);
  230. if (ctlr->attached == 0) {
  231. txd = ctlr->txd;
  232. rxd = ctlr->rxd;
  233. for (i = 0; i < Ntxd; ++i) {
  234. td = &txd[i];
  235. td->next = PCIWADDR(&txd[(i+1) % Ntxd]);
  236. td->buf = xspanalloc(sizeof(Etherpkt)+4, 4, 0);
  237. td->addr = PCIWADDR(td->buf);
  238. td->size = 0;
  239. coherence();
  240. td->stat = 0;
  241. }
  242. for (i = 0; i < Nrxd; ++i) {
  243. rd = &rxd[i];
  244. rd->next = PCIWADDR(&rxd[(i+1) % Nrxd]);
  245. rd->buf = xspanalloc(sizeof(Etherpkt)+4, 4, 0);
  246. rd->addr = PCIWADDR(rd->buf);
  247. rd->size = sizeof(Etherpkt)+4;
  248. coherence();
  249. rd->stat = OwnNic;
  250. }
  251. ctlr->txhead = ctlr->txtail = ctlr->rxtail = 0;
  252. mi = &ctlr->mii;
  253. miistatus(mi);
  254. phy = mi->curphy;
  255. s = splhi();
  256. iow32(ctlr, TxdAddr, PCIWADDR(&txd[0]));
  257. iow32(ctlr, RxdAddr, PCIWADDR(&rxd[0]));
  258. iow16(ctlr, Cr, (phy->fd? FullDuplex: 0) | NoAutoPoll | TxOn |
  259. RxOn | Start | Rdmd);
  260. iow16(ctlr, Isr, 0xFFFF);
  261. iow16(ctlr, Imr, 0xFFFF);
  262. iow8(ctlr, MiscIsr, 0xFF);
  263. iow8(ctlr, MiscImr, ~(3<<5));
  264. splx(s);
  265. ctlr->attached = 1;
  266. }
  267. // qunlock(&ctlr->attachlck);
  268. }
  269. static void
  270. txstart(Ether *edev)
  271. {
  272. Ctlr *ctlr;
  273. Desc *txd, *td;
  274. int txused, n;
  275. uint i;
  276. RingBuf *tb;
  277. ctlr = edev->ctlr;
  278. txd = ctlr->txd;
  279. i = ctlr->txhead;
  280. n = 0;
  281. for (txused = ctlr->txused; txused < Ntxd; txused++) {
  282. tb = &edev->tb[edev->ti];
  283. if(tb->owner != Interface)
  284. break;
  285. td = &txd[i];
  286. memmove(td->buf, tb->pkt, tb->len);
  287. /* could reduce number of intrs here */
  288. td->size = tb->len | TxChainStart | TxChainEnd | TxInt;
  289. coherence();
  290. td->stat = OwnNic;
  291. i = (i + 1) % Ntxd;
  292. n++;
  293. tb->owner = Host;
  294. edev->ti = NEXT(edev->ti, edev->ntb);
  295. }
  296. if (n)
  297. iow16(ctlr, Cr, ior16(ctlr, Cr) | Tdmd);
  298. ctlr->txhead = i;
  299. ctlr->txused = txused;
  300. }
  301. static void
  302. transmit(Ether *edev)
  303. {
  304. Ctlr *ctlr;
  305. ctlr = edev->ctlr;
  306. ilock(&ctlr->tlock);
  307. txstart(edev);
  308. iunlock(&ctlr->tlock);
  309. }
  310. static void
  311. txcomplete(Ether *edev)
  312. {
  313. Ctlr *ctlr;
  314. Desc *txd, *td;
  315. int txused;
  316. uint i;
  317. ulong stat;
  318. ctlr = edev->ctlr;
  319. txd = ctlr->txd;
  320. i = ctlr->txtail;
  321. for (txused = ctlr->txused; txused > 0; txused--) {
  322. td = &txd[i];
  323. stat = td->stat;
  324. if (stat & OwnNic)
  325. break;
  326. i = (i + 1) % Ntxd;
  327. }
  328. ctlr->txused = txused;
  329. ctlr->txtail = i;
  330. // if (txused <= Ntxd/2)
  331. txstart(edev);
  332. }
  333. static void
  334. interrupt(Ureg *, void *arg)
  335. {
  336. Ether *edev;
  337. Ctlr *ctlr;
  338. RingBuf *rb;
  339. ushort isr, misr;
  340. ulong stat;
  341. Desc *rxd, *rd;
  342. int n, size;
  343. uint i;
  344. edev = (Ether*)arg;
  345. ctlr = edev->ctlr;
  346. iow16(ctlr, Imr, 0);
  347. isr = ior16(ctlr, Isr);
  348. iow16(ctlr, Isr, 0xFFFF);
  349. /* don't care about used defined intrs */
  350. misr = ior16(ctlr, MiscIsr) & ~(3<<5);
  351. if (isr & RxOk) {
  352. rxd = ctlr->rxd;
  353. i = ctlr->rxtail;
  354. n = 0;
  355. while ((rxd[i].stat & OwnNic) == 0) {
  356. rd = &rxd[i];
  357. stat = rd->stat;
  358. if (stat & 0xFF)
  359. iprint("rx: %lux\n", stat & 0xFF);
  360. size = ((rd->stat>>16) & (2048-1)) - 4;
  361. rb = &edev->rb[edev->ri];
  362. if(rb->owner == Interface){
  363. rb->owner = Host;
  364. rb->len = size;
  365. memmove(rb->pkt, rd->buf, size);
  366. edev->ri = NEXT(edev->ri, edev->nrb);
  367. } else
  368. print("etherrhine: ether%d discarding input pkt;"
  369. " buffer ring too small\n",
  370. edev->ctlrno);
  371. rd->size = sizeof(Etherpkt)+4;
  372. coherence();
  373. rd->stat = OwnNic;
  374. i = (i + 1) % Nrxd;
  375. n++;
  376. }
  377. if (n)
  378. iow16(ctlr, Cr, ior16(ctlr, Cr) | Rdmd);
  379. ctlr->rxtail = i;
  380. isr &= ~RxOk;
  381. }
  382. if (isr & TxOk) {
  383. txcomplete(edev);
  384. isr &= ~TxOk;
  385. }
  386. if (isr | misr)
  387. iprint("etherrhine: unhandled irq(s). isr:%x misr:%x\n",
  388. isr, misr);
  389. iow16(ctlr, Imr, 0xFFFF);
  390. }
  391. static int
  392. miiread(Mii *mii, int phy, int reg)
  393. {
  394. Ctlr *ctlr;
  395. int n;
  396. ctlr = mii->ctlr;
  397. n = Nwait;
  398. while (n-- && ior8(ctlr, RhineMiiCr) & (Rcmd | Wcmd))
  399. microdelay(1);
  400. if (n == Nwait)
  401. iprint("etherrhine: miiread: timeout\n");
  402. iow8(ctlr, RhineMiiCr, 0);
  403. iow8(ctlr, RhineMiiPhy, phy);
  404. iow8(ctlr, RhineMiiAddr, reg);
  405. iow8(ctlr, RhineMiiCr, Rcmd);
  406. n = Nwait;
  407. while (n-- && ior8(ctlr, RhineMiiCr) & Rcmd)
  408. microdelay(1);
  409. if (n == Nwait)
  410. iprint("etherrhine: miiread: timeout\n");
  411. return ior16(ctlr, RhineMiiData);
  412. }
  413. static int
  414. miiwrite(Mii *mii, int phy, int reg, int data)
  415. {
  416. int n;
  417. Ctlr *ctlr;
  418. ctlr = mii->ctlr;
  419. n = Nwait;
  420. while (n-- && ior8(ctlr, RhineMiiCr) & (Rcmd | Wcmd))
  421. microdelay(1);
  422. if (n == Nwait)
  423. iprint("etherrhine: miiwrite: timeout\n");
  424. iow8(ctlr, RhineMiiCr, 0);
  425. iow8(ctlr, RhineMiiPhy, phy);
  426. iow8(ctlr, RhineMiiAddr, reg);
  427. iow16(ctlr, RhineMiiData, data);
  428. iow8(ctlr, RhineMiiCr, Wcmd);
  429. n = Nwait;
  430. while (n-- && ior8(ctlr, RhineMiiCr) & Wcmd)
  431. microdelay(1);
  432. if (n == Nwait)
  433. iprint("etherrhine: miiwrite: timeout\n");
  434. return 0;
  435. }
  436. static void
  437. reset(Ctlr* ctlr)
  438. {
  439. int r, timeo, revid;
  440. /*
  441. * Reset power management registers.
  442. */
  443. revid = pcicfgr8(ctlr->pci, PciRID);
  444. if(revid >= 0x40){
  445. /* Set power state D0. */
  446. csr8w(ctlr, Stickhw, csr8r(ctlr, Stickhw) & 0xFC);
  447. /* Disable force PME-enable. */
  448. csr8w(ctlr, Wolcgclr, 0x80);
  449. /* Clear WOL config and status bits. */
  450. csr8w(ctlr, Wolcrclr, 0xFF);
  451. csr8w(ctlr, Pwrcsrclr, 0xFF);
  452. }
  453. /*
  454. * Soft reset the controller.
  455. */
  456. csr16w(ctlr, Cr, Stop);
  457. csr16w(ctlr, Cr, Stop|Reset);
  458. for(timeo = 0; timeo < 10000; timeo++){
  459. if(!(csr16r(ctlr, Cr) & Reset))
  460. break;
  461. microdelay(1);
  462. }
  463. if(timeo >= 1000)
  464. return;
  465. /*
  466. * Load the MAC address into the PAR[01]
  467. * registers.
  468. */
  469. r = csr8r(ctlr, Eecsr);
  470. csr8w(ctlr, Eecsr, EeAutoLoad|r);
  471. for(timeo = 0; timeo < 100; timeo++){
  472. if(!(csr8r(ctlr, Cr) & EeAutoLoad))
  473. break;
  474. microdelay(1);
  475. }
  476. if(timeo >= 100)
  477. return;
  478. /*
  479. * Configure DMA and Rx/Tx thresholds.
  480. * If the Rx/Tx threshold bits in Bcr[01] are 0 then
  481. * the thresholds are determined by Rcr/Tcr.
  482. */
  483. r = csr8r(ctlr, Bcr0) & ~(CrftMASK|DmaMASK);
  484. csr8w(ctlr, Bcr0, r|Crft64|Dma64);
  485. r = csr8r(ctlr, Bcr1) & ~CtftMASK;
  486. csr8w(ctlr, Bcr1, r|Ctft64);
  487. r = csr8r(ctlr, Rcr) & ~(RrftMASK|Prom|Ar|Sep);
  488. csr8w(ctlr, Rcr, r|Ab|Am);
  489. csr32w(ctlr, Mcfilt0, ~0UL); /* accept all multicast */
  490. csr32w(ctlr, Mcfilt1, ~0UL);
  491. r = csr8r(ctlr, Tcr) & ~(RtsfMASK|Ofset|Lb1|Lb0);
  492. csr8w(ctlr, Tcr, r);
  493. }
  494. static void
  495. detach(Ether* edev)
  496. {
  497. reset(edev->ctlr);
  498. }
  499. static void
  500. init(Ether *edev)
  501. {
  502. Ctlr *ctlr;
  503. int i;
  504. ctlr = edev->ctlr;
  505. ilock(&ctlr->tlock);
  506. pcisetbme(ctlr->pci);
  507. reset(ctlr);
  508. iow8(ctlr, Eecsr, ior8(ctlr, Eecsr) | EeAutoLoad);
  509. for (i = 0; i < Nwait; ++i) {
  510. if ((ior8(ctlr, Eecsr) & EeAutoLoad) == 0)
  511. break;
  512. delay(5);
  513. }
  514. if (i >= Nwait)
  515. iprint("etherrhine: eeprom autoload timeout\n");
  516. for (i = 0; i < Eaddrlen; ++i)
  517. edev->ea[i] = ior8(ctlr, Eaddr + i);
  518. ctlr->mii.mir = miiread;
  519. ctlr->mii.miw = miiwrite;
  520. ctlr->mii.ctlr = ctlr;
  521. if(mii(&ctlr->mii, ~0) == 0 || ctlr->mii.curphy == nil){
  522. iunlock(&ctlr->tlock);
  523. iprint("etherrhine: init mii failure\n");
  524. return;
  525. }
  526. for (i = 0; i < NMiiPhy; ++i)
  527. if (ctlr->mii.phy[i] && ctlr->mii.phy[i]->oui != 0xFFFFF)
  528. ctlr->mii.curphy = ctlr->mii.phy[i];
  529. miistatus(&ctlr->mii);
  530. iow16(ctlr, Imr, 0);
  531. iow16(ctlr, Cr, ior16(ctlr, Cr) | Stop);
  532. iunlock(&ctlr->tlock);
  533. }
  534. static Pcidev *
  535. rhinematch(ulong)
  536. {
  537. static int nrhines = 0;
  538. int nfound = 0;
  539. Pcidev *p = nil;
  540. while(p = pcimatch(p, 0x1106, 0)){
  541. if(p->ccrb != Pcibcnet || p->ccru != Pciscether)
  542. continue;
  543. switch((p->did<<16)|p->vid){
  544. default:
  545. continue;
  546. case (0x3053<<16)|0x1106: /* Rhine III vt6105m (Soekris) */
  547. case (0x3065<<16)|0x1106: /* Rhine II */
  548. case (0x3106<<16)|0x1106: /* Rhine III */
  549. if (++nfound > nrhines) {
  550. nrhines++;
  551. return p;
  552. }
  553. break;
  554. }
  555. }
  556. return p;
  557. }
  558. int
  559. rhinepnp(Ether *edev)
  560. {
  561. Pcidev *p;
  562. Ctlr *ctlr;
  563. ulong port;
  564. if (edev->attach)
  565. return 0;
  566. p = rhinematch(edev->port);
  567. if (p == nil)
  568. return -1;
  569. port = p->mem[0].bar & ~1;
  570. if ((ctlr = malloc(sizeof(Ctlr))) == nil) {
  571. print("etherrhine: couldn't allocate memory for ctlr\n");
  572. return -1;
  573. }
  574. memset(ctlr, 0, sizeof(Ctlr));
  575. ctlr->txd = xspanalloc(sizeof(Desc) * Ntxd, 16, 0);
  576. ctlr->rxd = xspanalloc(sizeof(Desc) * Nrxd, 16, 0);
  577. ctlr->pci = p;
  578. ctlr->port = port;
  579. edev->ctlr = ctlr;
  580. edev->port = ctlr->port;
  581. edev->irq = p->intl;
  582. edev->tbdf = p->tbdf;
  583. init(edev);
  584. edev->attach = attach;
  585. edev->transmit = transmit;
  586. edev->interrupt = interrupt;
  587. edev->detach = detach;
  588. return 0;
  589. }
  590. int
  591. vt6102pnp(Ether *edev)
  592. {
  593. return rhinepnp(edev);
  594. }