2 * RDC R6040 Fast Ethernet MAC support
4 * Copyright (C) 2004 Sten Wang <sten.wang@rdc.com.tw>
6 * Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
7 * Florian Fainelli <florian@openwrt.org>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/version.h>
28 #include <linux/moduleparam.h>
29 #include <linux/string.h>
30 #include <linux/timer.h>
31 #include <linux/errno.h>
32 #include <linux/ioport.h>
33 #include <linux/slab.h>
34 #include <linux/interrupt.h>
35 #include <linux/pci.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <linux/skbuff.h>
39 #include <linux/init.h>
40 #include <linux/delay.h>
41 #include <linux/mii.h>
42 #include <linux/ethtool.h>
43 #include <linux/crc32.h>
44 #include <linux/spinlock.h>
45 #include <linux/bitops.h>
47 #include <linux/irq.h>
48 #include <linux/uaccess.h>
50 #include <asm/processor.h>
52 #define DRV_NAME "r6040"
53 #define DRV_VERSION "0.19"
54 #define DRV_RELDATE "16Jun2008"
56 /* define bits of a debug mask */
57 #define DBG_PHY 0x00000001 /*!< show PHY read/write */
58 #define DBG_FREE_BUFS 0x00000002 /*!< show calls to r6040_free_*bufs */
59 #define DBG_RING 0x00000004 /*!< debug init./freeing of descr rings */
60 #define DBG_RX_BUF 0x00000008 /*!< show alloc. of new rx buf (in IRQ context !) */
61 #define DBG_TX_BUF 0x00000010 /*!< show arrival of new tx buf */
62 #define DBG_TX_DONE 0x00000020 /*!< debug TX done */
63 #define DBG_RX_DESCR 0x00000040 /*!< debug rx descr to be processed */
64 #define DBG_RX_DATA 0x00000080 /*!< show some user data of incoming packet */
65 #define DBG_EXIT 0x00000100 /*!< show exit code calls */
66 #define DBG_INIT 0x00000200 /*!< show init. code calls */
67 #define DBG_TX_RING_DUMP 0x00000400 /*!< dump the tx ring after creation */
68 #define DBG_RX_RING_DUMP 0x00000800 /*!< dump the rx ring after creation */
69 #define DBG_TX_DESCR 0x00001000 /*!< dump the setting of a descr for tx */
70 #define DBG_TX_DATA 0x00002000 /*!< dump some tx data */
71 #define DBG_IRQ 0x00004000 /*!< print inside the irq handler */
72 #define DBG_POLL 0x00008000 /*!< dump info on poll procedure */
73 #define DBG_MAC_ADDR 0x00010000 /*!< debug mac address setting */
74 #define DBG_OPEN 0x00020000 /*!< debug open proc. */
77 module_param(debug
, int, 0);
78 MODULE_PARM_DESC(debug
, "debug mask (-1 for all)");
80 /* define which debugs are left in the code during compilation */
81 #define DEBUG (-1) /* all debugs */
83 #define dbg(l, f, ...) \
85 if ((DEBUG & l) && (debug & l)) { \
86 printk(KERN_INFO DRV_NAME " %s: " f, __FUNCTION__, ## __VA_ARGS__); \
90 #define err(f, ...) printk(KERN_WARNING DRV_NAME " %s: " f, __FUNCTION__, ## __VA_ARGS__)
92 /* PHY CHIP Address */
93 #define PHY1_ADDR 1 /* For MAC1 */
94 #define PHY2_ADDR 2 /* For MAC2 */
95 #define PHY_MODE 0x3100 /* PHY CHIP Register 0 */
96 #define PHY_CAP 0x01E1 /* PHY CHIP Register 4 */
98 /* Time in jiffies before concluding the transmitter is hung. */
99 #define TX_TIMEOUT (6000 * HZ / 1000)
101 /* RDC MAC I/O Size */
102 #define R6040_IO_SIZE 256
108 #define MCR0 0x00 /* Control register 0 */
109 #define MCR1 0x04 /* Control register 1 */
110 #define MAC_RST 0x0001 /* Reset the MAC */
111 #define MBCR 0x08 /* Bus control */
112 #define MT_ICR 0x0C /* TX interrupt control */
113 #define MR_ICR 0x10 /* RX interrupt control */
114 #define MTPR 0x14 /* TX poll command register */
115 #define MR_BSR 0x18 /* RX buffer size */
116 #define MR_DCR 0x1A /* RX descriptor control */
117 #define MLSR 0x1C /* Last status */
118 #define MMDIO 0x20 /* MDIO control register */
119 #define MDIO_WRITE 0x4000 /* MDIO write */
120 #define MDIO_READ 0x2000 /* MDIO read */
121 #define MMRD 0x24 /* MDIO read data register */
122 #define MMWD 0x28 /* MDIO write data register */
123 #define MTD_SA0 0x2C /* TX descriptor start address 0 */
124 #define MTD_SA1 0x30 /* TX descriptor start address 1 */
125 #define MRD_SA0 0x34 /* RX descriptor start address 0 */
126 #define MRD_SA1 0x38 /* RX descriptor start address 1 */
127 #define MISR 0x3C /* Status register */
128 #define MIER 0x40 /* INT enable register */
129 #define MSK_INT 0x0000 /* Mask off interrupts */
130 #define RX_FINISH 0x0001 /* rx finished irq */
131 #define RX_NO_DESC 0x0002 /* rx no descr. avail. irq */
132 #define RX_FIFO_FULL 0x0004 /* rx fifo full irq */
133 #define RX_EARLY 0x0008 /* rx early irq */
134 #define TX_FINISH 0x0010 /* tx finished irq */
135 #define TX_EARLY 0x0080 /* tx early irq */
136 #define EVENT_OVRFL 0x0100 /* event counter overflow irq */
137 #define LINK_CHANGED 0x0200 /* PHY link changed irq */
139 #define ME_CISR 0x44 /* Event counter INT status */
140 #define ME_CIER 0x48 /* Event counter INT enable */
141 #define MR_CNT 0x50 /* Successfully received packet counter */
142 #define ME_CNT0 0x52 /* Event counter 0 */
143 #define ME_CNT1 0x54 /* Event counter 1 */
144 #define ME_CNT2 0x56 /* Event counter 2 */
145 #define ME_CNT3 0x58 /* Event counter 3 */
146 #define MT_CNT 0x5A /* Successfully transmit packet counter */
147 #define ME_CNT4 0x5C /* Event counter 4 */
148 #define MP_CNT 0x5E /* Pause frame counter register */
149 #define MAR0 0x60 /* Hash table 0 */
150 #define MAR1 0x62 /* Hash table 1 */
151 #define MAR2 0x64 /* Hash table 2 */
152 #define MAR3 0x66 /* Hash table 3 */
153 #define MID_0L 0x68 /* Multicast address MID0 Low */
154 #define MID_0M 0x6A /* Multicast address MID0 Medium */
155 #define MID_0H 0x6C /* Multicast address MID0 High */
156 #define MID_1L 0x70 /* MID1 Low */
157 #define MID_1M 0x72 /* MID1 Medium */
158 #define MID_1H 0x74 /* MID1 High */
159 #define MID_2L 0x78 /* MID2 Low */
160 #define MID_2M 0x7A /* MID2 Medium */
161 #define MID_2H 0x7C /* MID2 High */
162 #define MID_3L 0x80 /* MID3 Low */
163 #define MID_3M 0x82 /* MID3 Medium */
164 #define MID_3H 0x84 /* MID3 High */
165 #define PHY_CC 0x88 /* PHY status change configuration register */
166 #define PHY_ST 0x8A /* PHY status register */
167 #define MAC_SM 0xAC /* MAC status machine */
168 #define MAC_ID 0xBE /* Identifier register */
170 #define TX_DCNT 0x80 /* TX descriptor count */
171 #define RX_DCNT 0x80 /* RX descriptor count */
172 #define MAX_BUF_SIZE 0x600
173 #define RX_DESC_SIZE (RX_DCNT * sizeof(struct r6040_descriptor))
174 #define TX_DESC_SIZE (TX_DCNT * sizeof(struct r6040_descriptor))
175 #define MBCR_DEFAULT 0x012A /* MAC Bus Control Register:
176 - wait 1 host clock until SDRAM bus request
177 becomes high priority
180 - FIFO transfer length: 16 byte */
181 #define MCAST_MAX 4 /* Max number multicast addresses to filter */
184 #define ICPLUS_PHY_ID 0x0243
186 MODULE_AUTHOR("Sten Wang <sten.wang@rdc.com.tw>,"
187 "Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>,"
188 "Florian Fainelli <florian@openwrt.org>");
189 MODULE_LICENSE("GPL");
190 MODULE_DESCRIPTION("RDC R6040 NAPI PCI FastEthernet driver");
192 /*! which rx interrupts do we allow */
193 #define RX_INTS (RX_FIFO_FULL|RX_NO_DESC|RX_FINISH)
194 /*! which tx interrupts do we allow */
195 #define TX_INTS (TX_FINISH)
196 #define INT_MASK (RX_INTS | TX_INTS)
198 struct r6040_descriptor
{
199 u16 status
, len
; /* 0-3 */
200 __le32 buf
; /* 4-7 */
201 __le32 ndesc
; /* 8-B */
203 char *vbufp
; /* 10-13 */
204 struct r6040_descriptor
*vndescp
; /* 14-17 */
205 struct sk_buff
*skb_ptr
; /* 18-1B */
206 u32 rev2
; /* 1C-1F */
207 } __attribute__((aligned(32)));
209 /*! defines for the status field in the r6040_descriptor */
210 #define DESC_STATUS_OWNER_MAC (1<<15) /*!< if set the MAC is the owner of this descriptor */
211 #define DESC_STATUS_RX_OK (1<<14) /*!< rx was successful */
212 #define DESC_STATUS_RX_ERR (1<<11) /*!< rx PHY error */
213 #define DESC_STATUS_RX_ERR_DRIBBLE (1<<10) /*!< rx dribble packet */
214 #define DESC_STATUS_RX_ERR_BUFLEN (1<< 9) /*!< rx length exceeded buffer size */
215 #define DESC_STATUS_RX_ERR_LONG (1<< 8) /*!< rx length > maximum packet length */
216 #define DESC_STATUS_RX_ERR_RUNT (1<< 7) /*!< rx: packet length < 64 byte */
217 #define DESC_STATUS_RX_ERR_CRC (1<< 6) /*!< rx: crc error */
218 #define DESC_STATUS_RX_BROADCAST (1<< 5) /*!< rx: broadcast (no error) */
219 #define DESC_STATUS_RX_MULTICAST (1<< 4) /*!< rx: multicast (no error) */
220 #define DESC_STATUS_RX_MCH_HIT (1<< 3) /*!< rx: multicast hit in hash table (no error) */
221 #define DESC_STATUS_RX_MIDH_HIT (1<< 2) /*!< rx: MID table hit (no error) */
222 #define DESC_STATUS_RX_IDX_MID_MASK 3 /*!< rx: mask for the index of matched MIDx */
224 struct r6040_private
{
225 spinlock_t lock
; /* driver lock */
226 struct timer_list timer
;
227 struct pci_dev
*pdev
;
228 struct r6040_descriptor
*rx_insert_ptr
;
229 struct r6040_descriptor
*rx_remove_ptr
;
230 struct r6040_descriptor
*tx_insert_ptr
;
231 struct r6040_descriptor
*tx_remove_ptr
;
232 struct r6040_descriptor
*rx_ring
;
233 struct r6040_descriptor
*tx_ring
;
234 dma_addr_t rx_ring_dma
;
235 dma_addr_t tx_ring_dma
;
236 u16 tx_free_desc
, phy_addr
, phy_mode
;
239 struct net_device
*dev
;
240 struct mii_if_info mii_if
;
241 struct napi_struct napi
;
245 struct net_device
*parent_dev
;
246 static char *parent
= "wlan0";
247 module_param(parent
, charp
, 0444);
248 MODULE_PARM_DESC(parent
, "Parent network device name to get the MAC address from");
250 static char version
[] __devinitdata
= KERN_INFO DRV_NAME
251 ": RDC R6040 NAPI net driver,"
252 "version "DRV_VERSION
" (" DRV_RELDATE
")\n";
254 static int phy_table
[] = { PHY1_ADDR
, PHY2_ADDR
};
256 /* forward declarations */
257 void r6040_multicast_list(struct net_device
*dev
);
259 /* jal2: comment out to get more symbols for debugging */
260 //#define STATIC static
264 /*! hexdump an memory area into a string. delim is taken as the delimiter between two bytes.
265 It is omitted if delim == '\0' */
266 STATIC
char *hex2str(void *addr
, char *buf
, int nr_bytes
, int delim
)
268 unsigned char *src
= addr
;
271 #define BIN2HEXDIGIT(x) ((x) < 10 ? '0'+(x) : 'A'-10+(x))
273 while (nr_bytes
> 0) {
274 *outb
++ = BIN2HEXDIGIT(*src
>>4);
275 *outb
++ = BIN2HEXDIGIT(*src
&0xf);
288 #endif /* #if DEBUG */
290 /* Read a word data from PHY Chip */
291 STATIC
int phy_read(void __iomem
*ioaddr
, int phy_addr
, int reg
)
297 iowrite16(MDIO_READ
+ reg
+ (phy_addr
<< 8), ioaddr
+ MMDIO
);
298 /* Wait for the read bit to be cleared */
300 cmd
= ioread16(ioaddr
+ MMDIO
);
306 err("phy addr x%x reg x%x timed out\n",
309 rc
=ioread16(ioaddr
+ MMRD
);
311 dbg(DBG_PHY
, "phy addr x%x reg x%x val x%x\n", phy_addr
, reg
, rc
);
315 /* Write a word data from PHY Chip */
316 STATIC
void phy_write(void __iomem
*ioaddr
, int phy_addr
, int reg
, u16 val
)
321 dbg(DBG_PHY
, "phy addr x%x reg x%x val x%x\n", phy_addr
, reg
, val
);
323 iowrite16(val
, ioaddr
+ MMWD
);
324 /* Write the command to the MDIO bus */
325 iowrite16(MDIO_WRITE
+ reg
+ (phy_addr
<< 8), ioaddr
+ MMDIO
);
326 /* Wait for the write bit to be cleared */
328 cmd
= ioread16(ioaddr
+ MMDIO
);
329 if (cmd
& MDIO_WRITE
)
333 err("phy addr x%x reg x%x val x%x timed out\n",
337 STATIC
int mdio_read(struct net_device
*dev
, int mii_id
, int reg
)
339 struct r6040_private
*lp
= netdev_priv(dev
);
340 void __iomem
*ioaddr
= lp
->base
;
342 return (phy_read(ioaddr
, lp
->phy_addr
, reg
));
345 STATIC
void mdio_write(struct net_device
*dev
, int mii_id
, int reg
, int val
)
347 struct r6040_private
*lp
= netdev_priv(dev
);
348 void __iomem
*ioaddr
= lp
->base
;
350 phy_write(ioaddr
, lp
->phy_addr
, reg
, val
);
353 void r6040_free_txbufs(struct net_device
*dev
)
355 struct r6040_private
*lp
= netdev_priv(dev
);
358 dbg(DBG_FREE_BUFS
, "ENTER\n");
359 for (i
= 0; i
< TX_DCNT
; i
++) {
360 if (lp
->tx_insert_ptr
->skb_ptr
) {
361 pci_unmap_single(lp
->pdev
,
362 le32_to_cpu(lp
->tx_insert_ptr
->buf
),
363 MAX_BUF_SIZE
, PCI_DMA_TODEVICE
);
364 dev_kfree_skb(lp
->tx_insert_ptr
->skb_ptr
);
365 lp
->rx_insert_ptr
->skb_ptr
= NULL
;
367 lp
->tx_insert_ptr
= lp
->tx_insert_ptr
->vndescp
;
369 dbg(DBG_FREE_BUFS
, "EXIT\n");
372 /*! unmap and free all rx skb */
373 void r6040_free_rxbufs(struct net_device
*dev
)
375 struct r6040_private
*lp
= netdev_priv(dev
);
378 dbg(DBG_FREE_BUFS
, "ENTER\n");
379 for (i
= 0; i
< RX_DCNT
; i
++) {
380 if (lp
->rx_insert_ptr
->skb_ptr
) {
381 pci_unmap_single(lp
->pdev
,
382 le32_to_cpu(lp
->rx_insert_ptr
->buf
),
383 MAX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
384 dev_kfree_skb(lp
->rx_insert_ptr
->skb_ptr
);
385 lp
->rx_insert_ptr
->skb_ptr
= NULL
;
387 lp
->rx_insert_ptr
= lp
->rx_insert_ptr
->vndescp
;
389 dbg(DBG_FREE_BUFS
, "EXIT\n");
393 void r6040_init_ring_desc(struct r6040_descriptor
*desc_ring
,
394 dma_addr_t desc_dma
, int size
)
396 struct r6040_descriptor
*desc
= desc_ring
;
397 dma_addr_t mapping
= desc_dma
;
399 dbg(DBG_RING
, "desc_ring %p desc_dma %08x size x%x\n",
400 desc_ring
, desc_dma
, size
);
404 mapping
+= sizeof(*desc
);
405 memset(desc
, 0, sizeof(*desc
));
406 desc
->ndesc
= cpu_to_le32(mapping
);
407 desc
->vndescp
= desc
+ 1;
411 /* last descriptor points to first one to close the descriptor ring */
413 desc
->ndesc
= cpu_to_le32(desc_dma
);
414 desc
->vndescp
= desc_ring
;
417 #if (DEBUG & DBG_TX_RING_DUMP)
418 /*! dump the tx ring to syslog */
420 dump_tx_ring(struct r6040_private
*lp
)
423 struct r6040_descriptor
*ptr
;
425 printk(KERN_INFO
"%s: nr_desc x%x tx_ring %p tx_ring_dma %08x "
426 "tx_insert %p tx_remove %p\n",
427 DRV_NAME
, TX_DCNT
, lp
->tx_ring
, lp
->tx_ring_dma
,
428 lp
->tx_insert_ptr
, lp
->tx_remove_ptr
);
431 for(i
=0, ptr
=lp
->tx_ring
; i
< TX_DCNT
; i
++, ptr
++) {
432 printk(KERN_INFO
"%s: %d. descr: status x%x len x%x "
433 "ndesc %08x vbufp %p vndescp %p skb_ptr %p\n",
434 DRV_NAME
, i
, ptr
->status
, ptr
->len
,
435 ptr
->ndesc
, ptr
->vbufp
, ptr
->vndescp
, ptr
->skb_ptr
);
439 #endif /* #if (DEBUG & DBG_TX_RING_DUMP) */
441 void r6040_init_txbufs(struct net_device
*dev
)
443 struct r6040_private
*lp
= netdev_priv(dev
);
445 lp
->tx_free_desc
= TX_DCNT
;
447 lp
->tx_remove_ptr
= lp
->tx_insert_ptr
= lp
->tx_ring
;
448 r6040_init_ring_desc(lp
->tx_ring
, lp
->tx_ring_dma
, TX_DCNT
);
450 #if (DEBUG & DBG_TX_RING_DUMP)
451 if (debug
& DBG_TX_RING_DUMP
) {
457 #if (DEBUG & DBG_RX_RING_DUMP)
458 /*! dump the rx ring to syslog */
460 dump_rx_ring(struct r6040_private
*lp
)
463 struct r6040_descriptor
*ptr
;
465 printk(KERN_INFO
"%s: nr_desc x%x rx_ring %p rx_ring_dma %08x "
466 "rx_insert %p rx_remove %p\n",
467 DRV_NAME
, RX_DCNT
, lp
->rx_ring
, lp
->rx_ring_dma
,
468 lp
->rx_insert_ptr
, lp
->rx_remove_ptr
);
471 for(i
=0, ptr
=lp
->rx_ring
; i
< RX_DCNT
; i
++, ptr
++) {
472 printk(KERN_INFO
"%s: %d. descr: status x%x len x%x "
473 "ndesc %08x vbufp %p vndescp %p skb_ptr %p\n",
474 DRV_NAME
, i
, ptr
->status
, ptr
->len
,
475 ptr
->ndesc
, ptr
->vbufp
, ptr
->vndescp
, ptr
->skb_ptr
);
479 #endif /* #if (DEBUG & DBG_TX_RING_DUMP) */
481 int r6040_alloc_rxbufs(struct net_device
*dev
)
483 struct r6040_private
*lp
= netdev_priv(dev
);
484 struct r6040_descriptor
*desc
;
488 lp
->rx_remove_ptr
= lp
->rx_insert_ptr
= lp
->rx_ring
;
489 r6040_init_ring_desc(lp
->rx_ring
, lp
->rx_ring_dma
, RX_DCNT
);
491 /* alloc skbs for the rx descriptors */
494 if (!(skb
=netdev_alloc_skb(dev
, MAX_BUF_SIZE
))) {
495 err("failed to alloc skb for rx\n");
500 desc
->buf
= cpu_to_le32(pci_map_single(lp
->pdev
,
502 MAX_BUF_SIZE
, PCI_DMA_FROMDEVICE
));
503 desc
->status
= DESC_STATUS_OWNER_MAC
;
504 desc
= desc
->vndescp
;
505 } while (desc
!= lp
->rx_ring
);
507 #if (DEBUG & DBG_RX_RING_DUMP)
508 if (debug
& DBG_RX_RING_DUMP
) {
516 /* dealloc all previously allocated skb */
517 r6040_free_rxbufs(dev
);
521 /*! reset MAC and set all registers */
522 void r6040_init_mac_regs(struct r6040_private
*lp
)
524 void __iomem
*ioaddr
= lp
->base
;
526 char obuf
[3*ETH_ALEN
] __attribute__ ((unused
));
528 /* Mask Off Interrupt */
529 iowrite16(MSK_INT
, ioaddr
+ MIER
);
532 iowrite16(MAC_RST
, ioaddr
+ MCR1
);
535 while ((ioread16(ioaddr
+ MCR1
) & MAC_RST
) && limit
-- > 0);
537 /* Reset internal state machine */
538 iowrite16(2, ioaddr
+ MAC_SM
);
539 iowrite16(0, ioaddr
+ MAC_SM
);
542 /* Restore MAC Addresses */
543 r6040_multicast_list(lp
->dev
);
545 /* TODO: restore multcast and hash table */
547 /* MAC Bus Control Register */
548 iowrite16(MBCR_DEFAULT
, ioaddr
+ MBCR
);
550 /* Buffer Size Register */
551 iowrite16(MAX_BUF_SIZE
, ioaddr
+ MR_BSR
);
553 /* write tx ring start address */
554 iowrite16(lp
->tx_ring_dma
, ioaddr
+ MTD_SA0
);
555 iowrite16(lp
->tx_ring_dma
>> 16, ioaddr
+ MTD_SA1
);
557 /* write rx ring start address */
558 iowrite16(lp
->rx_ring_dma
, ioaddr
+ MRD_SA0
);
559 iowrite16(lp
->rx_ring_dma
>> 16, ioaddr
+ MRD_SA1
);
561 /* set interrupt waiting time and packet numbers */
562 iowrite16(0, ioaddr
+ MT_ICR
);
563 iowrite16(0, ioaddr
+ MR_ICR
);
565 /* enable interrupts */
566 iowrite16(INT_MASK
, ioaddr
+ MIER
);
568 /* enable tx and rx */
569 iowrite16(lp
->mcr0
| 0x0002, ioaddr
);
571 /* let TX poll the descriptors - we may got called by r6040_tx_timeout which has left
572 some unsent tx buffers */
573 iowrite16(0x01, ioaddr
+ MTPR
);
576 void r6040_tx_timeout(struct net_device
*dev
)
578 struct r6040_private
*priv
= netdev_priv(dev
);
579 void __iomem
*ioaddr
= priv
->base
;
581 /* we read MISR, which clears on read (i.e. we may loose an RX interupt,
582 but this is an error anyhow ... */
583 printk(KERN_WARNING
"%s: transmit timed out, int enable %4.4x "
584 "status %4.4x, PHY status %4.4x\n",
585 dev
->name
, ioread16(ioaddr
+ MIER
),
586 ioread16(ioaddr
+ MISR
),
587 mdio_read(dev
, priv
->mii_if
.phy_id
, MII_BMSR
));
589 dev
->stats
.tx_errors
++;
591 /* Reset MAC and re-init all registers */
592 r6040_init_mac_regs(priv
);
595 struct net_device_stats
*r6040_get_stats(struct net_device
*dev
)
597 struct r6040_private
*priv
= netdev_priv(dev
);
598 void __iomem
*ioaddr
= priv
->base
;
601 spin_lock_irqsave(&priv
->lock
, flags
);
602 dev
->stats
.rx_crc_errors
+= ioread8(ioaddr
+ ME_CNT1
);
603 dev
->stats
.multicast
+= ioread8(ioaddr
+ ME_CNT0
);
604 spin_unlock_irqrestore(&priv
->lock
, flags
);
609 /* Stop RDC MAC and Free the allocated resource */
610 void r6040_down(struct net_device
*dev
)
612 struct r6040_private
*lp
= netdev_priv(dev
);
613 void __iomem
*ioaddr
= lp
->base
;
614 struct pci_dev
*pdev
= lp
->pdev
;
617 dbg(DBG_EXIT
, "ENTER\n");
620 iowrite16(MSK_INT
, ioaddr
+ MIER
); /* Mask Off Interrupt */
621 iowrite16(MAC_RST
, ioaddr
+ MCR1
); /* Reset RDC MAC */
623 while ((ioread16(ioaddr
+MCR1
) & 1) && limit
-- > 0);
626 err("timeout while waiting for reset done.\n");
628 free_irq(dev
->irq
, dev
);
631 r6040_free_rxbufs(dev
);
634 r6040_free_txbufs(dev
);
636 /* Free Descriptor memory */
637 pci_free_consistent(pdev
, RX_DESC_SIZE
, lp
->rx_ring
, lp
->rx_ring_dma
);
638 pci_free_consistent(pdev
, TX_DESC_SIZE
, lp
->tx_ring
, lp
->tx_ring_dma
);
640 dbg(DBG_EXIT
, "EXIT\n");
643 int r6040_close(struct net_device
*dev
)
645 struct r6040_private
*lp
= netdev_priv(dev
);
647 dbg(DBG_EXIT
, "ENTER\n");
650 del_timer_sync(&lp
->timer
);
651 spin_lock_irq(&lp
->lock
);
652 napi_disable(&lp
->napi
);
653 netif_stop_queue(dev
);
655 spin_unlock_irq(&lp
->lock
);
657 dbg(DBG_EXIT
, "EXIT\n");
661 /* Status of PHY CHIP. Returns 0x8000 for full duplex, 0 for half duplex */
662 STATIC
int phy_mode_chk(struct net_device
*dev
)
664 struct r6040_private
*lp
= netdev_priv(dev
);
665 void __iomem
*ioaddr
= lp
->base
;
668 /* PHY Link Status Check */
669 phy_dat
= phy_read(ioaddr
, lp
->phy_addr
, 1);
670 if (!(phy_dat
& 0x4))
671 phy_dat
= 0x8000; /* Link Failed, full duplex */
673 /* PHY Chip Auto-Negotiation Status */
674 phy_dat
= phy_read(ioaddr
, lp
->phy_addr
, 1);
675 if (phy_dat
& 0x0020) {
676 /* Auto Negotiation Mode */
677 phy_dat
= phy_read(ioaddr
, lp
->phy_addr
, 5);
678 phy_dat
&= phy_read(ioaddr
, lp
->phy_addr
, 4);
680 /* Force full duplex */
686 phy_dat
= phy_read(ioaddr
, lp
->phy_addr
, 0);
693 dbg(DBG_PHY
, "RETURN x%x\n", phy_dat
);
697 void r6040_set_carrier(struct mii_if_info
*mii
)
699 if (phy_mode_chk(mii
->dev
)) {
700 /* autoneg is off: Link is always assumed to be up */
701 if (!netif_carrier_ok(mii
->dev
))
702 netif_carrier_on(mii
->dev
);
704 phy_mode_chk(mii
->dev
);
707 int r6040_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
709 struct r6040_private
*lp
= netdev_priv(dev
);
710 struct mii_ioctl_data
*data
= if_mii(rq
);
713 if (!netif_running(dev
))
715 spin_lock_irq(&lp
->lock
);
716 rc
= generic_mii_ioctl(&lp
->mii_if
, data
, cmd
, NULL
);
717 spin_unlock_irq(&lp
->lock
);
718 r6040_set_carrier(&lp
->mii_if
);
722 int r6040_rx(struct net_device
*dev
, int limit
)
724 struct r6040_private
*priv
= netdev_priv(dev
);
726 struct r6040_descriptor
*descptr
= priv
->rx_remove_ptr
;
727 struct sk_buff
*skb_ptr
, *new_skb
;
728 char obuf
[2*32+1] __attribute__ ((unused
)); /* for debugging */
730 while (count
< limit
&& !(descptr
->status
& DESC_STATUS_OWNER_MAC
)) {
731 /* limit not reached and the descriptor belongs to the CPU */
733 dbg(DBG_RX_DESCR
, "descptr %p status x%x data len x%x\n",
734 descptr
, descptr
->status
, descptr
->len
);
736 /* Check for errors */
737 if (descptr
->status
& DESC_STATUS_RX_ERR
) {
739 dev
->stats
.rx_errors
++;
741 if (descptr
->status
& (DESC_STATUS_RX_ERR_DRIBBLE
|
742 DESC_STATUS_RX_ERR_BUFLEN
|
743 DESC_STATUS_RX_ERR_LONG
|
744 DESC_STATUS_RX_ERR_RUNT
)) {
745 /* packet too long or too short*/
746 dev
->stats
.rx_length_errors
++;
749 if (descptr
->status
& DESC_STATUS_RX_ERR_CRC
) {
750 dev
->stats
.rx_crc_errors
++;
755 /* successful received packet */
757 /* first try to allocate new skb. If this fails
758 we drop the packet and leave the old skb there.*/
759 new_skb
= netdev_alloc_skb(dev
, MAX_BUF_SIZE
);
761 dev
->stats
.rx_dropped
++;
764 skb_ptr
= descptr
->skb_ptr
;
765 skb_ptr
->dev
= priv
->dev
;
766 /* Do not count the CRC */
767 skb_put(skb_ptr
, descptr
->len
- 4);
768 pci_unmap_single(priv
->pdev
, le32_to_cpu(descptr
->buf
),
769 MAX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
770 skb_ptr
->protocol
= eth_type_trans(skb_ptr
, priv
->dev
);
772 dbg(DBG_RX_DATA
, "rx len x%x: %s...\n",
774 hex2str(skb_ptr
->data
, obuf
, sizeof(obuf
)/2, '\0'));
776 /* Send to upper layer */
777 netif_receive_skb(skb_ptr
);
778 dev
->last_rx
= jiffies
;
779 dev
->stats
.rx_packets
++;
780 dev
->stats
.rx_bytes
+= (descptr
->len
-4);
782 /* put new skb into descriptor */
783 descptr
->skb_ptr
= new_skb
;
784 descptr
->buf
= cpu_to_le32(pci_map_single(priv
->pdev
,
785 descptr
->skb_ptr
->data
,
786 MAX_BUF_SIZE
, PCI_DMA_FROMDEVICE
));
789 /* put the descriptor back to the MAC */
790 descptr
->status
= DESC_STATUS_OWNER_MAC
;
791 descptr
= descptr
->vndescp
;
792 count
++; /* shall we count errors and dropped packets as well? */
793 } /* while (limit && !(descptr->status & DESC_STATUS_OWNER_MAC)) */
795 /* remember next descriptor to check for rx */
796 priv
->rx_remove_ptr
= descptr
;
801 void r6040_tx(struct net_device
*dev
)
803 struct r6040_private
*priv
= netdev_priv(dev
);
804 struct r6040_descriptor
*descptr
;
805 void __iomem
*ioaddr
= priv
->base
;
806 struct sk_buff
*skb_ptr
;
809 spin_lock(&priv
->lock
);
810 descptr
= priv
->tx_remove_ptr
;
811 while (priv
->tx_free_desc
< TX_DCNT
) {
812 /* Check for errors */
813 err
= ioread16(ioaddr
+ MLSR
);
816 dev
->stats
.rx_fifo_errors
++;
817 if (err
& (0x2000 | 0x4000))
818 dev
->stats
.tx_carrier_errors
++;
820 dbg(DBG_TX_DONE
, "descptr %p status x%x err x%x jiffies %lu\n",
821 descptr
, descptr
->status
, err
, jiffies
);
823 if (descptr
->status
& 0x8000)
824 break; /* Not complete */
825 skb_ptr
= descptr
->skb_ptr
;
826 pci_unmap_single(priv
->pdev
, le32_to_cpu(descptr
->buf
),
827 skb_ptr
->len
, PCI_DMA_TODEVICE
);
829 dev_kfree_skb_irq(skb_ptr
);
830 descptr
->skb_ptr
= NULL
;
831 /* To next descriptor */
832 descptr
= descptr
->vndescp
;
833 priv
->tx_free_desc
++;
835 priv
->tx_remove_ptr
= descptr
;
837 if (priv
->tx_free_desc
)
838 netif_wake_queue(dev
);
839 spin_unlock(&priv
->lock
);
842 int r6040_poll(struct napi_struct
*napi
, int budget
)
844 struct r6040_private
*priv
=
845 container_of(napi
, struct r6040_private
, napi
);
846 struct net_device
*dev
= priv
->dev
;
847 void __iomem
*ioaddr
= priv
->base
;
850 work_done
= r6040_rx(dev
, budget
);
852 dbg(DBG_POLL
, "budget x%x done x%x\n", budget
, work_done
);
854 if (work_done
< budget
) {
855 netif_rx_complete(dev
, napi
);
856 /* Enable RX interrupt */
857 iowrite16(ioread16(ioaddr
+ MIER
) | RX_INTS
, ioaddr
+ MIER
);
862 /* The RDC interrupt handler. */
863 irqreturn_t
r6040_interrupt(int irq
, void *dev_id
)
865 struct net_device
*dev
= dev_id
;
866 struct r6040_private
*lp
= netdev_priv(dev
);
867 void __iomem
*ioaddr
= lp
->base
;
870 /* Read MISR status and clear */
871 status
= ioread16(ioaddr
+ MISR
);
873 dbg(DBG_IRQ
, "status x%x jiffies %lu\n", status
, jiffies
);
875 if (status
== 0x0000 || status
== 0xffff)
878 /* rx early / rx finish interrupt
879 or rx descriptor unavail. */
880 if (status
& RX_INTS
) {
881 if (status
& RX_NO_DESC
) {
882 /* rx descriptor unavail. */
883 dev
->stats
.rx_dropped
++;
884 dev
->stats
.rx_missed_errors
++;
886 /* Mask off RX interrupts */
887 iowrite16(ioread16(ioaddr
+ MIER
) & ~RX_INTS
, ioaddr
+ MIER
);
888 netif_rx_schedule(dev
, &lp
->napi
);
892 if (status
& RX_FIFO_FULL
) {
893 dev
->stats
.rx_fifo_errors
++;
896 /* TX interrupt request */
903 #ifdef CONFIG_NET_POLL_CONTROLLER
904 void r6040_poll_controller(struct net_device
*dev
)
906 disable_irq(dev
->irq
);
907 r6040_interrupt(dev
->irq
, dev
);
908 enable_irq(dev
->irq
);
913 int r6040_up(struct net_device
*dev
)
915 struct r6040_private
*lp
= netdev_priv(dev
);
916 void __iomem
*ioaddr
= lp
->base
;
919 dbg(DBG_INIT
, "ENTER\n");
921 /* Initialise and alloc RX/TX buffers */
922 r6040_init_txbufs(dev
);
923 if ((rc
=r6040_alloc_rxbufs(dev
)))
926 /* Read the PHY ID */
927 lp
->switch_sig
= phy_read(ioaddr
, 0, 2);
929 if (lp
->switch_sig
== ICPLUS_PHY_ID
) {
930 phy_write(ioaddr
, 29, 31, 0x175C); /* Enable registers */
931 lp
->phy_mode
= 0x8000;
934 phy_write(ioaddr
, lp
->phy_addr
, 4, PHY_CAP
);
935 phy_write(ioaddr
, lp
->phy_addr
, 0, PHY_MODE
);
937 if (PHY_MODE
== 0x3100)
938 lp
->phy_mode
= phy_mode_chk(dev
);
940 lp
->phy_mode
= (PHY_MODE
& 0x0100) ? 0x8000:0x0;
943 /* configure duplex mode */
944 lp
->mcr0
|= lp
->phy_mode
;
946 /* improve performance (by RDC guys) */
947 phy_write(ioaddr
, 30, 17, (phy_read(ioaddr
, 30, 17) | 0x4000));
948 phy_write(ioaddr
, 30, 17, ~((~phy_read(ioaddr
, 30, 17)) | 0x2000));
949 phy_write(ioaddr
, 0, 19, 0x0000);
950 phy_write(ioaddr
, 0, 30, 0x01F0);
952 /* Reset MAC and init all registers */
953 r6040_init_mac_regs(lp
);
959 A periodic timer routine
960 Polling PHY Chip Link Status
962 void r6040_timer(unsigned long data
)
964 struct net_device
*dev
= (struct net_device
*)data
;
965 struct r6040_private
*lp
= netdev_priv(dev
);
966 void __iomem
*ioaddr
= lp
->base
;
969 /* Polling PHY Chip Status */
970 if (PHY_MODE
== 0x3100)
971 phy_mode
= phy_mode_chk(dev
);
973 phy_mode
= (PHY_MODE
& 0x0100) ? 0x8000:0x0;
975 if (phy_mode
!= lp
->phy_mode
) {
976 lp
->phy_mode
= phy_mode
;
977 lp
->mcr0
= (lp
->mcr0
& 0x7fff) | phy_mode
;
978 iowrite16(lp
->mcr0
, ioaddr
);
979 printk(KERN_INFO
"Link Change x%x \n", ioread16(ioaddr
));
982 /* Timer active again */
983 mod_timer(&lp
->timer
, jiffies
+ round_jiffies(HZ
));
986 int r6040_open(struct net_device
*dev
)
988 struct r6040_private
*lp
= netdev_priv(dev
);
991 dbg(DBG_OPEN
, "ENTER\n");
992 /* Request IRQ and Register interrupt handler */
993 ret
= request_irq(dev
->irq
, &r6040_interrupt
,
994 IRQF_SHARED
, dev
->name
, dev
);
998 dbg(DBG_OPEN
, "got irq %d\n", dev
->irq
);
1000 /* Allocate Descriptor memory */
1002 pci_alloc_consistent(lp
->pdev
, RX_DESC_SIZE
, &lp
->rx_ring_dma
);
1006 dbg(DBG_OPEN
, "allocated rx ring\n");
1009 pci_alloc_consistent(lp
->pdev
, TX_DESC_SIZE
, &lp
->tx_ring_dma
);
1011 pci_free_consistent(lp
->pdev
, RX_DESC_SIZE
, lp
->rx_ring
,
1016 dbg(DBG_OPEN
, "allocated tx ring\n");
1018 if ((ret
=r6040_up(dev
))) {
1019 pci_free_consistent(lp
->pdev
, TX_DESC_SIZE
, lp
->tx_ring
,
1021 pci_free_consistent(lp
->pdev
, RX_DESC_SIZE
, lp
->rx_ring
,
1026 napi_enable(&lp
->napi
);
1027 netif_start_queue(dev
);
1029 /* set and active a timer process */
1030 setup_timer(&lp
->timer
, r6040_timer
, (unsigned long) dev
);
1031 if (lp
->switch_sig
!= ICPLUS_PHY_ID
)
1032 mod_timer(&lp
->timer
, jiffies
+ HZ
);
1036 int r6040_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1038 struct r6040_private
*lp
= netdev_priv(dev
);
1039 struct r6040_descriptor
*descptr
;
1040 void __iomem
*ioaddr
= lp
->base
;
1041 unsigned long flags
;
1042 int ret
= NETDEV_TX_OK
;
1044 /* Critical Section */
1045 spin_lock_irqsave(&lp
->lock
, flags
);
1047 /* TX resource check */
1048 if (!lp
->tx_free_desc
) {
1049 spin_unlock_irqrestore(&lp
->lock
, flags
);
1050 netif_stop_queue(dev
);
1051 printk(KERN_ERR DRV_NAME
": no tx descriptor\n");
1052 ret
= NETDEV_TX_BUSY
;
1056 /* Statistic Counter */
1057 dev
->stats
.tx_packets
++;
1058 dev
->stats
.tx_bytes
+= skb
->len
;
1059 /* Set TX descriptor & Transmit it */
1061 descptr
= lp
->tx_insert_ptr
;
1062 if (skb
->len
< MISR
)
1063 descptr
->len
= MISR
;
1065 descptr
->len
= skb
->len
;
1067 descptr
->skb_ptr
= skb
;
1068 descptr
->buf
= cpu_to_le32(pci_map_single(lp
->pdev
,
1069 skb
->data
, skb
->len
, PCI_DMA_TODEVICE
));
1071 dbg(DBG_TX_DESCR
, "desc @ %p: len x%x buf %08x skb->data %p skb->len x%x jiffies %lu\n",
1072 descptr
, descptr
->len
, descptr
->buf
, skb
->data
, skb
->len
, jiffies
);
1076 dbg(DBG_TX_DATA
, "tx len x%x: %s\n",
1077 descptr
->len
, hex2str(skb
->data
, obuf
, sizeof(obuf
)/2, '\0'));
1080 descptr
->status
= 0x8000;
1081 /* Trigger the MAC to check the TX descriptor */
1082 iowrite16(0x01, ioaddr
+ MTPR
);
1083 lp
->tx_insert_ptr
= descptr
->vndescp
;
1085 /* If no tx resource, stop */
1086 if (!lp
->tx_free_desc
)
1087 netif_stop_queue(dev
);
1089 dev
->trans_start
= jiffies
;
1090 spin_unlock_irqrestore(&lp
->lock
, flags
);
1094 /*! set MAC addresses and promiscous mode */
1095 void r6040_multicast_list(struct net_device
*dev
)
1097 struct r6040_private
*lp
= netdev_priv(dev
);
1098 void __iomem
*ioaddr
= lp
->base
;
1101 unsigned long flags
;
1102 struct dev_mc_list
*dmi
= dev
->mc_list
;
1104 char obuf
[3*ETH_ALEN
] __attribute__ ((unused
));
1107 adrp
= (u16
*)dev
->dev_addr
;
1108 iowrite16(adrp
[0], ioaddr
+ MID_0L
);
1109 iowrite16(adrp
[1], ioaddr
+ MID_0M
);
1110 iowrite16(adrp
[2], ioaddr
+ MID_0H
);
1112 dbg(DBG_MAC_ADDR
, "%s: set MAC addr %s\n",
1113 dev
->name
, hex2str(dev
->dev_addr
, obuf
, ETH_ALEN
, ':'));
1115 /* Promiscous Mode */
1116 spin_lock_irqsave(&lp
->lock
, flags
);
1118 /* Clear AMCP & PROM bits */
1119 reg
= ioread16(ioaddr
) & ~0x0120;
1120 if (dev
->flags
& IFF_PROMISC
) {
1124 /* Too many multicast addresses
1125 * accept all traffic */
1126 else if ((dev
->mc_count
> MCAST_MAX
)
1127 || (dev
->flags
& IFF_ALLMULTI
))
1130 iowrite16(reg
, ioaddr
);
1131 spin_unlock_irqrestore(&lp
->lock
, flags
);
1133 /* Build the hash table */
1134 if (dev
->mc_count
> MCAST_MAX
) {
1138 for (i
= 0; i
< 4; i
++)
1141 for (i
= 0; i
< dev
->mc_count
; i
++) {
1142 char *addrs
= dmi
->dmi_addr
;
1149 crc
= ether_crc_le(6, addrs
);
1151 hash_table
[crc
>> 4] |= 1 << (15 - (crc
& 0xf));
1153 /* Write the index of the hash table */
1154 for (i
= 0; i
< 4; i
++)
1155 iowrite16(hash_table
[i
] << 14, ioaddr
+ MCR1
);
1156 /* Fill the MAC hash tables with their values */
1157 iowrite16(hash_table
[0], ioaddr
+ MAR0
);
1158 iowrite16(hash_table
[1], ioaddr
+ MAR1
);
1159 iowrite16(hash_table
[2], ioaddr
+ MAR2
);
1160 iowrite16(hash_table
[3], ioaddr
+ MAR3
);
1162 /* Multicast Address 1~4 case */
1163 for (i
= 0, dmi
; (i
< dev
->mc_count
) && (i
< MCAST_MAX
); i
++) {
1164 adrp
= (u16
*)dmi
->dmi_addr
;
1165 iowrite16(adrp
[0], ioaddr
+ MID_1L
+ 8*i
);
1166 iowrite16(adrp
[1], ioaddr
+ MID_1M
+ 8*i
);
1167 iowrite16(adrp
[2], ioaddr
+ MID_1H
+ 8*i
);
1170 for (i
= dev
->mc_count
; i
< MCAST_MAX
; i
++) {
1171 iowrite16(0xffff, ioaddr
+ MID_0L
+ 8*i
);
1172 iowrite16(0xffff, ioaddr
+ MID_0M
+ 8*i
);
1173 iowrite16(0xffff, ioaddr
+ MID_0H
+ 8*i
);
1177 STATIC
void netdev_get_drvinfo(struct net_device
*dev
,
1178 struct ethtool_drvinfo
*info
)
1180 struct r6040_private
*rp
= netdev_priv(dev
);
1182 strcpy(info
->driver
, DRV_NAME
);
1183 strcpy(info
->version
, DRV_VERSION
);
1184 strcpy(info
->bus_info
, pci_name(rp
->pdev
));
1187 STATIC
int netdev_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1189 struct r6040_private
*rp
= netdev_priv(dev
);
1192 spin_lock_irq(&rp
->lock
);
1193 rc
= mii_ethtool_gset(&rp
->mii_if
, cmd
);
1194 spin_unlock_irq(&rp
->lock
);
1199 STATIC
int netdev_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1201 struct r6040_private
*rp
= netdev_priv(dev
);
1204 spin_lock_irq(&rp
->lock
);
1205 rc
= mii_ethtool_sset(&rp
->mii_if
, cmd
);
1206 spin_unlock_irq(&rp
->lock
);
1207 r6040_set_carrier(&rp
->mii_if
);
1212 STATIC u32
netdev_get_link(struct net_device
*dev
)
1214 struct r6040_private
*rp
= netdev_priv(dev
);
1216 return mii_link_ok(&rp
->mii_if
);
1219 static struct ethtool_ops netdev_ethtool_ops
= {
1220 .get_drvinfo
= netdev_get_drvinfo
,
1221 .get_settings
= netdev_get_settings
,
1222 .set_settings
= netdev_set_settings
,
1223 .get_link
= netdev_get_link
,
1226 int __devinit
r6040_init_one(struct pci_dev
*pdev
,
1227 const struct pci_device_id
*ent
)
1229 struct net_device
*dev
;
1230 struct r6040_private
*lp
;
1231 void __iomem
*ioaddr
;
1232 int err
, io_size
= R6040_IO_SIZE
;
1233 static int card_idx
= -1;
1237 printk(KERN_INFO
"%s\n", version
);
1238 printk(KERN_INFO DRV_NAME
": debug %x\n", debug
);
1240 err
= pci_enable_device(pdev
);
1244 /* this should always be supported */
1245 if (pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) {
1246 printk(KERN_ERR DRV_NAME
"32-bit PCI DMA addresses"
1247 "not supported by the card\n");
1250 if (pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
)) {
1251 printk(KERN_ERR DRV_NAME
"32-bit PCI DMA addresses"
1252 "not supported by the card\n");
1257 if (pci_resource_len(pdev
, 0) < io_size
) {
1258 printk(KERN_ERR
"Insufficient PCI resources, aborting\n");
1262 pioaddr
= pci_resource_start(pdev
, 0); /* IO map base address */
1263 pci_set_master(pdev
);
1265 dev
= alloc_etherdev(sizeof(struct r6040_private
));
1267 printk(KERN_ERR
"Failed to allocate etherdev\n");
1270 SET_NETDEV_DEV(dev
, &pdev
->dev
);
1271 lp
= netdev_priv(dev
);
1273 if (pci_request_regions(pdev
, DRV_NAME
)) {
1274 printk(KERN_ERR DRV_NAME
": Failed to request PCI regions\n");
1276 goto err_out_disable
;
1279 ioaddr
= pci_iomap(pdev
, bar
, io_size
);
1281 printk(KERN_ERR
"ioremap failed for device %s\n",
1286 /* Init system & device */
1288 dev
->irq
= pdev
->irq
;
1290 spin_lock_init(&lp
->lock
);
1291 pci_set_drvdata(pdev
, dev
);
1295 /* Link new device into r6040_root_dev */
1300 /* Init RDC private data */
1302 lp
->phy_addr
= phy_table
[card_idx
];
1305 /* The RDC-specific entries in the device structure. */
1306 dev
->open
= &r6040_open
;
1307 dev
->hard_start_xmit
= &r6040_start_xmit
;
1308 dev
->stop
= &r6040_close
;
1309 dev
->get_stats
= r6040_get_stats
;
1310 dev
->set_multicast_list
= &r6040_multicast_list
;
1311 dev
->do_ioctl
= &r6040_ioctl
;
1312 dev
->ethtool_ops
= &netdev_ethtool_ops
;
1313 dev
->tx_timeout
= &r6040_tx_timeout
;
1314 dev
->watchdog_timeo
= TX_TIMEOUT
;
1317 /* TODO: fix the setting of the MAC address.
1318 Right now you must either specify a netdevice with "parent=", whose
1319 address is copied or the (default) address of the Sitecom WL-153
1320 bootloader is used */
1321 static const u8 dflt_addr
[ETH_ALEN
] = {0,0x50,0xfc,2,3,4};
1323 memcpy(dev
->dev_addr
, parent_dev
->dev_addr
, ETH_ALEN
);
1325 printk(KERN_WARNING
"%s: no parent - using default mac address\n",
1327 memcpy(dev
->dev_addr
, dflt_addr
, ETH_ALEN
);
1329 dev
->dev_addr
[ETH_ALEN
-1] += card_idx
; /* + 0 or 1 */
1332 #ifdef CONFIG_NET_POLL_CONTROLLER
1333 dev
->poll_controller
= r6040_poll_controller
;
1335 netif_napi_add(dev
, &lp
->napi
, r6040_poll
, 64);
1336 lp
->mii_if
.dev
= dev
;
1337 lp
->mii_if
.mdio_read
= mdio_read
;
1338 lp
->mii_if
.mdio_write
= mdio_write
;
1339 lp
->mii_if
.phy_id
= lp
->phy_addr
;
1340 lp
->mii_if
.phy_id_mask
= 0x1f;
1341 lp
->mii_if
.reg_num_mask
= 0x1f;
1343 /* Register net device. After this dev->name assign */
1344 err
= register_netdev(dev
);
1346 printk(KERN_ERR DRV_NAME
": Failed to register net device\n");
1350 dbg(DBG_INIT
, "%s successfully registered\n", dev
->name
);
1354 pci_release_regions(pdev
);
1356 pci_disable_device(pdev
);
1357 pci_set_drvdata(pdev
, NULL
);
1363 void __devexit
r6040_remove_one(struct pci_dev
*pdev
)
1365 struct net_device
*dev
= pci_get_drvdata(pdev
);
1367 unregister_netdev(dev
);
1368 pci_release_regions(pdev
);
1370 pci_disable_device(pdev
);
1371 pci_set_drvdata(pdev
, NULL
);
1375 static struct pci_device_id r6040_pci_tbl
[] = {
1376 { PCI_DEVICE(PCI_VENDOR_ID_RDC
, 0x6040) },
1379 MODULE_DEVICE_TABLE(pci
, r6040_pci_tbl
);
1381 static struct pci_driver r6040_driver
= {
1383 .id_table
= r6040_pci_tbl
,
1384 .probe
= r6040_init_one
,
1385 .remove
= __devexit_p(r6040_remove_one
),
1389 static int __init
r6040_init(void)
1392 parent_dev
= dev_get_by_name(&init_net
, parent
);
1394 return pci_register_driver(&r6040_driver
);
1398 static void __exit
r6040_cleanup(void)
1400 pci_unregister_driver(&r6040_driver
);
1403 module_init(r6040_init
);
1404 module_exit(r6040_cleanup
);