2 A Davicom DM9102/DM9102A/DM9102A+DM9801/DM9102A+DM9802 NIC fast
3 ethernet driver for Linux.
4 Copyright (C) 1997 Sten Wang
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 DAVICOM Web-Site: www.davicom.com.tw
18 Author: Sten Wang, 886-3-5798797-8517, E-mail: sten_wang@davicom.com.tw
19 Maintainer: Tobias Ringstrom <tori@unhappy.mine.nu>
21 (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved.
23 Marcelo Tosatti <marcelo@conectiva.com.br> :
24 Made it compile in 2.3 (device to net_device)
26 Alan Cox <alan@lxorguk.ukuu.org.uk> :
27 Cleaned up for kernel merge.
28 Removed the back compatibility support
29 Reformatted, fixing spelling etc as I went
30 Removed IRQ 0-15 assumption
32 Jeff Garzik <jgarzik@pobox.com> :
33 Updated to use new PCI driver API.
34 Resource usage cleanups.
35 Report driver version to user.
37 Tobias Ringstrom <tori@unhappy.mine.nu> :
38 Cleaned up and added SMP safety. Thanks go to Jeff Garzik,
39 Andrew Morton and Frank Davis for the SMP safety fixes.
41 Vojtech Pavlik <vojtech@suse.cz> :
42 Cleaned up pointer arithmetics.
43 Fixed a lot of 64bit issues.
44 Cleaned up printk()s a bit.
45 Fixed some obvious big endian problems.
47 Tobias Ringstrom <tori@unhappy.mine.nu> :
48 Use time_after for jiffies calculation. Added ethtool
49 support. Updated PCI resource allocation. Do not
50 forget to unmap PCI mapped skbs.
52 Alan Cox <alan@lxorguk.ukuu.org.uk>
53 Added new PCI identifiers provided by Clear Zhang at ALi
54 for their 1563 ethernet device.
58 Check on 64 bit boxes.
59 Check and fix on big endian boxes.
61 Test and make sure PCI latency is now correct for all cases.
64 #define DRV_NAME "dmfe"
65 #define DRV_VERSION "1.36.4"
66 #define DRV_RELDATE "2002-01-17"
68 #include <linux/module.h>
69 #include <linux/kernel.h>
70 #include <linux/string.h>
71 #include <linux/timer.h>
72 #include <linux/ptrace.h>
73 #include <linux/errno.h>
74 #include <linux/ioport.h>
75 #include <linux/slab.h>
76 #include <linux/interrupt.h>
77 #include <linux/pci.h>
78 #include <linux/dma-mapping.h>
79 #include <linux/init.h>
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/ethtool.h>
83 #include <linux/skbuff.h>
84 #include <linux/delay.h>
85 #include <linux/spinlock.h>
86 #include <linux/crc32.h>
87 #include <linux/bitops.h>
89 #include <asm/processor.h>
92 #include <asm/uaccess.h>
96 /* Board/System/Debug information/definition ---------------- */
97 #define PCI_DM9132_ID 0x91321282 /* Davicom DM9132 ID */
98 #define PCI_DM9102_ID 0x91021282 /* Davicom DM9102 ID */
99 #define PCI_DM9100_ID 0x91001282 /* Davicom DM9100 ID */
100 #define PCI_DM9009_ID 0x90091282 /* Davicom DM9009 ID */
102 #define DM9102_IO_SIZE 0x80
103 #define DM9102A_IO_SIZE 0x100
104 #define TX_MAX_SEND_CNT 0x1 /* Maximum tx packet per time */
105 #define TX_DESC_CNT 0x10 /* Allocated Tx descriptors */
106 #define RX_DESC_CNT 0x20 /* Allocated Rx descriptors */
107 #define TX_FREE_DESC_CNT (TX_DESC_CNT - 2) /* Max TX packet count */
108 #define TX_WAKE_DESC_CNT (TX_DESC_CNT - 3) /* TX wakeup count */
109 #define DESC_ALL_CNT (TX_DESC_CNT + RX_DESC_CNT)
110 #define TX_BUF_ALLOC 0x600
111 #define RX_ALLOC_SIZE 0x620
112 #define DM910X_RESET 1
113 #define CR0_DEFAULT 0x00E00000 /* TX & RX burst mode */
114 #define CR6_DEFAULT 0x00080000 /* HD */
115 #define CR7_DEFAULT 0x180c1
116 #define CR15_DEFAULT 0x06 /* TxJabber RxWatchdog */
117 #define TDES0_ERR_MASK 0x4302 /* TXJT, LC, EC, FUE */
118 #define MAX_PACKET_SIZE 1514
119 #define DMFE_MAX_MULTICAST 14
120 #define RX_COPY_SIZE 100
121 #define MAX_CHECK_PACKET 0x8000
122 #define DM9801_NOISE_FLOOR 8
123 #define DM9802_NOISE_FLOOR 5
125 #define DMFE_WOL_LINKCHANGE 0x20000000
126 #define DMFE_WOL_SAMPLEPACKET 0x10000000
127 #define DMFE_WOL_MAGICPACKET 0x08000000
131 #define DMFE_100MHF 1
133 #define DMFE_100MFD 5
135 #define DMFE_1M_HPNA 0x10
137 #define DMFE_TXTH_72 0x400000 /* TX TH 72 byte */
138 #define DMFE_TXTH_96 0x404000 /* TX TH 96 byte */
139 #define DMFE_TXTH_128 0x0000 /* TX TH 128 byte */
140 #define DMFE_TXTH_256 0x4000 /* TX TH 256 byte */
141 #define DMFE_TXTH_512 0x8000 /* TX TH 512 byte */
142 #define DMFE_TXTH_1K 0xC000 /* TX TH 1K byte */
144 #define DMFE_TIMER_WUT (jiffies + HZ * 1)/* timer wakeup time : 1 second */
145 #define DMFE_TX_TIMEOUT ((3*HZ)/2) /* tx packet time-out time 1.5 s" */
146 #define DMFE_TX_KICK (HZ/2) /* tx packet Kick-out time 0.5 s" */
148 #define DMFE_DBUG(dbug_now, msg, value) \
150 if (dmfe_debug || (dbug_now)) \
151 printk(KERN_ERR DRV_NAME ": %s %lx\n",\
152 (msg), (long) (value)); \
155 #define SHOW_MEDIA_TYPE(mode) \
156 printk (KERN_INFO DRV_NAME ": Change Speed to %sMhz %s duplex\n" , \
157 (mode & 1) ? "100":"10", (mode & 4) ? "full":"half");
160 /* CR9 definition: SROM/MII */
161 #define CR9_SROM_READ 0x4800
163 #define CR9_SRCLK 0x2
164 #define CR9_CRDOUT 0x8
165 #define SROM_DATA_0 0x0
166 #define SROM_DATA_1 0x4
167 #define PHY_DATA_1 0x20000
168 #define PHY_DATA_0 0x00000
169 #define MDCLKH 0x10000
171 #define PHY_POWER_DOWN 0x800
173 #define SROM_V41_CODE 0x14
175 #define SROM_CLK_WRITE(data, ioaddr) \
176 outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr); \
178 outl(data|CR9_SROM_READ|CR9_SRCS|CR9_SRCLK,ioaddr); \
180 outl(data|CR9_SROM_READ|CR9_SRCS,ioaddr); \
183 #define __CHK_IO_SIZE(pci_id, dev_rev) \
184 (( ((pci_id)==PCI_DM9132_ID) || ((dev_rev) >= 0x30) ) ? \
185 DM9102A_IO_SIZE: DM9102_IO_SIZE)
187 #define CHK_IO_SIZE(pci_dev) \
188 (__CHK_IO_SIZE(((pci_dev)->device << 16) | (pci_dev)->vendor, \
189 (pci_dev)->revision))
192 #define DEVICE net_device
194 /* Structure/enum declaration ------------------------------- */
196 __le32 tdes0, tdes1, tdes2, tdes3; /* Data for the card */
197 char *tx_buf_ptr; /* Data for us */
198 struct tx_desc *next_tx_desc;
199 } __attribute__(( aligned(32) ));
202 __le32 rdes0, rdes1, rdes2, rdes3; /* Data for the card */
203 struct sk_buff *rx_skb_ptr; /* Data for us */
204 struct rx_desc *next_rx_desc;
205 } __attribute__(( aligned(32) ));
207 struct dmfe_board_info {
208 u32 chip_id; /* Chip vendor/Device ID */
209 u8 chip_revision; /* Chip revision */
210 struct DEVICE *next_dev; /* next device */
211 struct pci_dev *pdev; /* PCI device */
214 long ioaddr; /* I/O base address */
221 /* pointer for memory physical address */
222 dma_addr_t buf_pool_dma_ptr; /* Tx buffer pool memory */
223 dma_addr_t buf_pool_dma_start; /* Tx buffer pool align dword */
224 dma_addr_t desc_pool_dma_ptr; /* descriptor pool memory */
225 dma_addr_t first_tx_desc_dma;
226 dma_addr_t first_rx_desc_dma;
228 /* descriptor pointer */
229 unsigned char *buf_pool_ptr; /* Tx buffer pool memory */
230 unsigned char *buf_pool_start; /* Tx buffer pool align dword */
231 unsigned char *desc_pool_ptr; /* descriptor pool memory */
232 struct tx_desc *first_tx_desc;
233 struct tx_desc *tx_insert_ptr;
234 struct tx_desc *tx_remove_ptr;
235 struct rx_desc *first_rx_desc;
236 struct rx_desc *rx_insert_ptr;
237 struct rx_desc *rx_ready_ptr; /* packet come pointer */
238 unsigned long tx_packet_cnt; /* transmitted packet count */
239 unsigned long tx_queue_cnt; /* wait to send packet count */
240 unsigned long rx_avail_cnt; /* available rx descriptor count */
241 unsigned long interval_rx_cnt; /* rx packet count a callback time */
243 u16 HPNA_command; /* For HPNA register 16 */
244 u16 HPNA_timer; /* For HPNA remote device check */
246 u16 NIC_capability; /* NIC media capability */
247 u16 PHY_reg4; /* Saved Phyxcer register 4 value */
249 u8 HPNA_present; /* 0:none, 1:DM9801, 2:DM9802 */
250 u8 chip_type; /* Keep DM9102A chip type */
251 u8 media_mode; /* user specify media mode */
252 u8 op_mode; /* real work media mode */
254 u8 wait_reset; /* Hardware failed, need to reset */
255 u8 dm910x_chk_mode; /* Operating mode check */
256 u8 first_in_callback; /* Flag to record state */
257 u8 wol_mode; /* user WOL settings */
258 struct timer_list timer;
260 /* System defined statistic counter */
261 struct net_device_stats stats;
263 /* Driver defined statistic counter */
264 unsigned long tx_fifo_underrun;
265 unsigned long tx_loss_carrier;
266 unsigned long tx_no_carrier;
267 unsigned long tx_late_collision;
268 unsigned long tx_excessive_collision;
269 unsigned long tx_jabber_timeout;
270 unsigned long reset_count;
271 unsigned long reset_cr8;
272 unsigned long reset_fatal;
273 unsigned long reset_TXtimeout;
276 unsigned char srom[128];
280 DCR0 = 0x00, DCR1 = 0x08, DCR2 = 0x10, DCR3 = 0x18, DCR4 = 0x20,
281 DCR5 = 0x28, DCR6 = 0x30, DCR7 = 0x38, DCR8 = 0x40, DCR9 = 0x48,
282 DCR10 = 0x50, DCR11 = 0x58, DCR12 = 0x60, DCR13 = 0x68, DCR14 = 0x70,
287 CR6_RXSC = 0x2, CR6_PBF = 0x8, CR6_PM = 0x40, CR6_PAM = 0x80,
288 CR6_FDM = 0x200, CR6_TXSC = 0x2000, CR6_STI = 0x100000,
289 CR6_SFT = 0x200000, CR6_RXA = 0x40000000, CR6_NO_PURGE = 0x20000000
292 /* Global variable declaration ----------------------------- */
293 static int __devinitdata printed_version;
294 static char version[] __devinitdata =
295 KERN_INFO DRV_NAME ": Davicom DM9xxx net driver, version "
296 DRV_VERSION " (" DRV_RELDATE ")\n";
298 static int dmfe_debug;
299 static unsigned char dmfe_media_mode = DMFE_AUTO;
300 static u32 dmfe_cr6_user_set;
302 /* For module input parameter */
305 static unsigned char mode = 8;
306 static u8 chkmode = 1;
307 static u8 HPNA_mode; /* Default: Low Power/High Speed */
308 static u8 HPNA_rx_cmd; /* Default: Disable Rx remote command */
309 static u8 HPNA_tx_cmd; /* Default: Don't issue remote command */
310 static u8 HPNA_NoiseFloor; /* Default: HPNA NoiseFloor */
311 static u8 SF_mode; /* Special Function: 1:VLAN, 2:RX Flow Control
312 4: TX pause packet */
315 /* function declaration ------------------------------------- */
316 static int dmfe_open(struct DEVICE *);
317 static int dmfe_start_xmit(struct sk_buff *, struct DEVICE *);
318 static int dmfe_stop(struct DEVICE *);
319 static struct net_device_stats * dmfe_get_stats(struct DEVICE *);
320 static void dmfe_set_filter_mode(struct DEVICE *);
321 static const struct ethtool_ops netdev_ethtool_ops;
322 static u16 read_srom_word(long ,int);
323 static irqreturn_t dmfe_interrupt(int , void *);
324 #ifdef CONFIG_NET_POLL_CONTROLLER
325 static void poll_dmfe (struct net_device *dev);
327 static void dmfe_descriptor_init(struct dmfe_board_info *, unsigned long);
328 static void allocate_rx_buffer(struct dmfe_board_info *);
329 static void update_cr6(u32, unsigned long);
330 static void send_filter_frame(struct DEVICE * ,int);
331 static void dm9132_id_table(struct DEVICE * ,int);
332 static u16 phy_read(unsigned long, u8, u8, u32);
333 static void phy_write(unsigned long, u8, u8, u16, u32);
334 static void phy_write_1bit(unsigned long, u32);
335 static u16 phy_read_1bit(unsigned long);
336 static u8 dmfe_sense_speed(struct dmfe_board_info *);
337 static void dmfe_process_mode(struct dmfe_board_info *);
338 static void dmfe_timer(unsigned long);
339 static inline u32 cal_CRC(unsigned char *, unsigned int, u8);
340 static void dmfe_rx_packet(struct DEVICE *, struct dmfe_board_info *);
341 static void dmfe_free_tx_pkt(struct DEVICE *, struct dmfe_board_info *);
342 static void dmfe_reuse_skb(struct dmfe_board_info *, struct sk_buff *);
343 static void dmfe_dynamic_reset(struct DEVICE *);
344 static void dmfe_free_rxbuffer(struct dmfe_board_info *);
345 static void dmfe_init_dm910x(struct DEVICE *);
346 static void dmfe_parse_srom(struct dmfe_board_info *);
347 static void dmfe_program_DM9801(struct dmfe_board_info *, int);
348 static void dmfe_program_DM9802(struct dmfe_board_info *);
349 static void dmfe_HPNA_remote_cmd_chk(struct dmfe_board_info * );
350 static void dmfe_set_phyxcer(struct dmfe_board_info *);
352 /* DM910X network board routine ---------------------------- */
355 * Search DM910X board ,allocate space and register it
358 static int __devinit dmfe_init_one (struct pci_dev *pdev,
359 const struct pci_device_id *ent)
361 struct dmfe_board_info *db; /* board information structure */
362 struct net_device *dev;
366 DMFE_DBUG(0, "dmfe_init_one()", 0);
368 if (!printed_version++)
371 /* Init network device */
372 dev = alloc_etherdev(sizeof(*db));
375 SET_NETDEV_DEV(dev, &pdev->dev);
377 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
378 printk(KERN_WARNING DRV_NAME
379 ": 32-bit PCI DMA not available.\n");
384 /* Enable Master/IO access, Disable memory access */
385 err = pci_enable_device(pdev);
389 if (!pci_resource_start(pdev, 0)) {
390 printk(KERN_ERR DRV_NAME ": I/O base is zero\n");
392 goto err_out_disable;
395 if (pci_resource_len(pdev, 0) < (CHK_IO_SIZE(pdev)) ) {
396 printk(KERN_ERR DRV_NAME ": Allocated I/O size too small\n");
398 goto err_out_disable;
401 #if 0 /* pci_{enable_device,set_master} sets minimum latency for us now */
403 /* Set Latency Timer 80h */
404 /* FIXME: setting values > 32 breaks some SiS 559x stuff.
405 Need a PCI quirk.. */
407 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x80);
410 if (pci_request_regions(pdev, DRV_NAME)) {
411 printk(KERN_ERR DRV_NAME ": Failed to request PCI regions\n");
413 goto err_out_disable;
416 /* Init system & device */
417 db = netdev_priv(dev);
419 /* Allocate Tx/Rx descriptor memory */
420 db->desc_pool_ptr = pci_alloc_consistent(pdev, sizeof(struct tx_desc) *
421 DESC_ALL_CNT + 0x20, &db->desc_pool_dma_ptr);
422 if (!db->desc_pool_ptr)
425 db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC *
426 TX_DESC_CNT + 4, &db->buf_pool_dma_ptr);
427 if (!db->buf_pool_ptr)
428 goto err_out_free_desc;
430 db->first_tx_desc = (struct tx_desc *) db->desc_pool_ptr;
431 db->first_tx_desc_dma = db->desc_pool_dma_ptr;
432 db->buf_pool_start = db->buf_pool_ptr;
433 db->buf_pool_dma_start = db->buf_pool_dma_ptr;
435 db->chip_id = ent->driver_data;
436 db->ioaddr = pci_resource_start(pdev, 0);
437 db->chip_revision = pdev->revision;
442 dev->base_addr = db->ioaddr;
443 dev->irq = pdev->irq;
444 pci_set_drvdata(pdev, dev);
445 dev->open = &dmfe_open;
446 dev->hard_start_xmit = &dmfe_start_xmit;
447 dev->stop = &dmfe_stop;
448 dev->get_stats = &dmfe_get_stats;
449 dev->set_multicast_list = &dmfe_set_filter_mode;
450 #ifdef CONFIG_NET_POLL_CONTROLLER
451 dev->poll_controller = &poll_dmfe;
453 dev->ethtool_ops = &netdev_ethtool_ops;
454 netif_carrier_off(dev);
455 spin_lock_init(&db->lock);
457 pci_read_config_dword(pdev, 0x50, &pci_pmr);
459 if ( (pci_pmr == 0x10000) && (db->chip_revision == 0x31) )
460 db->chip_type = 1; /* DM9102A E3 */
464 /* read 64 word srom data */
465 for (i = 0; i < 64; i++)
466 ((__le16 *) db->srom)[i] =
467 cpu_to_le16(read_srom_word(db->ioaddr, i));
469 /* Set Node address */
470 for (i = 0; i < 6; i++)
471 dev->dev_addr[i] = db->srom[20 + i];
473 err = register_netdev (dev);
475 goto err_out_free_buf;
477 printk(KERN_INFO "%s: Davicom DM%04lx at pci%s, %pM, irq %d.\n",
479 ent->driver_data >> 16,
484 pci_set_master(pdev);
489 pci_free_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4,
490 db->buf_pool_ptr, db->buf_pool_dma_ptr);
492 pci_free_consistent(pdev, sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20,
493 db->desc_pool_ptr, db->desc_pool_dma_ptr);
495 pci_release_regions(pdev);
497 pci_disable_device(pdev);
499 pci_set_drvdata(pdev, NULL);
506 static void __devexit dmfe_remove_one (struct pci_dev *pdev)
508 struct net_device *dev = pci_get_drvdata(pdev);
509 struct dmfe_board_info *db = netdev_priv(dev);
511 DMFE_DBUG(0, "dmfe_remove_one()", 0);
515 unregister_netdev(dev);
517 pci_free_consistent(db->pdev, sizeof(struct tx_desc) *
518 DESC_ALL_CNT + 0x20, db->desc_pool_ptr,
519 db->desc_pool_dma_ptr);
520 pci_free_consistent(db->pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4,
521 db->buf_pool_ptr, db->buf_pool_dma_ptr);
522 pci_release_regions(pdev);
523 free_netdev(dev); /* free board information */
525 pci_set_drvdata(pdev, NULL);
528 DMFE_DBUG(0, "dmfe_remove_one() exit", 0);
533 * Open the interface.
534 * The interface is opened whenever "ifconfig" actives it.
537 static int dmfe_open(struct DEVICE *dev)
540 struct dmfe_board_info *db = netdev_priv(dev);
542 DMFE_DBUG(0, "dmfe_open", 0);
544 ret = request_irq(dev->irq, &dmfe_interrupt,
545 IRQF_SHARED, dev->name, dev);
549 /* system variable init */
550 db->cr6_data = CR6_DEFAULT | dmfe_cr6_user_set;
551 db->tx_packet_cnt = 0;
552 db->tx_queue_cnt = 0;
553 db->rx_avail_cnt = 0;
556 db->first_in_callback = 0;
557 db->NIC_capability = 0xf; /* All capability*/
558 db->PHY_reg4 = 0x1e0;
560 /* CR6 operation mode decision */
561 if ( !chkmode || (db->chip_id == PCI_DM9132_ID) ||
562 (db->chip_revision >= 0x30) ) {
563 db->cr6_data |= DMFE_TXTH_256;
564 db->cr0_data = CR0_DEFAULT;
565 db->dm910x_chk_mode=4; /* Enter the normal mode */
567 db->cr6_data |= CR6_SFT; /* Store & Forward mode */
569 db->dm910x_chk_mode = 1; /* Enter the check mode */
572 /* Initilize DM910X board */
573 dmfe_init_dm910x(dev);
575 /* Active System Interface */
576 netif_wake_queue(dev);
578 /* set and active a timer process */
579 init_timer(&db->timer);
580 db->timer.expires = DMFE_TIMER_WUT + HZ * 2;
581 db->timer.data = (unsigned long)dev;
582 db->timer.function = &dmfe_timer;
583 add_timer(&db->timer);
589 /* Initilize DM910X board
591 * Initilize TX/Rx descriptor chain structure
592 * Send the set-up frame
593 * Enable Tx/Rx machine
596 static void dmfe_init_dm910x(struct DEVICE *dev)
598 struct dmfe_board_info *db = netdev_priv(dev);
599 unsigned long ioaddr = db->ioaddr;
601 DMFE_DBUG(0, "dmfe_init_dm910x()", 0);
603 /* Reset DM910x MAC controller */
604 outl(DM910X_RESET, ioaddr + DCR0); /* RESET MAC */
606 outl(db->cr0_data, ioaddr + DCR0);
609 /* Phy addr : DM910(A)2/DM9132/9801, phy address = 1 */
612 /* Parser SROM and media mode */
614 db->media_mode = dmfe_media_mode;
616 /* RESET Phyxcer Chip by GPR port bit 7 */
617 outl(0x180, ioaddr + DCR12); /* Let bit 7 output port */
618 if (db->chip_id == PCI_DM9009_ID) {
619 outl(0x80, ioaddr + DCR12); /* Issue RESET signal */
620 mdelay(300); /* Delay 300 ms */
622 outl(0x0, ioaddr + DCR12); /* Clear RESET signal */
624 /* Process Phyxcer Media Mode */
625 if ( !(db->media_mode & 0x10) ) /* Force 1M mode */
626 dmfe_set_phyxcer(db);
628 /* Media Mode Process */
629 if ( !(db->media_mode & DMFE_AUTO) )
630 db->op_mode = db->media_mode; /* Force Mode */
632 /* Initiliaze Transmit/Receive decriptor and CR3/4 */
633 dmfe_descriptor_init(db, ioaddr);
635 /* Init CR6 to program DM910x operation */
636 update_cr6(db->cr6_data, ioaddr);
638 /* Send setup frame */
639 if (db->chip_id == PCI_DM9132_ID)
640 dm9132_id_table(dev, dev->mc_count); /* DM9132 */
642 send_filter_frame(dev, dev->mc_count); /* DM9102/DM9102A */
644 /* Init CR7, interrupt active bit */
645 db->cr7_data = CR7_DEFAULT;
646 outl(db->cr7_data, ioaddr + DCR7);
648 /* Init CR15, Tx jabber and Rx watchdog timer */
649 outl(db->cr15_data, ioaddr + DCR15);
651 /* Enable DM910X Tx/Rx function */
652 db->cr6_data |= CR6_RXSC | CR6_TXSC | 0x40000;
653 update_cr6(db->cr6_data, ioaddr);
658 * Hardware start transmission.
659 * Send a packet to media from the upper layer.
662 static int dmfe_start_xmit(struct sk_buff *skb, struct DEVICE *dev)
664 struct dmfe_board_info *db = netdev_priv(dev);
665 struct tx_desc *txptr;
668 DMFE_DBUG(0, "dmfe_start_xmit", 0);
670 /* Resource flag check */
671 netif_stop_queue(dev);
673 /* Too large packet check */
674 if (skb->len > MAX_PACKET_SIZE) {
675 printk(KERN_ERR DRV_NAME ": big packet = %d\n", (u16)skb->len);
680 spin_lock_irqsave(&db->lock, flags);
682 /* No Tx resource check, it never happen nromally */
683 if (db->tx_queue_cnt >= TX_FREE_DESC_CNT) {
684 spin_unlock_irqrestore(&db->lock, flags);
685 printk(KERN_ERR DRV_NAME ": No Tx resource %ld\n",
690 /* Disable NIC interrupt */
691 outl(0, dev->base_addr + DCR7);
693 /* transmit this packet */
694 txptr = db->tx_insert_ptr;
695 skb_copy_from_linear_data(skb, txptr->tx_buf_ptr, skb->len);
696 txptr->tdes1 = cpu_to_le32(0xe1000000 | skb->len);
698 /* Point to next transmit free descriptor */
699 db->tx_insert_ptr = txptr->next_tx_desc;
701 /* Transmit Packet Process */
702 if ( (!db->tx_queue_cnt) && (db->tx_packet_cnt < TX_MAX_SEND_CNT) ) {
703 txptr->tdes0 = cpu_to_le32(0x80000000); /* Set owner bit */
704 db->tx_packet_cnt++; /* Ready to send */
705 outl(0x1, dev->base_addr + DCR1); /* Issue Tx polling */
706 dev->trans_start = jiffies; /* saved time stamp */
708 db->tx_queue_cnt++; /* queue TX packet */
709 outl(0x1, dev->base_addr + DCR1); /* Issue Tx polling */
712 /* Tx resource check */
713 if ( db->tx_queue_cnt < TX_FREE_DESC_CNT )
714 netif_wake_queue(dev);
716 /* Restore CR7 to enable interrupt */
717 spin_unlock_irqrestore(&db->lock, flags);
718 outl(db->cr7_data, dev->base_addr + DCR7);
728 * Stop the interface.
729 * The interface is stopped when it is brought.
732 static int dmfe_stop(struct DEVICE *dev)
734 struct dmfe_board_info *db = netdev_priv(dev);
735 unsigned long ioaddr = dev->base_addr;
737 DMFE_DBUG(0, "dmfe_stop", 0);
740 netif_stop_queue(dev);
743 del_timer_sync(&db->timer);
745 /* Reset & stop DM910X board */
746 outl(DM910X_RESET, ioaddr + DCR0);
748 phy_write(db->ioaddr, db->phy_addr, 0, 0x8000, db->chip_id);
751 free_irq(dev->irq, dev);
753 /* free allocated rx buffer */
754 dmfe_free_rxbuffer(db);
757 /* show statistic counter */
758 printk(DRV_NAME ": FU:%lx EC:%lx LC:%lx NC:%lx"
759 " LOC:%lx TXJT:%lx RESET:%lx RCR8:%lx FAL:%lx TT:%lx\n",
760 db->tx_fifo_underrun, db->tx_excessive_collision,
761 db->tx_late_collision, db->tx_no_carrier, db->tx_loss_carrier,
762 db->tx_jabber_timeout, db->reset_count, db->reset_cr8,
763 db->reset_fatal, db->reset_TXtimeout);
771 * DM9102 insterrupt handler
772 * receive the packet to upper layer, free the transmitted packet
775 static irqreturn_t dmfe_interrupt(int irq, void *dev_id)
777 struct DEVICE *dev = dev_id;
778 struct dmfe_board_info *db = netdev_priv(dev);
779 unsigned long ioaddr = dev->base_addr;
782 DMFE_DBUG(0, "dmfe_interrupt()", 0);
784 spin_lock_irqsave(&db->lock, flags);
786 /* Got DM910X status */
787 db->cr5_data = inl(ioaddr + DCR5);
788 outl(db->cr5_data, ioaddr + DCR5);
789 if ( !(db->cr5_data & 0xc1) ) {
790 spin_unlock_irqrestore(&db->lock, flags);
794 /* Disable all interrupt in CR7 to solve the interrupt edge problem */
795 outl(0, ioaddr + DCR7);
797 /* Check system status */
798 if (db->cr5_data & 0x2000) {
799 /* system bus error happen */
800 DMFE_DBUG(1, "System bus error happen. CR5=", db->cr5_data);
802 db->wait_reset = 1; /* Need to RESET */
803 spin_unlock_irqrestore(&db->lock, flags);
807 /* Received the coming packet */
808 if ( (db->cr5_data & 0x40) && db->rx_avail_cnt )
809 dmfe_rx_packet(dev, db);
811 /* reallocate rx descriptor buffer */
812 if (db->rx_avail_cnt<RX_DESC_CNT)
813 allocate_rx_buffer(db);
815 /* Free the transmitted descriptor */
816 if ( db->cr5_data & 0x01)
817 dmfe_free_tx_pkt(dev, db);
820 if (db->dm910x_chk_mode & 0x2) {
821 db->dm910x_chk_mode = 0x4;
822 db->cr6_data |= 0x100;
823 update_cr6(db->cr6_data, db->ioaddr);
826 /* Restore CR7 to enable interrupt mask */
827 outl(db->cr7_data, ioaddr + DCR7);
829 spin_unlock_irqrestore(&db->lock, flags);
834 #ifdef CONFIG_NET_POLL_CONTROLLER
836 * Polling 'interrupt' - used by things like netconsole to send skbs
837 * without having to re-enable interrupts. It's not called while
838 * the interrupt routine is executing.
841 static void poll_dmfe (struct net_device *dev)
843 /* disable_irq here is not very nice, but with the lockless
844 interrupt handler we have no other choice. */
845 disable_irq(dev->irq);
846 dmfe_interrupt (dev->irq, dev);
847 enable_irq(dev->irq);
852 * Free TX resource after TX complete
855 static void dmfe_free_tx_pkt(struct DEVICE *dev, struct dmfe_board_info * db)
857 struct tx_desc *txptr;
858 unsigned long ioaddr = dev->base_addr;
861 txptr = db->tx_remove_ptr;
862 while(db->tx_packet_cnt) {
863 tdes0 = le32_to_cpu(txptr->tdes0);
864 /* printk(DRV_NAME ": tdes0=%x\n", tdes0); */
865 if (tdes0 & 0x80000000)
868 /* A packet sent completed */
870 db->stats.tx_packets++;
872 /* Transmit statistic counter */
873 if ( tdes0 != 0x7fffffff ) {
874 /* printk(DRV_NAME ": tdes0=%x\n", tdes0); */
875 db->stats.collisions += (tdes0 >> 3) & 0xf;
876 db->stats.tx_bytes += le32_to_cpu(txptr->tdes1) & 0x7ff;
877 if (tdes0 & TDES0_ERR_MASK) {
878 db->stats.tx_errors++;
880 if (tdes0 & 0x0002) { /* UnderRun */
881 db->tx_fifo_underrun++;
882 if ( !(db->cr6_data & CR6_SFT) ) {
883 db->cr6_data = db->cr6_data | CR6_SFT;
884 update_cr6(db->cr6_data, db->ioaddr);
888 db->tx_excessive_collision++;
890 db->tx_late_collision++;
894 db->tx_loss_carrier++;
896 db->tx_jabber_timeout++;
900 txptr = txptr->next_tx_desc;
903 /* Update TX remove pointer to next */
904 db->tx_remove_ptr = txptr;
906 /* Send the Tx packet in queue */
907 if ( (db->tx_packet_cnt < TX_MAX_SEND_CNT) && db->tx_queue_cnt ) {
908 txptr->tdes0 = cpu_to_le32(0x80000000); /* Set owner bit */
909 db->tx_packet_cnt++; /* Ready to send */
911 outl(0x1, ioaddr + DCR1); /* Issue Tx polling */
912 dev->trans_start = jiffies; /* saved time stamp */
915 /* Resource available check */
916 if ( db->tx_queue_cnt < TX_WAKE_DESC_CNT )
917 netif_wake_queue(dev); /* Active upper layer, send again */
922 * Calculate the CRC valude of the Rx packet
923 * flag = 1 : return the reverse CRC (for the received packet CRC)
924 * 0 : return the normal CRC (for Hash Table index)
927 static inline u32 cal_CRC(unsigned char * Data, unsigned int Len, u8 flag)
929 u32 crc = crc32(~0, Data, Len);
930 if (flag) crc = ~crc;
936 * Receive the come packet and pass to upper layer
939 static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
941 struct rx_desc *rxptr;
942 struct sk_buff *skb, *newskb;
946 rxptr = db->rx_ready_ptr;
948 while(db->rx_avail_cnt) {
949 rdes0 = le32_to_cpu(rxptr->rdes0);
950 if (rdes0 & 0x80000000) /* packet owner check */
954 db->interval_rx_cnt++;
956 pci_unmap_single(db->pdev, le32_to_cpu(rxptr->rdes2),
957 RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE);
959 if ( (rdes0 & 0x300) != 0x300) {
960 /* A packet without First/Last flag */
962 DMFE_DBUG(0, "Reuse SK buffer, rdes0", rdes0);
963 dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
965 /* A packet with First/Last flag */
966 rxlen = ( (rdes0 >> 16) & 0x3fff) - 4;
968 /* error summary bit check */
969 if (rdes0 & 0x8000) {
970 /* This is a error packet */
971 //printk(DRV_NAME ": rdes0: %lx\n", rdes0);
972 db->stats.rx_errors++;
974 db->stats.rx_fifo_errors++;
976 db->stats.rx_crc_errors++;
978 db->stats.rx_length_errors++;
981 if ( !(rdes0 & 0x8000) ||
982 ((db->cr6_data & CR6_PM) && (rxlen>6)) ) {
983 skb = rxptr->rx_skb_ptr;
985 /* Received Packet CRC check need or not */
986 if ( (db->dm910x_chk_mode & 1) &&
987 (cal_CRC(skb->data, rxlen, 1) !=
988 (*(u32 *) (skb->data+rxlen) ))) { /* FIXME (?) */
989 /* Found a error received packet */
990 dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
991 db->dm910x_chk_mode = 3;
993 /* Good packet, send to upper layer */
994 /* Shorst packet used new SKB */
995 if ((rxlen < RX_COPY_SIZE) &&
996 ((newskb = dev_alloc_skb(rxlen + 2))
1000 /* size less than COPY_SIZE, allocate a rxlen SKB */
1001 skb_reserve(skb, 2); /* 16byte align */
1002 skb_copy_from_linear_data(rxptr->rx_skb_ptr,
1003 skb_put(skb, rxlen),
1005 dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
1007 skb_put(skb, rxlen);
1009 skb->protocol = eth_type_trans(skb, dev);
1011 db->stats.rx_packets++;
1012 db->stats.rx_bytes += rxlen;
1015 /* Reuse SKB buffer when the packet is error */
1016 DMFE_DBUG(0, "Reuse SK buffer, rdes0", rdes0);
1017 dmfe_reuse_skb(db, rxptr->rx_skb_ptr);
1021 rxptr = rxptr->next_rx_desc;
1024 db->rx_ready_ptr = rxptr;
1029 * Get statistics from driver.
1032 static struct net_device_stats * dmfe_get_stats(struct DEVICE *dev)
1034 struct dmfe_board_info *db = netdev_priv(dev);
1036 DMFE_DBUG(0, "dmfe_get_stats", 0);
1042 * Set DM910X multicast address
1045 static void dmfe_set_filter_mode(struct DEVICE * dev)
1047 struct dmfe_board_info *db = netdev_priv(dev);
1048 unsigned long flags;
1050 DMFE_DBUG(0, "dmfe_set_filter_mode()", 0);
1051 spin_lock_irqsave(&db->lock, flags);
1053 if (dev->flags & IFF_PROMISC) {
1054 DMFE_DBUG(0, "Enable PROM Mode", 0);
1055 db->cr6_data |= CR6_PM | CR6_PBF;
1056 update_cr6(db->cr6_data, db->ioaddr);
1057 spin_unlock_irqrestore(&db->lock, flags);
1061 if (dev->flags & IFF_ALLMULTI || dev->mc_count > DMFE_MAX_MULTICAST) {
1062 DMFE_DBUG(0, "Pass all multicast address", dev->mc_count);
1063 db->cr6_data &= ~(CR6_PM | CR6_PBF);
1064 db->cr6_data |= CR6_PAM;
1065 spin_unlock_irqrestore(&db->lock, flags);
1069 DMFE_DBUG(0, "Set multicast address", dev->mc_count);
1070 if (db->chip_id == PCI_DM9132_ID)
1071 dm9132_id_table(dev, dev->mc_count); /* DM9132 */
1073 send_filter_frame(dev, dev->mc_count); /* DM9102/DM9102A */
1074 spin_unlock_irqrestore(&db->lock, flags);
1081 static void dmfe_ethtool_get_drvinfo(struct net_device *dev,
1082 struct ethtool_drvinfo *info)
1084 struct dmfe_board_info *np = netdev_priv(dev);
1086 strcpy(info->driver, DRV_NAME);
1087 strcpy(info->version, DRV_VERSION);
1089 strcpy(info->bus_info, pci_name(np->pdev));
1091 sprintf(info->bus_info, "EISA 0x%lx %d",
1092 dev->base_addr, dev->irq);
1095 static int dmfe_ethtool_set_wol(struct net_device *dev,
1096 struct ethtool_wolinfo *wolinfo)
1098 struct dmfe_board_info *db = netdev_priv(dev);
1100 if (wolinfo->wolopts & (WAKE_UCAST | WAKE_MCAST | WAKE_BCAST |
1101 WAKE_ARP | WAKE_MAGICSECURE))
1104 db->wol_mode = wolinfo->wolopts;
1108 static void dmfe_ethtool_get_wol(struct net_device *dev,
1109 struct ethtool_wolinfo *wolinfo)
1111 struct dmfe_board_info *db = netdev_priv(dev);
1113 wolinfo->supported = WAKE_PHY | WAKE_MAGIC;
1114 wolinfo->wolopts = db->wol_mode;
1119 static const struct ethtool_ops netdev_ethtool_ops = {
1120 .get_drvinfo = dmfe_ethtool_get_drvinfo,
1121 .get_link = ethtool_op_get_link,
1122 .set_wol = dmfe_ethtool_set_wol,
1123 .get_wol = dmfe_ethtool_get_wol,
1127 * A periodic timer routine
1128 * Dynamic media sense, allocate Rx buffer...
1131 static void dmfe_timer(unsigned long data)
1134 unsigned char tmp_cr12;
1135 struct DEVICE *dev = (struct DEVICE *) data;
1136 struct dmfe_board_info *db = netdev_priv(dev);
1137 unsigned long flags;
1139 int link_ok, link_ok_phy;
1141 DMFE_DBUG(0, "dmfe_timer()", 0);
1142 spin_lock_irqsave(&db->lock, flags);
1144 /* Media mode process when Link OK before enter this route */
1145 if (db->first_in_callback == 0) {
1146 db->first_in_callback = 1;
1147 if (db->chip_type && (db->chip_id==PCI_DM9102_ID)) {
1148 db->cr6_data &= ~0x40000;
1149 update_cr6(db->cr6_data, db->ioaddr);
1150 phy_write(db->ioaddr,
1151 db->phy_addr, 0, 0x1000, db->chip_id);
1152 db->cr6_data |= 0x40000;
1153 update_cr6(db->cr6_data, db->ioaddr);
1154 db->timer.expires = DMFE_TIMER_WUT + HZ * 2;
1155 add_timer(&db->timer);
1156 spin_unlock_irqrestore(&db->lock, flags);
1162 /* Operating Mode Check */
1163 if ( (db->dm910x_chk_mode & 0x1) &&
1164 (db->stats.rx_packets > MAX_CHECK_PACKET) )
1165 db->dm910x_chk_mode = 0x4;
1167 /* Dynamic reset DM910X : system error or transmit time-out */
1168 tmp_cr8 = inl(db->ioaddr + DCR8);
1169 if ( (db->interval_rx_cnt==0) && (tmp_cr8) ) {
1173 db->interval_rx_cnt = 0;
1175 /* TX polling kick monitor */
1176 if ( db->tx_packet_cnt &&
1177 time_after(jiffies, dev->trans_start + DMFE_TX_KICK) ) {
1178 outl(0x1, dev->base_addr + DCR1); /* Tx polling again */
1181 if ( time_after(jiffies, dev->trans_start + DMFE_TX_TIMEOUT) ) {
1182 db->reset_TXtimeout++;
1184 printk(KERN_WARNING "%s: Tx timeout - resetting\n",
1189 if (db->wait_reset) {
1190 DMFE_DBUG(0, "Dynamic Reset device", db->tx_packet_cnt);
1192 dmfe_dynamic_reset(dev);
1193 db->first_in_callback = 0;
1194 db->timer.expires = DMFE_TIMER_WUT;
1195 add_timer(&db->timer);
1196 spin_unlock_irqrestore(&db->lock, flags);
1200 /* Link status check, Dynamic media type change */
1201 if (db->chip_id == PCI_DM9132_ID)
1202 tmp_cr12 = inb(db->ioaddr + DCR9 + 3); /* DM9132 */
1204 tmp_cr12 = inb(db->ioaddr + DCR12); /* DM9102/DM9102A */
1206 if ( ((db->chip_id == PCI_DM9102_ID) &&
1207 (db->chip_revision == 0x30)) ||
1208 ((db->chip_id == PCI_DM9132_ID) &&
1209 (db->chip_revision == 0x10)) ) {
1217 /*0x43 is used instead of 0x3 because bit 6 should represent
1218 link status of external PHY */
1219 link_ok = (tmp_cr12 & 0x43) ? 1 : 0;
1222 /* If chip reports that link is failed it could be because external
1223 PHY link status pin is not conected correctly to chip
1224 To be sure ask PHY too.
1227 /* need a dummy read because of PHY's register latch*/
1228 phy_read (db->ioaddr, db->phy_addr, 1, db->chip_id);
1229 link_ok_phy = (phy_read (db->ioaddr,
1230 db->phy_addr, 1, db->chip_id) & 0x4) ? 1 : 0;
1232 if (link_ok_phy != link_ok) {
1233 DMFE_DBUG (0, "PHY and chip report different link status", 0);
1234 link_ok = link_ok | link_ok_phy;
1237 if ( !link_ok && netif_carrier_ok(dev)) {
1239 DMFE_DBUG(0, "Link Failed", tmp_cr12);
1240 netif_carrier_off(dev);
1242 /* For Force 10/100M Half/Full mode: Enable Auto-Nego mode */
1243 /* AUTO or force 1M Homerun/Longrun don't need */
1244 if ( !(db->media_mode & 0x38) )
1245 phy_write(db->ioaddr, db->phy_addr,
1246 0, 0x1000, db->chip_id);
1248 /* AUTO mode, if INT phyxcer link failed, select EXT device */
1249 if (db->media_mode & DMFE_AUTO) {
1250 /* 10/100M link failed, used 1M Home-Net */
1251 db->cr6_data|=0x00040000; /* bit18=1, MII */
1252 db->cr6_data&=~0x00000200; /* bit9=0, HD mode */
1253 update_cr6(db->cr6_data, db->ioaddr);
1255 } else if (!netif_carrier_ok(dev)) {
1257 DMFE_DBUG(0, "Link link OK", tmp_cr12);
1259 /* Auto Sense Speed */
1260 if ( !(db->media_mode & DMFE_AUTO) || !dmfe_sense_speed(db)) {
1261 netif_carrier_on(dev);
1262 SHOW_MEDIA_TYPE(db->op_mode);
1265 dmfe_process_mode(db);
1268 /* HPNA remote command check */
1269 if (db->HPNA_command & 0xf00) {
1271 if (!db->HPNA_timer)
1272 dmfe_HPNA_remote_cmd_chk(db);
1275 /* Timer active again */
1276 db->timer.expires = DMFE_TIMER_WUT;
1277 add_timer(&db->timer);
1278 spin_unlock_irqrestore(&db->lock, flags);
1283 * Dynamic reset the DM910X board
1285 * Free Tx/Rx allocated memory
1286 * Reset DM910X board
1287 * Re-initilize DM910X board
1290 static void dmfe_dynamic_reset(struct DEVICE *dev)
1292 struct dmfe_board_info *db = netdev_priv(dev);
1294 DMFE_DBUG(0, "dmfe_dynamic_reset()", 0);
1296 /* Sopt MAC controller */
1297 db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */
1298 update_cr6(db->cr6_data, dev->base_addr);
1299 outl(0, dev->base_addr + DCR7); /* Disable Interrupt */
1300 outl(inl(dev->base_addr + DCR5), dev->base_addr + DCR5);
1302 /* Disable upper layer interface */
1303 netif_stop_queue(dev);
1305 /* Free Rx Allocate buffer */
1306 dmfe_free_rxbuffer(db);
1308 /* system variable init */
1309 db->tx_packet_cnt = 0;
1310 db->tx_queue_cnt = 0;
1311 db->rx_avail_cnt = 0;
1312 netif_carrier_off(dev);
1315 /* Re-initilize DM910X board */
1316 dmfe_init_dm910x(dev);
1318 /* Restart upper layer interface */
1319 netif_wake_queue(dev);
1324 * free all allocated rx buffer
1327 static void dmfe_free_rxbuffer(struct dmfe_board_info * db)
1329 DMFE_DBUG(0, "dmfe_free_rxbuffer()", 0);
1331 /* free allocated rx buffer */
1332 while (db->rx_avail_cnt) {
1333 dev_kfree_skb(db->rx_ready_ptr->rx_skb_ptr);
1334 db->rx_ready_ptr = db->rx_ready_ptr->next_rx_desc;
1341 * Reuse the SK buffer
1344 static void dmfe_reuse_skb(struct dmfe_board_info *db, struct sk_buff * skb)
1346 struct rx_desc *rxptr = db->rx_insert_ptr;
1348 if (!(rxptr->rdes0 & cpu_to_le32(0x80000000))) {
1349 rxptr->rx_skb_ptr = skb;
1350 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev,
1351 skb->data, RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
1353 rxptr->rdes0 = cpu_to_le32(0x80000000);
1355 db->rx_insert_ptr = rxptr->next_rx_desc;
1357 DMFE_DBUG(0, "SK Buffer reuse method error", db->rx_avail_cnt);
1362 * Initialize transmit/Receive descriptor
1363 * Using Chain structure, and allocate Tx/Rx buffer
1366 static void dmfe_descriptor_init(struct dmfe_board_info *db, unsigned long ioaddr)
1368 struct tx_desc *tmp_tx;
1369 struct rx_desc *tmp_rx;
1370 unsigned char *tmp_buf;
1371 dma_addr_t tmp_tx_dma, tmp_rx_dma;
1372 dma_addr_t tmp_buf_dma;
1375 DMFE_DBUG(0, "dmfe_descriptor_init()", 0);
1377 /* tx descriptor start pointer */
1378 db->tx_insert_ptr = db->first_tx_desc;
1379 db->tx_remove_ptr = db->first_tx_desc;
1380 outl(db->first_tx_desc_dma, ioaddr + DCR4); /* TX DESC address */
1382 /* rx descriptor start pointer */
1383 db->first_rx_desc = (void *)db->first_tx_desc +
1384 sizeof(struct tx_desc) * TX_DESC_CNT;
1386 db->first_rx_desc_dma = db->first_tx_desc_dma +
1387 sizeof(struct tx_desc) * TX_DESC_CNT;
1388 db->rx_insert_ptr = db->first_rx_desc;
1389 db->rx_ready_ptr = db->first_rx_desc;
1390 outl(db->first_rx_desc_dma, ioaddr + DCR3); /* RX DESC address */
1392 /* Init Transmit chain */
1393 tmp_buf = db->buf_pool_start;
1394 tmp_buf_dma = db->buf_pool_dma_start;
1395 tmp_tx_dma = db->first_tx_desc_dma;
1396 for (tmp_tx = db->first_tx_desc, i = 0; i < TX_DESC_CNT; i++, tmp_tx++) {
1397 tmp_tx->tx_buf_ptr = tmp_buf;
1398 tmp_tx->tdes0 = cpu_to_le32(0);
1399 tmp_tx->tdes1 = cpu_to_le32(0x81000000); /* IC, chain */
1400 tmp_tx->tdes2 = cpu_to_le32(tmp_buf_dma);
1401 tmp_tx_dma += sizeof(struct tx_desc);
1402 tmp_tx->tdes3 = cpu_to_le32(tmp_tx_dma);
1403 tmp_tx->next_tx_desc = tmp_tx + 1;
1404 tmp_buf = tmp_buf + TX_BUF_ALLOC;
1405 tmp_buf_dma = tmp_buf_dma + TX_BUF_ALLOC;
1407 (--tmp_tx)->tdes3 = cpu_to_le32(db->first_tx_desc_dma);
1408 tmp_tx->next_tx_desc = db->first_tx_desc;
1410 /* Init Receive descriptor chain */
1411 tmp_rx_dma=db->first_rx_desc_dma;
1412 for (tmp_rx = db->first_rx_desc, i = 0; i < RX_DESC_CNT; i++, tmp_rx++) {
1413 tmp_rx->rdes0 = cpu_to_le32(0);
1414 tmp_rx->rdes1 = cpu_to_le32(0x01000600);
1415 tmp_rx_dma += sizeof(struct rx_desc);
1416 tmp_rx->rdes3 = cpu_to_le32(tmp_rx_dma);
1417 tmp_rx->next_rx_desc = tmp_rx + 1;
1419 (--tmp_rx)->rdes3 = cpu_to_le32(db->first_rx_desc_dma);
1420 tmp_rx->next_rx_desc = db->first_rx_desc;
1422 /* pre-allocate Rx buffer */
1423 allocate_rx_buffer(db);
1429 * Firstly stop DM910X , then written value and start
1432 static void update_cr6(u32 cr6_data, unsigned long ioaddr)
1436 cr6_tmp = cr6_data & ~0x2002; /* stop Tx/Rx */
1437 outl(cr6_tmp, ioaddr + DCR6);
1439 outl(cr6_data, ioaddr + DCR6);
1445 * Send a setup frame for DM9132
1446 * This setup frame initilize DM910X address filter mode
1449 static void dm9132_id_table(struct DEVICE *dev, int mc_cnt)
1451 struct dev_mc_list *mcptr;
1453 unsigned long ioaddr = dev->base_addr+0xc0; /* ID Table */
1455 u16 i, hash_table[4];
1457 DMFE_DBUG(0, "dm9132_id_table()", 0);
1460 addrptr = (u16 *) dev->dev_addr;
1461 outw(addrptr[0], ioaddr);
1463 outw(addrptr[1], ioaddr);
1465 outw(addrptr[2], ioaddr);
1468 /* Clear Hash Table */
1469 for (i = 0; i < 4; i++)
1470 hash_table[i] = 0x0;
1472 /* broadcast address */
1473 hash_table[3] = 0x8000;
1475 /* the multicast address in Hash Table : 64 bits */
1476 for (mcptr = dev->mc_list, i = 0; i < mc_cnt; i++, mcptr = mcptr->next) {
1477 hash_val = cal_CRC( (char *) mcptr->dmi_addr, 6, 0) & 0x3f;
1478 hash_table[hash_val / 16] |= (u16) 1 << (hash_val % 16);
1481 /* Write the hash table to MAC MD table */
1482 for (i = 0; i < 4; i++, ioaddr += 4)
1483 outw(hash_table[i], ioaddr);
1488 * Send a setup frame for DM9102/DM9102A
1489 * This setup frame initilize DM910X address filter mode
1492 static void send_filter_frame(struct DEVICE *dev, int mc_cnt)
1494 struct dmfe_board_info *db = netdev_priv(dev);
1495 struct dev_mc_list *mcptr;
1496 struct tx_desc *txptr;
1501 DMFE_DBUG(0, "send_filter_frame()", 0);
1503 txptr = db->tx_insert_ptr;
1504 suptr = (u32 *) txptr->tx_buf_ptr;
1507 addrptr = (u16 *) dev->dev_addr;
1508 *suptr++ = addrptr[0];
1509 *suptr++ = addrptr[1];
1510 *suptr++ = addrptr[2];
1512 /* broadcast address */
1517 /* fit the multicast address */
1518 for (mcptr = dev->mc_list, i = 0; i < mc_cnt; i++, mcptr = mcptr->next) {
1519 addrptr = (u16 *) mcptr->dmi_addr;
1520 *suptr++ = addrptr[0];
1521 *suptr++ = addrptr[1];
1522 *suptr++ = addrptr[2];
1531 /* prepare the setup frame */
1532 db->tx_insert_ptr = txptr->next_tx_desc;
1533 txptr->tdes1 = cpu_to_le32(0x890000c0);
1535 /* Resource Check and Send the setup packet */
1536 if (!db->tx_packet_cnt) {
1537 /* Resource Empty */
1538 db->tx_packet_cnt++;
1539 txptr->tdes0 = cpu_to_le32(0x80000000);
1540 update_cr6(db->cr6_data | 0x2000, dev->base_addr);
1541 outl(0x1, dev->base_addr + DCR1); /* Issue Tx polling */
1542 update_cr6(db->cr6_data, dev->base_addr);
1543 dev->trans_start = jiffies;
1545 db->tx_queue_cnt++; /* Put in TX queue */
1550 * Allocate rx buffer,
1551 * As possible as allocate maxiumn Rx buffer
1554 static void allocate_rx_buffer(struct dmfe_board_info *db)
1556 struct rx_desc *rxptr;
1557 struct sk_buff *skb;
1559 rxptr = db->rx_insert_ptr;
1561 while(db->rx_avail_cnt < RX_DESC_CNT) {
1562 if ( ( skb = dev_alloc_skb(RX_ALLOC_SIZE) ) == NULL )
1564 rxptr->rx_skb_ptr = skb; /* FIXME (?) */
1565 rxptr->rdes2 = cpu_to_le32( pci_map_single(db->pdev, skb->data,
1566 RX_ALLOC_SIZE, PCI_DMA_FROMDEVICE) );
1568 rxptr->rdes0 = cpu_to_le32(0x80000000);
1569 rxptr = rxptr->next_rx_desc;
1573 db->rx_insert_ptr = rxptr;
1578 * Read one word data from the serial ROM
1581 static u16 read_srom_word(long ioaddr, int offset)
1585 long cr9_ioaddr = ioaddr + DCR9;
1587 outl(CR9_SROM_READ, cr9_ioaddr);
1588 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr);
1590 /* Send the Read Command 110b */
1591 SROM_CLK_WRITE(SROM_DATA_1, cr9_ioaddr);
1592 SROM_CLK_WRITE(SROM_DATA_1, cr9_ioaddr);
1593 SROM_CLK_WRITE(SROM_DATA_0, cr9_ioaddr);
1595 /* Send the offset */
1596 for (i = 5; i >= 0; i--) {
1597 srom_data = (offset & (1 << i)) ? SROM_DATA_1 : SROM_DATA_0;
1598 SROM_CLK_WRITE(srom_data, cr9_ioaddr);
1601 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr);
1603 for (i = 16; i > 0; i--) {
1604 outl(CR9_SROM_READ | CR9_SRCS | CR9_SRCLK, cr9_ioaddr);
1606 srom_data = (srom_data << 1) |
1607 ((inl(cr9_ioaddr) & CR9_CRDOUT) ? 1 : 0);
1608 outl(CR9_SROM_READ | CR9_SRCS, cr9_ioaddr);
1612 outl(CR9_SROM_READ, cr9_ioaddr);
1618 * Auto sense the media mode
1621 static u8 dmfe_sense_speed(struct dmfe_board_info * db)
1626 /* CR6 bit18=0, select 10/100M */
1627 update_cr6( (db->cr6_data & ~0x40000), db->ioaddr);
1629 phy_mode = phy_read(db->ioaddr, db->phy_addr, 1, db->chip_id);
1630 phy_mode = phy_read(db->ioaddr, db->phy_addr, 1, db->chip_id);
1632 if ( (phy_mode & 0x24) == 0x24 ) {
1633 if (db->chip_id == PCI_DM9132_ID) /* DM9132 */
1634 phy_mode = phy_read(db->ioaddr,
1635 db->phy_addr, 7, db->chip_id) & 0xf000;
1636 else /* DM9102/DM9102A */
1637 phy_mode = phy_read(db->ioaddr,
1638 db->phy_addr, 17, db->chip_id) & 0xf000;
1639 /* printk(DRV_NAME ": Phy_mode %x ",phy_mode); */
1641 case 0x1000: db->op_mode = DMFE_10MHF; break;
1642 case 0x2000: db->op_mode = DMFE_10MFD; break;
1643 case 0x4000: db->op_mode = DMFE_100MHF; break;
1644 case 0x8000: db->op_mode = DMFE_100MFD; break;
1645 default: db->op_mode = DMFE_10MHF;
1650 db->op_mode = DMFE_10MHF;
1651 DMFE_DBUG(0, "Link Failed :", phy_mode);
1660 * Set 10/100 phyxcer capability
1661 * AUTO mode : phyxcer register4 is NIC capability
1662 * Force mode: phyxcer register4 is the force media
1665 static void dmfe_set_phyxcer(struct dmfe_board_info *db)
1669 /* Select 10/100M phyxcer */
1670 db->cr6_data &= ~0x40000;
1671 update_cr6(db->cr6_data, db->ioaddr);
1673 /* DM9009 Chip: Phyxcer reg18 bit12=0 */
1674 if (db->chip_id == PCI_DM9009_ID) {
1675 phy_reg = phy_read(db->ioaddr,
1676 db->phy_addr, 18, db->chip_id) & ~0x1000;
1678 phy_write(db->ioaddr,
1679 db->phy_addr, 18, phy_reg, db->chip_id);
1682 /* Phyxcer capability setting */
1683 phy_reg = phy_read(db->ioaddr, db->phy_addr, 4, db->chip_id) & ~0x01e0;
1685 if (db->media_mode & DMFE_AUTO) {
1687 phy_reg |= db->PHY_reg4;
1690 switch(db->media_mode) {
1691 case DMFE_10MHF: phy_reg |= 0x20; break;
1692 case DMFE_10MFD: phy_reg |= 0x40; break;
1693 case DMFE_100MHF: phy_reg |= 0x80; break;
1694 case DMFE_100MFD: phy_reg |= 0x100; break;
1696 if (db->chip_id == PCI_DM9009_ID) phy_reg &= 0x61;
1699 /* Write new capability to Phyxcer Reg4 */
1700 if ( !(phy_reg & 0x01e0)) {
1701 phy_reg|=db->PHY_reg4;
1702 db->media_mode|=DMFE_AUTO;
1704 phy_write(db->ioaddr, db->phy_addr, 4, phy_reg, db->chip_id);
1706 /* Restart Auto-Negotiation */
1707 if ( db->chip_type && (db->chip_id == PCI_DM9102_ID) )
1708 phy_write(db->ioaddr, db->phy_addr, 0, 0x1800, db->chip_id);
1709 if ( !db->chip_type )
1710 phy_write(db->ioaddr, db->phy_addr, 0, 0x1200, db->chip_id);
1716 * AUTO mode : PHY controller in Auto-negotiation Mode
1717 * Force mode: PHY controller in force mode with HUB
1718 * N-way force capability with SWITCH
1721 static void dmfe_process_mode(struct dmfe_board_info *db)
1725 /* Full Duplex Mode Check */
1726 if (db->op_mode & 0x4)
1727 db->cr6_data |= CR6_FDM; /* Set Full Duplex Bit */
1729 db->cr6_data &= ~CR6_FDM; /* Clear Full Duplex Bit */
1731 /* Transciver Selection */
1732 if (db->op_mode & 0x10) /* 1M HomePNA */
1733 db->cr6_data |= 0x40000;/* External MII select */
1735 db->cr6_data &= ~0x40000;/* Internal 10/100 transciver */
1737 update_cr6(db->cr6_data, db->ioaddr);
1739 /* 10/100M phyxcer force mode need */
1740 if ( !(db->media_mode & 0x18)) {
1742 phy_reg = phy_read(db->ioaddr, db->phy_addr, 6, db->chip_id);
1743 if ( !(phy_reg & 0x1) ) {
1744 /* parter without N-Way capability */
1746 switch(db->op_mode) {
1747 case DMFE_10MHF: phy_reg = 0x0; break;
1748 case DMFE_10MFD: phy_reg = 0x100; break;
1749 case DMFE_100MHF: phy_reg = 0x2000; break;
1750 case DMFE_100MFD: phy_reg = 0x2100; break;
1752 phy_write(db->ioaddr,
1753 db->phy_addr, 0, phy_reg, db->chip_id);
1754 if ( db->chip_type && (db->chip_id == PCI_DM9102_ID) )
1756 phy_write(db->ioaddr,
1757 db->phy_addr, 0, phy_reg, db->chip_id);
1764 * Write a word to Phy register
1767 static void phy_write(unsigned long iobase, u8 phy_addr, u8 offset,
1768 u16 phy_data, u32 chip_id)
1771 unsigned long ioaddr;
1773 if (chip_id == PCI_DM9132_ID) {
1774 ioaddr = iobase + 0x80 + offset * 4;
1775 outw(phy_data, ioaddr);
1777 /* DM9102/DM9102A Chip */
1778 ioaddr = iobase + DCR9;
1780 /* Send 33 synchronization clock to Phy controller */
1781 for (i = 0; i < 35; i++)
1782 phy_write_1bit(ioaddr, PHY_DATA_1);
1784 /* Send start command(01) to Phy */
1785 phy_write_1bit(ioaddr, PHY_DATA_0);
1786 phy_write_1bit(ioaddr, PHY_DATA_1);
1788 /* Send write command(01) to Phy */
1789 phy_write_1bit(ioaddr, PHY_DATA_0);
1790 phy_write_1bit(ioaddr, PHY_DATA_1);
1792 /* Send Phy address */
1793 for (i = 0x10; i > 0; i = i >> 1)
1794 phy_write_1bit(ioaddr,
1795 phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
1797 /* Send register address */
1798 for (i = 0x10; i > 0; i = i >> 1)
1799 phy_write_1bit(ioaddr,
1800 offset & i ? PHY_DATA_1 : PHY_DATA_0);
1802 /* written trasnition */
1803 phy_write_1bit(ioaddr, PHY_DATA_1);
1804 phy_write_1bit(ioaddr, PHY_DATA_0);
1806 /* Write a word data to PHY controller */
1807 for ( i = 0x8000; i > 0; i >>= 1)
1808 phy_write_1bit(ioaddr,
1809 phy_data & i ? PHY_DATA_1 : PHY_DATA_0);
1815 * Read a word data from phy register
1818 static u16 phy_read(unsigned long iobase, u8 phy_addr, u8 offset, u32 chip_id)
1822 unsigned long ioaddr;
1824 if (chip_id == PCI_DM9132_ID) {
1826 ioaddr = iobase + 0x80 + offset * 4;
1827 phy_data = inw(ioaddr);
1829 /* DM9102/DM9102A Chip */
1830 ioaddr = iobase + DCR9;
1832 /* Send 33 synchronization clock to Phy controller */
1833 for (i = 0; i < 35; i++)
1834 phy_write_1bit(ioaddr, PHY_DATA_1);
1836 /* Send start command(01) to Phy */
1837 phy_write_1bit(ioaddr, PHY_DATA_0);
1838 phy_write_1bit(ioaddr, PHY_DATA_1);
1840 /* Send read command(10) to Phy */
1841 phy_write_1bit(ioaddr, PHY_DATA_1);
1842 phy_write_1bit(ioaddr, PHY_DATA_0);
1844 /* Send Phy address */
1845 for (i = 0x10; i > 0; i = i >> 1)
1846 phy_write_1bit(ioaddr,
1847 phy_addr & i ? PHY_DATA_1 : PHY_DATA_0);
1849 /* Send register address */
1850 for (i = 0x10; i > 0; i = i >> 1)
1851 phy_write_1bit(ioaddr,
1852 offset & i ? PHY_DATA_1 : PHY_DATA_0);
1854 /* Skip transition state */
1855 phy_read_1bit(ioaddr);
1857 /* read 16bit data */
1858 for (phy_data = 0, i = 0; i < 16; i++) {
1860 phy_data |= phy_read_1bit(ioaddr);
1869 * Write one bit data to Phy Controller
1872 static void phy_write_1bit(unsigned long ioaddr, u32 phy_data)
1874 outl(phy_data, ioaddr); /* MII Clock Low */
1876 outl(phy_data | MDCLKH, ioaddr); /* MII Clock High */
1878 outl(phy_data, ioaddr); /* MII Clock Low */
1884 * Read one bit phy data from PHY controller
1887 static u16 phy_read_1bit(unsigned long ioaddr)
1891 outl(0x50000, ioaddr);
1893 phy_data = ( inl(ioaddr) >> 19 ) & 0x1;
1894 outl(0x40000, ioaddr);
1902 * Parser SROM and media mode
1905 static void dmfe_parse_srom(struct dmfe_board_info * db)
1907 char * srom = db->srom;
1908 int dmfe_mode, tmp_reg;
1910 DMFE_DBUG(0, "dmfe_parse_srom() ", 0);
1913 db->cr15_data = CR15_DEFAULT;
1915 /* Check SROM Version */
1916 if ( ( (int) srom[18] & 0xff) == SROM_V41_CODE) {
1918 /* Get NIC support media mode */
1919 db->NIC_capability = le16_to_cpup((__le16 *) (srom + 34));
1921 for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) {
1922 switch( db->NIC_capability & tmp_reg ) {
1923 case 0x1: db->PHY_reg4 |= 0x0020; break;
1924 case 0x2: db->PHY_reg4 |= 0x0040; break;
1925 case 0x4: db->PHY_reg4 |= 0x0080; break;
1926 case 0x8: db->PHY_reg4 |= 0x0100; break;
1930 /* Media Mode Force or not check */
1931 dmfe_mode = (le32_to_cpup((__le32 *) (srom + 34)) &
1932 le32_to_cpup((__le32 *) (srom + 36)));
1934 case 0x4: dmfe_media_mode = DMFE_100MHF; break; /* 100MHF */
1935 case 0x2: dmfe_media_mode = DMFE_10MFD; break; /* 10MFD */
1936 case 0x8: dmfe_media_mode = DMFE_100MFD; break; /* 100MFD */
1938 case 0x200: dmfe_media_mode = DMFE_1M_HPNA; break;/* HomePNA */
1941 /* Special Function setting */
1943 if ( (SF_mode & 0x1) || (srom[43] & 0x80) )
1944 db->cr15_data |= 0x40;
1947 if ( (SF_mode & 0x2) || (srom[40] & 0x1) )
1948 db->cr15_data |= 0x400;
1950 /* TX pause packet */
1951 if ( (SF_mode & 0x4) || (srom[40] & 0xe) )
1952 db->cr15_data |= 0x9800;
1955 /* Parse HPNA parameter */
1956 db->HPNA_command = 1;
1958 /* Accept remote command or not */
1959 if (HPNA_rx_cmd == 0)
1960 db->HPNA_command |= 0x8000;
1962 /* Issue remote command & operation mode */
1963 if (HPNA_tx_cmd == 1)
1964 switch(HPNA_mode) { /* Issue Remote Command */
1965 case 0: db->HPNA_command |= 0x0904; break;
1966 case 1: db->HPNA_command |= 0x0a00; break;
1967 case 2: db->HPNA_command |= 0x0506; break;
1968 case 3: db->HPNA_command |= 0x0602; break;
1971 switch(HPNA_mode) { /* Don't Issue */
1972 case 0: db->HPNA_command |= 0x0004; break;
1973 case 1: db->HPNA_command |= 0x0000; break;
1974 case 2: db->HPNA_command |= 0x0006; break;
1975 case 3: db->HPNA_command |= 0x0002; break;
1978 /* Check DM9801 or DM9802 present or not */
1979 db->HPNA_present = 0;
1980 update_cr6(db->cr6_data|0x40000, db->ioaddr);
1981 tmp_reg = phy_read(db->ioaddr, db->phy_addr, 3, db->chip_id);
1982 if ( ( tmp_reg & 0xfff0 ) == 0xb900 ) {
1983 /* DM9801 or DM9802 present */
1985 if ( phy_read(db->ioaddr, db->phy_addr, 31, db->chip_id) == 0x4404) {
1986 /* DM9801 HomeRun */
1987 db->HPNA_present = 1;
1988 dmfe_program_DM9801(db, tmp_reg);
1990 /* DM9802 LongRun */
1991 db->HPNA_present = 2;
1992 dmfe_program_DM9802(db);
2000 * Init HomeRun DM9801
2003 static void dmfe_program_DM9801(struct dmfe_board_info * db, int HPNA_rev)
2007 if ( !HPNA_NoiseFloor ) HPNA_NoiseFloor = DM9801_NOISE_FLOOR;
2009 case 0xb900: /* DM9801 E3 */
2010 db->HPNA_command |= 0x1000;
2011 reg25 = phy_read(db->ioaddr, db->phy_addr, 24, db->chip_id);
2012 reg25 = ( (reg25 + HPNA_NoiseFloor) & 0xff) | 0xf000;
2013 reg17 = phy_read(db->ioaddr, db->phy_addr, 17, db->chip_id);
2015 case 0xb901: /* DM9801 E4 */
2016 reg25 = phy_read(db->ioaddr, db->phy_addr, 25, db->chip_id);
2017 reg25 = (reg25 & 0xff00) + HPNA_NoiseFloor;
2018 reg17 = phy_read(db->ioaddr, db->phy_addr, 17, db->chip_id);
2019 reg17 = (reg17 & 0xfff0) + HPNA_NoiseFloor + 3;
2021 case 0xb902: /* DM9801 E5 */
2022 case 0xb903: /* DM9801 E6 */
2024 db->HPNA_command |= 0x1000;
2025 reg25 = phy_read(db->ioaddr, db->phy_addr, 25, db->chip_id);
2026 reg25 = (reg25 & 0xff00) + HPNA_NoiseFloor - 5;
2027 reg17 = phy_read(db->ioaddr, db->phy_addr, 17, db->chip_id);
2028 reg17 = (reg17 & 0xfff0) + HPNA_NoiseFloor;
2031 phy_write(db->ioaddr, db->phy_addr, 16, db->HPNA_command, db->chip_id);
2032 phy_write(db->ioaddr, db->phy_addr, 17, reg17, db->chip_id);
2033 phy_write(db->ioaddr, db->phy_addr, 25, reg25, db->chip_id);
2038 * Init HomeRun DM9802
2041 static void dmfe_program_DM9802(struct dmfe_board_info * db)
2045 if ( !HPNA_NoiseFloor ) HPNA_NoiseFloor = DM9802_NOISE_FLOOR;
2046 phy_write(db->ioaddr, db->phy_addr, 16, db->HPNA_command, db->chip_id);
2047 phy_reg = phy_read(db->ioaddr, db->phy_addr, 25, db->chip_id);
2048 phy_reg = ( phy_reg & 0xff00) + HPNA_NoiseFloor;
2049 phy_write(db->ioaddr, db->phy_addr, 25, phy_reg, db->chip_id);
2054 * Check remote HPNA power and speed status. If not correct,
2055 * issue command again.
2058 static void dmfe_HPNA_remote_cmd_chk(struct dmfe_board_info * db)
2062 /* Got remote device status */
2063 phy_reg = phy_read(db->ioaddr, db->phy_addr, 17, db->chip_id) & 0x60;
2065 case 0x00: phy_reg = 0x0a00;break; /* LP/LS */
2066 case 0x20: phy_reg = 0x0900;break; /* LP/HS */
2067 case 0x40: phy_reg = 0x0600;break; /* HP/LS */
2068 case 0x60: phy_reg = 0x0500;break; /* HP/HS */
2071 /* Check remote device status match our setting ot not */
2072 if ( phy_reg != (db->HPNA_command & 0x0f00) ) {
2073 phy_write(db->ioaddr, db->phy_addr, 16, db->HPNA_command,
2077 db->HPNA_timer=600; /* Match, every 10 minutes, check */
2082 static struct pci_device_id dmfe_pci_tbl[] = {
2083 { 0x1282, 0x9132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_DM9132_ID },
2084 { 0x1282, 0x9102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_DM9102_ID },
2085 { 0x1282, 0x9100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_DM9100_ID },
2086 { 0x1282, 0x9009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_DM9009_ID },
2089 MODULE_DEVICE_TABLE(pci, dmfe_pci_tbl);
2093 static int dmfe_suspend(struct pci_dev *pci_dev, pm_message_t state)
2095 struct net_device *dev = pci_get_drvdata(pci_dev);
2096 struct dmfe_board_info *db = netdev_priv(dev);
2099 /* Disable upper layer interface */
2100 netif_device_detach(dev);
2103 db->cr6_data &= ~(CR6_RXSC | CR6_TXSC);
2104 update_cr6(db->cr6_data, dev->base_addr);
2106 /* Disable Interrupt */
2107 outl(0, dev->base_addr + DCR7);
2108 outl(inl (dev->base_addr + DCR5), dev->base_addr + DCR5);
2110 /* Fre RX buffers */
2111 dmfe_free_rxbuffer(db);
2114 pci_read_config_dword(pci_dev, 0x40, &tmp);
2115 tmp &= ~(DMFE_WOL_LINKCHANGE|DMFE_WOL_MAGICPACKET);
2117 if (db->wol_mode & WAKE_PHY)
2118 tmp |= DMFE_WOL_LINKCHANGE;
2119 if (db->wol_mode & WAKE_MAGIC)
2120 tmp |= DMFE_WOL_MAGICPACKET;
2122 pci_write_config_dword(pci_dev, 0x40, tmp);
2124 pci_enable_wake(pci_dev, PCI_D3hot, 1);
2125 pci_enable_wake(pci_dev, PCI_D3cold, 1);
2127 /* Power down device*/
2128 pci_save_state(pci_dev);
2129 pci_set_power_state(pci_dev, pci_choose_state (pci_dev, state));
2134 static int dmfe_resume(struct pci_dev *pci_dev)
2136 struct net_device *dev = pci_get_drvdata(pci_dev);
2139 pci_set_power_state(pci_dev, PCI_D0);
2140 pci_restore_state(pci_dev);
2142 /* Re-initilize DM910X board */
2143 dmfe_init_dm910x(dev);
2146 pci_read_config_dword(pci_dev, 0x40, &tmp);
2148 tmp &= ~(DMFE_WOL_LINKCHANGE | DMFE_WOL_MAGICPACKET);
2149 pci_write_config_dword(pci_dev, 0x40, tmp);
2151 pci_enable_wake(pci_dev, PCI_D3hot, 0);
2152 pci_enable_wake(pci_dev, PCI_D3cold, 0);
2154 /* Restart upper layer interface */
2155 netif_device_attach(dev);
2160 #define dmfe_suspend NULL
2161 #define dmfe_resume NULL
2164 static struct pci_driver dmfe_driver = {
2166 .id_table = dmfe_pci_tbl,
2167 .probe = dmfe_init_one,
2168 .remove = __devexit_p(dmfe_remove_one),
2169 .suspend = dmfe_suspend,
2170 .resume = dmfe_resume
2173 MODULE_AUTHOR("Sten Wang, sten_wang@davicom.com.tw");
2174 MODULE_DESCRIPTION("Davicom DM910X fast ethernet driver");
2175 MODULE_LICENSE("GPL");
2176 MODULE_VERSION(DRV_VERSION);
2178 module_param(debug, int, 0);
2179 module_param(mode, byte, 0);
2180 module_param(cr6set, int, 0);
2181 module_param(chkmode, byte, 0);
2182 module_param(HPNA_mode, byte, 0);
2183 module_param(HPNA_rx_cmd, byte, 0);
2184 module_param(HPNA_tx_cmd, byte, 0);
2185 module_param(HPNA_NoiseFloor, byte, 0);
2186 module_param(SF_mode, byte, 0);
2187 MODULE_PARM_DESC(debug, "Davicom DM9xxx enable debugging (0-1)");
2188 MODULE_PARM_DESC(mode, "Davicom DM9xxx: "
2189 "Bit 0: 10/100Mbps, bit 2: duplex, bit 8: HomePNA");
2191 MODULE_PARM_DESC(SF_mode, "Davicom DM9xxx special function "
2192 "(bit 0: VLAN, bit 1 Flow Control, bit 2: TX pause packet)");
2195 * when user used insmod to add module, system invoked init_module()
2196 * to initilize and register.
2199 static int __init dmfe_init_module(void)
2204 printed_version = 1;
2206 DMFE_DBUG(0, "init_module() ", debug);
2209 dmfe_debug = debug; /* set debug flag */
2211 dmfe_cr6_user_set = cr6set;
2219 dmfe_media_mode = mode;
2221 default:dmfe_media_mode = DMFE_AUTO;
2226 HPNA_mode = 0; /* Default: LP/HS */
2227 if (HPNA_rx_cmd > 1)
2228 HPNA_rx_cmd = 0; /* Default: Ignored remote cmd */
2229 if (HPNA_tx_cmd > 1)
2230 HPNA_tx_cmd = 0; /* Default: Don't issue remote cmd */
2231 if (HPNA_NoiseFloor > 15)
2232 HPNA_NoiseFloor = 0;
2234 rc = pci_register_driver(&dmfe_driver);
2244 * when user used rmmod to delete module, system invoked clean_module()
2245 * to un-register all registered services.
2248 static void __exit dmfe_cleanup_module(void)
2250 DMFE_DBUG(0, "dmfe_clean_module() ", debug);
2251 pci_unregister_driver(&dmfe_driver);
2254 module_init(dmfe_init_module);
2255 module_exit(dmfe_cleanup_module);