etherrhine.c 13 KB

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