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@redhat.com> :
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@redhat.com>
53 Added new PCI identifiers provided by Clear Zhang at ALi
54 for their 1563 ethernet device.
58 Implement pci_driver::suspend() and pci_driver::resume()
59 power management methods.
61 Check on 64 bit boxes.
62 Check and fix on big endian boxes.
64 Test and make sure PCI latency is now correct for all cases.
67 #define DRV_NAME "dmfe"
68 #define DRV_VERSION "1.36.4"
69 #define DRV_RELDATE "2002-01-17"
71 #include <linux/module.h>
72 #include <linux/kernel.h>
73 #include <linux/string.h>
74 #include <linux/timer.h>
75 #include <linux/ptrace.h>
76 #include <linux/errno.h>
77 #include <linux/ioport.h>
78 #include <linux/slab.h>
79 #include <linux/interrupt.h>
80 #include <linux/pci.h>
81 #include <linux/init.h>
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/ethtool.h>
85 #include <linux/skbuff.h>
86 #include <linux/delay.h>
87 #include <linux/spinlock.h>
88 #include <linux/crc32.h>
89 #include <linux/bitops.h>
91 #include <asm/processor.h>
94 #include <asm/uaccess.h>
98 /* Board/System/Debug information/definition ---------------- */
99 #define PCI_DM9132_ID 0x91321282 /* Davicom DM9132 ID */
100 #define PCI_DM9102_ID 0x91021282 /* Davicom DM9102 ID */
101 #define PCI_DM9100_ID 0x91001282 /* Davicom DM9100 ID */
102 #define PCI_DM9009_ID 0x90091282 /* Davicom DM9009 ID */
104 #define DM9102_IO_SIZE 0x80
105 #define DM9102A_IO_SIZE 0x100
106 #define TX_MAX_SEND_CNT 0x1 /* Maximum tx packet per time */
107 #define TX_DESC_CNT 0x10 /* Allocated Tx descriptors */
108 #define RX_DESC_CNT 0x20 /* Allocated Rx descriptors */
109 #define TX_FREE_DESC_CNT (TX_DESC_CNT - 2) /* Max TX packet count */
110 #define TX_WAKE_DESC_CNT (TX_DESC_CNT - 3) /* TX wakeup count */
111 #define DESC_ALL_CNT (TX_DESC_CNT + RX_DESC_CNT)
112 #define TX_BUF_ALLOC 0x600
113 #define RX_ALLOC_SIZE 0x620
114 #define DM910X_RESET 1
115 #define CR0_DEFAULT 0x00E00000 /* TX & RX burst mode */
116 #define CR6_DEFAULT 0x00080000 /* HD */
117 #define CR7_DEFAULT 0x180c1
118 #define CR15_DEFAULT 0x06 /* TxJabber RxWatchdog */
119 #define TDES0_ERR_MASK 0x4302 /* TXJT, LC, EC, FUE */
120 #define MAX_PACKET_SIZE 1514
121 #define DMFE_MAX_MULTICAST 14
122 #define RX_COPY_SIZE 100
123 #define MAX_CHECK_PACKET 0x8000
124 #define DM9801_NOISE_FLOOR 8
125 #define DM9802_NOISE_FLOOR 5
128 #define DMFE_100MHF 1
130 #define DMFE_100MFD 5
132 #define DMFE_1M_HPNA 0x10
134 #define DMFE_TXTH_72 0x400000 /* TX TH 72 byte */
135 #define DMFE_TXTH_96 0x404000 /* TX TH 96 byte */
136 #define DMFE_TXTH_128 0x0000 /* TX TH 128 byte */
137 #define DMFE_TXTH_256 0x4000 /* TX TH 256 byte */
138 #define DMFE_TXTH_512 0x8000 /* TX TH 512 byte */
139 #define DMFE_TXTH_1K 0xC000 /* TX TH 1K byte */
141 #define DMFE_TIMER_WUT (jiffies + HZ * 1)/* timer wakeup time : 1 second */
142 #define DMFE_TX_TIMEOUT ((3*HZ)/2) /* tx packet time-out time 1.5 s" */
143 #define DMFE_TX_KICK (HZ/2) /* tx packet Kick-out time 0.5 s" */
145 #define DMFE_DBUG(dbug_now, msg, value) if (dmfe_debug || (dbug_now)) printk(KERN_ERR DRV_NAME ": %s %lx\n", (msg), (long) (value))
147 #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");
150 /* CR9 definition: SROM/MII */
151 #define CR9_SROM_READ 0x4800
153 #define CR9_SRCLK 0x2
154 #define CR9_CRDOUT 0x8
155 #define SROM_DATA_0 0x0
156 #define SROM_DATA_1 0x4
157 #define PHY_DATA_1 0x20000
158 #define PHY_DATA_0 0x00000
159 #define MDCLKH 0x10000
161 #define PHY_POWER_DOWN 0x800
163 #define SROM_V41_CODE 0x14
165 #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);
167 #define __CHK_IO_SIZE(pci_id, dev_rev) ( ((pci_id)==PCI_DM9132_ID) || ((dev_rev) >= 0x02000030) ) ? DM9102A_IO_SIZE: DM9102_IO_SIZE
168 #define CHK_IO_SIZE(pci_dev, dev_rev) __CHK_IO_SIZE(((pci_dev)->device << 16) | (pci_dev)->vendor, dev_rev)
171 #define DEVICE net_device
173 /* Structure/enum declaration ------------------------------- */
175 u32 tdes0
, tdes1
, tdes2
, tdes3
; /* Data for the card */
176 char *tx_buf_ptr
; /* Data for us */
177 struct tx_desc
*next_tx_desc
;
178 } __attribute__(( aligned(32) ));
181 u32 rdes0
, rdes1
, rdes2
, rdes3
; /* Data for the card */
182 struct sk_buff
*rx_skb_ptr
; /* Data for us */
183 struct rx_desc
*next_rx_desc
;
184 } __attribute__(( aligned(32) ));
186 struct dmfe_board_info
{
187 u32 chip_id
; /* Chip vendor/Device ID */
188 u32 chip_revision
; /* Chip revision */
189 struct DEVICE
*next_dev
; /* next device */
190 struct pci_dev
*pdev
; /* PCI device */
193 long ioaddr
; /* I/O base address */
200 /* pointer for memory physical address */
201 dma_addr_t buf_pool_dma_ptr
; /* Tx buffer pool memory */
202 dma_addr_t buf_pool_dma_start
; /* Tx buffer pool align dword */
203 dma_addr_t desc_pool_dma_ptr
; /* descriptor pool memory */
204 dma_addr_t first_tx_desc_dma
;
205 dma_addr_t first_rx_desc_dma
;
207 /* descriptor pointer */
208 unsigned char *buf_pool_ptr
; /* Tx buffer pool memory */
209 unsigned char *buf_pool_start
; /* Tx buffer pool align dword */
210 unsigned char *desc_pool_ptr
; /* descriptor pool memory */
211 struct tx_desc
*first_tx_desc
;
212 struct tx_desc
*tx_insert_ptr
;
213 struct tx_desc
*tx_remove_ptr
;
214 struct rx_desc
*first_rx_desc
;
215 struct rx_desc
*rx_insert_ptr
;
216 struct rx_desc
*rx_ready_ptr
; /* packet come pointer */
217 unsigned long tx_packet_cnt
; /* transmitted packet count */
218 unsigned long tx_queue_cnt
; /* wait to send packet count */
219 unsigned long rx_avail_cnt
; /* available rx descriptor count */
220 unsigned long interval_rx_cnt
; /* rx packet count a callback time */
222 u16 HPNA_command
; /* For HPNA register 16 */
223 u16 HPNA_timer
; /* For HPNA remote device check */
225 u16 NIC_capability
; /* NIC media capability */
226 u16 PHY_reg4
; /* Saved Phyxcer register 4 value */
228 u8 HPNA_present
; /* 0:none, 1:DM9801, 2:DM9802 */
229 u8 chip_type
; /* Keep DM9102A chip type */
230 u8 media_mode
; /* user specify media mode */
231 u8 op_mode
; /* real work media mode */
233 u8 link_failed
; /* Ever link failed */
234 u8 wait_reset
; /* Hardware failed, need to reset */
235 u8 dm910x_chk_mode
; /* Operating mode check */
236 u8 first_in_callback
; /* Flag to record state */
237 struct timer_list timer
;
239 /* System defined statistic counter */
240 struct net_device_stats stats
;
242 /* Driver defined statistic counter */
243 unsigned long tx_fifo_underrun
;
244 unsigned long tx_loss_carrier
;
245 unsigned long tx_no_carrier
;
246 unsigned long tx_late_collision
;
247 unsigned long tx_excessive_collision
;
248 unsigned long tx_jabber_timeout
;
249 unsigned long reset_count
;
250 unsigned long reset_cr8
;
251 unsigned long reset_fatal
;
252 unsigned long reset_TXtimeout
;
255 unsigned char srom
[128];
259 DCR0
= 0x00, DCR1
= 0x08, DCR2
= 0x10, DCR3
= 0x18, DCR4
= 0x20,
260 DCR5
= 0x28, DCR6
= 0x30, DCR7
= 0x38, DCR8
= 0x40, DCR9
= 0x48,
261 DCR10
= 0x50, DCR11
= 0x58, DCR12
= 0x60, DCR13
= 0x68, DCR14
= 0x70,
266 CR6_RXSC
= 0x2, CR6_PBF
= 0x8, CR6_PM
= 0x40, CR6_PAM
= 0x80,
267 CR6_FDM
= 0x200, CR6_TXSC
= 0x2000, CR6_STI
= 0x100000,
268 CR6_SFT
= 0x200000, CR6_RXA
= 0x40000000, CR6_NO_PURGE
= 0x20000000
271 /* Global variable declaration ----------------------------- */
272 static int __devinitdata printed_version
;
273 static char version
[] __devinitdata
=
274 KERN_INFO DRV_NAME
": Davicom DM9xxx net driver, version "
275 DRV_VERSION
" (" DRV_RELDATE
")\n";
277 static int dmfe_debug
;
278 static unsigned char dmfe_media_mode
= DMFE_AUTO
;
279 static u32 dmfe_cr6_user_set
;
281 /* For module input parameter */
284 static unsigned char mode
= 8;
285 static u8 chkmode
= 1;
286 static u8 HPNA_mode
; /* Default: Low Power/High Speed */
287 static u8 HPNA_rx_cmd
; /* Default: Disable Rx remote command */
288 static u8 HPNA_tx_cmd
; /* Default: Don't issue remote command */
289 static u8 HPNA_NoiseFloor
; /* Default: HPNA NoiseFloor */
290 static u8 SF_mode
; /* Special Function: 1:VLAN, 2:RX Flow Control
291 4: TX pause packet */
294 /* function declaration ------------------------------------- */
295 static int dmfe_open(struct DEVICE
*);
296 static int dmfe_start_xmit(struct sk_buff
*, struct DEVICE
*);
297 static int dmfe_stop(struct DEVICE
*);
298 static struct net_device_stats
* dmfe_get_stats(struct DEVICE
*);
299 static void dmfe_set_filter_mode(struct DEVICE
*);
300 static struct ethtool_ops netdev_ethtool_ops
;
301 static u16
read_srom_word(long ,int);
302 static irqreturn_t
dmfe_interrupt(int , void *, struct pt_regs
*);
303 #ifdef CONFIG_NET_POLL_CONTROLLER
304 static void poll_dmfe (struct net_device
*dev
);
306 static void dmfe_descriptor_init(struct dmfe_board_info
*, unsigned long);
307 static void allocate_rx_buffer(struct dmfe_board_info
*);
308 static void update_cr6(u32
, unsigned long);
309 static void send_filter_frame(struct DEVICE
* ,int);
310 static void dm9132_id_table(struct DEVICE
* ,int);
311 static u16
phy_read(unsigned long, u8
, u8
, u32
);
312 static void phy_write(unsigned long, u8
, u8
, u16
, u32
);
313 static void phy_write_1bit(unsigned long, u32
);
314 static u16
phy_read_1bit(unsigned long);
315 static u8
dmfe_sense_speed(struct dmfe_board_info
*);
316 static void dmfe_process_mode(struct dmfe_board_info
*);
317 static void dmfe_timer(unsigned long);
318 static inline u32
cal_CRC(unsigned char *, unsigned int, u8
);
319 static void dmfe_rx_packet(struct DEVICE
*, struct dmfe_board_info
*);
320 static void dmfe_free_tx_pkt(struct DEVICE
*, struct dmfe_board_info
*);
321 static void dmfe_reuse_skb(struct dmfe_board_info
*, struct sk_buff
*);
322 static void dmfe_dynamic_reset(struct DEVICE
*);
323 static void dmfe_free_rxbuffer(struct dmfe_board_info
*);
324 static void dmfe_init_dm910x(struct DEVICE
*);
325 static void dmfe_parse_srom(struct dmfe_board_info
*);
326 static void dmfe_program_DM9801(struct dmfe_board_info
*, int);
327 static void dmfe_program_DM9802(struct dmfe_board_info
*);
328 static void dmfe_HPNA_remote_cmd_chk(struct dmfe_board_info
* );
329 static void dmfe_set_phyxcer(struct dmfe_board_info
*);
331 /* DM910X network baord routine ---------------------------- */
334 * Search DM910X board ,allocate space and register it
337 static int __devinit
dmfe_init_one (struct pci_dev
*pdev
,
338 const struct pci_device_id
*ent
)
340 struct dmfe_board_info
*db
; /* board information structure */
341 struct net_device
*dev
;
342 u32 dev_rev
, pci_pmr
;
345 DMFE_DBUG(0, "dmfe_init_one()", 0);
347 if (!printed_version
++)
350 /* Init network device */
351 dev
= alloc_etherdev(sizeof(*db
));
354 SET_MODULE_OWNER(dev
);
355 SET_NETDEV_DEV(dev
, &pdev
->dev
);
357 if (pci_set_dma_mask(pdev
, 0xffffffff)) {
358 printk(KERN_WARNING DRV_NAME
": 32-bit PCI DMA not available.\n");
363 /* Enable Master/IO access, Disable memory access */
364 err
= pci_enable_device(pdev
);
368 if (!pci_resource_start(pdev
, 0)) {
369 printk(KERN_ERR DRV_NAME
": I/O base is zero\n");
371 goto err_out_disable
;
374 /* Read Chip revision */
375 pci_read_config_dword(pdev
, PCI_REVISION_ID
, &dev_rev
);
377 if (pci_resource_len(pdev
, 0) < (CHK_IO_SIZE(pdev
, dev_rev
)) ) {
378 printk(KERN_ERR DRV_NAME
": Allocated I/O size too small\n");
380 goto err_out_disable
;
383 #if 0 /* pci_{enable_device,set_master} sets minimum latency for us now */
385 /* Set Latency Timer 80h */
386 /* FIXME: setting values > 32 breaks some SiS 559x stuff.
387 Need a PCI quirk.. */
389 pci_write_config_byte(pdev
, PCI_LATENCY_TIMER
, 0x80);
392 if (pci_request_regions(pdev
, DRV_NAME
)) {
393 printk(KERN_ERR DRV_NAME
": Failed to request PCI regions\n");
395 goto err_out_disable
;
398 /* Init system & device */
399 db
= netdev_priv(dev
);
401 /* Allocate Tx/Rx descriptor memory */
402 db
->desc_pool_ptr
= pci_alloc_consistent(pdev
, sizeof(struct tx_desc
) * DESC_ALL_CNT
+ 0x20, &db
->desc_pool_dma_ptr
);
403 db
->buf_pool_ptr
= pci_alloc_consistent(pdev
, TX_BUF_ALLOC
* TX_DESC_CNT
+ 4, &db
->buf_pool_dma_ptr
);
405 db
->first_tx_desc
= (struct tx_desc
*) db
->desc_pool_ptr
;
406 db
->first_tx_desc_dma
= db
->desc_pool_dma_ptr
;
407 db
->buf_pool_start
= db
->buf_pool_ptr
;
408 db
->buf_pool_dma_start
= db
->buf_pool_dma_ptr
;
410 db
->chip_id
= ent
->driver_data
;
411 db
->ioaddr
= pci_resource_start(pdev
, 0);
412 db
->chip_revision
= dev_rev
;
416 dev
->base_addr
= db
->ioaddr
;
417 dev
->irq
= pdev
->irq
;
418 pci_set_drvdata(pdev
, dev
);
419 dev
->open
= &dmfe_open
;
420 dev
->hard_start_xmit
= &dmfe_start_xmit
;
421 dev
->stop
= &dmfe_stop
;
422 dev
->get_stats
= &dmfe_get_stats
;
423 dev
->set_multicast_list
= &dmfe_set_filter_mode
;
424 #ifdef CONFIG_NET_POLL_CONTROLLER
425 dev
->poll_controller
= &poll_dmfe
;
427 dev
->ethtool_ops
= &netdev_ethtool_ops
;
428 spin_lock_init(&db
->lock
);
430 pci_read_config_dword(pdev
, 0x50, &pci_pmr
);
432 if ( (pci_pmr
== 0x10000) && (dev_rev
== 0x02000031) )
433 db
->chip_type
= 1; /* DM9102A E3 */
437 /* read 64 word srom data */
438 for (i
= 0; i
< 64; i
++)
439 ((u16
*) db
->srom
)[i
] = cpu_to_le16(read_srom_word(db
->ioaddr
, i
));
441 /* Set Node address */
442 for (i
= 0; i
< 6; i
++)
443 dev
->dev_addr
[i
] = db
->srom
[20 + i
];
445 err
= register_netdev (dev
);
449 printk(KERN_INFO
"%s: Davicom DM%04lx at pci%s,",
451 ent
->driver_data
>> 16,
453 for (i
= 0; i
< 6; i
++)
454 printk("%c%02x", i
? ':' : ' ', dev
->dev_addr
[i
]);
455 printk(", irq %d.\n", dev
->irq
);
457 pci_set_master(pdev
);
462 pci_release_regions(pdev
);
464 pci_disable_device(pdev
);
466 pci_set_drvdata(pdev
, NULL
);
473 static void __devexit
dmfe_remove_one (struct pci_dev
*pdev
)
475 struct net_device
*dev
= pci_get_drvdata(pdev
);
476 struct dmfe_board_info
*db
= netdev_priv(dev
);
478 DMFE_DBUG(0, "dmfe_remove_one()", 0);
481 pci_free_consistent(db
->pdev
, sizeof(struct tx_desc
) *
482 DESC_ALL_CNT
+ 0x20, db
->desc_pool_ptr
,
483 db
->desc_pool_dma_ptr
);
484 pci_free_consistent(db
->pdev
, TX_BUF_ALLOC
* TX_DESC_CNT
+ 4,
485 db
->buf_pool_ptr
, db
->buf_pool_dma_ptr
);
486 unregister_netdev(dev
);
487 pci_release_regions(pdev
);
488 free_netdev(dev
); /* free board information */
489 pci_set_drvdata(pdev
, NULL
);
492 DMFE_DBUG(0, "dmfe_remove_one() exit", 0);
497 * Open the interface.
498 * The interface is opened whenever "ifconfig" actives it.
501 static int dmfe_open(struct DEVICE
*dev
)
504 struct dmfe_board_info
*db
= netdev_priv(dev
);
506 DMFE_DBUG(0, "dmfe_open", 0);
508 ret
= request_irq(dev
->irq
, &dmfe_interrupt
, SA_SHIRQ
, dev
->name
, dev
);
512 /* system variable init */
513 db
->cr6_data
= CR6_DEFAULT
| dmfe_cr6_user_set
;
514 db
->tx_packet_cnt
= 0;
515 db
->tx_queue_cnt
= 0;
516 db
->rx_avail_cnt
= 0;
520 db
->first_in_callback
= 0;
521 db
->NIC_capability
= 0xf; /* All capability*/
522 db
->PHY_reg4
= 0x1e0;
524 /* CR6 operation mode decision */
525 if ( !chkmode
|| (db
->chip_id
== PCI_DM9132_ID
) ||
526 (db
->chip_revision
>= 0x02000030) ) {
527 db
->cr6_data
|= DMFE_TXTH_256
;
528 db
->cr0_data
= CR0_DEFAULT
;
529 db
->dm910x_chk_mode
=4; /* Enter the normal mode */
531 db
->cr6_data
|= CR6_SFT
; /* Store & Forward mode */
533 db
->dm910x_chk_mode
= 1; /* Enter the check mode */
536 /* Initilize DM910X board */
537 dmfe_init_dm910x(dev
);
539 /* Active System Interface */
540 netif_wake_queue(dev
);
542 /* set and active a timer process */
543 init_timer(&db
->timer
);
544 db
->timer
.expires
= DMFE_TIMER_WUT
+ HZ
* 2;
545 db
->timer
.data
= (unsigned long)dev
;
546 db
->timer
.function
= &dmfe_timer
;
547 add_timer(&db
->timer
);
553 /* Initilize DM910X board
555 * Initilize TX/Rx descriptor chain structure
556 * Send the set-up frame
557 * Enable Tx/Rx machine
560 static void dmfe_init_dm910x(struct DEVICE
*dev
)
562 struct dmfe_board_info
*db
= netdev_priv(dev
);
563 unsigned long ioaddr
= db
->ioaddr
;
565 DMFE_DBUG(0, "dmfe_init_dm910x()", 0);
567 /* Reset DM910x MAC controller */
568 outl(DM910X_RESET
, ioaddr
+ DCR0
); /* RESET MAC */
570 outl(db
->cr0_data
, ioaddr
+ DCR0
);
573 /* Phy addr : DM910(A)2/DM9132/9801, phy address = 1 */
576 /* Parser SROM and media mode */
578 db
->media_mode
= dmfe_media_mode
;
580 /* RESET Phyxcer Chip by GPR port bit 7 */
581 outl(0x180, ioaddr
+ DCR12
); /* Let bit 7 output port */
582 if (db
->chip_id
== PCI_DM9009_ID
) {
583 outl(0x80, ioaddr
+ DCR12
); /* Issue RESET signal */
584 mdelay(300); /* Delay 300 ms */
586 outl(0x0, ioaddr
+ DCR12
); /* Clear RESET signal */
588 /* Process Phyxcer Media Mode */
589 if ( !(db
->media_mode
& 0x10) ) /* Force 1M mode */
590 dmfe_set_phyxcer(db
);
592 /* Media Mode Process */
593 if ( !(db
->media_mode
& DMFE_AUTO
) )
594 db
->op_mode
= db
->media_mode
; /* Force Mode */
596 /* Initiliaze Transmit/Receive decriptor and CR3/4 */
597 dmfe_descriptor_init(db
, ioaddr
);
599 /* Init CR6 to program DM910x operation */
600 update_cr6(db
->cr6_data
, ioaddr
);
602 /* Send setup frame */
603 if (db
->chip_id
== PCI_DM9132_ID
)
604 dm9132_id_table(dev
, dev
->mc_count
); /* DM9132 */
606 send_filter_frame(dev
, dev
->mc_count
); /* DM9102/DM9102A */
608 /* Init CR7, interrupt active bit */
609 db
->cr7_data
= CR7_DEFAULT
;
610 outl(db
->cr7_data
, ioaddr
+ DCR7
);
612 /* Init CR15, Tx jabber and Rx watchdog timer */
613 outl(db
->cr15_data
, ioaddr
+ DCR15
);
615 /* Enable DM910X Tx/Rx function */
616 db
->cr6_data
|= CR6_RXSC
| CR6_TXSC
| 0x40000;
617 update_cr6(db
->cr6_data
, ioaddr
);
622 * Hardware start transmission.
623 * Send a packet to media from the upper layer.
626 static int dmfe_start_xmit(struct sk_buff
*skb
, struct DEVICE
*dev
)
628 struct dmfe_board_info
*db
= netdev_priv(dev
);
629 struct tx_desc
*txptr
;
632 DMFE_DBUG(0, "dmfe_start_xmit", 0);
634 /* Resource flag check */
635 netif_stop_queue(dev
);
637 /* Too large packet check */
638 if (skb
->len
> MAX_PACKET_SIZE
) {
639 printk(KERN_ERR DRV_NAME
": big packet = %d\n", (u16
)skb
->len
);
644 spin_lock_irqsave(&db
->lock
, flags
);
646 /* No Tx resource check, it never happen nromally */
647 if (db
->tx_queue_cnt
>= TX_FREE_DESC_CNT
) {
648 spin_unlock_irqrestore(&db
->lock
, flags
);
649 printk(KERN_ERR DRV_NAME
": No Tx resource %ld\n", db
->tx_queue_cnt
);
653 /* Disable NIC interrupt */
654 outl(0, dev
->base_addr
+ DCR7
);
656 /* transmit this packet */
657 txptr
= db
->tx_insert_ptr
;
658 memcpy(txptr
->tx_buf_ptr
, skb
->data
, skb
->len
);
659 txptr
->tdes1
= cpu_to_le32(0xe1000000 | skb
->len
);
661 /* Point to next transmit free descriptor */
662 db
->tx_insert_ptr
= txptr
->next_tx_desc
;
664 /* Transmit Packet Process */
665 if ( (!db
->tx_queue_cnt
) && (db
->tx_packet_cnt
< TX_MAX_SEND_CNT
) ) {
666 txptr
->tdes0
= cpu_to_le32(0x80000000); /* Set owner bit */
667 db
->tx_packet_cnt
++; /* Ready to send */
668 outl(0x1, dev
->base_addr
+ DCR1
); /* Issue Tx polling */
669 dev
->trans_start
= jiffies
; /* saved time stamp */
671 db
->tx_queue_cnt
++; /* queue TX packet */
672 outl(0x1, dev
->base_addr
+ DCR1
); /* Issue Tx polling */
675 /* Tx resource check */
676 if ( db
->tx_queue_cnt
< TX_FREE_DESC_CNT
)
677 netif_wake_queue(dev
);
679 /* Restore CR7 to enable interrupt */
680 spin_unlock_irqrestore(&db
->lock
, flags
);
681 outl(db
->cr7_data
, dev
->base_addr
+ DCR7
);
691 * Stop the interface.
692 * The interface is stopped when it is brought.
695 static int dmfe_stop(struct DEVICE
*dev
)
697 struct dmfe_board_info
*db
= netdev_priv(dev
);
698 unsigned long ioaddr
= dev
->base_addr
;
700 DMFE_DBUG(0, "dmfe_stop", 0);
703 netif_stop_queue(dev
);
706 del_timer_sync(&db
->timer
);
708 /* Reset & stop DM910X board */
709 outl(DM910X_RESET
, ioaddr
+ DCR0
);
711 phy_write(db
->ioaddr
, db
->phy_addr
, 0, 0x8000, db
->chip_id
);
714 free_irq(dev
->irq
, dev
);
716 /* free allocated rx buffer */
717 dmfe_free_rxbuffer(db
);
720 /* show statistic counter */
721 printk(DRV_NAME
": FU:%lx EC:%lx LC:%lx NC:%lx LOC:%lx TXJT:%lx RESET:%lx RCR8:%lx FAL:%lx TT:%lx\n",
722 db
->tx_fifo_underrun
, db
->tx_excessive_collision
,
723 db
->tx_late_collision
, db
->tx_no_carrier
, db
->tx_loss_carrier
,
724 db
->tx_jabber_timeout
, db
->reset_count
, db
->reset_cr8
,
725 db
->reset_fatal
, db
->reset_TXtimeout
);
733 * DM9102 insterrupt handler
734 * receive the packet to upper layer, free the transmitted packet
737 static irqreturn_t
dmfe_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
739 struct DEVICE
*dev
= dev_id
;
740 struct dmfe_board_info
*db
= netdev_priv(dev
);
741 unsigned long ioaddr
= dev
->base_addr
;
744 DMFE_DBUG(0, "dmfe_interrupt()", 0);
747 DMFE_DBUG(1, "dmfe_interrupt() without DEVICE arg", 0);
751 spin_lock_irqsave(&db
->lock
, flags
);
753 /* Got DM910X status */
754 db
->cr5_data
= inl(ioaddr
+ DCR5
);
755 outl(db
->cr5_data
, ioaddr
+ DCR5
);
756 if ( !(db
->cr5_data
& 0xc1) ) {
757 spin_unlock_irqrestore(&db
->lock
, flags
);
761 /* Disable all interrupt in CR7 to solve the interrupt edge problem */
762 outl(0, ioaddr
+ DCR7
);
764 /* Check system status */
765 if (db
->cr5_data
& 0x2000) {
766 /* system bus error happen */
767 DMFE_DBUG(1, "System bus error happen. CR5=", db
->cr5_data
);
769 db
->wait_reset
= 1; /* Need to RESET */
770 spin_unlock_irqrestore(&db
->lock
, flags
);
774 /* Received the coming packet */
775 if ( (db
->cr5_data
& 0x40) && db
->rx_avail_cnt
)
776 dmfe_rx_packet(dev
, db
);
778 /* reallocate rx descriptor buffer */
779 if (db
->rx_avail_cnt
<RX_DESC_CNT
)
780 allocate_rx_buffer(db
);
782 /* Free the transmitted descriptor */
783 if ( db
->cr5_data
& 0x01)
784 dmfe_free_tx_pkt(dev
, db
);
787 if (db
->dm910x_chk_mode
& 0x2) {
788 db
->dm910x_chk_mode
= 0x4;
789 db
->cr6_data
|= 0x100;
790 update_cr6(db
->cr6_data
, db
->ioaddr
);
793 /* Restore CR7 to enable interrupt mask */
794 outl(db
->cr7_data
, ioaddr
+ DCR7
);
796 spin_unlock_irqrestore(&db
->lock
, flags
);
801 #ifdef CONFIG_NET_POLL_CONTROLLER
803 * Polling 'interrupt' - used by things like netconsole to send skbs
804 * without having to re-enable interrupts. It's not called while
805 * the interrupt routine is executing.
808 static void poll_dmfe (struct net_device
*dev
)
810 /* disable_irq here is not very nice, but with the lockless
811 interrupt handler we have no other choice. */
812 disable_irq(dev
->irq
);
813 dmfe_interrupt (dev
->irq
, dev
, NULL
);
814 enable_irq(dev
->irq
);
819 * Free TX resource after TX complete
822 static void dmfe_free_tx_pkt(struct DEVICE
*dev
, struct dmfe_board_info
* db
)
824 struct tx_desc
*txptr
;
825 unsigned long ioaddr
= dev
->base_addr
;
828 txptr
= db
->tx_remove_ptr
;
829 while(db
->tx_packet_cnt
) {
830 tdes0
= le32_to_cpu(txptr
->tdes0
);
831 /* printk(DRV_NAME ": tdes0=%x\n", tdes0); */
832 if (tdes0
& 0x80000000)
835 /* A packet sent completed */
837 db
->stats
.tx_packets
++;
839 /* Transmit statistic counter */
840 if ( tdes0
!= 0x7fffffff ) {
841 /* printk(DRV_NAME ": tdes0=%x\n", tdes0); */
842 db
->stats
.collisions
+= (tdes0
>> 3) & 0xf;
843 db
->stats
.tx_bytes
+= le32_to_cpu(txptr
->tdes1
) & 0x7ff;
844 if (tdes0
& TDES0_ERR_MASK
) {
845 db
->stats
.tx_errors
++;
847 if (tdes0
& 0x0002) { /* UnderRun */
848 db
->tx_fifo_underrun
++;
849 if ( !(db
->cr6_data
& CR6_SFT
) ) {
850 db
->cr6_data
= db
->cr6_data
| CR6_SFT
;
851 update_cr6(db
->cr6_data
, db
->ioaddr
);
855 db
->tx_excessive_collision
++;
857 db
->tx_late_collision
++;
861 db
->tx_loss_carrier
++;
863 db
->tx_jabber_timeout
++;
867 txptr
= txptr
->next_tx_desc
;
870 /* Update TX remove pointer to next */
871 db
->tx_remove_ptr
= txptr
;
873 /* Send the Tx packet in queue */
874 if ( (db
->tx_packet_cnt
< TX_MAX_SEND_CNT
) && db
->tx_queue_cnt
) {
875 txptr
->tdes0
= cpu_to_le32(0x80000000); /* Set owner bit */
876 db
->tx_packet_cnt
++; /* Ready to send */
878 outl(0x1, ioaddr
+ DCR1
); /* Issue Tx polling */
879 dev
->trans_start
= jiffies
; /* saved time stamp */
882 /* Resource available check */
883 if ( db
->tx_queue_cnt
< TX_WAKE_DESC_CNT
)
884 netif_wake_queue(dev
); /* Active upper layer, send again */
889 * Calculate the CRC valude of the Rx packet
890 * flag = 1 : return the reverse CRC (for the received packet CRC)
891 * 0 : return the normal CRC (for Hash Table index)
894 static inline u32
cal_CRC(unsigned char * Data
, unsigned int Len
, u8 flag
)
896 u32 crc
= crc32(~0, Data
, Len
);
897 if (flag
) crc
= ~crc
;
903 * Receive the come packet and pass to upper layer
906 static void dmfe_rx_packet(struct DEVICE
*dev
, struct dmfe_board_info
* db
)
908 struct rx_desc
*rxptr
;
913 rxptr
= db
->rx_ready_ptr
;
915 while(db
->rx_avail_cnt
) {
916 rdes0
= le32_to_cpu(rxptr
->rdes0
);
917 if (rdes0
& 0x80000000) /* packet owner check */
921 db
->interval_rx_cnt
++;
923 pci_unmap_single(db
->pdev
, le32_to_cpu(rxptr
->rdes2
), RX_ALLOC_SIZE
, PCI_DMA_FROMDEVICE
);
924 if ( (rdes0
& 0x300) != 0x300) {
925 /* A packet without First/Last flag */
927 DMFE_DBUG(0, "Reuse SK buffer, rdes0", rdes0
);
928 dmfe_reuse_skb(db
, rxptr
->rx_skb_ptr
);
930 /* A packet with First/Last flag */
931 rxlen
= ( (rdes0
>> 16) & 0x3fff) - 4;
933 /* error summary bit check */
934 if (rdes0
& 0x8000) {
935 /* This is a error packet */
936 //printk(DRV_NAME ": rdes0: %lx\n", rdes0);
937 db
->stats
.rx_errors
++;
939 db
->stats
.rx_fifo_errors
++;
941 db
->stats
.rx_crc_errors
++;
943 db
->stats
.rx_length_errors
++;
946 if ( !(rdes0
& 0x8000) ||
947 ((db
->cr6_data
& CR6_PM
) && (rxlen
>6)) ) {
948 skb
= rxptr
->rx_skb_ptr
;
950 /* Received Packet CRC check need or not */
951 if ( (db
->dm910x_chk_mode
& 1) &&
952 (cal_CRC(skb
->tail
, rxlen
, 1) !=
953 (*(u32
*) (skb
->tail
+rxlen
) ))) { /* FIXME (?) */
954 /* Found a error received packet */
955 dmfe_reuse_skb(db
, rxptr
->rx_skb_ptr
);
956 db
->dm910x_chk_mode
= 3;
958 /* Good packet, send to upper layer */
959 /* Shorst packet used new SKB */
960 if ( (rxlen
< RX_COPY_SIZE
) &&
961 ( (skb
= dev_alloc_skb(rxlen
+ 2) )
963 /* size less than COPY_SIZE, allocate a rxlen SKB */
965 skb_reserve(skb
, 2); /* 16byte align */
966 memcpy(skb_put(skb
, rxlen
), rxptr
->rx_skb_ptr
->tail
, rxlen
);
967 dmfe_reuse_skb(db
, rxptr
->rx_skb_ptr
);
972 skb
->protocol
= eth_type_trans(skb
, dev
);
974 dev
->last_rx
= jiffies
;
975 db
->stats
.rx_packets
++;
976 db
->stats
.rx_bytes
+= rxlen
;
979 /* Reuse SKB buffer when the packet is error */
980 DMFE_DBUG(0, "Reuse SK buffer, rdes0", rdes0
);
981 dmfe_reuse_skb(db
, rxptr
->rx_skb_ptr
);
985 rxptr
= rxptr
->next_rx_desc
;
988 db
->rx_ready_ptr
= rxptr
;
993 * Get statistics from driver.
996 static struct net_device_stats
* dmfe_get_stats(struct DEVICE
*dev
)
998 struct dmfe_board_info
*db
= netdev_priv(dev
);
1000 DMFE_DBUG(0, "dmfe_get_stats", 0);
1006 * Set DM910X multicast address
1009 static void dmfe_set_filter_mode(struct DEVICE
* dev
)
1011 struct dmfe_board_info
*db
= netdev_priv(dev
);
1012 unsigned long flags
;
1014 DMFE_DBUG(0, "dmfe_set_filter_mode()", 0);
1015 spin_lock_irqsave(&db
->lock
, flags
);
1017 if (dev
->flags
& IFF_PROMISC
) {
1018 DMFE_DBUG(0, "Enable PROM Mode", 0);
1019 db
->cr6_data
|= CR6_PM
| CR6_PBF
;
1020 update_cr6(db
->cr6_data
, db
->ioaddr
);
1021 spin_unlock_irqrestore(&db
->lock
, flags
);
1025 if (dev
->flags
& IFF_ALLMULTI
|| dev
->mc_count
> DMFE_MAX_MULTICAST
) {
1026 DMFE_DBUG(0, "Pass all multicast address", dev
->mc_count
);
1027 db
->cr6_data
&= ~(CR6_PM
| CR6_PBF
);
1028 db
->cr6_data
|= CR6_PAM
;
1029 spin_unlock_irqrestore(&db
->lock
, flags
);
1033 DMFE_DBUG(0, "Set multicast address", dev
->mc_count
);
1034 if (db
->chip_id
== PCI_DM9132_ID
)
1035 dm9132_id_table(dev
, dev
->mc_count
); /* DM9132 */
1037 send_filter_frame(dev
, dev
->mc_count
); /* DM9102/DM9102A */
1038 spin_unlock_irqrestore(&db
->lock
, flags
);
1041 static void netdev_get_drvinfo(struct net_device
*dev
,
1042 struct ethtool_drvinfo
*info
)
1044 struct dmfe_board_info
*np
= netdev_priv(dev
);
1046 strcpy(info
->driver
, DRV_NAME
);
1047 strcpy(info
->version
, DRV_VERSION
);
1049 strcpy(info
->bus_info
, pci_name(np
->pdev
));
1051 sprintf(info
->bus_info
, "EISA 0x%lx %d",
1052 dev
->base_addr
, dev
->irq
);
1055 static struct ethtool_ops netdev_ethtool_ops
= {
1056 .get_drvinfo
= netdev_get_drvinfo
,
1060 * A periodic timer routine
1061 * Dynamic media sense, allocate Rx buffer...
1064 static void dmfe_timer(unsigned long data
)
1067 unsigned char tmp_cr12
;
1068 struct DEVICE
*dev
= (struct DEVICE
*) data
;
1069 struct dmfe_board_info
*db
= netdev_priv(dev
);
1070 unsigned long flags
;
1072 DMFE_DBUG(0, "dmfe_timer()", 0);
1073 spin_lock_irqsave(&db
->lock
, flags
);
1075 /* Media mode process when Link OK before enter this route */
1076 if (db
->first_in_callback
== 0) {
1077 db
->first_in_callback
= 1;
1078 if (db
->chip_type
&& (db
->chip_id
==PCI_DM9102_ID
)) {
1079 db
->cr6_data
&= ~0x40000;
1080 update_cr6(db
->cr6_data
, db
->ioaddr
);
1081 phy_write(db
->ioaddr
, db
->phy_addr
, 0, 0x1000, db
->chip_id
);
1082 db
->cr6_data
|= 0x40000;
1083 update_cr6(db
->cr6_data
, db
->ioaddr
);
1084 db
->timer
.expires
= DMFE_TIMER_WUT
+ HZ
* 2;
1085 add_timer(&db
->timer
);
1086 spin_unlock_irqrestore(&db
->lock
, flags
);
1092 /* Operating Mode Check */
1093 if ( (db
->dm910x_chk_mode
& 0x1) &&
1094 (db
->stats
.rx_packets
> MAX_CHECK_PACKET
) )
1095 db
->dm910x_chk_mode
= 0x4;
1097 /* Dynamic reset DM910X : system error or transmit time-out */
1098 tmp_cr8
= inl(db
->ioaddr
+ DCR8
);
1099 if ( (db
->interval_rx_cnt
==0) && (tmp_cr8
) ) {
1103 db
->interval_rx_cnt
= 0;
1105 /* TX polling kick monitor */
1106 if ( db
->tx_packet_cnt
&&
1107 time_after(jiffies
, dev
->trans_start
+ DMFE_TX_KICK
) ) {
1108 outl(0x1, dev
->base_addr
+ DCR1
); /* Tx polling again */
1111 if ( time_after(jiffies
, dev
->trans_start
+ DMFE_TX_TIMEOUT
) ) {
1112 db
->reset_TXtimeout
++;
1114 printk(KERN_WARNING
"%s: Tx timeout - resetting\n",
1119 if (db
->wait_reset
) {
1120 DMFE_DBUG(0, "Dynamic Reset device", db
->tx_packet_cnt
);
1122 dmfe_dynamic_reset(dev
);
1123 db
->first_in_callback
= 0;
1124 db
->timer
.expires
= DMFE_TIMER_WUT
;
1125 add_timer(&db
->timer
);
1126 spin_unlock_irqrestore(&db
->lock
, flags
);
1130 /* Link status check, Dynamic media type change */
1131 if (db
->chip_id
== PCI_DM9132_ID
)
1132 tmp_cr12
= inb(db
->ioaddr
+ DCR9
+ 3); /* DM9132 */
1134 tmp_cr12
= inb(db
->ioaddr
+ DCR12
); /* DM9102/DM9102A */
1136 if ( ((db
->chip_id
== PCI_DM9102_ID
) &&
1137 (db
->chip_revision
== 0x02000030)) ||
1138 ((db
->chip_id
== PCI_DM9132_ID
) &&
1139 (db
->chip_revision
== 0x02000010)) ) {
1142 tmp_cr12
= 0x0; /* Link failed */
1144 tmp_cr12
= 0x3; /* Link OK */
1147 if ( !(tmp_cr12
& 0x3) && !db
->link_failed
) {
1149 DMFE_DBUG(0, "Link Failed", tmp_cr12
);
1150 db
->link_failed
= 1;
1152 /* For Force 10/100M Half/Full mode: Enable Auto-Nego mode */
1153 /* AUTO or force 1M Homerun/Longrun don't need */
1154 if ( !(db
->media_mode
& 0x38) )
1155 phy_write(db
->ioaddr
, db
->phy_addr
, 0, 0x1000, db
->chip_id
);
1157 /* AUTO mode, if INT phyxcer link failed, select EXT device */
1158 if (db
->media_mode
& DMFE_AUTO
) {
1159 /* 10/100M link failed, used 1M Home-Net */
1160 db
->cr6_data
|=0x00040000; /* bit18=1, MII */
1161 db
->cr6_data
&=~0x00000200; /* bit9=0, HD mode */
1162 update_cr6(db
->cr6_data
, db
->ioaddr
);
1165 if ((tmp_cr12
& 0x3) && db
->link_failed
) {
1166 DMFE_DBUG(0, "Link link OK", tmp_cr12
);
1167 db
->link_failed
= 0;
1169 /* Auto Sense Speed */
1170 if ( (db
->media_mode
& DMFE_AUTO
) &&
1171 dmfe_sense_speed(db
) )
1172 db
->link_failed
= 1;
1173 dmfe_process_mode(db
);
1174 /* SHOW_MEDIA_TYPE(db->op_mode); */
1177 /* HPNA remote command check */
1178 if (db
->HPNA_command
& 0xf00) {
1180 if (!db
->HPNA_timer
)
1181 dmfe_HPNA_remote_cmd_chk(db
);
1184 /* Timer active again */
1185 db
->timer
.expires
= DMFE_TIMER_WUT
;
1186 add_timer(&db
->timer
);
1187 spin_unlock_irqrestore(&db
->lock
, flags
);
1192 * Dynamic reset the DM910X board
1194 * Free Tx/Rx allocated memory
1195 * Reset DM910X board
1196 * Re-initilize DM910X board
1199 static void dmfe_dynamic_reset(struct DEVICE
*dev
)
1201 struct dmfe_board_info
*db
= netdev_priv(dev
);
1203 DMFE_DBUG(0, "dmfe_dynamic_reset()", 0);
1205 /* Sopt MAC controller */
1206 db
->cr6_data
&= ~(CR6_RXSC
| CR6_TXSC
); /* Disable Tx/Rx */
1207 update_cr6(db
->cr6_data
, dev
->base_addr
);
1208 outl(0, dev
->base_addr
+ DCR7
); /* Disable Interrupt */
1209 outl(inl(dev
->base_addr
+ DCR5
), dev
->base_addr
+ DCR5
);
1211 /* Disable upper layer interface */
1212 netif_stop_queue(dev
);
1214 /* Free Rx Allocate buffer */
1215 dmfe_free_rxbuffer(db
);
1217 /* system variable init */
1218 db
->tx_packet_cnt
= 0;
1219 db
->tx_queue_cnt
= 0;
1220 db
->rx_avail_cnt
= 0;
1221 db
->link_failed
= 1;
1224 /* Re-initilize DM910X board */
1225 dmfe_init_dm910x(dev
);
1227 /* Restart upper layer interface */
1228 netif_wake_queue(dev
);
1233 * free all allocated rx buffer
1236 static void dmfe_free_rxbuffer(struct dmfe_board_info
* db
)
1238 DMFE_DBUG(0, "dmfe_free_rxbuffer()", 0);
1240 /* free allocated rx buffer */
1241 while (db
->rx_avail_cnt
) {
1242 dev_kfree_skb(db
->rx_ready_ptr
->rx_skb_ptr
);
1243 db
->rx_ready_ptr
= db
->rx_ready_ptr
->next_rx_desc
;
1250 * Reuse the SK buffer
1253 static void dmfe_reuse_skb(struct dmfe_board_info
*db
, struct sk_buff
* skb
)
1255 struct rx_desc
*rxptr
= db
->rx_insert_ptr
;
1257 if (!(rxptr
->rdes0
& cpu_to_le32(0x80000000))) {
1258 rxptr
->rx_skb_ptr
= skb
;
1259 rxptr
->rdes2
= cpu_to_le32( pci_map_single(db
->pdev
, skb
->tail
, RX_ALLOC_SIZE
, PCI_DMA_FROMDEVICE
) );
1261 rxptr
->rdes0
= cpu_to_le32(0x80000000);
1263 db
->rx_insert_ptr
= rxptr
->next_rx_desc
;
1265 DMFE_DBUG(0, "SK Buffer reuse method error", db
->rx_avail_cnt
);
1270 * Initialize transmit/Receive descriptor
1271 * Using Chain structure, and allocate Tx/Rx buffer
1274 static void dmfe_descriptor_init(struct dmfe_board_info
*db
, unsigned long ioaddr
)
1276 struct tx_desc
*tmp_tx
;
1277 struct rx_desc
*tmp_rx
;
1278 unsigned char *tmp_buf
;
1279 dma_addr_t tmp_tx_dma
, tmp_rx_dma
;
1280 dma_addr_t tmp_buf_dma
;
1283 DMFE_DBUG(0, "dmfe_descriptor_init()", 0);
1285 /* tx descriptor start pointer */
1286 db
->tx_insert_ptr
= db
->first_tx_desc
;
1287 db
->tx_remove_ptr
= db
->first_tx_desc
;
1288 outl(db
->first_tx_desc_dma
, ioaddr
+ DCR4
); /* TX DESC address */
1290 /* rx descriptor start pointer */
1291 db
->first_rx_desc
= (void *)db
->first_tx_desc
+ sizeof(struct tx_desc
) * TX_DESC_CNT
;
1292 db
->first_rx_desc_dma
= db
->first_tx_desc_dma
+ sizeof(struct tx_desc
) * TX_DESC_CNT
;
1293 db
->rx_insert_ptr
= db
->first_rx_desc
;
1294 db
->rx_ready_ptr
= db
->first_rx_desc
;
1295 outl(db
->first_rx_desc_dma
, ioaddr
+ DCR3
); /* RX DESC address */
1297 /* Init Transmit chain */
1298 tmp_buf
= db
->buf_pool_start
;
1299 tmp_buf_dma
= db
->buf_pool_dma_start
;
1300 tmp_tx_dma
= db
->first_tx_desc_dma
;
1301 for (tmp_tx
= db
->first_tx_desc
, i
= 0; i
< TX_DESC_CNT
; i
++, tmp_tx
++) {
1302 tmp_tx
->tx_buf_ptr
= tmp_buf
;
1303 tmp_tx
->tdes0
= cpu_to_le32(0);
1304 tmp_tx
->tdes1
= cpu_to_le32(0x81000000); /* IC, chain */
1305 tmp_tx
->tdes2
= cpu_to_le32(tmp_buf_dma
);
1306 tmp_tx_dma
+= sizeof(struct tx_desc
);
1307 tmp_tx
->tdes3
= cpu_to_le32(tmp_tx_dma
);
1308 tmp_tx
->next_tx_desc
= tmp_tx
+ 1;
1309 tmp_buf
= tmp_buf
+ TX_BUF_ALLOC
;
1310 tmp_buf_dma
= tmp_buf_dma
+ TX_BUF_ALLOC
;
1312 (--tmp_tx
)->tdes3
= cpu_to_le32(db
->first_tx_desc_dma
);
1313 tmp_tx
->next_tx_desc
= db
->first_tx_desc
;
1315 /* Init Receive descriptor chain */
1316 tmp_rx_dma
=db
->first_rx_desc_dma
;
1317 for (tmp_rx
= db
->first_rx_desc
, i
= 0; i
< RX_DESC_CNT
; i
++, tmp_rx
++) {
1318 tmp_rx
->rdes0
= cpu_to_le32(0);
1319 tmp_rx
->rdes1
= cpu_to_le32(0x01000600);
1320 tmp_rx_dma
+= sizeof(struct rx_desc
);
1321 tmp_rx
->rdes3
= cpu_to_le32(tmp_rx_dma
);
1322 tmp_rx
->next_rx_desc
= tmp_rx
+ 1;
1324 (--tmp_rx
)->rdes3
= cpu_to_le32(db
->first_rx_desc_dma
);
1325 tmp_rx
->next_rx_desc
= db
->first_rx_desc
;
1327 /* pre-allocate Rx buffer */
1328 allocate_rx_buffer(db
);
1334 * Firstly stop DM910X , then written value and start
1337 static void update_cr6(u32 cr6_data
, unsigned long ioaddr
)
1341 cr6_tmp
= cr6_data
& ~0x2002; /* stop Tx/Rx */
1342 outl(cr6_tmp
, ioaddr
+ DCR6
);
1344 outl(cr6_data
, ioaddr
+ DCR6
);
1350 * Send a setup frame for DM9132
1351 * This setup frame initilize DM910X address filter mode
1354 static void dm9132_id_table(struct DEVICE
*dev
, int mc_cnt
)
1356 struct dev_mc_list
*mcptr
;
1358 unsigned long ioaddr
= dev
->base_addr
+0xc0; /* ID Table */
1360 u16 i
, hash_table
[4];
1362 DMFE_DBUG(0, "dm9132_id_table()", 0);
1365 addrptr
= (u16
*) dev
->dev_addr
;
1366 outw(addrptr
[0], ioaddr
);
1368 outw(addrptr
[1], ioaddr
);
1370 outw(addrptr
[2], ioaddr
);
1373 /* Clear Hash Table */
1374 for (i
= 0; i
< 4; i
++)
1375 hash_table
[i
] = 0x0;
1377 /* broadcast address */
1378 hash_table
[3] = 0x8000;
1380 /* the multicast address in Hash Table : 64 bits */
1381 for (mcptr
= dev
->mc_list
, i
= 0; i
< mc_cnt
; i
++, mcptr
= mcptr
->next
) {
1382 hash_val
= cal_CRC( (char *) mcptr
->dmi_addr
, 6, 0) & 0x3f;
1383 hash_table
[hash_val
/ 16] |= (u16
) 1 << (hash_val
% 16);
1386 /* Write the hash table to MAC MD table */
1387 for (i
= 0; i
< 4; i
++, ioaddr
+= 4)
1388 outw(hash_table
[i
], ioaddr
);
1393 * Send a setup frame for DM9102/DM9102A
1394 * This setup frame initilize DM910X address filter mode
1397 static void send_filter_frame(struct DEVICE
*dev
, int mc_cnt
)
1399 struct dmfe_board_info
*db
= netdev_priv(dev
);
1400 struct dev_mc_list
*mcptr
;
1401 struct tx_desc
*txptr
;
1406 DMFE_DBUG(0, "send_filter_frame()", 0);
1408 txptr
= db
->tx_insert_ptr
;
1409 suptr
= (u32
*) txptr
->tx_buf_ptr
;
1412 addrptr
= (u16
*) dev
->dev_addr
;
1413 *suptr
++ = addrptr
[0];
1414 *suptr
++ = addrptr
[1];
1415 *suptr
++ = addrptr
[2];
1417 /* broadcast address */
1422 /* fit the multicast address */
1423 for (mcptr
= dev
->mc_list
, i
= 0; i
< mc_cnt
; i
++, mcptr
= mcptr
->next
) {
1424 addrptr
= (u16
*) mcptr
->dmi_addr
;
1425 *suptr
++ = addrptr
[0];
1426 *suptr
++ = addrptr
[1];
1427 *suptr
++ = addrptr
[2];
1436 /* prepare the setup frame */
1437 db
->tx_insert_ptr
= txptr
->next_tx_desc
;
1438 txptr
->tdes1
= cpu_to_le32(0x890000c0);
1440 /* Resource Check and Send the setup packet */
1441 if (!db
->tx_packet_cnt
) {
1442 /* Resource Empty */
1443 db
->tx_packet_cnt
++;
1444 txptr
->tdes0
= cpu_to_le32(0x80000000);
1445 update_cr6(db
->cr6_data
| 0x2000, dev
->base_addr
);
1446 outl(0x1, dev
->base_addr
+ DCR1
); /* Issue Tx polling */
1447 update_cr6(db
->cr6_data
, dev
->base_addr
);
1448 dev
->trans_start
= jiffies
;
1450 db
->tx_queue_cnt
++; /* Put in TX queue */
1455 * Allocate rx buffer,
1456 * As possible as allocate maxiumn Rx buffer
1459 static void allocate_rx_buffer(struct dmfe_board_info
*db
)
1461 struct rx_desc
*rxptr
;
1462 struct sk_buff
*skb
;
1464 rxptr
= db
->rx_insert_ptr
;
1466 while(db
->rx_avail_cnt
< RX_DESC_CNT
) {
1467 if ( ( skb
= dev_alloc_skb(RX_ALLOC_SIZE
) ) == NULL
)
1469 rxptr
->rx_skb_ptr
= skb
; /* FIXME (?) */
1470 rxptr
->rdes2
= cpu_to_le32( pci_map_single(db
->pdev
, skb
->tail
, RX_ALLOC_SIZE
, PCI_DMA_FROMDEVICE
) );
1472 rxptr
->rdes0
= cpu_to_le32(0x80000000);
1473 rxptr
= rxptr
->next_rx_desc
;
1477 db
->rx_insert_ptr
= rxptr
;
1482 * Read one word data from the serial ROM
1485 static u16
read_srom_word(long ioaddr
, int offset
)
1489 long cr9_ioaddr
= ioaddr
+ DCR9
;
1491 outl(CR9_SROM_READ
, cr9_ioaddr
);
1492 outl(CR9_SROM_READ
| CR9_SRCS
, cr9_ioaddr
);
1494 /* Send the Read Command 110b */
1495 SROM_CLK_WRITE(SROM_DATA_1
, cr9_ioaddr
);
1496 SROM_CLK_WRITE(SROM_DATA_1
, cr9_ioaddr
);
1497 SROM_CLK_WRITE(SROM_DATA_0
, cr9_ioaddr
);
1499 /* Send the offset */
1500 for (i
= 5; i
>= 0; i
--) {
1501 srom_data
= (offset
& (1 << i
)) ? SROM_DATA_1
: SROM_DATA_0
;
1502 SROM_CLK_WRITE(srom_data
, cr9_ioaddr
);
1505 outl(CR9_SROM_READ
| CR9_SRCS
, cr9_ioaddr
);
1507 for (i
= 16; i
> 0; i
--) {
1508 outl(CR9_SROM_READ
| CR9_SRCS
| CR9_SRCLK
, cr9_ioaddr
);
1510 srom_data
= (srom_data
<< 1) | ((inl(cr9_ioaddr
) & CR9_CRDOUT
) ? 1 : 0);
1511 outl(CR9_SROM_READ
| CR9_SRCS
, cr9_ioaddr
);
1515 outl(CR9_SROM_READ
, cr9_ioaddr
);
1521 * Auto sense the media mode
1524 static u8
dmfe_sense_speed(struct dmfe_board_info
* db
)
1529 /* CR6 bit18=0, select 10/100M */
1530 update_cr6( (db
->cr6_data
& ~0x40000), db
->ioaddr
);
1532 phy_mode
= phy_read(db
->ioaddr
, db
->phy_addr
, 1, db
->chip_id
);
1533 phy_mode
= phy_read(db
->ioaddr
, db
->phy_addr
, 1, db
->chip_id
);
1535 if ( (phy_mode
& 0x24) == 0x24 ) {
1536 if (db
->chip_id
== PCI_DM9132_ID
) /* DM9132 */
1537 phy_mode
= phy_read(db
->ioaddr
, db
->phy_addr
, 7, db
->chip_id
) & 0xf000;
1538 else /* DM9102/DM9102A */
1539 phy_mode
= phy_read(db
->ioaddr
, db
->phy_addr
, 17, db
->chip_id
) & 0xf000;
1540 /* printk(DRV_NAME ": Phy_mode %x ",phy_mode); */
1542 case 0x1000: db
->op_mode
= DMFE_10MHF
; break;
1543 case 0x2000: db
->op_mode
= DMFE_10MFD
; break;
1544 case 0x4000: db
->op_mode
= DMFE_100MHF
; break;
1545 case 0x8000: db
->op_mode
= DMFE_100MFD
; break;
1546 default: db
->op_mode
= DMFE_10MHF
;
1551 db
->op_mode
= DMFE_10MHF
;
1552 DMFE_DBUG(0, "Link Failed :", phy_mode
);
1561 * Set 10/100 phyxcer capability
1562 * AUTO mode : phyxcer register4 is NIC capability
1563 * Force mode: phyxcer register4 is the force media
1566 static void dmfe_set_phyxcer(struct dmfe_board_info
*db
)
1570 /* Select 10/100M phyxcer */
1571 db
->cr6_data
&= ~0x40000;
1572 update_cr6(db
->cr6_data
, db
->ioaddr
);
1574 /* DM9009 Chip: Phyxcer reg18 bit12=0 */
1575 if (db
->chip_id
== PCI_DM9009_ID
) {
1576 phy_reg
= phy_read(db
->ioaddr
, db
->phy_addr
, 18, db
->chip_id
) & ~0x1000;
1577 phy_write(db
->ioaddr
, db
->phy_addr
, 18, phy_reg
, db
->chip_id
);
1580 /* Phyxcer capability setting */
1581 phy_reg
= phy_read(db
->ioaddr
, db
->phy_addr
, 4, db
->chip_id
) & ~0x01e0;
1583 if (db
->media_mode
& DMFE_AUTO
) {
1585 phy_reg
|= db
->PHY_reg4
;
1588 switch(db
->media_mode
) {
1589 case DMFE_10MHF
: phy_reg
|= 0x20; break;
1590 case DMFE_10MFD
: phy_reg
|= 0x40; break;
1591 case DMFE_100MHF
: phy_reg
|= 0x80; break;
1592 case DMFE_100MFD
: phy_reg
|= 0x100; break;
1594 if (db
->chip_id
== PCI_DM9009_ID
) phy_reg
&= 0x61;
1597 /* Write new capability to Phyxcer Reg4 */
1598 if ( !(phy_reg
& 0x01e0)) {
1599 phy_reg
|=db
->PHY_reg4
;
1600 db
->media_mode
|=DMFE_AUTO
;
1602 phy_write(db
->ioaddr
, db
->phy_addr
, 4, phy_reg
, db
->chip_id
);
1604 /* Restart Auto-Negotiation */
1605 if ( db
->chip_type
&& (db
->chip_id
== PCI_DM9102_ID
) )
1606 phy_write(db
->ioaddr
, db
->phy_addr
, 0, 0x1800, db
->chip_id
);
1607 if ( !db
->chip_type
)
1608 phy_write(db
->ioaddr
, db
->phy_addr
, 0, 0x1200, db
->chip_id
);
1614 * AUTO mode : PHY controller in Auto-negotiation Mode
1615 * Force mode: PHY controller in force mode with HUB
1616 * N-way force capability with SWITCH
1619 static void dmfe_process_mode(struct dmfe_board_info
*db
)
1623 /* Full Duplex Mode Check */
1624 if (db
->op_mode
& 0x4)
1625 db
->cr6_data
|= CR6_FDM
; /* Set Full Duplex Bit */
1627 db
->cr6_data
&= ~CR6_FDM
; /* Clear Full Duplex Bit */
1629 /* Transciver Selection */
1630 if (db
->op_mode
& 0x10) /* 1M HomePNA */
1631 db
->cr6_data
|= 0x40000;/* External MII select */
1633 db
->cr6_data
&= ~0x40000;/* Internal 10/100 transciver */
1635 update_cr6(db
->cr6_data
, db
->ioaddr
);
1637 /* 10/100M phyxcer force mode need */
1638 if ( !(db
->media_mode
& 0x18)) {
1640 phy_reg
= phy_read(db
->ioaddr
, db
->phy_addr
, 6, db
->chip_id
);
1641 if ( !(phy_reg
& 0x1) ) {
1642 /* parter without N-Way capability */
1644 switch(db
->op_mode
) {
1645 case DMFE_10MHF
: phy_reg
= 0x0; break;
1646 case DMFE_10MFD
: phy_reg
= 0x100; break;
1647 case DMFE_100MHF
: phy_reg
= 0x2000; break;
1648 case DMFE_100MFD
: phy_reg
= 0x2100; break;
1650 phy_write(db
->ioaddr
, db
->phy_addr
, 0, phy_reg
, db
->chip_id
);
1651 if ( db
->chip_type
&& (db
->chip_id
== PCI_DM9102_ID
) )
1653 phy_write(db
->ioaddr
, db
->phy_addr
, 0, phy_reg
, db
->chip_id
);
1660 * Write a word to Phy register
1663 static void phy_write(unsigned long iobase
, u8 phy_addr
, u8 offset
, u16 phy_data
, u32 chip_id
)
1666 unsigned long ioaddr
;
1668 if (chip_id
== PCI_DM9132_ID
) {
1669 ioaddr
= iobase
+ 0x80 + offset
* 4;
1670 outw(phy_data
, ioaddr
);
1672 /* DM9102/DM9102A Chip */
1673 ioaddr
= iobase
+ DCR9
;
1675 /* Send 33 synchronization clock to Phy controller */
1676 for (i
= 0; i
< 35; i
++)
1677 phy_write_1bit(ioaddr
, PHY_DATA_1
);
1679 /* Send start command(01) to Phy */
1680 phy_write_1bit(ioaddr
, PHY_DATA_0
);
1681 phy_write_1bit(ioaddr
, PHY_DATA_1
);
1683 /* Send write command(01) to Phy */
1684 phy_write_1bit(ioaddr
, PHY_DATA_0
);
1685 phy_write_1bit(ioaddr
, PHY_DATA_1
);
1687 /* Send Phy address */
1688 for (i
= 0x10; i
> 0; i
= i
>> 1)
1689 phy_write_1bit(ioaddr
, phy_addr
& i
? PHY_DATA_1
: PHY_DATA_0
);
1691 /* Send register address */
1692 for (i
= 0x10; i
> 0; i
= i
>> 1)
1693 phy_write_1bit(ioaddr
, offset
& i
? PHY_DATA_1
: PHY_DATA_0
);
1695 /* written trasnition */
1696 phy_write_1bit(ioaddr
, PHY_DATA_1
);
1697 phy_write_1bit(ioaddr
, PHY_DATA_0
);
1699 /* Write a word data to PHY controller */
1700 for ( i
= 0x8000; i
> 0; i
>>= 1)
1701 phy_write_1bit(ioaddr
, phy_data
& i
? PHY_DATA_1
: PHY_DATA_0
);
1707 * Read a word data from phy register
1710 static u16
phy_read(unsigned long iobase
, u8 phy_addr
, u8 offset
, u32 chip_id
)
1714 unsigned long ioaddr
;
1716 if (chip_id
== PCI_DM9132_ID
) {
1718 ioaddr
= iobase
+ 0x80 + offset
* 4;
1719 phy_data
= inw(ioaddr
);
1721 /* DM9102/DM9102A Chip */
1722 ioaddr
= iobase
+ DCR9
;
1724 /* Send 33 synchronization clock to Phy controller */
1725 for (i
= 0; i
< 35; i
++)
1726 phy_write_1bit(ioaddr
, PHY_DATA_1
);
1728 /* Send start command(01) to Phy */
1729 phy_write_1bit(ioaddr
, PHY_DATA_0
);
1730 phy_write_1bit(ioaddr
, PHY_DATA_1
);
1732 /* Send read command(10) to Phy */
1733 phy_write_1bit(ioaddr
, PHY_DATA_1
);
1734 phy_write_1bit(ioaddr
, PHY_DATA_0
);
1736 /* Send Phy address */
1737 for (i
= 0x10; i
> 0; i
= i
>> 1)
1738 phy_write_1bit(ioaddr
, phy_addr
& i
? PHY_DATA_1
: PHY_DATA_0
);
1740 /* Send register address */
1741 for (i
= 0x10; i
> 0; i
= i
>> 1)
1742 phy_write_1bit(ioaddr
, offset
& i
? PHY_DATA_1
: PHY_DATA_0
);
1744 /* Skip transition state */
1745 phy_read_1bit(ioaddr
);
1747 /* read 16bit data */
1748 for (phy_data
= 0, i
= 0; i
< 16; i
++) {
1750 phy_data
|= phy_read_1bit(ioaddr
);
1759 * Write one bit data to Phy Controller
1762 static void phy_write_1bit(unsigned long ioaddr
, u32 phy_data
)
1764 outl(phy_data
, ioaddr
); /* MII Clock Low */
1766 outl(phy_data
| MDCLKH
, ioaddr
); /* MII Clock High */
1768 outl(phy_data
, ioaddr
); /* MII Clock Low */
1774 * Read one bit phy data from PHY controller
1777 static u16
phy_read_1bit(unsigned long ioaddr
)
1781 outl(0x50000, ioaddr
);
1783 phy_data
= ( inl(ioaddr
) >> 19 ) & 0x1;
1784 outl(0x40000, ioaddr
);
1792 * Parser SROM and media mode
1795 static void dmfe_parse_srom(struct dmfe_board_info
* db
)
1797 char * srom
= db
->srom
;
1798 int dmfe_mode
, tmp_reg
;
1800 DMFE_DBUG(0, "dmfe_parse_srom() ", 0);
1803 db
->cr15_data
= CR15_DEFAULT
;
1805 /* Check SROM Version */
1806 if ( ( (int) srom
[18] & 0xff) == SROM_V41_CODE
) {
1808 /* Get NIC support media mode */
1809 db
->NIC_capability
= le16_to_cpup(srom
+ 34);
1811 for (tmp_reg
= 1; tmp_reg
< 0x10; tmp_reg
<<= 1) {
1812 switch( db
->NIC_capability
& tmp_reg
) {
1813 case 0x1: db
->PHY_reg4
|= 0x0020; break;
1814 case 0x2: db
->PHY_reg4
|= 0x0040; break;
1815 case 0x4: db
->PHY_reg4
|= 0x0080; break;
1816 case 0x8: db
->PHY_reg4
|= 0x0100; break;
1820 /* Media Mode Force or not check */
1821 dmfe_mode
= le32_to_cpup(srom
+ 34) & le32_to_cpup(srom
+ 36);
1823 case 0x4: dmfe_media_mode
= DMFE_100MHF
; break; /* 100MHF */
1824 case 0x2: dmfe_media_mode
= DMFE_10MFD
; break; /* 10MFD */
1825 case 0x8: dmfe_media_mode
= DMFE_100MFD
; break; /* 100MFD */
1827 case 0x200: dmfe_media_mode
= DMFE_1M_HPNA
; break;/* HomePNA */
1830 /* Special Function setting */
1832 if ( (SF_mode
& 0x1) || (srom
[43] & 0x80) )
1833 db
->cr15_data
|= 0x40;
1836 if ( (SF_mode
& 0x2) || (srom
[40] & 0x1) )
1837 db
->cr15_data
|= 0x400;
1839 /* TX pause packet */
1840 if ( (SF_mode
& 0x4) || (srom
[40] & 0xe) )
1841 db
->cr15_data
|= 0x9800;
1844 /* Parse HPNA parameter */
1845 db
->HPNA_command
= 1;
1847 /* Accept remote command or not */
1848 if (HPNA_rx_cmd
== 0)
1849 db
->HPNA_command
|= 0x8000;
1851 /* Issue remote command & operation mode */
1852 if (HPNA_tx_cmd
== 1)
1853 switch(HPNA_mode
) { /* Issue Remote Command */
1854 case 0: db
->HPNA_command
|= 0x0904; break;
1855 case 1: db
->HPNA_command
|= 0x0a00; break;
1856 case 2: db
->HPNA_command
|= 0x0506; break;
1857 case 3: db
->HPNA_command
|= 0x0602; break;
1860 switch(HPNA_mode
) { /* Don't Issue */
1861 case 0: db
->HPNA_command
|= 0x0004; break;
1862 case 1: db
->HPNA_command
|= 0x0000; break;
1863 case 2: db
->HPNA_command
|= 0x0006; break;
1864 case 3: db
->HPNA_command
|= 0x0002; break;
1867 /* Check DM9801 or DM9802 present or not */
1868 db
->HPNA_present
= 0;
1869 update_cr6(db
->cr6_data
|0x40000, db
->ioaddr
);
1870 tmp_reg
= phy_read(db
->ioaddr
, db
->phy_addr
, 3, db
->chip_id
);
1871 if ( ( tmp_reg
& 0xfff0 ) == 0xb900 ) {
1872 /* DM9801 or DM9802 present */
1874 if ( phy_read(db
->ioaddr
, db
->phy_addr
, 31, db
->chip_id
) == 0x4404) {
1875 /* DM9801 HomeRun */
1876 db
->HPNA_present
= 1;
1877 dmfe_program_DM9801(db
, tmp_reg
);
1879 /* DM9802 LongRun */
1880 db
->HPNA_present
= 2;
1881 dmfe_program_DM9802(db
);
1889 * Init HomeRun DM9801
1892 static void dmfe_program_DM9801(struct dmfe_board_info
* db
, int HPNA_rev
)
1896 if ( !HPNA_NoiseFloor
) HPNA_NoiseFloor
= DM9801_NOISE_FLOOR
;
1898 case 0xb900: /* DM9801 E3 */
1899 db
->HPNA_command
|= 0x1000;
1900 reg25
= phy_read(db
->ioaddr
, db
->phy_addr
, 24, db
->chip_id
);
1901 reg25
= ( (reg25
+ HPNA_NoiseFloor
) & 0xff) | 0xf000;
1902 reg17
= phy_read(db
->ioaddr
, db
->phy_addr
, 17, db
->chip_id
);
1904 case 0xb901: /* DM9801 E4 */
1905 reg25
= phy_read(db
->ioaddr
, db
->phy_addr
, 25, db
->chip_id
);
1906 reg25
= (reg25
& 0xff00) + HPNA_NoiseFloor
;
1907 reg17
= phy_read(db
->ioaddr
, db
->phy_addr
, 17, db
->chip_id
);
1908 reg17
= (reg17
& 0xfff0) + HPNA_NoiseFloor
+ 3;
1910 case 0xb902: /* DM9801 E5 */
1911 case 0xb903: /* DM9801 E6 */
1913 db
->HPNA_command
|= 0x1000;
1914 reg25
= phy_read(db
->ioaddr
, db
->phy_addr
, 25, db
->chip_id
);
1915 reg25
= (reg25
& 0xff00) + HPNA_NoiseFloor
- 5;
1916 reg17
= phy_read(db
->ioaddr
, db
->phy_addr
, 17, db
->chip_id
);
1917 reg17
= (reg17
& 0xfff0) + HPNA_NoiseFloor
;
1920 phy_write(db
->ioaddr
, db
->phy_addr
, 16, db
->HPNA_command
, db
->chip_id
);
1921 phy_write(db
->ioaddr
, db
->phy_addr
, 17, reg17
, db
->chip_id
);
1922 phy_write(db
->ioaddr
, db
->phy_addr
, 25, reg25
, db
->chip_id
);
1927 * Init HomeRun DM9802
1930 static void dmfe_program_DM9802(struct dmfe_board_info
* db
)
1934 if ( !HPNA_NoiseFloor
) HPNA_NoiseFloor
= DM9802_NOISE_FLOOR
;
1935 phy_write(db
->ioaddr
, db
->phy_addr
, 16, db
->HPNA_command
, db
->chip_id
);
1936 phy_reg
= phy_read(db
->ioaddr
, db
->phy_addr
, 25, db
->chip_id
);
1937 phy_reg
= ( phy_reg
& 0xff00) + HPNA_NoiseFloor
;
1938 phy_write(db
->ioaddr
, db
->phy_addr
, 25, phy_reg
, db
->chip_id
);
1943 * Check remote HPNA power and speed status. If not correct,
1944 * issue command again.
1947 static void dmfe_HPNA_remote_cmd_chk(struct dmfe_board_info
* db
)
1951 /* Got remote device status */
1952 phy_reg
= phy_read(db
->ioaddr
, db
->phy_addr
, 17, db
->chip_id
) & 0x60;
1954 case 0x00: phy_reg
= 0x0a00;break; /* LP/LS */
1955 case 0x20: phy_reg
= 0x0900;break; /* LP/HS */
1956 case 0x40: phy_reg
= 0x0600;break; /* HP/LS */
1957 case 0x60: phy_reg
= 0x0500;break; /* HP/HS */
1960 /* Check remote device status match our setting ot not */
1961 if ( phy_reg
!= (db
->HPNA_command
& 0x0f00) ) {
1962 phy_write(db
->ioaddr
, db
->phy_addr
, 16, db
->HPNA_command
, db
->chip_id
);
1965 db
->HPNA_timer
=600; /* Match, every 10 minutes, check */
1970 static struct pci_device_id dmfe_pci_tbl
[] = {
1971 { 0x1282, 0x9132, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, PCI_DM9132_ID
},
1972 { 0x1282, 0x9102, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, PCI_DM9102_ID
},
1973 { 0x1282, 0x9100, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, PCI_DM9100_ID
},
1974 { 0x1282, 0x9009, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, PCI_DM9009_ID
},
1977 MODULE_DEVICE_TABLE(pci
, dmfe_pci_tbl
);
1980 static struct pci_driver dmfe_driver
= {
1982 .id_table
= dmfe_pci_tbl
,
1983 .probe
= dmfe_init_one
,
1984 .remove
= __devexit_p(dmfe_remove_one
),
1987 MODULE_AUTHOR("Sten Wang, sten_wang@davicom.com.tw");
1988 MODULE_DESCRIPTION("Davicom DM910X fast ethernet driver");
1989 MODULE_LICENSE("GPL");
1990 MODULE_VERSION(DRV_VERSION
);
1992 module_param(debug
, int, 0);
1993 module_param(mode
, byte
, 0);
1994 module_param(cr6set
, int, 0);
1995 module_param(chkmode
, byte
, 0);
1996 module_param(HPNA_mode
, byte
, 0);
1997 module_param(HPNA_rx_cmd
, byte
, 0);
1998 module_param(HPNA_tx_cmd
, byte
, 0);
1999 module_param(HPNA_NoiseFloor
, byte
, 0);
2000 module_param(SF_mode
, byte
, 0);
2001 MODULE_PARM_DESC(debug
, "Davicom DM9xxx enable debugging (0-1)");
2002 MODULE_PARM_DESC(mode
, "Davicom DM9xxx: Bit 0: 10/100Mbps, bit 2: duplex, bit 8: HomePNA");
2003 MODULE_PARM_DESC(SF_mode
, "Davicom DM9xxx special function (bit 0: VLAN, bit 1 Flow Control, bit 2: TX pause packet)");
2006 * when user used insmod to add module, system invoked init_module()
2007 * to initilize and register.
2010 static int __init
dmfe_init_module(void)
2015 printed_version
= 1;
2017 DMFE_DBUG(0, "init_module() ", debug
);
2020 dmfe_debug
= debug
; /* set debug flag */
2022 dmfe_cr6_user_set
= cr6set
;
2030 dmfe_media_mode
= mode
;
2032 default:dmfe_media_mode
= DMFE_AUTO
;
2037 HPNA_mode
= 0; /* Default: LP/HS */
2038 if (HPNA_rx_cmd
> 1)
2039 HPNA_rx_cmd
= 0; /* Default: Ignored remote cmd */
2040 if (HPNA_tx_cmd
> 1)
2041 HPNA_tx_cmd
= 0; /* Default: Don't issue remote cmd */
2042 if (HPNA_NoiseFloor
> 15)
2043 HPNA_NoiseFloor
= 0;
2045 rc
= pci_module_init(&dmfe_driver
);
2055 * when user used rmmod to delete module, system invoked clean_module()
2056 * to un-register all registered services.
2059 static void __exit
dmfe_cleanup_module(void)
2061 DMFE_DBUG(0, "dmfe_clean_module() ", debug
);
2062 pci_unregister_driver(&dmfe_driver
);
2065 module_init(dmfe_init_module
);
2066 module_exit(dmfe_cleanup_module
);