您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

davicom.c 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. static struct nic_operations davicom_operations;
  107. static struct pci_driver davicom_driver;
  108. /* PCI Bus parameters */
  109. static unsigned short vendor, dev_id;
  110. static unsigned long ioaddr;
  111. /* Note: transmit and receive buffers must be longword aligned and
  112. longword divisable */
  113. /* transmit descriptor and buffer */
  114. #define NTXD 2
  115. static struct txdesc txd[NTXD] __attribute__ ((aligned(4)));
  116. static unsigned char txb[BUFLEN] __attribute__ ((aligned(4)));
  117. /* receive descriptor(s) and buffer(s) */
  118. #define NRXD 4
  119. static struct rxdesc rxd[NRXD] __attribute__ ((aligned(4)));
  120. static unsigned char rxb[NRXD * BUFLEN] __attribute__ ((aligned(4)));
  121. static int rxd_tail;
  122. static int TxPtr;
  123. /*********************************************************************/
  124. /* Function Prototypes */
  125. /*********************************************************************/
  126. static void whereami(const char *str);
  127. static int read_eeprom(unsigned long ioaddr, int location, int addr_len);
  128. static int davicom_probe(struct dev *dev);
  129. static void davicom_init_chain(struct nic *nic); /* Sten 10/9 */
  130. static void davicom_reset(struct nic *nic);
  131. static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
  132. unsigned int s, const char *p);
  133. static int davicom_poll(struct nic *nic, int retrieve);
  134. static void davicom_disable(struct nic *nic);
  135. #ifdef DAVICOM_DEBUG
  136. static void davicom_more(void);
  137. #endif /* DAVICOM_DEBUG */
  138. static void davicom_wait(unsigned int nticks);
  139. static int phy_read(int);
  140. static void phy_write(int, u16);
  141. static void phy_write_1bit(u32, u32);
  142. static int phy_read_1bit(u32);
  143. static void davicom_media_chk(struct nic *);
  144. /*********************************************************************/
  145. /* Utility Routines */
  146. /*********************************************************************/
  147. static inline void whereami(const char *str, struct pci_device *pci)
  148. {
  149. printf("%s\n", str);
  150. /* sleep(2); */
  151. }
  152. #ifdef DAVICOM_DEBUG
  153. static void davicom_more()
  154. {
  155. printf("\n\n-- more --");
  156. while (!iskey())
  157. /* wait */;
  158. getchar();
  159. printf("\n\n");
  160. }
  161. #endif /* DAVICOM_DEBUG */
  162. static void davicom_wait(unsigned int nticks)
  163. {
  164. unsigned int to = currticks() + nticks;
  165. while (currticks() < to)
  166. /* wait */ ;
  167. }
  168. /*********************************************************************/
  169. /* For DAVICOM phyxcer register by MII interface */
  170. /*********************************************************************/
  171. /*
  172. Read a word data from phy register
  173. */
  174. static int phy_read(int location)
  175. {
  176. int i, phy_addr=1;
  177. u16 phy_data;
  178. u32 io_dcr9;
  179. whereami("phy_read\n");
  180. io_dcr9 = ioaddr + CSR9;
  181. /* Send 33 synchronization clock to Phy controller */
  182. for (i=0; i<34; i++)
  183. phy_write_1bit(io_dcr9, PHY_DATA_1);
  184. /* Send start command(01) to Phy */
  185. phy_write_1bit(io_dcr9, PHY_DATA_0);
  186. phy_write_1bit(io_dcr9, PHY_DATA_1);
  187. /* Send read command(10) to Phy */
  188. phy_write_1bit(io_dcr9, PHY_DATA_1);
  189. phy_write_1bit(io_dcr9, PHY_DATA_0);
  190. /* Send Phy addres */
  191. for (i=0x10; i>0; i=i>>1)
  192. phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
  193. /* Send register addres */
  194. for (i=0x10; i>0; i=i>>1)
  195. phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
  196. /* Skip transition state */
  197. phy_read_1bit(io_dcr9);
  198. /* read 16bit data */
  199. for (phy_data=0, i=0; i<16; i++) {
  200. phy_data<<=1;
  201. phy_data|=phy_read_1bit(io_dcr9);
  202. }
  203. return phy_data;
  204. }
  205. /*
  206. Write a word to Phy register
  207. */
  208. static void phy_write(int location, u16 phy_data)
  209. {
  210. u16 i, phy_addr=1;
  211. u32 io_dcr9;
  212. whereami("phy_write\n");
  213. io_dcr9 = ioaddr + CSR9;
  214. /* Send 33 synchronization clock to Phy controller */
  215. for (i=0; i<34; i++)
  216. phy_write_1bit(io_dcr9, PHY_DATA_1);
  217. /* Send start command(01) to Phy */
  218. phy_write_1bit(io_dcr9, PHY_DATA_0);
  219. phy_write_1bit(io_dcr9, PHY_DATA_1);
  220. /* Send write command(01) to Phy */
  221. phy_write_1bit(io_dcr9, PHY_DATA_0);
  222. phy_write_1bit(io_dcr9, PHY_DATA_1);
  223. /* Send Phy addres */
  224. for (i=0x10; i>0; i=i>>1)
  225. phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
  226. /* Send register addres */
  227. for (i=0x10; i>0; i=i>>1)
  228. phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
  229. /* written trasnition */
  230. phy_write_1bit(io_dcr9, PHY_DATA_1);
  231. phy_write_1bit(io_dcr9, PHY_DATA_0);
  232. /* Write a word data to PHY controller */
  233. for (i=0x8000; i>0; i>>=1)
  234. phy_write_1bit(io_dcr9, phy_data&i ? PHY_DATA_1: PHY_DATA_0);
  235. }
  236. /*
  237. Write one bit data to Phy Controller
  238. */
  239. static void phy_write_1bit(u32 ee_addr, u32 phy_data)
  240. {
  241. whereami("phy_write_1bit\n");
  242. outl(phy_data, ee_addr); /* MII Clock Low */
  243. eeprom_delay();
  244. outl(phy_data|MDCLKH, ee_addr); /* MII Clock High */
  245. eeprom_delay();
  246. outl(phy_data, ee_addr); /* MII Clock Low */
  247. eeprom_delay();
  248. }
  249. /*
  250. Read one bit phy data from PHY controller
  251. */
  252. static int phy_read_1bit(u32 ee_addr)
  253. {
  254. int phy_data;
  255. whereami("phy_read_1bit\n");
  256. outl(0x50000, ee_addr);
  257. eeprom_delay();
  258. phy_data=(inl(ee_addr)>>19) & 0x1;
  259. outl(0x40000, ee_addr);
  260. eeprom_delay();
  261. return phy_data;
  262. }
  263. /*
  264. DM9801/DM9802 present check and program
  265. */
  266. static void HPNA_process(void)
  267. {
  268. if ( (phy_read(3) & 0xfff0) == 0xb900 ) {
  269. if ( phy_read(31) == 0x4404 ) {
  270. /* DM9801 present */
  271. if (phy_read(3) == 0xb901)
  272. phy_write(16, 0x5); /* DM9801 E4 */
  273. else
  274. phy_write(16, 0x1005); /* DM9801 E3 and others */
  275. phy_write(25, ((phy_read(24) + 3) & 0xff) | 0xf000);
  276. } else {
  277. /* DM9802 present */
  278. phy_write(16, 0x5);
  279. phy_write(25, (phy_read(25) & 0xff00) + 2);
  280. }
  281. }
  282. }
  283. /*
  284. Sense media mode and set CR6
  285. */
  286. static void davicom_media_chk(struct nic * nic __unused)
  287. {
  288. unsigned long to, csr6;
  289. csr6 = 0x00200000; /* SF */
  290. outl(csr6, ioaddr + CSR6);
  291. #define PCI_DEVICE_ID_DM9009 0x9009
  292. if (vendor == PCI_VENDOR_ID_DAVICOM && dev_id == PCI_DEVICE_ID_DM9009) {
  293. /* Set to 10BaseT mode for DM9009 */
  294. phy_write(0, 0);
  295. } else {
  296. /* For DM9102/DM9102A */
  297. to = currticks() + 2 * TICKS_PER_SEC;
  298. while ( ((phy_read(1) & 0x24)!=0x24) && (currticks() < to))
  299. /* wait */ ;
  300. if ( (phy_read(1) & 0x24) == 0x24 ) {
  301. if (phy_read(17) & 0xa000)
  302. csr6 |= 0x00000200; /* Full Duplex mode */
  303. } else
  304. csr6 |= 0x00040000; /* Select DM9801/DM9802 when Ethernet link failed */
  305. }
  306. /* set the chip's operating mode */
  307. outl(csr6, ioaddr + CSR6);
  308. /* DM9801/DM9802 present check & program */
  309. if (csr6 & 0x40000)
  310. HPNA_process();
  311. }
  312. /*********************************************************************/
  313. /* EEPROM Reading Code */
  314. /*********************************************************************/
  315. /* EEPROM routines adapted from the Linux Tulip Code */
  316. /* Reading a serial EEPROM is a "bit" grungy, but we work our way
  317. through:->.
  318. */
  319. static int read_eeprom(unsigned long ioaddr, int location, int addr_len)
  320. {
  321. int i;
  322. unsigned short retval = 0;
  323. long ee_addr = ioaddr + CSR9;
  324. int read_cmd = location | EE_READ_CMD;
  325. whereami("read_eeprom\n");
  326. outl(EE_ENB & ~EE_CS, ee_addr);
  327. outl(EE_ENB, ee_addr);
  328. /* Shift the read command bits out. */
  329. for (i = 4 + addr_len; i >= 0; i--) {
  330. short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
  331. outl(EE_ENB | dataval, ee_addr);
  332. eeprom_delay();
  333. outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
  334. eeprom_delay();
  335. }
  336. outl(EE_ENB, ee_addr);
  337. for (i = 16; i > 0; i--) {
  338. outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
  339. eeprom_delay();
  340. retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
  341. outl(EE_ENB, ee_addr);
  342. eeprom_delay();
  343. }
  344. /* Terminate the EEPROM access. */
  345. outl(EE_ENB & ~EE_CS, ee_addr);
  346. return retval;
  347. }
  348. /*********************************************************************/
  349. /* davicom_init_chain - setup the tx and rx descriptors */
  350. /* Sten 10/9 */
  351. /*********************************************************************/
  352. static void davicom_init_chain(struct nic *nic)
  353. {
  354. int i;
  355. /* setup the transmit descriptor */
  356. /* Sten: Set 2 TX descriptor but use one TX buffer because
  357. it transmit a packet and wait complete every time. */
  358. for (i=0; i<NTXD; i++) {
  359. txd[i].buf1addr = (void *)virt_to_bus(&txb[0]); /* Used same TX buffer */
  360. txd[i].buf2addr = (void *)virt_to_bus(&txd[i+1]); /* Point to Next TX desc */
  361. txd[i].buf1sz = 0;
  362. txd[i].buf2sz = 0;
  363. txd[i].control = 0x184; /* Begin/End/Chain */
  364. txd[i].status = 0x00000000; /* give ownership to Host */
  365. }
  366. /* construct perfect filter frame with mac address as first match
  367. and broadcast address for all others */
  368. for (i=0; i<192; i++) txb[i] = 0xFF;
  369. txb[0] = nic->node_addr[0];
  370. txb[1] = nic->node_addr[1];
  371. txb[4] = nic->node_addr[2];
  372. txb[5] = nic->node_addr[3];
  373. txb[8] = nic->node_addr[4];
  374. txb[9] = nic->node_addr[5];
  375. /* setup receive descriptor */
  376. for (i=0; i<NRXD; i++) {
  377. rxd[i].buf1addr = (void *)virt_to_bus(&rxb[i * BUFLEN]);
  378. rxd[i].buf2addr = (void *)virt_to_bus(&rxd[i+1]); /* Point to Next RX desc */
  379. rxd[i].buf1sz = BUFLEN;
  380. rxd[i].buf2sz = 0; /* not used */
  381. rxd[i].control = 0x4; /* Chain Structure */
  382. rxd[i].status = 0x80000000; /* give ownership to device */
  383. }
  384. /* Chain the last descriptor to first */
  385. txd[NTXD - 1].buf2addr = (void *)virt_to_bus(&txd[0]);
  386. rxd[NRXD - 1].buf2addr = (void *)virt_to_bus(&rxd[0]);
  387. TxPtr = 0;
  388. rxd_tail = 0;
  389. }
  390. /*********************************************************************/
  391. /* davicom_reset - Reset adapter */
  392. /*********************************************************************/
  393. static void davicom_reset(struct nic *nic)
  394. {
  395. unsigned long to;
  396. whereami("davicom_reset\n");
  397. /* Stop Tx and RX */
  398. outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
  399. /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
  400. outl(0x00000001, ioaddr + CSR0);
  401. davicom_wait(TICKS_PER_SEC);
  402. /* TX/RX descriptor burst */
  403. outl(0x0C00000, ioaddr + CSR0); /* Sten 10/9 */
  404. /* set up transmit and receive descriptors */
  405. davicom_init_chain(nic); /* Sten 10/9 */
  406. /* Point to receive descriptor */
  407. outl(virt_to_bus(&rxd[0]), ioaddr + CSR3);
  408. outl(virt_to_bus(&txd[0]), ioaddr + CSR4); /* Sten 10/9 */
  409. /* According phyxcer media mode to set CR6,
  410. DM9102/A phyxcer can auto-detect media mode */
  411. davicom_media_chk(nic);
  412. /* Prepare Setup Frame Sten 10/9 */
  413. txd[TxPtr].buf1sz = 192;
  414. txd[TxPtr].control = 0x024; /* SF/CE */
  415. txd[TxPtr].status = 0x80000000; /* Give ownership to device */
  416. /* Start Tx */
  417. outl(inl(ioaddr + CSR6) | 0x00002000, ioaddr + CSR6);
  418. /* immediate transmit demand */
  419. outl(0, ioaddr + CSR1);
  420. to = currticks() + TX_TIME_OUT;
  421. while ((txd[TxPtr].status & 0x80000000) && (currticks() < to)) /* Sten 10/9 */
  422. /* wait */ ;
  423. if (currticks() >= to) {
  424. printf ("TX Setup Timeout!\n");
  425. }
  426. /* Point to next TX descriptor */
  427. TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr; /* Sten 10/9 */
  428. #ifdef DAVICOM_DEBUG
  429. printf("txd.status = %X\n", txd.status);
  430. printf("ticks = %d\n", currticks() - (to - TX_TIME_OUT));
  431. davicom_more();
  432. #endif
  433. /* enable RX */
  434. outl(inl(ioaddr + CSR6) | 0x00000002, ioaddr + CSR6);
  435. /* immediate poll demand */
  436. outl(0, ioaddr + CSR2);
  437. }
  438. /*********************************************************************/
  439. /* eth_transmit - Transmit a frame */
  440. /*********************************************************************/
  441. static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
  442. unsigned int s, const char *p)
  443. {
  444. unsigned long to;
  445. whereami("davicom_transmit\n");
  446. /* Stop Tx */
  447. /* outl(inl(ioaddr + CSR6) & ~0x00002000, ioaddr + CSR6); */
  448. /* setup ethernet header */
  449. memcpy(&txb[0], d, ETH_ALEN); /* DA 6byte */
  450. memcpy(&txb[ETH_ALEN], nic->node_addr, ETH_ALEN); /* SA 6byte*/
  451. txb[ETH_ALEN*2] = (t >> 8) & 0xFF; /* Frame type: 2byte */
  452. txb[ETH_ALEN*2+1] = t & 0xFF;
  453. memcpy(&txb[ETH_HLEN], p, s); /* Frame data */
  454. /* setup the transmit descriptor */
  455. txd[TxPtr].buf1sz = ETH_HLEN+s;
  456. txd[TxPtr].control = 0x00000184; /* LS+FS+CE */
  457. txd[TxPtr].status = 0x80000000; /* give ownership to device */
  458. /* immediate transmit demand */
  459. outl(0, ioaddr + CSR1);
  460. to = currticks() + TX_TIME_OUT;
  461. while ((txd[TxPtr].status & 0x80000000) && (currticks() < to))
  462. /* wait */ ;
  463. if (currticks() >= to) {
  464. printf ("TX Timeout!\n");
  465. }
  466. /* Point to next TX descriptor */
  467. TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr; /* Sten 10/9 */
  468. }
  469. /*********************************************************************/
  470. /* eth_poll - Wait for a frame */
  471. /*********************************************************************/
  472. static int davicom_poll(struct nic *nic, int retrieve)
  473. {
  474. whereami("davicom_poll\n");
  475. if (rxd[rxd_tail].status & 0x80000000)
  476. return 0;
  477. if ( ! retrieve ) return 1;
  478. whereami("davicom_poll got one\n");
  479. nic->packetlen = (rxd[rxd_tail].status & 0x3FFF0000) >> 16;
  480. if( rxd[rxd_tail].status & 0x00008000){
  481. rxd[rxd_tail].status = 0x80000000;
  482. rxd_tail++;
  483. if (rxd_tail == NRXD) rxd_tail = 0;
  484. return 0;
  485. }
  486. /* copy packet to working buffer */
  487. /* XXX - this copy could be avoided with a little more work
  488. but for now we are content with it because the optimised
  489. memcpy is quite fast */
  490. memcpy(nic->packet, rxb + rxd_tail * BUFLEN, nic->packetlen);
  491. /* return the descriptor and buffer to receive ring */
  492. rxd[rxd_tail].status = 0x80000000;
  493. rxd_tail++;
  494. if (rxd_tail == NRXD) rxd_tail = 0;
  495. return 1;
  496. }
  497. /*********************************************************************/
  498. /* eth_disable - Disable the interface */
  499. /*********************************************************************/
  500. static void davicom_disable ( struct nic *nic ) {
  501. whereami("davicom_disable\n");
  502. davicom_reset(nic);
  503. /* disable interrupts */
  504. outl(0x00000000, ioaddr + CSR7);
  505. /* Stop the chip's Tx and Rx processes. */
  506. outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
  507. /* Clear the missed-packet counter. */
  508. (volatile unsigned long)inl(ioaddr + CSR8);
  509. }
  510. /*********************************************************************/
  511. /* eth_irq - enable, disable and force interrupts */
  512. /*********************************************************************/
  513. static void davicom_irq(struct nic *nic __unused, irq_action_t action __unused)
  514. {
  515. switch ( action ) {
  516. case DISABLE :
  517. break;
  518. case ENABLE :
  519. break;
  520. case FORCE :
  521. break;
  522. }
  523. }
  524. /*********************************************************************/
  525. /* eth_probe - Look for an adapter */
  526. /*********************************************************************/
  527. static int davicom_probe ( struct dev *dev ) {
  528. struct nic *nic = nic_device ( dev );
  529. unsigned int i;
  530. whereami("davicom_probe\n");
  531. if (pci->ioaddr == 0)
  532. return 0;
  533. vendor = pci->vendor;
  534. dev_id = pci->dev_id;
  535. ioaddr = pci->ioaddr;
  536. nic->irqno = 0;
  537. nic->ioaddr = pci->ioaddr;
  538. /* wakeup chip */
  539. pci_write_config_dword(pci, 0x40, 0x00000000);
  540. /* Stop the chip's Tx and Rx processes. */
  541. outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
  542. /* Clear the missed-packet counter. */
  543. (volatile unsigned long)inl(ioaddr + CSR8);
  544. /* Get MAC Address */
  545. /* read EEPROM data */
  546. for (i = 0; i < sizeof(ee_data)/2; i++)
  547. ((unsigned short *)ee_data)[i] =
  548. le16_to_cpu(read_eeprom(ioaddr, i, EEPROM_ADDRLEN));
  549. /* extract MAC address from EEPROM buffer */
  550. for (i=0; i<ETH_ALEN; i++)
  551. nic->node_addr[i] = ee_data[20+i];
  552. printf("Davicom %! at ioaddr %#hX\n", nic->node_addr, ioaddr);
  553. /* initialize device */
  554. davicom_reset(nic);
  555. nic->nic_op = &davicom_operations;
  556. return 1;
  557. }
  558. static struct nic_operations davicom_operations = {
  559. .connect = dummy_connect,
  560. .poll = davicom_poll,
  561. .transmit = davicom_transmit,
  562. .irq = davicom_irq,
  563. .disable = davicom_disable,
  564. };
  565. static struct pci_id davicom_nics[] = {
  566. PCI_ROM(0x1282, 0x9100, "davicom9100", "Davicom 9100"),
  567. PCI_ROM(0x1282, 0x9102, "davicom9102", "Davicom 9102"),
  568. PCI_ROM(0x1282, 0x9009, "davicom9009", "Davicom 9009"),
  569. PCI_ROM(0x1282, 0x9132, "davicom9132", "Davicom 9132"), /* Needs probably some fixing */
  570. };
  571. static struct pci_driver davicom_driver =
  572. PCI_DRIVER ( "DAVICOM", davicom_nics, PCI_NO_CLASS );
  573. BOOT_DRIVER ( "DAVICOM", find_pci_boot_device, davicom_driver, davicom_probe );