You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

davicom.c 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. #ifdef ALLMULTI
  2. #error multicast support is not yet implemented
  3. #endif
  4. /*
  5. DAVICOM DM9009/DM9102/DM9102A Etherboot Driver V1.00
  6. This driver was ported from Marty Connor's Tulip Etherboot driver.
  7. Thanks Marty Connor (mdc@etherboot.org)
  8. This davicom etherboot driver supports DM9009/DM9102/DM9102A/
  9. DM9102A+DM9801/DM9102A+DM9802 NICs.
  10. This software may be used and distributed according to the terms
  11. of the GNU Public License, incorporated herein by reference.
  12. */
  13. /*********************************************************************/
  14. /* Revision History */
  15. /*********************************************************************/
  16. /*
  17. 19 OCT 2000 Sten 1.00
  18. Different half and full duplex mode
  19. Do the different programming for DM9801/DM9802
  20. 12 OCT 2000 Sten 0.90
  21. This driver was ported from tulip driver and it
  22. has the following difference.
  23. Changed symbol tulip/TULIP to davicom/DAVICOM
  24. Deleted some code that did not use in this driver.
  25. Used chain-strcture to replace ring structure
  26. for both TX/RX descriptor.
  27. Allocated two tx descriptor.
  28. According current media mode to set operating
  29. register(CR6)
  30. */
  31. /*********************************************************************/
  32. /* Declarations */
  33. /*********************************************************************/
  34. #include "etherboot.h"
  35. #include "nic.h"
  36. #include "pci.h"
  37. #undef DAVICOM_DEBUG
  38. #undef DAVICOM_DEBUG_WHERE
  39. #define TX_TIME_OUT 2*TICKS_PER_SEC
  40. typedef unsigned char u8;
  41. typedef signed char s8;
  42. typedef unsigned short u16;
  43. typedef signed short s16;
  44. typedef unsigned int u32;
  45. typedef signed int s32;
  46. /* Register offsets for davicom device */
  47. enum davicom_offsets {
  48. CSR0=0, CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
  49. CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
  50. CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78, CSR16=0x80, CSR20=0xA0
  51. };
  52. /* EEPROM Address width definitions */
  53. #define EEPROM_ADDRLEN 6
  54. #define EEPROM_SIZE 32 /* 1 << EEPROM_ADDRLEN */
  55. /* Used to be 128, but we only need to read enough to get the MAC
  56. address at bytes 20..25 */
  57. /* Data Read from the EEPROM */
  58. static unsigned char ee_data[EEPROM_SIZE];
  59. /* The EEPROM commands include the alway-set leading bit. */
  60. #define EE_WRITE_CMD (5 << addr_len)
  61. #define EE_READ_CMD (6 << addr_len)
  62. #define EE_ERASE_CMD (7 << addr_len)
  63. /* EEPROM_Ctrl bits. */
  64. #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
  65. #define EE_CS 0x01 /* EEPROM chip select. */
  66. #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
  67. #define EE_WRITE_0 0x01
  68. #define EE_WRITE_1 0x05
  69. #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
  70. #define EE_ENB (0x4800 | EE_CS)
  71. /* Sten 10/11 for phyxcer */
  72. #define PHY_DATA_0 0x0
  73. #define PHY_DATA_1 0x20000
  74. #define MDCLKH 0x10000
  75. /* Delay between EEPROM clock transitions. Even at 33Mhz current PCI
  76. implementations don't overrun the EEPROM clock. We add a bus
  77. turn-around to insure that this remains true. */
  78. #define eeprom_delay() inl(ee_addr)
  79. /* helpful macro if on a big_endian machine for changing byte order.
  80. not strictly needed on Intel
  81. Already defined in Etherboot includes
  82. #define le16_to_cpu(val) (val)
  83. */
  84. /* transmit and receive descriptor format */
  85. struct txdesc {
  86. volatile unsigned long status; /* owner, status */
  87. unsigned long buf1sz:11, /* size of buffer 1 */
  88. buf2sz:11, /* size of buffer 2 */
  89. control:10; /* control bits */
  90. const unsigned char *buf1addr; /* buffer 1 address */
  91. const unsigned char *buf2addr; /* buffer 2 address */
  92. };
  93. struct rxdesc {
  94. volatile unsigned long status; /* owner, status */
  95. unsigned long buf1sz:11, /* size of buffer 1 */
  96. buf2sz:11, /* size of buffer 2 */
  97. control:10; /* control bits */
  98. unsigned char *buf1addr; /* buffer 1 address */
  99. unsigned char *buf2addr; /* buffer 2 address */
  100. };
  101. /* Size of transmit and receive buffers */
  102. #define BUFLEN 1536
  103. /*********************************************************************/
  104. /* Global Storage */
  105. /*********************************************************************/
  106. /* PCI Bus parameters */
  107. static unsigned short vendor, dev_id;
  108. static unsigned long ioaddr;
  109. /* Note: transmit and receive buffers must be longword aligned and
  110. longword divisable */
  111. /* transmit descriptor and buffer */
  112. #define NTXD 2
  113. static struct txdesc txd[NTXD] __attribute__ ((aligned(4)));
  114. static unsigned char txb[BUFLEN] __attribute__ ((aligned(4)));
  115. /* receive descriptor(s) and buffer(s) */
  116. #define NRXD 4
  117. static struct rxdesc rxd[NRXD] __attribute__ ((aligned(4)));
  118. static unsigned char rxb[NRXD * BUFLEN] __attribute__ ((aligned(4)));
  119. static int rxd_tail;
  120. static int TxPtr;
  121. /*********************************************************************/
  122. /* Function Prototypes */
  123. /*********************************************************************/
  124. static void whereami(const char *str);
  125. static int read_eeprom(unsigned long ioaddr, int location, int addr_len);
  126. static int davicom_probe(struct dev *dev, struct pci_device *pci);
  127. static void davicom_init_chain(struct nic *nic); /* Sten 10/9 */
  128. static void davicom_reset(struct nic *nic);
  129. static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
  130. unsigned int s, const char *p);
  131. static int davicom_poll(struct nic *nic, int retrieve);
  132. static void davicom_disable(struct dev *dev);
  133. #ifdef DAVICOM_DEBUG
  134. static void davicom_more(void);
  135. #endif /* DAVICOM_DEBUG */
  136. static void davicom_wait(unsigned int nticks);
  137. static int phy_read(int);
  138. static void phy_write(int, u16);
  139. static void phy_write_1bit(u32, u32);
  140. static int phy_read_1bit(u32);
  141. static void davicom_media_chk(struct nic *);
  142. /*********************************************************************/
  143. /* Utility Routines */
  144. /*********************************************************************/
  145. static inline void whereami(const char *str)
  146. {
  147. printf("%s\n", str);
  148. /* sleep(2); */
  149. }
  150. #ifdef DAVICOM_DEBUG
  151. static void davicom_more()
  152. {
  153. printf("\n\n-- more --");
  154. while (!iskey())
  155. /* wait */;
  156. getchar();
  157. printf("\n\n");
  158. }
  159. #endif /* DAVICOM_DEBUG */
  160. static void davicom_wait(unsigned int nticks)
  161. {
  162. unsigned int to = currticks() + nticks;
  163. while (currticks() < to)
  164. /* wait */ ;
  165. }
  166. /*********************************************************************/
  167. /* For DAVICOM phyxcer register by MII interface */
  168. /*********************************************************************/
  169. /*
  170. Read a word data from phy register
  171. */
  172. static int phy_read(int location)
  173. {
  174. int i, phy_addr=1;
  175. u16 phy_data;
  176. u32 io_dcr9;
  177. whereami("phy_read\n");
  178. io_dcr9 = ioaddr + CSR9;
  179. /* Send 33 synchronization clock to Phy controller */
  180. for (i=0; i<34; i++)
  181. phy_write_1bit(io_dcr9, PHY_DATA_1);
  182. /* Send start command(01) to Phy */
  183. phy_write_1bit(io_dcr9, PHY_DATA_0);
  184. phy_write_1bit(io_dcr9, PHY_DATA_1);
  185. /* Send read command(10) to Phy */
  186. phy_write_1bit(io_dcr9, PHY_DATA_1);
  187. phy_write_1bit(io_dcr9, PHY_DATA_0);
  188. /* Send Phy addres */
  189. for (i=0x10; i>0; i=i>>1)
  190. phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
  191. /* Send register addres */
  192. for (i=0x10; i>0; i=i>>1)
  193. phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
  194. /* Skip transition state */
  195. phy_read_1bit(io_dcr9);
  196. /* read 16bit data */
  197. for (phy_data=0, i=0; i<16; i++) {
  198. phy_data<<=1;
  199. phy_data|=phy_read_1bit(io_dcr9);
  200. }
  201. return phy_data;
  202. }
  203. /*
  204. Write a word to Phy register
  205. */
  206. static void phy_write(int location, u16 phy_data)
  207. {
  208. u16 i, phy_addr=1;
  209. u32 io_dcr9;
  210. whereami("phy_write\n");
  211. io_dcr9 = ioaddr + CSR9;
  212. /* Send 33 synchronization clock to Phy controller */
  213. for (i=0; i<34; i++)
  214. phy_write_1bit(io_dcr9, PHY_DATA_1);
  215. /* Send start command(01) to Phy */
  216. phy_write_1bit(io_dcr9, PHY_DATA_0);
  217. phy_write_1bit(io_dcr9, PHY_DATA_1);
  218. /* Send write command(01) to Phy */
  219. phy_write_1bit(io_dcr9, PHY_DATA_0);
  220. phy_write_1bit(io_dcr9, PHY_DATA_1);
  221. /* Send Phy addres */
  222. for (i=0x10; i>0; i=i>>1)
  223. phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
  224. /* Send register addres */
  225. for (i=0x10; i>0; i=i>>1)
  226. phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
  227. /* written trasnition */
  228. phy_write_1bit(io_dcr9, PHY_DATA_1);
  229. phy_write_1bit(io_dcr9, PHY_DATA_0);
  230. /* Write a word data to PHY controller */
  231. for (i=0x8000; i>0; i>>=1)
  232. phy_write_1bit(io_dcr9, phy_data&i ? PHY_DATA_1: PHY_DATA_0);
  233. }
  234. /*
  235. Write one bit data to Phy Controller
  236. */
  237. static void phy_write_1bit(u32 ee_addr, u32 phy_data)
  238. {
  239. whereami("phy_write_1bit\n");
  240. outl(phy_data, ee_addr); /* MII Clock Low */
  241. eeprom_delay();
  242. outl(phy_data|MDCLKH, ee_addr); /* MII Clock High */
  243. eeprom_delay();
  244. outl(phy_data, ee_addr); /* MII Clock Low */
  245. eeprom_delay();
  246. }
  247. /*
  248. Read one bit phy data from PHY controller
  249. */
  250. static int phy_read_1bit(u32 ee_addr)
  251. {
  252. int phy_data;
  253. whereami("phy_read_1bit\n");
  254. outl(0x50000, ee_addr);
  255. eeprom_delay();
  256. phy_data=(inl(ee_addr)>>19) & 0x1;
  257. outl(0x40000, ee_addr);
  258. eeprom_delay();
  259. return phy_data;
  260. }
  261. /*
  262. DM9801/DM9802 present check and program
  263. */
  264. static void HPNA_process(void)
  265. {
  266. if ( (phy_read(3) & 0xfff0) == 0xb900 ) {
  267. if ( phy_read(31) == 0x4404 ) {
  268. /* DM9801 present */
  269. if (phy_read(3) == 0xb901)
  270. phy_write(16, 0x5); /* DM9801 E4 */
  271. else
  272. phy_write(16, 0x1005); /* DM9801 E3 and others */
  273. phy_write(25, ((phy_read(24) + 3) & 0xff) | 0xf000);
  274. } else {
  275. /* DM9802 present */
  276. phy_write(16, 0x5);
  277. phy_write(25, (phy_read(25) & 0xff00) + 2);
  278. }
  279. }
  280. }
  281. /*
  282. Sense media mode and set CR6
  283. */
  284. static void davicom_media_chk(struct nic * nic __unused)
  285. {
  286. unsigned long to, csr6;
  287. csr6 = 0x00200000; /* SF */
  288. outl(csr6, ioaddr + CSR6);
  289. #define PCI_DEVICE_ID_DM9009 0x9009
  290. if (vendor == PCI_VENDOR_ID_DAVICOM && dev_id == PCI_DEVICE_ID_DM9009) {
  291. /* Set to 10BaseT mode for DM9009 */
  292. phy_write(0, 0);
  293. } else {
  294. /* For DM9102/DM9102A */
  295. to = currticks() + 2 * TICKS_PER_SEC;
  296. while ( ((phy_read(1) & 0x24)!=0x24) && (currticks() < to))
  297. /* wait */ ;
  298. if ( (phy_read(1) & 0x24) == 0x24 ) {
  299. if (phy_read(17) & 0xa000)
  300. csr6 |= 0x00000200; /* Full Duplex mode */
  301. } else
  302. csr6 |= 0x00040000; /* Select DM9801/DM9802 when Ethernet link failed */
  303. }
  304. /* set the chip's operating mode */
  305. outl(csr6, ioaddr + CSR6);
  306. /* DM9801/DM9802 present check & program */
  307. if (csr6 & 0x40000)
  308. HPNA_process();
  309. }
  310. /*********************************************************************/
  311. /* EEPROM Reading Code */
  312. /*********************************************************************/
  313. /* EEPROM routines adapted from the Linux Tulip Code */
  314. /* Reading a serial EEPROM is a "bit" grungy, but we work our way
  315. through:->.
  316. */
  317. static int read_eeprom(unsigned long ioaddr, int location, int addr_len)
  318. {
  319. int i;
  320. unsigned short retval = 0;
  321. long ee_addr = ioaddr + CSR9;
  322. int read_cmd = location | EE_READ_CMD;
  323. whereami("read_eeprom\n");
  324. outl(EE_ENB & ~EE_CS, ee_addr);
  325. outl(EE_ENB, ee_addr);
  326. /* Shift the read command bits out. */
  327. for (i = 4 + addr_len; i >= 0; i--) {
  328. short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
  329. outl(EE_ENB | dataval, ee_addr);
  330. eeprom_delay();
  331. outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
  332. eeprom_delay();
  333. }
  334. outl(EE_ENB, ee_addr);
  335. for (i = 16; i > 0; i--) {
  336. outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
  337. eeprom_delay();
  338. retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
  339. outl(EE_ENB, ee_addr);
  340. eeprom_delay();
  341. }
  342. /* Terminate the EEPROM access. */
  343. outl(EE_ENB & ~EE_CS, ee_addr);
  344. return retval;
  345. }
  346. /*********************************************************************/
  347. /* davicom_init_chain - setup the tx and rx descriptors */
  348. /* Sten 10/9 */
  349. /*********************************************************************/
  350. static void davicom_init_chain(struct nic *nic)
  351. {
  352. int i;
  353. /* setup the transmit descriptor */
  354. /* Sten: Set 2 TX descriptor but use one TX buffer because
  355. it transmit a packet and wait complete every time. */
  356. for (i=0; i<NTXD; i++) {
  357. txd[i].buf1addr = (void *)virt_to_bus(&txb[0]); /* Used same TX buffer */
  358. txd[i].buf2addr = (void *)virt_to_bus(&txd[i+1]); /* Point to Next TX desc */
  359. txd[i].buf1sz = 0;
  360. txd[i].buf2sz = 0;
  361. txd[i].control = 0x184; /* Begin/End/Chain */
  362. txd[i].status = 0x00000000; /* give ownership to Host */
  363. }
  364. /* construct perfect filter frame with mac address as first match
  365. and broadcast address for all others */
  366. for (i=0; i<192; i++) txb[i] = 0xFF;
  367. txb[0] = nic->node_addr[0];
  368. txb[1] = nic->node_addr[1];
  369. txb[4] = nic->node_addr[2];
  370. txb[5] = nic->node_addr[3];
  371. txb[8] = nic->node_addr[4];
  372. txb[9] = nic->node_addr[5];
  373. /* setup receive descriptor */
  374. for (i=0; i<NRXD; i++) {
  375. rxd[i].buf1addr = (void *)virt_to_bus(&rxb[i * BUFLEN]);
  376. rxd[i].buf2addr = (void *)virt_to_bus(&rxd[i+1]); /* Point to Next RX desc */
  377. rxd[i].buf1sz = BUFLEN;
  378. rxd[i].buf2sz = 0; /* not used */
  379. rxd[i].control = 0x4; /* Chain Structure */
  380. rxd[i].status = 0x80000000; /* give ownership to device */
  381. }
  382. /* Chain the last descriptor to first */
  383. txd[NTXD - 1].buf2addr = (void *)virt_to_bus(&txd[0]);
  384. rxd[NRXD - 1].buf2addr = (void *)virt_to_bus(&rxd[0]);
  385. TxPtr = 0;
  386. rxd_tail = 0;
  387. }
  388. /*********************************************************************/
  389. /* davicom_reset - Reset adapter */
  390. /*********************************************************************/
  391. static void davicom_reset(struct nic *nic)
  392. {
  393. unsigned long to;
  394. whereami("davicom_reset\n");
  395. /* Stop Tx and RX */
  396. outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
  397. /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
  398. outl(0x00000001, ioaddr + CSR0);
  399. davicom_wait(TICKS_PER_SEC);
  400. /* TX/RX descriptor burst */
  401. outl(0x0C00000, ioaddr + CSR0); /* Sten 10/9 */
  402. /* set up transmit and receive descriptors */
  403. davicom_init_chain(nic); /* Sten 10/9 */
  404. /* Point to receive descriptor */
  405. outl(virt_to_bus(&rxd[0]), ioaddr + CSR3);
  406. outl(virt_to_bus(&txd[0]), ioaddr + CSR4); /* Sten 10/9 */
  407. /* According phyxcer media mode to set CR6,
  408. DM9102/A phyxcer can auto-detect media mode */
  409. davicom_media_chk(nic);
  410. /* Prepare Setup Frame Sten 10/9 */
  411. txd[TxPtr].buf1sz = 192;
  412. txd[TxPtr].control = 0x024; /* SF/CE */
  413. txd[TxPtr].status = 0x80000000; /* Give ownership to device */
  414. /* Start Tx */
  415. outl(inl(ioaddr + CSR6) | 0x00002000, ioaddr + CSR6);
  416. /* immediate transmit demand */
  417. outl(0, ioaddr + CSR1);
  418. to = currticks() + TX_TIME_OUT;
  419. while ((txd[TxPtr].status & 0x80000000) && (currticks() < to)) /* Sten 10/9 */
  420. /* wait */ ;
  421. if (currticks() >= to) {
  422. printf ("TX Setup Timeout!\n");
  423. }
  424. /* Point to next TX descriptor */
  425. TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr; /* Sten 10/9 */
  426. #ifdef DAVICOM_DEBUG
  427. printf("txd.status = %X\n", txd.status);
  428. printf("ticks = %d\n", currticks() - (to - TX_TIME_OUT));
  429. davicom_more();
  430. #endif
  431. /* enable RX */
  432. outl(inl(ioaddr + CSR6) | 0x00000002, ioaddr + CSR6);
  433. /* immediate poll demand */
  434. outl(0, ioaddr + CSR2);
  435. }
  436. /*********************************************************************/
  437. /* eth_transmit - Transmit a frame */
  438. /*********************************************************************/
  439. static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
  440. unsigned int s, const char *p)
  441. {
  442. unsigned long to;
  443. whereami("davicom_transmit\n");
  444. /* Stop Tx */
  445. /* outl(inl(ioaddr + CSR6) & ~0x00002000, ioaddr + CSR6); */
  446. /* setup ethernet header */
  447. memcpy(&txb[0], d, ETH_ALEN); /* DA 6byte */
  448. memcpy(&txb[ETH_ALEN], nic->node_addr, ETH_ALEN); /* SA 6byte*/
  449. txb[ETH_ALEN*2] = (t >> 8) & 0xFF; /* Frame type: 2byte */
  450. txb[ETH_ALEN*2+1] = t & 0xFF;
  451. memcpy(&txb[ETH_HLEN], p, s); /* Frame data */
  452. /* setup the transmit descriptor */
  453. txd[TxPtr].buf1sz = ETH_HLEN+s;
  454. txd[TxPtr].control = 0x00000184; /* LS+FS+CE */
  455. txd[TxPtr].status = 0x80000000; /* give ownership to device */
  456. /* immediate transmit demand */
  457. outl(0, ioaddr + CSR1);
  458. to = currticks() + TX_TIME_OUT;
  459. while ((txd[TxPtr].status & 0x80000000) && (currticks() < to))
  460. /* wait */ ;
  461. if (currticks() >= to) {
  462. printf ("TX Timeout!\n");
  463. }
  464. /* Point to next TX descriptor */
  465. TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr; /* Sten 10/9 */
  466. }
  467. /*********************************************************************/
  468. /* eth_poll - Wait for a frame */
  469. /*********************************************************************/
  470. static int davicom_poll(struct nic *nic, int retrieve)
  471. {
  472. whereami("davicom_poll\n");
  473. if (rxd[rxd_tail].status & 0x80000000)
  474. return 0;
  475. if ( ! retrieve ) return 1;
  476. whereami("davicom_poll got one\n");
  477. nic->packetlen = (rxd[rxd_tail].status & 0x3FFF0000) >> 16;
  478. if( rxd[rxd_tail].status & 0x00008000){
  479. rxd[rxd_tail].status = 0x80000000;
  480. rxd_tail++;
  481. if (rxd_tail == NRXD) rxd_tail = 0;
  482. return 0;
  483. }
  484. /* copy packet to working buffer */
  485. /* XXX - this copy could be avoided with a little more work
  486. but for now we are content with it because the optimised
  487. memcpy is quite fast */
  488. memcpy(nic->packet, rxb + rxd_tail * BUFLEN, nic->packetlen);
  489. /* return the descriptor and buffer to receive ring */
  490. rxd[rxd_tail].status = 0x80000000;
  491. rxd_tail++;
  492. if (rxd_tail == NRXD) rxd_tail = 0;
  493. return 1;
  494. }
  495. /*********************************************************************/
  496. /* eth_disable - Disable the interface */
  497. /*********************************************************************/
  498. static void davicom_disable ( struct nic *nic ) {
  499. whereami("davicom_disable\n");
  500. davicom_reset(nic);
  501. /* disable interrupts */
  502. outl(0x00000000, ioaddr + CSR7);
  503. /* Stop the chip's Tx and Rx processes. */
  504. outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
  505. /* Clear the missed-packet counter. */
  506. (volatile unsigned long)inl(ioaddr + CSR8);
  507. }
  508. /*********************************************************************/
  509. /* eth_irq - enable, disable and force interrupts */
  510. /*********************************************************************/
  511. static void davicom_irq(struct nic *nic __unused, irq_action_t action __unused)
  512. {
  513. switch ( action ) {
  514. case DISABLE :
  515. break;
  516. case ENABLE :
  517. break;
  518. case FORCE :
  519. break;
  520. }
  521. }
  522. /*********************************************************************/
  523. /* eth_probe - Look for an adapter */
  524. /*********************************************************************/
  525. static int davicom_probe ( struct dev *dev ) {
  526. struct nic *nic = nic_device ( dev );
  527. struct pci_device *pci = pci_device ( dev );
  528. unsigned int i;
  529. whereami("davicom_probe\n");
  530. if (pci->ioaddr == 0)
  531. return 0;
  532. vendor = pci->vendor;
  533. dev_id = pci->dev_id;
  534. ioaddr = pci->ioaddr & ~3;
  535. nic->irqno = 0;
  536. nic->ioaddr = pci->ioaddr & ~3;
  537. /* wakeup chip */
  538. pcibios_write_config_dword(pci->bus, pci->devfn, 0x40, 0x00000000);
  539. /* Stop the chip's Tx and Rx processes. */
  540. outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
  541. /* Clear the missed-packet counter. */
  542. (volatile unsigned long)inl(ioaddr + CSR8);
  543. /* Get MAC Address */
  544. /* read EEPROM data */
  545. for (i = 0; i < sizeof(ee_data)/2; i++)
  546. ((unsigned short *)ee_data)[i] =
  547. le16_to_cpu(read_eeprom(ioaddr, i, EEPROM_ADDRLEN));
  548. /* extract MAC address from EEPROM buffer */
  549. for (i=0; i<ETH_ALEN; i++)
  550. nic->node_addr[i] = ee_data[20+i];
  551. printf("Davicom %! at ioaddr %#hX\n", nic->node_addr, ioaddr);
  552. /* initialize device */
  553. davicom_reset(nic);
  554. dev->disable = davicom_disable;
  555. nic->poll = davicom_poll;
  556. nic->transmit = davicom_transmit;
  557. nic->irq = davicom_irq;
  558. return 1;
  559. }
  560. static struct pci_id davicom_nics[] = {
  561. PCI_ROM(0x1282, 0x9100, "davicom9100", "Davicom 9100"),
  562. PCI_ROM(0x1282, 0x9102, "davicom9102", "Davicom 9102"),
  563. PCI_ROM(0x1282, 0x9009, "davicom9009", "Davicom 9009"),
  564. PCI_ROM(0x1282, 0x9132, "davicom9132", "Davicom 9132"), /* Needs probably some fixing */
  565. };
  566. static struct pci_driver davicom_driver =
  567. PCI_DRIVER ( "DAVICOM", davicom_nics, PCI_NO_CLASS );
  568. BOOT_DRIVER ( "DAVICOM", davicom_probe );