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 FILE_LICENCE ( GPL_ANY
);
20 /*********************************************************************/
21 /* Revision History */
22 /*********************************************************************/
26 Different half and full duplex mode
27 Do the different programming for DM9801/DM9802
30 This driver was ported from tulip driver and it
31 has the following difference.
32 Changed symbol tulip/TULIP to davicom/DAVICOM
33 Deleted some code that did not use in this driver.
34 Used chain-strcture to replace ring structure
35 for both TX/RX descriptor.
36 Allocated two tx descriptor.
37 According current media mode to set operating
42 /*********************************************************************/
44 /*********************************************************************/
46 #include "etherboot.h"
49 #include <gpxe/ethernet.h>
52 #undef DAVICOM_DEBUG_WHERE
54 #define TX_TIME_OUT 2*TICKS_PER_SEC
56 /* Register offsets for davicom device */
57 enum davicom_offsets
{
58 CSR0
=0, CSR1
=0x08, CSR2
=0x10, CSR3
=0x18, CSR4
=0x20, CSR5
=0x28,
59 CSR6
=0x30, CSR7
=0x38, CSR8
=0x40, CSR9
=0x48, CSR10
=0x50, CSR11
=0x58,
60 CSR12
=0x60, CSR13
=0x68, CSR14
=0x70, CSR15
=0x78, CSR16
=0x80, CSR20
=0xA0
63 /* EEPROM Address width definitions */
64 #define EEPROM_ADDRLEN 6
65 #define EEPROM_SIZE 32 /* 1 << EEPROM_ADDRLEN */
66 /* Used to be 128, but we only need to read enough to get the MAC
67 address at bytes 20..25 */
69 /* Data Read from the EEPROM */
70 static unsigned char ee_data
[EEPROM_SIZE
];
72 /* The EEPROM commands include the alway-set leading bit. */
73 #define EE_WRITE_CMD (5 << addr_len)
74 #define EE_READ_CMD (6 << addr_len)
75 #define EE_ERASE_CMD (7 << addr_len)
77 /* EEPROM_Ctrl bits. */
78 #define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */
79 #define EE_CS 0x01 /* EEPROM chip select. */
80 #define EE_DATA_WRITE 0x04 /* EEPROM chip data in. */
81 #define EE_WRITE_0 0x01
82 #define EE_WRITE_1 0x05
83 #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
84 #define EE_ENB (0x4800 | EE_CS)
86 /* Sten 10/11 for phyxcer */
87 #define PHY_DATA_0 0x0
88 #define PHY_DATA_1 0x20000
89 #define MDCLKH 0x10000
91 /* Delay between EEPROM clock transitions. Even at 33Mhz current PCI
92 implementations don't overrun the EEPROM clock. We add a bus
93 turn-around to insure that this remains true. */
94 #define eeprom_delay() inl(ee_addr)
96 /* helpful macro if on a big_endian machine for changing byte order.
97 not strictly needed on Intel
98 Already defined in Etherboot includes
99 #define le16_to_cpu(val) (val)
102 /* transmit and receive descriptor format */
104 volatile unsigned long status
; /* owner, status */
105 unsigned long buf1sz
:11, /* size of buffer 1 */
106 buf2sz
:11, /* size of buffer 2 */
107 control
:10; /* control bits */
108 const unsigned char *buf1addr
; /* buffer 1 address */
109 const unsigned char *buf2addr
; /* buffer 2 address */
113 volatile unsigned long status
; /* owner, status */
114 unsigned long buf1sz
:11, /* size of buffer 1 */
115 buf2sz
:11, /* size of buffer 2 */
116 control
:10; /* control bits */
117 unsigned char *buf1addr
; /* buffer 1 address */
118 unsigned char *buf2addr
; /* buffer 2 address */
121 /* Size of transmit and receive buffers */
124 /*********************************************************************/
126 /*********************************************************************/
128 static struct nic_operations davicom_operations
;
130 /* PCI Bus parameters */
131 static unsigned short vendor
, dev_id
;
132 static unsigned long ioaddr
;
134 /* Note: transmit and receive buffers must be longword aligned and
135 longword divisable */
137 /* transmit descriptor and buffer */
141 struct txdesc txd
[NTXD
] __attribute__ ((aligned(4)));
142 unsigned char txb
[BUFLEN
] __attribute__ ((aligned(4)));
143 struct rxdesc rxd
[NRXD
] __attribute__ ((aligned(4)));
144 unsigned char rxb
[NRXD
* BUFLEN
] __attribute__ ((aligned(4)));
145 } davicom_bufs __shared
;
146 #define txd davicom_bufs.txd
147 #define txb davicom_bufs.txb
148 #define rxd davicom_bufs.rxd
149 #define rxb davicom_bufs.rxb
154 /*********************************************************************/
155 /* Function Prototypes */
156 /*********************************************************************/
157 static void whereami(const char *str
);
158 static int read_eeprom(unsigned long ioaddr
, int location
, int addr_len
);
159 static int davicom_probe(struct nic
*nic
,struct pci_device
*pci
);
160 static void davicom_init_chain(struct nic
*nic
); /* Sten 10/9 */
161 static void davicom_reset(struct nic
*nic
);
162 static void davicom_transmit(struct nic
*nic
, const char *d
, unsigned int t
,
163 unsigned int s
, const char *p
);
164 static int davicom_poll(struct nic
*nic
, int retrieve
);
165 static void davicom_disable(struct nic
*nic
);
167 static void davicom_more(void);
168 #endif /* DAVICOM_DEBUG */
169 static void davicom_wait(unsigned int nticks
);
170 static int phy_read(int);
171 static void phy_write(int, u16
);
172 static void phy_write_1bit(u32
, u32
);
173 static int phy_read_1bit(u32
);
174 static void davicom_media_chk(struct nic
*);
177 /*********************************************************************/
178 /* Utility Routines */
179 /*********************************************************************/
180 static inline void whereami(const char *str
)
187 static void davicom_more()
189 printf("\n\n-- more --");
195 #endif /* DAVICOM_DEBUG */
197 static void davicom_wait(unsigned int nticks
)
199 unsigned int to
= currticks() + nticks
;
200 while (currticks() < to
)
205 /*********************************************************************/
206 /* For DAVICOM phyxcer register by MII interface */
207 /*********************************************************************/
209 Read a word data from phy register
211 static int phy_read(int location
)
217 whereami("phy_read\n");
219 io_dcr9
= ioaddr
+ CSR9
;
221 /* Send 33 synchronization clock to Phy controller */
223 phy_write_1bit(io_dcr9
, PHY_DATA_1
);
225 /* Send start command(01) to Phy */
226 phy_write_1bit(io_dcr9
, PHY_DATA_0
);
227 phy_write_1bit(io_dcr9
, PHY_DATA_1
);
229 /* Send read command(10) to Phy */
230 phy_write_1bit(io_dcr9
, PHY_DATA_1
);
231 phy_write_1bit(io_dcr9
, PHY_DATA_0
);
233 /* Send Phy addres */
234 for (i
=0x10; i
>0; i
=i
>>1)
235 phy_write_1bit(io_dcr9
, phy_addr
&i
? PHY_DATA_1
: PHY_DATA_0
);
237 /* Send register addres */
238 for (i
=0x10; i
>0; i
=i
>>1)
239 phy_write_1bit(io_dcr9
, location
&i
? PHY_DATA_1
: PHY_DATA_0
);
241 /* Skip transition state */
242 phy_read_1bit(io_dcr9
);
244 /* read 16bit data */
245 for (phy_data
=0, i
=0; i
<16; i
++) {
247 phy_data
|=phy_read_1bit(io_dcr9
);
254 Write a word to Phy register
256 static void phy_write(int location
, u16 phy_data
)
261 whereami("phy_write\n");
263 io_dcr9
= ioaddr
+ CSR9
;
265 /* Send 33 synchronization clock to Phy controller */
267 phy_write_1bit(io_dcr9
, PHY_DATA_1
);
269 /* Send start command(01) to Phy */
270 phy_write_1bit(io_dcr9
, PHY_DATA_0
);
271 phy_write_1bit(io_dcr9
, PHY_DATA_1
);
273 /* Send write command(01) to Phy */
274 phy_write_1bit(io_dcr9
, PHY_DATA_0
);
275 phy_write_1bit(io_dcr9
, PHY_DATA_1
);
277 /* Send Phy addres */
278 for (i
=0x10; i
>0; i
=i
>>1)
279 phy_write_1bit(io_dcr9
, phy_addr
&i
? PHY_DATA_1
: PHY_DATA_0
);
281 /* Send register addres */
282 for (i
=0x10; i
>0; i
=i
>>1)
283 phy_write_1bit(io_dcr9
, location
&i
? PHY_DATA_1
: PHY_DATA_0
);
285 /* written trasnition */
286 phy_write_1bit(io_dcr9
, PHY_DATA_1
);
287 phy_write_1bit(io_dcr9
, PHY_DATA_0
);
289 /* Write a word data to PHY controller */
290 for (i
=0x8000; i
>0; i
>>=1)
291 phy_write_1bit(io_dcr9
, phy_data
&i
? PHY_DATA_1
: PHY_DATA_0
);
295 Write one bit data to Phy Controller
297 static void phy_write_1bit(u32 ee_addr
, u32 phy_data
)
299 whereami("phy_write_1bit\n");
300 outl(phy_data
, ee_addr
); /* MII Clock Low */
302 outl(phy_data
|MDCLKH
, ee_addr
); /* MII Clock High */
304 outl(phy_data
, ee_addr
); /* MII Clock Low */
309 Read one bit phy data from PHY controller
311 static int phy_read_1bit(u32 ee_addr
)
315 whereami("phy_read_1bit\n");
317 outl(0x50000, ee_addr
);
320 phy_data
=(inl(ee_addr
)>>19) & 0x1;
322 outl(0x40000, ee_addr
);
329 DM9801/DM9802 present check and program
331 static void HPNA_process(void)
334 if ( (phy_read(3) & 0xfff0) == 0xb900 ) {
335 if ( phy_read(31) == 0x4404 ) {
337 if (phy_read(3) == 0xb901)
338 phy_write(16, 0x5); /* DM9801 E4 */
340 phy_write(16, 0x1005); /* DM9801 E3 and others */
341 phy_write(25, ((phy_read(24) + 3) & 0xff) | 0xf000);
345 phy_write(25, (phy_read(25) & 0xff00) + 2);
351 Sense media mode and set CR6
353 static void davicom_media_chk(struct nic
* nic __unused
)
355 unsigned long to
, csr6
;
357 csr6
= 0x00200000; /* SF */
358 outl(csr6
, ioaddr
+ CSR6
);
360 #define PCI_DEVICE_ID_DM9009 0x9009
361 if (vendor
== PCI_VENDOR_ID_DAVICOM
&& dev_id
== PCI_DEVICE_ID_DM9009
) {
362 /* Set to 10BaseT mode for DM9009 */
365 /* For DM9102/DM9102A */
366 to
= currticks() + 2 * TICKS_PER_SEC
;
367 while ( ((phy_read(1) & 0x24)!=0x24) && (currticks() < to
))
370 if ( (phy_read(1) & 0x24) == 0x24 ) {
371 if (phy_read(17) & 0xa000)
372 csr6
|= 0x00000200; /* Full Duplex mode */
374 csr6
|= 0x00040000; /* Select DM9801/DM9802 when Ethernet link failed */
377 /* set the chip's operating mode */
378 outl(csr6
, ioaddr
+ CSR6
);
380 /* DM9801/DM9802 present check & program */
386 /*********************************************************************/
387 /* EEPROM Reading Code */
388 /*********************************************************************/
389 /* EEPROM routines adapted from the Linux Tulip Code */
390 /* Reading a serial EEPROM is a "bit" grungy, but we work our way
393 static int read_eeprom(unsigned long ioaddr
, int location
, int addr_len
)
396 unsigned short retval
= 0;
397 long ee_addr
= ioaddr
+ CSR9
;
398 int read_cmd
= location
| EE_READ_CMD
;
400 whereami("read_eeprom\n");
402 outl(EE_ENB
& ~EE_CS
, ee_addr
);
403 outl(EE_ENB
, ee_addr
);
405 /* Shift the read command bits out. */
406 for (i
= 4 + addr_len
; i
>= 0; i
--) {
407 short dataval
= (read_cmd
& (1 << i
)) ? EE_DATA_WRITE
: 0;
408 outl(EE_ENB
| dataval
, ee_addr
);
410 outl(EE_ENB
| dataval
| EE_SHIFT_CLK
, ee_addr
);
413 outl(EE_ENB
, ee_addr
);
415 for (i
= 16; i
> 0; i
--) {
416 outl(EE_ENB
| EE_SHIFT_CLK
, ee_addr
);
418 retval
= (retval
<< 1) | ((inl(ee_addr
) & EE_DATA_READ
) ? 1 : 0);
419 outl(EE_ENB
, ee_addr
);
423 /* Terminate the EEPROM access. */
424 outl(EE_ENB
& ~EE_CS
, ee_addr
);
428 /*********************************************************************/
429 /* davicom_init_chain - setup the tx and rx descriptors */
431 /*********************************************************************/
432 static void davicom_init_chain(struct nic
*nic
)
436 /* setup the transmit descriptor */
437 /* Sten: Set 2 TX descriptor but use one TX buffer because
438 it transmit a packet and wait complete every time. */
439 for (i
=0; i
<NTXD
; i
++) {
440 txd
[i
].buf1addr
= (void *)virt_to_bus(&txb
[0]); /* Used same TX buffer */
441 txd
[i
].buf2addr
= (void *)virt_to_bus(&txd
[i
+1]); /* Point to Next TX desc */
444 txd
[i
].control
= 0x184; /* Begin/End/Chain */
445 txd
[i
].status
= 0x00000000; /* give ownership to Host */
448 /* construct perfect filter frame with mac address as first match
449 and broadcast address for all others */
450 for (i
=0; i
<192; i
++) txb
[i
] = 0xFF;
451 txb
[0] = nic
->node_addr
[0];
452 txb
[1] = nic
->node_addr
[1];
453 txb
[4] = nic
->node_addr
[2];
454 txb
[5] = nic
->node_addr
[3];
455 txb
[8] = nic
->node_addr
[4];
456 txb
[9] = nic
->node_addr
[5];
458 /* setup receive descriptor */
459 for (i
=0; i
<NRXD
; i
++) {
460 rxd
[i
].buf1addr
= (void *)virt_to_bus(&rxb
[i
* BUFLEN
]);
461 rxd
[i
].buf2addr
= (void *)virt_to_bus(&rxd
[i
+1]); /* Point to Next RX desc */
462 rxd
[i
].buf1sz
= BUFLEN
;
463 rxd
[i
].buf2sz
= 0; /* not used */
464 rxd
[i
].control
= 0x4; /* Chain Structure */
465 rxd
[i
].status
= 0x80000000; /* give ownership to device */
468 /* Chain the last descriptor to first */
469 txd
[NTXD
- 1].buf2addr
= (void *)virt_to_bus(&txd
[0]);
470 rxd
[NRXD
- 1].buf2addr
= (void *)virt_to_bus(&rxd
[0]);
476 /*********************************************************************/
477 /* davicom_reset - Reset adapter */
478 /*********************************************************************/
479 static void davicom_reset(struct nic
*nic
)
483 whereami("davicom_reset\n");
486 outl(inl(ioaddr
+ CSR6
) & ~0x00002002, ioaddr
+ CSR6
);
488 /* Reset the chip, holding bit 0 set at least 50 PCI cycles. */
489 outl(0x00000001, ioaddr
+ CSR0
);
491 davicom_wait(TICKS_PER_SEC
);
493 /* TX/RX descriptor burst */
494 outl(0x0C00000, ioaddr
+ CSR0
); /* Sten 10/9 */
496 /* set up transmit and receive descriptors */
497 davicom_init_chain(nic
); /* Sten 10/9 */
499 /* Point to receive descriptor */
500 outl(virt_to_bus(&rxd
[0]), ioaddr
+ CSR3
);
501 outl(virt_to_bus(&txd
[0]), ioaddr
+ CSR4
); /* Sten 10/9 */
503 /* According phyxcer media mode to set CR6,
504 DM9102/A phyxcer can auto-detect media mode */
505 davicom_media_chk(nic
);
507 /* Prepare Setup Frame Sten 10/9 */
508 txd
[TxPtr
].buf1sz
= 192;
509 txd
[TxPtr
].control
= 0x024; /* SF/CE */
510 txd
[TxPtr
].status
= 0x80000000; /* Give ownership to device */
513 outl(inl(ioaddr
+ CSR6
) | 0x00002000, ioaddr
+ CSR6
);
514 /* immediate transmit demand */
515 outl(0, ioaddr
+ CSR1
);
517 to
= currticks() + TX_TIME_OUT
;
518 while ((txd
[TxPtr
].status
& 0x80000000) && (currticks() < to
)) /* Sten 10/9 */
521 if (currticks() >= to
) {
522 printf ("TX Setup Timeout!\n");
524 /* Point to next TX descriptor */
525 TxPtr
= (++TxPtr
>= NTXD
) ? 0:TxPtr
; /* Sten 10/9 */
528 printf("txd.status = %X\n", txd
.status
);
529 printf("ticks = %d\n", currticks() - (to
- TX_TIME_OUT
));
534 outl(inl(ioaddr
+ CSR6
) | 0x00000002, ioaddr
+ CSR6
);
535 /* immediate poll demand */
536 outl(0, ioaddr
+ CSR2
);
540 /*********************************************************************/
541 /* eth_transmit - Transmit a frame */
542 /*********************************************************************/
543 static void davicom_transmit(struct nic
*nic
, const char *d
, unsigned int t
,
544 unsigned int s
, const char *p
)
548 whereami("davicom_transmit\n");
551 /* outl(inl(ioaddr + CSR6) & ~0x00002000, ioaddr + CSR6); */
553 /* setup ethernet header */
554 memcpy(&txb
[0], d
, ETH_ALEN
); /* DA 6byte */
555 memcpy(&txb
[ETH_ALEN
], nic
->node_addr
, ETH_ALEN
); /* SA 6byte*/
556 txb
[ETH_ALEN
*2] = (t
>> 8) & 0xFF; /* Frame type: 2byte */
557 txb
[ETH_ALEN
*2+1] = t
& 0xFF;
558 memcpy(&txb
[ETH_HLEN
], p
, s
); /* Frame data */
560 /* setup the transmit descriptor */
561 txd
[TxPtr
].buf1sz
= ETH_HLEN
+s
;
562 txd
[TxPtr
].control
= 0x00000184; /* LS+FS+CE */
563 txd
[TxPtr
].status
= 0x80000000; /* give ownership to device */
565 /* immediate transmit demand */
566 outl(0, ioaddr
+ CSR1
);
568 to
= currticks() + TX_TIME_OUT
;
569 while ((txd
[TxPtr
].status
& 0x80000000) && (currticks() < to
))
572 if (currticks() >= to
) {
573 printf ("TX Timeout!\n");
576 /* Point to next TX descriptor */
577 TxPtr
= (++TxPtr
>= NTXD
) ? 0:TxPtr
; /* Sten 10/9 */
581 /*********************************************************************/
582 /* eth_poll - Wait for a frame */
583 /*********************************************************************/
584 static int davicom_poll(struct nic
*nic
, int retrieve
)
586 whereami("davicom_poll\n");
588 if (rxd
[rxd_tail
].status
& 0x80000000)
591 if ( ! retrieve
) return 1;
593 whereami("davicom_poll got one\n");
595 nic
->packetlen
= (rxd
[rxd_tail
].status
& 0x3FFF0000) >> 16;
597 if( rxd
[rxd_tail
].status
& 0x00008000){
598 rxd
[rxd_tail
].status
= 0x80000000;
600 if (rxd_tail
== NRXD
) rxd_tail
= 0;
604 /* copy packet to working buffer */
605 /* XXX - this copy could be avoided with a little more work
606 but for now we are content with it because the optimised
607 memcpy is quite fast */
609 memcpy(nic
->packet
, rxb
+ rxd_tail
* BUFLEN
, nic
->packetlen
);
611 /* return the descriptor and buffer to receive ring */
612 rxd
[rxd_tail
].status
= 0x80000000;
614 if (rxd_tail
== NRXD
) rxd_tail
= 0;
619 /*********************************************************************/
620 /* eth_disable - Disable the interface */
621 /*********************************************************************/
622 static void davicom_disable ( struct nic
*nic
) {
624 whereami("davicom_disable\n");
628 /* disable interrupts */
629 outl(0x00000000, ioaddr
+ CSR7
);
631 /* Stop the chip's Tx and Rx processes. */
632 outl(inl(ioaddr
+ CSR6
) & ~0x00002002, ioaddr
+ CSR6
);
634 /* Clear the missed-packet counter. */
639 /*********************************************************************/
640 /* eth_irq - enable, disable and force interrupts */
641 /*********************************************************************/
642 static void davicom_irq(struct nic
*nic __unused
, irq_action_t action __unused
)
655 /*********************************************************************/
656 /* eth_probe - Look for an adapter */
657 /*********************************************************************/
658 static int davicom_probe ( struct nic
*nic
, struct pci_device
*pci
) {
662 whereami("davicom_probe\n");
664 if (pci
->ioaddr
== 0)
667 vendor
= pci
->vendor
;
668 dev_id
= pci
->device
;
669 ioaddr
= pci
->ioaddr
;
671 nic
->ioaddr
= pci
->ioaddr
;
675 pci_write_config_dword(pci
, 0x40, 0x00000000);
677 /* Stop the chip's Tx and Rx processes. */
678 outl(inl(ioaddr
+ CSR6
) & ~0x00002002, ioaddr
+ CSR6
);
680 /* Clear the missed-packet counter. */
683 /* Get MAC Address */
684 /* read EEPROM data */
685 for (i
= 0; i
< sizeof(ee_data
)/2; i
++)
686 ((unsigned short *)ee_data
)[i
] =
687 le16_to_cpu(read_eeprom(ioaddr
, i
, EEPROM_ADDRLEN
));
689 /* extract MAC address from EEPROM buffer */
690 for (i
=0; i
<ETH_ALEN
; i
++)
691 nic
->node_addr
[i
] = ee_data
[20+i
];
693 DBG ( "Davicom %s at IOADDR %4.4lx\n", eth_ntoa ( nic
->node_addr
), ioaddr
);
695 /* initialize device */
697 nic
->nic_op
= &davicom_operations
;
701 static struct nic_operations davicom_operations
= {
702 .connect
= dummy_connect
,
703 .poll
= davicom_poll
,
704 .transmit
= davicom_transmit
,
709 static struct pci_device_id davicom_nics
[] = {
710 PCI_ROM(0x1282, 0x9100, "davicom9100", "Davicom 9100", 0),
711 PCI_ROM(0x1282, 0x9102, "davicom9102", "Davicom 9102", 0),
712 PCI_ROM(0x1282, 0x9009, "davicom9009", "Davicom 9009", 0),
713 PCI_ROM(0x1282, 0x9132, "davicom9132", "Davicom 9132", 0), /* Needs probably some fixing */
716 PCI_DRIVER ( davicom_driver
, davicom_nics
, PCI_NO_CLASS
);
718 DRIVER ( "DAVICOM", nic_driver
, pci_driver
, davicom_driver
,
719 davicom_probe
, davicom_disable
);