1 /**************************************************************************
3 * dmfe.c -- Etherboot device driver for the Davicom
4 * DM9102/DM9102A/DM9102A+DM9801/DM9102A+DM9802 NIC fast ethernet card
6 * Written 2003-2003 by Timothy Legge <tlegge@rogers.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * Portions of this code based on:
25 * dmfe.c: A Davicom DM9102/DM9102A/DM9102A+DM9801/DM9102A+DM9802
26 * NIC fast ethernet driver for Linux.
27 * Copyright (C) 1997 Sten Wang
28 * (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
33 * v1.0 10-02-2004 timlegge Boots ltsp needs cleanup
35 * Indent Options: indent -kr -i8
38 ***************************************************************************/
40 FILE_LICENCE ( GPL2_OR_LATER );
42 /* to get some global routines like printf */
43 #include "etherboot.h"
44 /* to get the interface to the body of the program */
46 /* to get the PCI support functions, if this is a PCI NIC */
48 #include <ipxe/ethernet.h>
50 /* #define EDEBUG 1 */
52 #define dprintf(x) printf x
57 /* Condensed operations for readability. */
58 #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
59 #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
61 /* Board/System/Debug information/definition ---------------- */
62 #define PCI_DM9132_ID 0x91321282 /* Davicom DM9132 ID */
63 #define PCI_DM9102_ID 0x91021282 /* Davicom DM9102 ID */
64 #define PCI_DM9100_ID 0x91001282 /* Davicom DM9100 ID */
65 #define PCI_DM9009_ID 0x90091282 /* Davicom DM9009 ID */
67 #define DM9102_IO_SIZE 0x80
68 #define DM9102A_IO_SIZE 0x100
69 #define TX_MAX_SEND_CNT 0x1 /* Maximum tx packet per time */
70 #define TX_DESC_CNT 0x10 /* Allocated Tx descriptors */
71 #define RX_DESC_CNT 0x20 /* Allocated Rx descriptors */
72 #define TX_FREE_DESC_CNT (TX_DESC_CNT - 2) /* Max TX packet count */
73 #define TX_WAKE_DESC_CNT (TX_DESC_CNT - 3) /* TX wakeup count */
74 #define DESC_ALL_CNT (TX_DESC_CNT + RX_DESC_CNT)
75 #define TX_BUF_ALLOC 0x600
76 #define RX_ALLOC_SIZE 0x620
77 #define DM910X_RESET 1
78 #define CR0_DEFAULT 0x00E00000 /* TX & RX burst mode */
79 #define CR6_DEFAULT 0x00080000 /* HD */
80 #define CR7_DEFAULT 0x180c1
81 #define CR15_DEFAULT 0x06 /* TxJabber RxWatchdog */
82 #define TDES0_ERR_MASK 0x4302 /* TXJT, LC, EC, FUE */
83 #define MAX_PACKET_SIZE 1514
84 #define DMFE_MAX_MULTICAST 14
85 #define RX_COPY_SIZE 100
86 #define MAX_CHECK_PACKET 0x8000
87 #define DM9801_NOISE_FLOOR 8
88 #define DM9802_NOISE_FLOOR 5
95 #define DMFE_1M_HPNA 0x10
97 #define DMFE_TXTH_72 0x400000 /* TX TH 72 byte */
98 #define DMFE_TXTH_96 0x404000 /* TX TH 96 byte */
99 #define DMFE_TXTH_128 0x0000 /* TX TH 128 byte */
100 #define DMFE_TXTH_256 0x4000 /* TX TH 256 byte */
101 #define DMFE_TXTH_512 0x8000 /* TX TH 512 byte */
102 #define DMFE_TXTH_1K 0xC000 /* TX TH 1K byte */
104 #define DMFE_TIMER_WUT (jiffies + HZ * 1) /* timer wakeup time : 1 second */
105 #define DMFE_TX_TIMEOUT ((3*HZ)/2) /* tx packet time-out time 1.5 s" */
106 #define DMFE_TX_KICK (HZ/2) /* tx packet Kick-out time 0.5 s" */
108 #define DMFE_DBUG(dbug_now, msg, value) if (dmfe_debug || (dbug_now)) printk(KERN_ERR DRV_NAME ": %s %lx\n", (msg), (long) (value))
110 #define SHOW_MEDIA_TYPE(mode) printk(KERN_ERR DRV_NAME ": Change Speed to %sMhz %s duplex\n",mode & 1 ?"100":"10", mode & 4 ? "full":"half");
113 /* CR9 definition: SROM/MII */
114 #define CR9_SROM_READ 0x4800
116 #define CR9_SRCLK 0x2
117 #define CR9_CRDOUT 0x8
118 #define SROM_DATA_0 0x0
119 #define SROM_DATA_1 0x4
120 #define PHY_DATA_1 0x20000
121 #define PHY_DATA_0 0x00000
122 #define MDCLKH 0x10000
124 #define PHY_POWER_DOWN 0x800
126 #define SROM_V41_CODE 0x14
128 #define SROM_CLK_WRITE(data, ioaddr) outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr);udelay(5);outl(data|CR9_SROM_READ|CR9_SRCS|CR9_SRCLK,ioaddr);udelay(5);outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr);udelay(5);
130 #define __CHK_IO_SIZE(pci_id, dev_rev) ( ((pci_id)==PCI_DM9132_ID) || ((dev_rev) >= 0x02000030) ) ? DM9102A_IO_SIZE: DM9102_IO_SIZE
131 #define CHK_IO_SIZE(pci_dev, dev_rev) __CHK_IO_SIZE(((pci_dev)->device << 16) | (pci_dev)->vendor, dev_rev)
134 #define DEVICE net_device
136 /* Structure/enum declaration ------------------------------- */
138 u32 tdes0, tdes1, tdes2, tdes3; /* Data for the card */
139 void * tx_buf_ptr; /* Data for us */
140 struct tx_desc * next_tx_desc;
141 } __attribute__ ((aligned(32)));
144 u32 rdes0, rdes1, rdes2, rdes3; /* Data for the card */
145 void * rx_skb_ptr; /* Data for us */
146 struct rx_desc * next_rx_desc;
147 } __attribute__ ((aligned(32)));
149 static struct dmfe_private {
150 u32 chip_id; /* Chip vendor/Device ID */
151 u32 chip_revision; /* Chip revision */
158 u16 HPNA_command; /* For HPNA register 16 */
159 u16 HPNA_timer; /* For HPNA remote device check */
160 u16 NIC_capability; /* NIC media capability */
161 u16 PHY_reg4; /* Saved Phyxcer register 4 value */
163 u8 HPNA_present; /* 0:none, 1:DM9801, 2:DM9802 */
164 u8 chip_type; /* Keep DM9102A chip type */
165 u8 media_mode; /* user specify media mode */
166 u8 op_mode; /* real work media mode */
168 u8 dm910x_chk_mode; /* Operating mode check */
171 unsigned char srom[128];
177 static struct dmfe_private *db;
180 DCR0 = 0x00, DCR1 = 0x08, DCR2 = 0x10, DCR3 = 0x18, DCR4 = 0x20,
181 DCR5 = 0x28, DCR6 = 0x30, DCR7 = 0x38, DCR8 = 0x40, DCR9 = 0x48,
182 DCR10 = 0x50, DCR11 = 0x58, DCR12 = 0x60, DCR13 = 0x68, DCR14 =
188 CR6_RXSC = 0x2, CR6_PBF = 0x8, CR6_PM = 0x40, CR6_PAM = 0x80,
189 CR6_FDM = 0x200, CR6_TXSC = 0x2000, CR6_STI = 0x100000,
190 CR6_SFT = 0x200000, CR6_RXA = 0x40000000, CR6_NO_PURGE = 0x20000000
193 /* Global variable declaration ----------------------------- */
194 static struct nic_operations dmfe_operations;
196 static unsigned char dmfe_media_mode = DMFE_AUTO;
197 static u32 dmfe_cr6_user_set;
199 /* For module input parameter */
200 static u8 chkmode = 1;
201 static u8 HPNA_mode; /* Default: Low Power/High Speed */
202 static u8 HPNA_rx_cmd; /* Default: Disable Rx remote command */
203 static u8 HPNA_tx_cmd; /* Default: Don't issue remote command */
204 static u8 HPNA_NoiseFloor; /* Default: HPNA NoiseFloor */
205 static u8 SF_mode; /* Special Function: 1:VLAN, 2:RX Flow Control
206 4: TX pause packet */
209 /**********************************************
210 * Descriptor Ring and Buffer defination
211 ***********************************************/
213 struct tx_desc txd[TX_DESC_CNT] __attribute__ ((aligned(32)));
214 unsigned char txb[TX_BUF_ALLOC * TX_DESC_CNT]
215 __attribute__ ((aligned(32)));
216 struct rx_desc rxd[RX_DESC_CNT] __attribute__ ((aligned(32)));
217 unsigned char rxb[RX_ALLOC_SIZE * RX_DESC_CNT]
218 __attribute__ ((aligned(32)));
219 } dmfe_bufs __shared;
220 #define txd dmfe_bufs.txd
221 #define txb dmfe_bufs.txb
222 #define rxd dmfe_bufs.rxd
223 #define rxb dmfe_bufs.rxb
225 /* NIC specific static variables go here */
226 static long int BASE;
228 static u16 read_srom_word(long ioaddr, int offset);
229 static void dmfe_init_dm910x(struct nic *nic);
230 static void dmfe_descriptor_init(struct nic *, unsigned long ioaddr);
231 static void update_cr6(u32, unsigned long);
232 static void send_filter_frame(struct nic *nic);
233 static void dm9132_id_table(struct nic *nic);
235 static u16 phy_read(unsigned long, u8, u8, u32);
236 static void phy_write(unsigned long, u8, u8, u16, u32);
237 static void phy_write_1bit(unsigned long, u32);
238 static u16 phy_read_1bit(unsigned long);
239 static void dmfe_set_phyxcer(struct nic *nic);
241 static void dmfe_parse_srom(struct nic *nic);
242 static void dmfe_program_DM9801(struct nic *nic, int);
243 static void dmfe_program_DM9802(struct nic *nic);
245 static void dmfe_reset(struct nic *nic)
247 /* system variable init */
248 db->cr6_data = CR6_DEFAULT | dmfe_cr6_user_set;
250 db->NIC_capability = 0xf; /* All capability */
251 db->PHY_reg4 = 0x1e0;
253 /* CR6 operation mode decision */
254 if (!chkmode || (db->chip_id == PCI_DM9132_ID) ||
255 (db->chip_revision >= 0x02000030)) {
256 db->cr6_data |= DMFE_TXTH_256;
257 db->cr0_data = CR0_DEFAULT;
258 db->dm910x_chk_mode = 4; /* Enter the normal mode */
260 db->cr6_data |= CR6_SFT; /* Store & Forward mode */
262 db->dm910x_chk_mode = 1; /* Enter the check mode */
264 /* Initialize DM910X board */
265 dmfe_init_dm910x(nic);
270 /* Initialize DM910X board
272 * Initialize TX/Rx descriptor chain structure
273 * Send the set-up frame
274 * Enable Tx/Rx machine
277 static void dmfe_init_dm910x(struct nic *nic)
279 unsigned long ioaddr = BASE;
281 /* Reset DM910x MAC controller */
282 outl(DM910X_RESET, ioaddr + DCR0); /* RESET MAC */
284 outl(db->cr0_data, ioaddr + DCR0);
287 /* Phy addr : DM910(A)2/DM9132/9801, phy address = 1 */
290 /* Parser SROM and media mode */
291 dmfe_parse_srom(nic);
292 db->media_mode = dmfe_media_mode;
294 /* RESET Phyxcer Chip by GPR port bit 7 */
295 outl(0x180, ioaddr + DCR12); /* Let bit 7 output port */
296 if (db->chip_id == PCI_DM9009_ID) {
297 outl(0x80, ioaddr + DCR12); /* Issue RESET signal */
298 mdelay(300); /* Delay 300 ms */
300 outl(0x0, ioaddr + DCR12); /* Clear RESET signal */
302 /* Process Phyxcer Media Mode */
303 if (!(db->media_mode & 0x10)) /* Force 1M mode */
304 dmfe_set_phyxcer(nic);
306 /* Media Mode Process */
307 if (!(db->media_mode & DMFE_AUTO))
308 db->op_mode = db->media_mode; /* Force Mode */
310 /* Initiliaze Transmit/Receive descriptor and CR3/4 */
311 dmfe_descriptor_init(nic, ioaddr);
313 /* tx descriptor start pointer */
314 outl(virt_to_le32desc(&txd[0]), ioaddr + DCR4); /* TX DESC address */
316 /* rx descriptor start pointer */
317 outl(virt_to_le32desc(&rxd[0]), ioaddr + DCR3); /* RX DESC address */
319 /* Init CR6 to program DM910x operation */
320 update_cr6(db->cr6_data, ioaddr);
322 /* Send setup frame */
323 if (db->chip_id == PCI_DM9132_ID) {
324 dm9132_id_table(nic); /* DM9132 */
326 send_filter_frame(nic); /* DM9102/DM9102A */
329 /* Init CR7, interrupt active bit */
330 db->cr7_data = CR7_DEFAULT;
331 outl(db->cr7_data, ioaddr + DCR7);
332 /* Init CR15, Tx jabber and Rx watchdog timer */
333 outl(db->cr15_data, ioaddr + DCR15);
334 /* Enable DM910X Tx/Rx function */
335 db->cr6_data |= CR6_RXSC | CR6_TXSC | 0x40000;
336 update_cr6(db->cr6_data, ioaddr);
339 void hex_dump(const char *data, const unsigned int len);
341 /**************************************************************************
342 POLL - Wait for a frame
343 ***************************************************************************/
344 static int dmfe_poll(struct nic *nic, int retrieve)
347 int entry = db->cur_rx % RX_DESC_CNT;
349 rdes0 = le32_to_cpu(rxd[entry].rdes0);
350 if (rdes0 & 0x80000000)
356 if ((rdes0 & 0x300) != 0x300) {
357 /* A packet without First/Last flag */
358 printf("strange Packet\n");
359 rxd[entry].rdes0 = cpu_to_le32(0x80000000);
362 /* A packet with First/Last flag */
363 rxlen = ((rdes0 >> 16) & 0x3fff) - 4;
364 /* error summary bit check */
365 if (rdes0 & 0x8000) {
369 if (!(rdes0 & 0x8000) ||
370 ((db->cr6_data & CR6_PM) && (rxlen > 6))) {
371 if (db->dm910x_chk_mode & 1)
372 printf("Silly check mode\n");
374 nic->packetlen = rxlen;
375 memcpy(nic->packet, rxb + (entry * RX_ALLOC_SIZE),
379 rxd[entry].rdes0 = cpu_to_le32(0x80000000);
384 static void dmfe_irq(struct nic *nic __unused, irq_action_t action __unused)
396 /**************************************************************************
397 TRANSMIT - Transmit a frame
398 ***************************************************************************/
399 static void dmfe_transmit(struct nic *nic,
400 const char *dest, /* Destination */
401 unsigned int type, /* Type */
402 unsigned int size, /* size */
403 const char *packet) /* Packet */
408 ptxb = &txb[db->cur_tx];
411 outl(0, BASE + DCR7);
412 memcpy(ptxb, dest, ETH_ALEN);
413 memcpy(ptxb + ETH_ALEN, nic->node_addr, ETH_ALEN);
414 nstype = htons((u16) type);
415 memcpy(ptxb + 2 * ETH_ALEN, (u8 *) & nstype, 2);
416 memcpy(ptxb + ETH_HLEN, packet, size);
419 while (size < ETH_ZLEN)
422 /* setup the transmit descriptor */
423 txd[db->cur_tx].tdes1 = cpu_to_le32(0xe1000000 | size);
424 txd[db->cur_tx].tdes0 = cpu_to_le32(0x80000000); /* give ownership to device */
426 /* immediate transmit demand */
427 outl(0x1, BASE + DCR1);
428 outl(db->cr7_data, BASE + DCR7);
430 /* Point to next TX descriptor */
432 db->cur_tx = db->cur_tx % TX_DESC_CNT;
435 /**************************************************************************
436 DISABLE - Turn off ethernet interface
437 ***************************************************************************/
438 static void dmfe_disable ( struct nic *nic __unused ) {
439 /* Reset & stop DM910X board */
440 outl(DM910X_RESET, BASE + DCR0);
442 phy_write(BASE, db->phy_addr, 0, 0x8000, db->chip_id);
446 /**************************************************************************
447 PROBE - Look for an adapter, this routine's visible to the outside
448 ***************************************************************************/
450 #define board_found 1
452 static int dmfe_probe ( struct nic *nic, struct pci_device *pci ) {
454 uint32_t dev_rev, pci_pmr;
457 if (pci->ioaddr == 0)
461 printf("dmfe.c: Found %s Vendor=0x%hX Device=0x%hX\n",
462 pci->id->name, pci->vendor, pci->device);
464 /* Read Chip revision */
465 pci_read_config_dword(pci, PCI_REVISION_ID, &dev_rev);
466 dprintf(("Revision %lX\n", dev_rev));
468 /* point to private storage */
471 db->chip_id = ((u32) pci->device << 16) | pci->vendor;
472 BASE = pci_bar_start(pci, PCI_BASE_ADDRESS_0);
473 db->chip_revision = dev_rev;
475 pci_read_config_dword(pci, 0x50, &pci_pmr);
477 if ((pci_pmr == 0x10000) && (dev_rev == 0x02000031))
478 db->chip_type = 1; /* DM9102A E3 */
482 dprintf(("Chip type : %d\n", db->chip_type));
484 /* read 64 word srom data */
485 for (i = 0; i < 64; i++)
486 ((u16 *) db->srom)[i] = cpu_to_le16(read_srom_word(BASE, i));
488 /* Set Node address */
489 for (i = 0; i < 6; i++)
490 nic->node_addr[i] = db->srom[20 + i];
492 /* Print out some hardware info */
493 DBG ( "%s: %s at ioaddr %4.4lx\n",
494 pci->id->name, eth_ntoa ( nic->node_addr ), BASE );
496 /* Set the card as PCI Bus Master */
497 adjust_pci_device(pci);
502 nic->ioaddr = pci->ioaddr;
504 /* point to NIC specific routines */
505 nic->nic_op = &dmfe_operations;
511 * Initialize transmit/Receive descriptor
512 * Using Chain structure, and allocate Tx/Rx buffer
515 static void dmfe_descriptor_init(struct nic *nic __unused, unsigned long ioaddr)
521 /* tx descriptor start pointer */
522 outl(virt_to_le32desc(&txd[0]), ioaddr + DCR4); /* TX DESC address */
524 /* rx descriptor start pointer */
525 outl(virt_to_le32desc(&rxd[0]), ioaddr + DCR3); /* RX DESC address */
527 /* Init Transmit chain */
528 for (i = 0; i < TX_DESC_CNT; i++) {
529 txd[i].tx_buf_ptr = &txb[i];
530 txd[i].tdes0 = cpu_to_le32(0);
531 txd[i].tdes1 = cpu_to_le32(0x81000000); /* IC, chain */
532 txd[i].tdes2 = cpu_to_le32(virt_to_bus(&txb[i]));
533 txd[i].tdes3 = cpu_to_le32(virt_to_bus(&txd[i + 1]));
534 txd[i].next_tx_desc = &txd[i + 1];
536 /* Mark the last entry as wrapping the ring */
537 txd[i - 1].tdes3 = virt_to_le32desc(&txd[0]);
538 txd[i - 1].next_tx_desc = &txd[0];
540 /* receive descriptor chain */
541 for (i = 0; i < RX_DESC_CNT; i++) {
542 rxd[i].rx_skb_ptr = &rxb[i * RX_ALLOC_SIZE];
543 rxd[i].rdes0 = cpu_to_le32(0x80000000);
544 rxd[i].rdes1 = cpu_to_le32(0x01000600);
546 cpu_to_le32(virt_to_bus(&rxb[i * RX_ALLOC_SIZE]));
547 rxd[i].rdes3 = cpu_to_le32(virt_to_bus(&rxd[i + 1]));
548 rxd[i].next_rx_desc = &rxd[i + 1];
550 /* Mark the last entry as wrapping the ring */
551 rxd[i - 1].rdes3 = cpu_to_le32(virt_to_bus(&rxd[0]));
552 rxd[i - 1].next_rx_desc = &rxd[0];
558 * Firstly stop DM910X , then written value and start
561 static void update_cr6(u32 cr6_data, unsigned long ioaddr)
565 cr6_tmp = cr6_data & ~0x2002; /* stop Tx/Rx */
566 outl(cr6_tmp, ioaddr + DCR6);
568 outl(cr6_data, ioaddr + DCR6);
574 * Send a setup frame for DM9132
575 * This setup frame initialize DM910X address filter mode
578 static void dm9132_id_table(struct nic *nic __unused)
583 unsigned long ioaddr = BASE + 0xc0; /* ID Table */
585 u16 i, hash_table[4];
587 dprintf(("dm9132_id_table\n"));
589 printf("FIXME: This function is broken. If you have this card contact "
590 "Timothy Legge at the etherboot-user list\n");
593 //DMFE_DBUG(0, "dm9132_id_table()", 0);
596 addrptr = (u16 *) nic->node_addr;
597 outw(addrptr[0], ioaddr);
599 outw(addrptr[1], ioaddr);
601 outw(addrptr[2], ioaddr);
604 /* Clear Hash Table */
605 for (i = 0; i < 4; i++)
608 /* broadcast address */
609 hash_table[3] = 0x8000;
611 /* the multicast address in Hash Table : 64 bits */
612 for (mcptr = mc_list, i = 0; i < mc_cnt; i++, mcptr = mcptr->next) {
613 hash_val = cal_CRC((char *) mcptr->dmi_addr, 6, 0) & 0x3f;
614 hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16);
617 /* Write the hash table to MAC MD table */
618 for (i = 0; i < 4; i++, ioaddr += 4)
619 outw(hash_table[i], ioaddr);
625 * Send a setup frame for DM9102/DM9102A
626 * This setup frame initialize DM910X address filter mode
629 static void send_filter_frame(struct nic *nic)
635 dprintf(("send_filter_frame\n"));
636 /* point to the current txb incase multiple tx_rings are used */
637 ptxb = &txb[db->cur_tx];
639 /* construct perfect filter frame with mac address as first match
640 and broadcast address for all others */
641 for (i = 0; i < 192; i++)
643 ptxb[0] = nic->node_addr[0];
644 ptxb[1] = nic->node_addr[1];
645 ptxb[4] = nic->node_addr[2];
646 ptxb[5] = nic->node_addr[3];
647 ptxb[8] = nic->node_addr[4];
648 ptxb[9] = nic->node_addr[5];
650 /* prepare the setup frame */
651 txd[db->cur_tx].tdes1 = cpu_to_le32(0x890000c0);
652 txd[db->cur_tx].tdes0 = cpu_to_le32(0x80000000);
653 update_cr6(db->cr6_data | 0x2000, BASE);
654 outl(0x1, BASE + DCR1); /* Issue Tx polling */
655 update_cr6(db->cr6_data, BASE);
660 * Read one word data from the serial ROM
663 static u16 read_srom_word(long ioaddr, int offset)
667 long cr9_ioaddr = ioaddr + DCR9;
669 outl(CR9_SROM_READ, cr9_ioaddr);
670 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr);
672 /* Send the Read Command 110b */
673 SROM_CLK_WRITE(SROM_DATA_1, cr9_ioaddr);
674 SROM_CLK_WRITE(SROM_DATA_1, cr9_ioaddr);
675 SROM_CLK_WRITE(SROM_DATA_0, cr9_ioaddr);
677 /* Send the offset */
678 for (i = 5; i >= 0; i--) {
680 (offset & (1 << i)) ? SROM_DATA_1 : SROM_DATA_0;
681 SROM_CLK_WRITE(srom_data, cr9_ioaddr);
684 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr);
686 for (i = 16; i > 0; i--) {
687 outl(CR9_SROM_READ | CR9_SRCS | CR9_SRCLK, cr9_ioaddr);
690 (srom_data << 1) | ((inl(cr9_ioaddr) & CR9_CRDOUT) ? 1
692 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr);
696 outl(CR9_SROM_READ, cr9_ioaddr);
702 * Auto sense the media mode
706 static u8 dmfe_sense_speed(struct nic *nic __unused)
711 /* CR6 bit18=0, select 10/100M */
712 update_cr6((db->cr6_data & ~0x40000), BASE);
714 phy_mode = phy_read(BASE, db->phy_addr, 1, db->chip_id);
715 phy_mode = phy_read(BASE, db->phy_addr, 1, db->chip_id);
717 if ((phy_mode & 0x24) == 0x24) {
718 if (db->chip_id == PCI_DM9132_ID) /* DM9132 */
720 phy_read(BASE, db->phy_addr, 7,
721 db->chip_id) & 0xf000;
722 else /* DM9102/DM9102A */
724 phy_read(BASE, db->phy_addr, 17,
725 db->chip_id) & 0xf000;
726 /* printk(DRV_NAME ": Phy_mode %x ",phy_mode); */
729 db->op_mode = DMFE_10MHF;
732 db->op_mode = DMFE_10MFD;
735 db->op_mode = DMFE_100MHF;
738 db->op_mode = DMFE_100MFD;
741 db->op_mode = DMFE_10MHF;
746 db->op_mode = DMFE_10MHF;
747 //DMFE_DBUG(0, "Link Failed :", phy_mode);
756 * Set 10/100 phyxcer capability
757 * AUTO mode : phyxcer register4 is NIC capability
758 * Force mode: phyxcer register4 is the force media
761 static void dmfe_set_phyxcer(struct nic *nic __unused)
765 /* Select 10/100M phyxcer */
766 db->cr6_data &= ~0x40000;
767 update_cr6(db->cr6_data, BASE);
769 /* DM9009 Chip: Phyxcer reg18 bit12=0 */
770 if (db->chip_id == PCI_DM9009_ID) {
772 phy_read(BASE, db->phy_addr, 18,
773 db->chip_id) & ~0x1000;
774 phy_write(BASE, db->phy_addr, 18, phy_reg, db->chip_id);
777 /* Phyxcer capability setting */
778 phy_reg = phy_read(BASE, db->phy_addr, 4, db->chip_id) & ~0x01e0;
780 if (db->media_mode & DMFE_AUTO) {
782 phy_reg |= db->PHY_reg4;
785 switch (db->media_mode) {
799 if (db->chip_id == PCI_DM9009_ID)
803 /* Write new capability to Phyxcer Reg4 */
804 if (!(phy_reg & 0x01e0)) {
805 phy_reg |= db->PHY_reg4;
806 db->media_mode |= DMFE_AUTO;
808 phy_write(BASE, db->phy_addr, 4, phy_reg, db->chip_id);
810 /* Restart Auto-Negotiation */
811 if (db->chip_type && (db->chip_id == PCI_DM9102_ID))
812 phy_write(BASE, db->phy_addr, 0, 0x1800, db->chip_id);
814 phy_write(BASE, db->phy_addr, 0, 0x1200, db->chip_id);
820 * AUTO mode : PHY controller in Auto-negotiation Mode
821 * Force mode: PHY controller in force mode with HUB
822 * N-way force capability with SWITCH
826 static void dmfe_process_mode(struct nic *nic __unused)
830 /* Full Duplex Mode Check */
831 if (db->op_mode & 0x4)
832 db->cr6_data |= CR6_FDM; /* Set Full Duplex Bit */
834 db->cr6_data &= ~CR6_FDM; /* Clear Full Duplex Bit */
836 /* Transciver Selection */
837 if (db->op_mode & 0x10) /* 1M HomePNA */
838 db->cr6_data |= 0x40000; /* External MII select */
840 db->cr6_data &= ~0x40000; /* Internal 10/100 transciver */
842 update_cr6(db->cr6_data, BASE);
844 /* 10/100M phyxcer force mode need */
845 if (!(db->media_mode & 0x18)) {
847 phy_reg = phy_read(BASE, db->phy_addr, 6, db->chip_id);
848 if (!(phy_reg & 0x1)) {
849 /* parter without N-Way capability */
851 switch (db->op_mode) {
865 phy_write(BASE, db->phy_addr, 0, phy_reg,
868 && (db->chip_id == PCI_DM9102_ID))
870 phy_write(BASE, db->phy_addr, 0, phy_reg,
878 * Write a word to Phy register
881 static void phy_write(unsigned long iobase, u8 phy_addr, u8 offset,
882 u16 phy_data, u32 chip_id)
885 unsigned long ioaddr;
887 if (chip_id == PCI_DM9132_ID) {
888 ioaddr = iobase + 0x80 + offset * 4;
889 outw(phy_data, ioaddr);
891 /* DM9102/DM9102A Chip */
892 ioaddr = iobase + DCR9;
894 /* Send 33 synchronization clock to Phy controller */
895 for (i = 0; i < 35; i++)
896 phy_write_1bit(ioaddr, PHY_DATA_1);
898 /* Send start command(01) to Phy */
899 phy_write_1bit(ioaddr, PHY_DATA_0);
900 phy_write_1bit(ioaddr, PHY_DATA_1);
902 /* Send write command(01) to Phy */
903 phy_write_1bit(ioaddr, PHY_DATA_0);
904 phy_write_1bit(ioaddr, PHY_DATA_1);
906 /* Send Phy address */
907 for (i = 0x10; i > 0; i = i >> 1)
908 phy_write_1bit(ioaddr,
909 phy_addr & i ? PHY_DATA_1 :
912 /* Send register address */
913 for (i = 0x10; i > 0; i = i >> 1)
914 phy_write_1bit(ioaddr,
915 offset & i ? PHY_DATA_1 :
918 /* written trasnition */
919 phy_write_1bit(ioaddr, PHY_DATA_1);
920 phy_write_1bit(ioaddr, PHY_DATA_0);
922 /* Write a word data to PHY controller */
923 for (i = 0x8000; i > 0; i >>= 1)
924 phy_write_1bit(ioaddr,
925 phy_data & i ? PHY_DATA_1 :
932 * Read a word data from phy register
935 static u16 phy_read(unsigned long iobase, u8 phy_addr, u8 offset,
940 unsigned long ioaddr;
942 if (chip_id == PCI_DM9132_ID) {
944 ioaddr = iobase + 0x80 + offset * 4;
945 phy_data = inw(ioaddr);
947 /* DM9102/DM9102A Chip */
948 ioaddr = iobase + DCR9;
950 /* Send 33 synchronization clock to Phy controller */
951 for (i = 0; i < 35; i++)
952 phy_write_1bit(ioaddr, PHY_DATA_1);
954 /* Send start command(01) to Phy */
955 phy_write_1bit(ioaddr, PHY_DATA_0);
956 phy_write_1bit(ioaddr, PHY_DATA_1);
958 /* Send read command(10) to Phy */
959 phy_write_1bit(ioaddr, PHY_DATA_1);
960 phy_write_1bit(ioaddr, PHY_DATA_0);
962 /* Send Phy address */
963 for (i = 0x10; i > 0; i = i >> 1)
964 phy_write_1bit(ioaddr,
965 phy_addr & i ? PHY_DATA_1 :
968 /* Send register address */
969 for (i = 0x10; i > 0; i = i >> 1)
970 phy_write_1bit(ioaddr,
971 offset & i ? PHY_DATA_1 :
974 /* Skip transition state */
975 phy_read_1bit(ioaddr);
977 /* read 16bit data */
978 for (phy_data = 0, i = 0; i < 16; i++) {
980 phy_data |= phy_read_1bit(ioaddr);
989 * Write one bit data to Phy Controller
992 static void phy_write_1bit(unsigned long ioaddr, u32 phy_data)
994 outl(phy_data, ioaddr); /* MII Clock Low */
996 outl(phy_data | MDCLKH, ioaddr); /* MII Clock High */
998 outl(phy_data, ioaddr); /* MII Clock Low */
1004 * Read one bit phy data from PHY controller
1007 static u16 phy_read_1bit(unsigned long ioaddr)
1011 outl(0x50000, ioaddr);
1013 phy_data = (inl(ioaddr) >> 19) & 0x1;
1014 outl(0x40000, ioaddr);
1022 * Parser SROM and media mode
1025 static void dmfe_parse_srom(struct nic *nic)
1027 unsigned char *srom = db->srom;
1028 int dmfe_mode, tmp_reg;
1031 db->cr15_data = CR15_DEFAULT;
1033 /* Check SROM Version */
1034 if (((int) srom[18] & 0xff) == SROM_V41_CODE) {
1036 /* Get NIC support media mode */
1037 db->NIC_capability = *(u16 *) (srom + 34);
1039 for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) {
1040 switch (db->NIC_capability & tmp_reg) {
1042 db->PHY_reg4 |= 0x0020;
1045 db->PHY_reg4 |= 0x0040;
1048 db->PHY_reg4 |= 0x0080;
1051 db->PHY_reg4 |= 0x0100;
1056 /* Media Mode Force or not check */
1057 dmfe_mode = *((int *) srom + 34) & *((int *) srom + 36);
1058 switch (dmfe_mode) {
1060 dmfe_media_mode = DMFE_100MHF;
1063 dmfe_media_mode = DMFE_10MFD;
1066 dmfe_media_mode = DMFE_100MFD;
1070 dmfe_media_mode = DMFE_1M_HPNA;
1071 break; /* HomePNA */
1074 /* Special Function setting */
1076 if ((SF_mode & 0x1) || (srom[43] & 0x80))
1077 db->cr15_data |= 0x40;
1080 if ((SF_mode & 0x2) || (srom[40] & 0x1))
1081 db->cr15_data |= 0x400;
1083 /* TX pause packet */
1084 if ((SF_mode & 0x4) || (srom[40] & 0xe))
1085 db->cr15_data |= 0x9800;
1088 /* Parse HPNA parameter */
1089 db->HPNA_command = 1;
1091 /* Accept remote command or not */
1092 if (HPNA_rx_cmd == 0)
1093 db->HPNA_command |= 0x8000;
1095 /* Issue remote command & operation mode */
1096 if (HPNA_tx_cmd == 1)
1097 switch (HPNA_mode) { /* Issue Remote Command */
1099 db->HPNA_command |= 0x0904;
1102 db->HPNA_command |= 0x0a00;
1105 db->HPNA_command |= 0x0506;
1108 db->HPNA_command |= 0x0602;
1111 switch (HPNA_mode) { /* Don't Issue */
1113 db->HPNA_command |= 0x0004;
1116 db->HPNA_command |= 0x0000;
1119 db->HPNA_command |= 0x0006;
1122 db->HPNA_command |= 0x0002;
1126 /* Check DM9801 or DM9802 present or not */
1127 db->HPNA_present = 0;
1128 update_cr6(db->cr6_data | 0x40000, BASE);
1129 tmp_reg = phy_read(BASE, db->phy_addr, 3, db->chip_id);
1130 if ((tmp_reg & 0xfff0) == 0xb900) {
1131 /* DM9801 or DM9802 present */
1133 if (phy_read(BASE, db->phy_addr, 31, db->chip_id) ==
1135 /* DM9801 HomeRun */
1136 db->HPNA_present = 1;
1137 dmfe_program_DM9801(nic, tmp_reg);
1139 /* DM9802 LongRun */
1140 db->HPNA_present = 2;
1141 dmfe_program_DM9802(nic);
1148 * Init HomeRun DM9801
1151 static void dmfe_program_DM9801(struct nic *nic __unused, int HPNA_rev)
1155 if (!HPNA_NoiseFloor)
1156 HPNA_NoiseFloor = DM9801_NOISE_FLOOR;
1158 case 0xb900: /* DM9801 E3 */
1159 db->HPNA_command |= 0x1000;
1160 reg25 = phy_read(BASE, db->phy_addr, 24, db->chip_id);
1161 reg25 = ((reg25 + HPNA_NoiseFloor) & 0xff) | 0xf000;
1162 reg17 = phy_read(BASE, db->phy_addr, 17, db->chip_id);
1164 case 0xb901: /* DM9801 E4 */
1165 reg25 = phy_read(BASE, db->phy_addr, 25, db->chip_id);
1166 reg25 = (reg25 & 0xff00) + HPNA_NoiseFloor;
1167 reg17 = phy_read(BASE, db->phy_addr, 17, db->chip_id);
1168 reg17 = (reg17 & 0xfff0) + HPNA_NoiseFloor + 3;
1170 case 0xb902: /* DM9801 E5 */
1171 case 0xb903: /* DM9801 E6 */
1173 db->HPNA_command |= 0x1000;
1174 reg25 = phy_read(BASE, db->phy_addr, 25, db->chip_id);
1175 reg25 = (reg25 & 0xff00) + HPNA_NoiseFloor - 5;
1176 reg17 = phy_read(BASE, db->phy_addr, 17, db->chip_id);
1177 reg17 = (reg17 & 0xfff0) + HPNA_NoiseFloor;
1180 phy_write(BASE, db->phy_addr, 16, db->HPNA_command, db->chip_id);
1181 phy_write(BASE, db->phy_addr, 17, reg17, db->chip_id);
1182 phy_write(BASE, db->phy_addr, 25, reg25, db->chip_id);
1187 * Init HomeRun DM9802
1190 static void dmfe_program_DM9802(struct nic *nic __unused)
1194 if (!HPNA_NoiseFloor)
1195 HPNA_NoiseFloor = DM9802_NOISE_FLOOR;
1196 phy_write(BASE, db->phy_addr, 16, db->HPNA_command, db->chip_id);
1197 phy_reg = phy_read(BASE, db->phy_addr, 25, db->chip_id);
1198 phy_reg = (phy_reg & 0xff00) + HPNA_NoiseFloor;
1199 phy_write(BASE, db->phy_addr, 25, phy_reg, db->chip_id);
1202 static struct nic_operations dmfe_operations = {
1203 .connect = dummy_connect,
1205 .transmit = dmfe_transmit,
1210 static struct pci_device_id dmfe_nics[] = {
1211 PCI_ROM(0x1282, 0x9100, "dmfe9100", "Davicom 9100", 0),
1212 PCI_ROM(0x1282, 0x9102, "dmfe9102", "Davicom 9102", 0),
1213 PCI_ROM(0x1282, 0x9009, "dmfe9009", "Davicom 9009", 0),
1214 PCI_ROM(0x1282, 0x9132, "dmfe9132", "Davicom 9132", 0), /* Needs probably some fixing */
1217 PCI_DRIVER ( dmfe_driver, dmfe_nics, PCI_NO_CLASS );
1219 DRIVER ( "DMFE/PCI", nic_driver, pci_driver, dmfe_driver,
1220 dmfe_probe, dmfe_disable );