2 #error multicast support is not yet implemented
5 DAVICOM DM9009/DM9102/DM9102A Etherboot Driver V1.00
7 This driver was ported from Marty Connor's Tulip Etherboot driver.
8 Thanks Marty Connor (mdc@etherboot.org)
10 This davicom etherboot driver supports DM9009/DM9102/DM9102A/
11 DM9102A+DM9801/DM9102A+DM9802 NICs.
13 This software may be used and distributed according to the terms
14 of the GNU Public License, incorporated herein by reference.
18 /*********************************************************************/
19 /* Revision History */
20 /*********************************************************************/
24 Different half and full duplex mode
25 Do the different programming for DM9801/DM9802
28 This driver was ported from tulip driver and it
29 has the following difference.
30 Changed symbol tulip/TULIP to davicom/DAVICOM
31 Deleted some code that did not use in this driver.
32 Used chain-strcture to replace ring structure
33 for both TX/RX descriptor.
34 Allocated two tx descriptor.
35 According current media mode to set operating
40 /*********************************************************************/
42 /*********************************************************************/
44 #include "etherboot.h"
49 #undef DAVICOM_DEBUG_WHERE
51 #define TX_TIME_OUT 2*TICKS_PER_SEC
53 /* Register offsets for davicom device */
54 enum davicom_offsets {
55 CSR0=0, CSR1=0x08, CSR2=0x10, CSR3=0x18, CSR4=0x20, CSR5=0x28,
56 CSR6=0x30, CSR7=0x38, CSR8=0x40, CSR9=0x48, CSR10=0x50, CSR11=0x58,
57 CSR12=0x60, CSR13=0x68, CSR14=0x70, CSR15=0x78, CSR16=0x80, CSR20=0xA0
60 /* EEPROM Address width definitions */
61 #define EEPROM_ADDRLEN 6
62 #define EEPROM_SIZE 32 /* 1 << EEPROM_ADDRLEN */
63 /* Used to be 128, but we only need to read enough to get the MAC
64 address at bytes 20..25 */
66 /* Data Read from the EEPROM */
67 static unsigned char ee_data[EEPROM_SIZE];
69 /* The EEPROM commands include the alway-set leading bit. */
70 #define EE_WRITE_CMD (5 << addr_len)
71 #define EE_READ_CMD (6 << addr_len)
72 #define EE_ERASE_CMD (7 << addr_len)
74 /* EEPROM_Ctrl bits. */
75 #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
76 #define EE_CS 0x01 /* EEPROM chip select. */
77 #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
78 #define EE_WRITE_0 0x01
79 #define EE_WRITE_1 0x05
80 #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
81 #define EE_ENB (0x4800 | EE_CS)
83 /* Sten 10/11 for phyxcer */
84 #define PHY_DATA_0 0x0
85 #define PHY_DATA_1 0x20000
86 #define MDCLKH 0x10000
88 /* Delay between EEPROM clock transitions. Even at 33Mhz current PCI
89 implementations don't overrun the EEPROM clock. We add a bus
90 turn-around to insure that this remains true. */
91 #define eeprom_delay() inl(ee_addr)
93 /* helpful macro if on a big_endian machine for changing byte order.
94 not strictly needed on Intel
95 Already defined in Etherboot includes
96 #define le16_to_cpu(val) (val)
99 /* transmit and receive descriptor format */
101 volatile unsigned long status; /* owner, status */
102 unsigned long buf1sz:11, /* size of buffer 1 */
103 buf2sz:11, /* size of buffer 2 */
104 control:10; /* control bits */
105 const unsigned char *buf1addr; /* buffer 1 address */
106 const unsigned char *buf2addr; /* buffer 2 address */
110 volatile unsigned long status; /* owner, status */
111 unsigned long buf1sz:11, /* size of buffer 1 */
112 buf2sz:11, /* size of buffer 2 */
113 control:10; /* control bits */
114 unsigned char *buf1addr; /* buffer 1 address */
115 unsigned char *buf2addr; /* buffer 2 address */
118 /* Size of transmit and receive buffers */
121 /*********************************************************************/
123 /*********************************************************************/
125 static struct nic_operations davicom_operations;
127 /* PCI Bus parameters */
128 static unsigned short vendor, dev_id;
129 static unsigned long ioaddr;
131 /* Note: transmit and receive buffers must be longword aligned and
132 longword divisable */
134 /* transmit descriptor and buffer */
138 struct txdesc txd[NTXD] __attribute__ ((aligned(4)));
139 unsigned char txb[BUFLEN] __attribute__ ((aligned(4)));
140 struct rxdesc rxd[NRXD] __attribute__ ((aligned(4)));
141 unsigned char rxb[NRXD * BUFLEN] __attribute__ ((aligned(4)));
142 } davicom_bufs __shared;
143 #define txd davicom_bufs.txd
144 #define txb davicom_bufs.txb
145 #define rxd davicom_bufs.rxd
146 #define rxb davicom_bufs.rxb
151 /*********************************************************************/
152 /* Function Prototypes */
153 /*********************************************************************/
154 static void whereami(const char *str);
155 static int read_eeprom(unsigned long ioaddr, int location, int addr_len);
156 static int davicom_probe(struct nic *nic,struct pci_device *pci);
157 static void davicom_init_chain(struct nic *nic); /* Sten 10/9 */
158 static void davicom_reset(struct nic *nic);
159 static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
160 unsigned int s, const char *p);
161 static int davicom_poll(struct nic *nic, int retrieve);
162 static void davicom_disable(struct nic *nic, struct pci_device *pci);
164 static void davicom_more(void);
165 #endif /* DAVICOM_DEBUG */
166 static void davicom_wait(unsigned int nticks);
167 static int phy_read(int);
168 static void phy_write(int, u16);
169 static void phy_write_1bit(u32, u32);
170 static int phy_read_1bit(u32);
171 static void davicom_media_chk(struct nic *);
174 /*********************************************************************/
175 /* Utility Routines */
176 /*********************************************************************/
177 static inline void whereami(const char *str)
184 static void davicom_more()
186 printf("\n\n-- more --");
192 #endif /* DAVICOM_DEBUG */
194 static void davicom_wait(unsigned int nticks)
196 unsigned int to = currticks() + nticks;
197 while (currticks() < to)
202 /*********************************************************************/
203 /* For DAVICOM phyxcer register by MII interface */
204 /*********************************************************************/
206 Read a word data from phy register
208 static int phy_read(int location)
214 whereami("phy_read\n");
216 io_dcr9 = ioaddr + CSR9;
218 /* Send 33 synchronization clock to Phy controller */
220 phy_write_1bit(io_dcr9, PHY_DATA_1);
222 /* Send start command(01) to Phy */
223 phy_write_1bit(io_dcr9, PHY_DATA_0);
224 phy_write_1bit(io_dcr9, PHY_DATA_1);
226 /* Send read command(10) to Phy */
227 phy_write_1bit(io_dcr9, PHY_DATA_1);
228 phy_write_1bit(io_dcr9, PHY_DATA_0);
230 /* Send Phy addres */
231 for (i=0x10; i>0; i=i>>1)
232 phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
234 /* Send register addres */
235 for (i=0x10; i>0; i=i>>1)
236 phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
238 /* Skip transition state */
239 phy_read_1bit(io_dcr9);
241 /* read 16bit data */
242 for (phy_data=0, i=0; i<16; i++) {
244 phy_data|=phy_read_1bit(io_dcr9);
251 Write a word to Phy register
253 static void phy_write(int location, u16 phy_data)
258 whereami("phy_write\n");
260 io_dcr9 = ioaddr + CSR9;
262 /* Send 33 synchronization clock to Phy controller */
264 phy_write_1bit(io_dcr9, PHY_DATA_1);
266 /* Send start command(01) to Phy */
267 phy_write_1bit(io_dcr9, PHY_DATA_0);
268 phy_write_1bit(io_dcr9, PHY_DATA_1);
270 /* Send write command(01) to Phy */
271 phy_write_1bit(io_dcr9, PHY_DATA_0);
272 phy_write_1bit(io_dcr9, PHY_DATA_1);
274 /* Send Phy addres */
275 for (i=0x10; i>0; i=i>>1)
276 phy_write_1bit(io_dcr9, phy_addr&i ? PHY_DATA_1: PHY_DATA_0);
278 /* Send register addres */
279 for (i=0x10; i>0; i=i>>1)
280 phy_write_1bit(io_dcr9, location&i ? PHY_DATA_1: PHY_DATA_0);
282 /* written trasnition */
283 phy_write_1bit(io_dcr9, PHY_DATA_1);
284 phy_write_1bit(io_dcr9, PHY_DATA_0);
286 /* Write a word data to PHY controller */
287 for (i=0x8000; i>0; i>>=1)
288 phy_write_1bit(io_dcr9, phy_data&i ? PHY_DATA_1: PHY_DATA_0);
292 Write one bit data to Phy Controller
294 static void phy_write_1bit(u32 ee_addr, u32 phy_data)
296 whereami("phy_write_1bit\n");
297 outl(phy_data, ee_addr); /* MII Clock Low */
299 outl(phy_data|MDCLKH, ee_addr); /* MII Clock High */
301 outl(phy_data, ee_addr); /* MII Clock Low */
306 Read one bit phy data from PHY controller
308 static int phy_read_1bit(u32 ee_addr)
312 whereami("phy_read_1bit\n");
314 outl(0x50000, ee_addr);
317 phy_data=(inl(ee_addr)>>19) & 0x1;
319 outl(0x40000, ee_addr);
326 DM9801/DM9802 present check and program
328 static void HPNA_process(void)
331 if ( (phy_read(3) & 0xfff0) == 0xb900 ) {
332 if ( phy_read(31) == 0x4404 ) {
334 if (phy_read(3) == 0xb901)
335 phy_write(16, 0x5); /* DM9801 E4 */
337 phy_write(16, 0x1005); /* DM9801 E3 and others */
338 phy_write(25, ((phy_read(24) + 3) & 0xff) | 0xf000);
342 phy_write(25, (phy_read(25) & 0xff00) + 2);
348 Sense media mode and set CR6
350 static void davicom_media_chk(struct nic * nic __unused)
352 unsigned long to, csr6;
354 csr6 = 0x00200000; /* SF */
355 outl(csr6, ioaddr + CSR6);
357 #define PCI_DEVICE_ID_DM9009 0x9009
358 if (vendor == PCI_VENDOR_ID_DAVICOM && dev_id == PCI_DEVICE_ID_DM9009) {
359 /* Set to 10BaseT mode for DM9009 */
362 /* For DM9102/DM9102A */
363 to = currticks() + 2 * TICKS_PER_SEC;
364 while ( ((phy_read(1) & 0x24)!=0x24) && (currticks() < to))
367 if ( (phy_read(1) & 0x24) == 0x24 ) {
368 if (phy_read(17) & 0xa000)
369 csr6 |= 0x00000200; /* Full Duplex mode */
371 csr6 |= 0x00040000; /* Select DM9801/DM9802 when Ethernet link failed */
374 /* set the chip's operating mode */
375 outl(csr6, ioaddr + CSR6);
377 /* DM9801/DM9802 present check & program */
383 /*********************************************************************/
384 /* EEPROM Reading Code */
385 /*********************************************************************/
386 /* EEPROM routines adapted from the Linux Tulip Code */
387 /* Reading a serial EEPROM is a "bit" grungy, but we work our way
390 static int read_eeprom(unsigned long ioaddr, int location, int addr_len)
393 unsigned short retval = 0;
394 long ee_addr = ioaddr + CSR9;
395 int read_cmd = location | EE_READ_CMD;
397 whereami("read_eeprom\n");
399 outl(EE_ENB & ~EE_CS, ee_addr);
400 outl(EE_ENB, ee_addr);
402 /* Shift the read command bits out. */
403 for (i = 4 + addr_len; i >= 0; i--) {
404 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
405 outl(EE_ENB | dataval, ee_addr);
407 outl(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr);
410 outl(EE_ENB, ee_addr);
412 for (i = 16; i > 0; i--) {
413 outl(EE_ENB | EE_SHIFT_CLK, ee_addr);
415 retval = (retval << 1) | ((inl(ee_addr) & EE_DATA_READ) ? 1 : 0);
416 outl(EE_ENB, ee_addr);
420 /* Terminate the EEPROM access. */
421 outl(EE_ENB & ~EE_CS, ee_addr);
425 /*********************************************************************/
426 /* davicom_init_chain - setup the tx and rx descriptors */
428 /*********************************************************************/
429 static void davicom_init_chain(struct nic *nic)
433 /* setup the transmit descriptor */
434 /* Sten: Set 2 TX descriptor but use one TX buffer because
435 it transmit a packet and wait complete every time. */
436 for (i=0; i<NTXD; i++) {
437 txd[i].buf1addr = (void *)virt_to_bus(&txb[0]); /* Used same TX buffer */
438 txd[i].buf2addr = (void *)virt_to_bus(&txd[i+1]); /* Point to Next TX desc */
441 txd[i].control = 0x184; /* Begin/End/Chain */
442 txd[i].status = 0x00000000; /* give ownership to Host */
445 /* construct perfect filter frame with mac address as first match
446 and broadcast address for all others */
447 for (i=0; i<192; i++) txb[i] = 0xFF;
448 txb[0] = nic->node_addr[0];
449 txb[1] = nic->node_addr[1];
450 txb[4] = nic->node_addr[2];
451 txb[5] = nic->node_addr[3];
452 txb[8] = nic->node_addr[4];
453 txb[9] = nic->node_addr[5];
455 /* setup receive descriptor */
456 for (i=0; i<NRXD; i++) {
457 rxd[i].buf1addr = (void *)virt_to_bus(&rxb[i * BUFLEN]);
458 rxd[i].buf2addr = (void *)virt_to_bus(&rxd[i+1]); /* Point to Next RX desc */
459 rxd[i].buf1sz = BUFLEN;
460 rxd[i].buf2sz = 0; /* not used */
461 rxd[i].control = 0x4; /* Chain Structure */
462 rxd[i].status = 0x80000000; /* give ownership to device */
465 /* Chain the last descriptor to first */
466 txd[NTXD - 1].buf2addr = (void *)virt_to_bus(&txd[0]);
467 rxd[NRXD - 1].buf2addr = (void *)virt_to_bus(&rxd[0]);
473 /*********************************************************************/
474 /* davicom_reset - Reset adapter */
475 /*********************************************************************/
476 static void davicom_reset(struct nic *nic)
480 whereami("davicom_reset\n");
483 outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
485 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
486 outl(0x00000001, ioaddr + CSR0);
488 davicom_wait(TICKS_PER_SEC);
490 /* TX/RX descriptor burst */
491 outl(0x0C00000, ioaddr + CSR0); /* Sten 10/9 */
493 /* set up transmit and receive descriptors */
494 davicom_init_chain(nic); /* Sten 10/9 */
496 /* Point to receive descriptor */
497 outl(virt_to_bus(&rxd[0]), ioaddr + CSR3);
498 outl(virt_to_bus(&txd[0]), ioaddr + CSR4); /* Sten 10/9 */
500 /* According phyxcer media mode to set CR6,
501 DM9102/A phyxcer can auto-detect media mode */
502 davicom_media_chk(nic);
504 /* Prepare Setup Frame Sten 10/9 */
505 txd[TxPtr].buf1sz = 192;
506 txd[TxPtr].control = 0x024; /* SF/CE */
507 txd[TxPtr].status = 0x80000000; /* Give ownership to device */
510 outl(inl(ioaddr + CSR6) | 0x00002000, ioaddr + CSR6);
511 /* immediate transmit demand */
512 outl(0, ioaddr + CSR1);
514 to = currticks() + TX_TIME_OUT;
515 while ((txd[TxPtr].status & 0x80000000) && (currticks() < to)) /* Sten 10/9 */
518 if (currticks() >= to) {
519 printf ("TX Setup Timeout!\n");
521 /* Point to next TX descriptor */
522 TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr; /* Sten 10/9 */
525 printf("txd.status = %X\n", txd.status);
526 printf("ticks = %d\n", currticks() - (to - TX_TIME_OUT));
531 outl(inl(ioaddr + CSR6) | 0x00000002, ioaddr + CSR6);
532 /* immediate poll demand */
533 outl(0, ioaddr + CSR2);
537 /*********************************************************************/
538 /* eth_transmit - Transmit a frame */
539 /*********************************************************************/
540 static void davicom_transmit(struct nic *nic, const char *d, unsigned int t,
541 unsigned int s, const char *p)
545 whereami("davicom_transmit\n");
548 /* outl(inl(ioaddr + CSR6) & ~0x00002000, ioaddr + CSR6); */
550 /* setup ethernet header */
551 memcpy(&txb[0], d, ETH_ALEN); /* DA 6byte */
552 memcpy(&txb[ETH_ALEN], nic->node_addr, ETH_ALEN); /* SA 6byte*/
553 txb[ETH_ALEN*2] = (t >> 8) & 0xFF; /* Frame type: 2byte */
554 txb[ETH_ALEN*2+1] = t & 0xFF;
555 memcpy(&txb[ETH_HLEN], p, s); /* Frame data */
557 /* setup the transmit descriptor */
558 txd[TxPtr].buf1sz = ETH_HLEN+s;
559 txd[TxPtr].control = 0x00000184; /* LS+FS+CE */
560 txd[TxPtr].status = 0x80000000; /* give ownership to device */
562 /* immediate transmit demand */
563 outl(0, ioaddr + CSR1);
565 to = currticks() + TX_TIME_OUT;
566 while ((txd[TxPtr].status & 0x80000000) && (currticks() < to))
569 if (currticks() >= to) {
570 printf ("TX Timeout!\n");
573 /* Point to next TX descriptor */
574 TxPtr = (++TxPtr >= NTXD) ? 0:TxPtr; /* Sten 10/9 */
578 /*********************************************************************/
579 /* eth_poll - Wait for a frame */
580 /*********************************************************************/
581 static int davicom_poll(struct nic *nic, int retrieve)
583 whereami("davicom_poll\n");
585 if (rxd[rxd_tail].status & 0x80000000)
588 if ( ! retrieve ) return 1;
590 whereami("davicom_poll got one\n");
592 nic->packetlen = (rxd[rxd_tail].status & 0x3FFF0000) >> 16;
594 if( rxd[rxd_tail].status & 0x00008000){
595 rxd[rxd_tail].status = 0x80000000;
597 if (rxd_tail == NRXD) rxd_tail = 0;
601 /* copy packet to working buffer */
602 /* XXX - this copy could be avoided with a little more work
603 but for now we are content with it because the optimised
604 memcpy is quite fast */
606 memcpy(nic->packet, rxb + rxd_tail * BUFLEN, nic->packetlen);
608 /* return the descriptor and buffer to receive ring */
609 rxd[rxd_tail].status = 0x80000000;
611 if (rxd_tail == NRXD) rxd_tail = 0;
616 /*********************************************************************/
617 /* eth_disable - Disable the interface */
618 /*********************************************************************/
619 static void davicom_disable ( struct nic *nic, struct pci_device *pci __unused ) {
621 whereami("davicom_disable\n");
625 /* disable interrupts */
626 outl(0x00000000, ioaddr + CSR7);
628 /* Stop the chip's Tx and Rx processes. */
629 outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
631 /* Clear the missed-packet counter. */
632 (volatile unsigned long)inl(ioaddr + CSR8);
636 /*********************************************************************/
637 /* eth_irq - enable, disable and force interrupts */
638 /*********************************************************************/
639 static void davicom_irq(struct nic *nic __unused, irq_action_t action __unused)
652 /*********************************************************************/
653 /* eth_probe - Look for an adapter */
654 /*********************************************************************/
655 static int davicom_probe ( struct nic *nic, struct pci_device *pci ) {
659 whereami("davicom_probe\n");
661 if (pci->ioaddr == 0)
664 vendor = pci->vendor;
665 dev_id = pci->device;
666 ioaddr = pci->ioaddr;
668 pci_fill_nic ( nic, pci );
671 pci_write_config_dword(pci, 0x40, 0x00000000);
673 /* Stop the chip's Tx and Rx processes. */
674 outl(inl(ioaddr + CSR6) & ~0x00002002, ioaddr + CSR6);
676 /* Clear the missed-packet counter. */
677 (volatile unsigned long)inl(ioaddr + CSR8);
679 /* Get MAC Address */
680 /* read EEPROM data */
681 for (i = 0; i < sizeof(ee_data)/2; i++)
682 ((unsigned short *)ee_data)[i] =
683 le16_to_cpu(read_eeprom(ioaddr, i, EEPROM_ADDRLEN));
685 /* extract MAC address from EEPROM buffer */
686 for (i=0; i<ETH_ALEN; i++)
687 nic->node_addr[i] = ee_data[20+i];
689 printf("Davicom %! at ioaddr %#hX\n", nic->node_addr, ioaddr);
691 /* initialize device */
693 nic->nic_op = &davicom_operations;
697 static struct nic_operations davicom_operations = {
698 .connect = dummy_connect,
699 .poll = davicom_poll,
700 .transmit = davicom_transmit,
705 static struct pci_device_id davicom_nics[] = {
706 PCI_ROM(0x1282, 0x9100, "davicom9100", "Davicom 9100"),
707 PCI_ROM(0x1282, 0x9102, "davicom9102", "Davicom 9102"),
708 PCI_ROM(0x1282, 0x9009, "davicom9009", "Davicom 9009"),
709 PCI_ROM(0x1282, 0x9132, "davicom9132", "Davicom 9132"), /* Needs probably some fixing */
712 PCI_DRIVER ( davicom_driver, davicom_nics, PCI_NO_CLASS );
714 DRIVER ( "DAVICOM", nic_driver, pci_driver, davicom_driver,
715 davicom_probe, davicom_disable );