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 static char *parent
= "wlan0";
246 module_param(parent
, charp
, 0444);
247 MODULE_PARM_DESC(parent
, "Parent network device name to get the MAC address from");
249 static u8 mac_base
[ETH_ALEN
] = {0,0x50,0xfc,2,3,4};
250 module_param_array(mac_base
, byte
, NULL
, 0444);
251 MODULE_PARM_DESC(mac_base
, "Starting MAC address");
253 static int reverse
= 1;
254 module_param(reverse
, invbool
, 0444);
255 MODULE_PARM_DESC(reverse
, "Reverse card indices");
257 static char version
[] __devinitdata
= DRV_NAME
258 ": RDC R6040 NAPI net driver,"
259 "version "DRV_VERSION
" (" DRV_RELDATE
")";
261 static int phy_table
[] = { PHY1_ADDR
, PHY2_ADDR
};
263 /* forward declarations */
264 void r6040_multicast_list(struct net_device
*dev
);
266 /* jal2: comment out to get more symbols for debugging */
267 //#define STATIC static
271 /*! hexdump an memory area into a string. delim is taken as the delimiter between two bytes.
272 It is omitted if delim == '\0' */
273 STATIC
char *hex2str(void *addr
, char *buf
, int nr_bytes
, int delim
)
275 unsigned char *src
= addr
;
278 #define BIN2HEXDIGIT(x) ((x) < 10 ? '0'+(x) : 'A'-10+(x))
280 while (nr_bytes
> 0) {
281 *outb
++ = BIN2HEXDIGIT(*src
>>4);
282 *outb
++ = BIN2HEXDIGIT(*src
&0xf);
295 #endif /* #if DEBUG */
297 /* Read a word data from PHY Chip */
298 STATIC
int phy_read(void __iomem
*ioaddr
, int phy_addr
, int reg
)
304 iowrite16(MDIO_READ
+ reg
+ (phy_addr
<< 8), ioaddr
+ MMDIO
);
305 /* Wait for the read bit to be cleared */
307 cmd
= ioread16(ioaddr
+ MMDIO
);
313 err("phy addr x%x reg x%x timed out\n",
316 rc
=ioread16(ioaddr
+ MMRD
);
318 dbg(DBG_PHY
, "phy addr x%x reg x%x val x%x\n", phy_addr
, reg
, rc
);
322 /* Write a word data from PHY Chip */
323 STATIC
void phy_write(void __iomem
*ioaddr
, int phy_addr
, int reg
, u16 val
)
328 dbg(DBG_PHY
, "phy addr x%x reg x%x val x%x\n", phy_addr
, reg
, val
);
330 iowrite16(val
, ioaddr
+ MMWD
);
331 /* Write the command to the MDIO bus */
332 iowrite16(MDIO_WRITE
+ reg
+ (phy_addr
<< 8), ioaddr
+ MMDIO
);
333 /* Wait for the write bit to be cleared */
335 cmd
= ioread16(ioaddr
+ MMDIO
);
336 if (cmd
& MDIO_WRITE
)
340 err("phy addr x%x reg x%x val x%x timed out\n",
344 STATIC
int mdio_read(struct net_device
*dev
, int mii_id
, int reg
)
346 struct r6040_private
*lp
= netdev_priv(dev
);
347 void __iomem
*ioaddr
= lp
->base
;
349 return (phy_read(ioaddr
, lp
->phy_addr
, reg
));
352 STATIC
void mdio_write(struct net_device
*dev
, int mii_id
, int reg
, int val
)
354 struct r6040_private
*lp
= netdev_priv(dev
);
355 void __iomem
*ioaddr
= lp
->base
;
357 phy_write(ioaddr
, lp
->phy_addr
, reg
, val
);
360 void r6040_free_txbufs(struct net_device
*dev
)
362 struct r6040_private
*lp
= netdev_priv(dev
);
365 dbg(DBG_FREE_BUFS
, "ENTER\n");
366 for (i
= 0; i
< TX_DCNT
; i
++) {
367 if (lp
->tx_insert_ptr
->skb_ptr
) {
368 pci_unmap_single(lp
->pdev
,
369 le32_to_cpu(lp
->tx_insert_ptr
->buf
),
370 MAX_BUF_SIZE
, PCI_DMA_TODEVICE
);
371 dev_kfree_skb(lp
->tx_insert_ptr
->skb_ptr
);
372 lp
->tx_insert_ptr
->skb_ptr
= NULL
;
374 lp
->tx_insert_ptr
= lp
->tx_insert_ptr
->vndescp
;
376 dbg(DBG_FREE_BUFS
, "EXIT\n");
379 /*! unmap and free all rx skb */
380 void r6040_free_rxbufs(struct net_device
*dev
)
382 struct r6040_private
*lp
= netdev_priv(dev
);
385 dbg(DBG_FREE_BUFS
, "ENTER\n");
386 for (i
= 0; i
< RX_DCNT
; i
++) {
387 if (lp
->rx_insert_ptr
->skb_ptr
) {
388 pci_unmap_single(lp
->pdev
,
389 le32_to_cpu(lp
->rx_insert_ptr
->buf
),
390 MAX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
391 dev_kfree_skb(lp
->rx_insert_ptr
->skb_ptr
);
392 lp
->rx_insert_ptr
->skb_ptr
= NULL
;
394 lp
->rx_insert_ptr
= lp
->rx_insert_ptr
->vndescp
;
396 dbg(DBG_FREE_BUFS
, "EXIT\n");
400 void r6040_init_ring_desc(struct r6040_descriptor
*desc_ring
,
401 dma_addr_t desc_dma
, int size
)
403 struct r6040_descriptor
*desc
= desc_ring
;
404 dma_addr_t mapping
= desc_dma
;
406 dbg(DBG_RING
, "desc_ring %p desc_dma %08x size x%x\n",
407 desc_ring
, desc_dma
, size
);
411 mapping
+= sizeof(*desc
);
412 memset(desc
, 0, sizeof(*desc
));
413 desc
->ndesc
= cpu_to_le32(mapping
);
414 desc
->vndescp
= desc
+ 1;
418 /* last descriptor points to first one to close the descriptor ring */
420 desc
->ndesc
= cpu_to_le32(desc_dma
);
421 desc
->vndescp
= desc_ring
;
424 #if (DEBUG & DBG_TX_RING_DUMP)
425 /*! dump the tx ring to syslog */
427 dump_tx_ring(struct r6040_private
*lp
)
430 struct r6040_descriptor
*ptr
;
432 printk(KERN_INFO
"%s: nr_desc x%x tx_ring %p tx_ring_dma %08x "
433 "tx_insert %p tx_remove %p\n",
434 DRV_NAME
, TX_DCNT
, lp
->tx_ring
, lp
->tx_ring_dma
,
435 lp
->tx_insert_ptr
, lp
->tx_remove_ptr
);
438 for(i
=0, ptr
=lp
->tx_ring
; i
< TX_DCNT
; i
++, ptr
++) {
439 printk(KERN_INFO
"%s: %d. descr: status x%x len x%x "
440 "ndesc %08x vbufp %p vndescp %p skb_ptr %p\n",
441 DRV_NAME
, i
, ptr
->status
, ptr
->len
,
442 ptr
->ndesc
, ptr
->vbufp
, ptr
->vndescp
, ptr
->skb_ptr
);
446 #endif /* #if (DEBUG & DBG_TX_RING_DUMP) */
448 void r6040_init_txbufs(struct net_device
*dev
)
450 struct r6040_private
*lp
= netdev_priv(dev
);
452 lp
->tx_free_desc
= TX_DCNT
;
454 lp
->tx_remove_ptr
= lp
->tx_insert_ptr
= lp
->tx_ring
;
455 r6040_init_ring_desc(lp
->tx_ring
, lp
->tx_ring_dma
, TX_DCNT
);
457 #if (DEBUG & DBG_TX_RING_DUMP)
458 if (debug
& DBG_TX_RING_DUMP
) {
464 #if (DEBUG & DBG_RX_RING_DUMP)
465 /*! dump the rx ring to syslog */
467 dump_rx_ring(struct r6040_private
*lp
)
470 struct r6040_descriptor
*ptr
;
472 printk(KERN_INFO
"%s: nr_desc x%x rx_ring %p rx_ring_dma %08x "
473 "rx_insert %p rx_remove %p\n",
474 DRV_NAME
, RX_DCNT
, lp
->rx_ring
, lp
->rx_ring_dma
,
475 lp
->rx_insert_ptr
, lp
->rx_remove_ptr
);
478 for(i
=0, ptr
=lp
->rx_ring
; i
< RX_DCNT
; i
++, ptr
++) {
479 printk(KERN_INFO
"%s: %d. descr: status x%x len x%x "
480 "ndesc %08x vbufp %p vndescp %p skb_ptr %p\n",
481 DRV_NAME
, i
, ptr
->status
, ptr
->len
,
482 ptr
->ndesc
, ptr
->vbufp
, ptr
->vndescp
, ptr
->skb_ptr
);
486 #endif /* #if (DEBUG & DBG_TX_RING_DUMP) */
488 int r6040_alloc_rxbufs(struct net_device
*dev
)
490 struct r6040_private
*lp
= netdev_priv(dev
);
491 struct r6040_descriptor
*desc
;
495 lp
->rx_remove_ptr
= lp
->rx_insert_ptr
= lp
->rx_ring
;
496 r6040_init_ring_desc(lp
->rx_ring
, lp
->rx_ring_dma
, RX_DCNT
);
498 /* alloc skbs for the rx descriptors */
501 if (!(skb
=netdev_alloc_skb(dev
, MAX_BUF_SIZE
))) {
502 err("failed to alloc skb for rx\n");
507 desc
->buf
= cpu_to_le32(pci_map_single(lp
->pdev
,
509 MAX_BUF_SIZE
, PCI_DMA_FROMDEVICE
));
510 desc
->status
= DESC_STATUS_OWNER_MAC
;
511 desc
= desc
->vndescp
;
512 } while (desc
!= lp
->rx_ring
);
514 #if (DEBUG & DBG_RX_RING_DUMP)
515 if (debug
& DBG_RX_RING_DUMP
) {
523 /* dealloc all previously allocated skb */
524 r6040_free_rxbufs(dev
);
528 /*! reset MAC and set all registers */
529 void r6040_init_mac_regs(struct r6040_private
*lp
)
531 void __iomem
*ioaddr
= lp
->base
;
533 char obuf
[3*ETH_ALEN
] __attribute__ ((unused
));
535 /* Mask Off Interrupt */
536 iowrite16(MSK_INT
, ioaddr
+ MIER
);
539 iowrite16(MAC_RST
, ioaddr
+ MCR1
);
542 while ((ioread16(ioaddr
+ MCR1
) & MAC_RST
) && limit
-- > 0);
544 /* Reset internal state machine */
545 iowrite16(2, ioaddr
+ MAC_SM
);
546 iowrite16(0, ioaddr
+ MAC_SM
);
549 /* Restore MAC Addresses */
550 r6040_multicast_list(lp
->dev
);
552 /* TODO: restore multcast and hash table */
554 /* MAC Bus Control Register */
555 iowrite16(MBCR_DEFAULT
, ioaddr
+ MBCR
);
557 /* Buffer Size Register */
558 iowrite16(MAX_BUF_SIZE
, ioaddr
+ MR_BSR
);
560 /* write tx ring start address */
561 iowrite16(lp
->tx_ring_dma
, ioaddr
+ MTD_SA0
);
562 iowrite16(lp
->tx_ring_dma
>> 16, ioaddr
+ MTD_SA1
);
564 /* write rx ring start address */
565 iowrite16(lp
->rx_ring_dma
, ioaddr
+ MRD_SA0
);
566 iowrite16(lp
->rx_ring_dma
>> 16, ioaddr
+ MRD_SA1
);
568 /* set interrupt waiting time and packet numbers */
569 iowrite16(0, ioaddr
+ MT_ICR
);
570 iowrite16(0, ioaddr
+ MR_ICR
);
572 /* enable interrupts */
573 iowrite16(INT_MASK
, ioaddr
+ MIER
);
575 /* enable tx and rx */
576 iowrite16(lp
->mcr0
| 0x0002, ioaddr
);
578 /* let TX poll the descriptors - we may got called by r6040_tx_timeout which has left
579 some unsent tx buffers */
580 iowrite16(0x01, ioaddr
+ MTPR
);
583 void r6040_tx_timeout(struct net_device
*dev
)
585 struct r6040_private
*priv
= netdev_priv(dev
);
586 void __iomem
*ioaddr
= priv
->base
;
588 /* we read MISR, which clears on read (i.e. we may loose an RX interupt,
589 but this is an error anyhow ... */
590 printk(KERN_WARNING
"%s: transmit timed out, int enable %4.4x "
591 "status %4.4x, PHY status %4.4x\n",
592 dev
->name
, ioread16(ioaddr
+ MIER
),
593 ioread16(ioaddr
+ MISR
),
594 mdio_read(dev
, priv
->mii_if
.phy_id
, MII_BMSR
));
596 dev
->stats
.tx_errors
++;
598 /* Reset MAC and re-init all registers */
599 r6040_init_mac_regs(priv
);
602 struct net_device_stats
*r6040_get_stats(struct net_device
*dev
)
604 struct r6040_private
*priv
= netdev_priv(dev
);
605 void __iomem
*ioaddr
= priv
->base
;
608 spin_lock_irqsave(&priv
->lock
, flags
);
609 dev
->stats
.rx_crc_errors
+= ioread8(ioaddr
+ ME_CNT1
);
610 dev
->stats
.multicast
+= ioread8(ioaddr
+ ME_CNT0
);
611 spin_unlock_irqrestore(&priv
->lock
, flags
);
616 /* Stop RDC MAC and Free the allocated resource */
617 void r6040_down(struct net_device
*dev
)
619 struct r6040_private
*lp
= netdev_priv(dev
);
620 void __iomem
*ioaddr
= lp
->base
;
621 struct pci_dev
*pdev
= lp
->pdev
;
624 dbg(DBG_EXIT
, "ENTER\n");
627 iowrite16(MSK_INT
, ioaddr
+ MIER
); /* Mask Off Interrupt */
628 iowrite16(MAC_RST
, ioaddr
+ MCR1
); /* Reset RDC MAC */
630 while ((ioread16(ioaddr
+MCR1
) & 1) && limit
-- > 0);
633 err("timeout while waiting for reset done.\n");
635 free_irq(dev
->irq
, dev
);
638 r6040_free_rxbufs(dev
);
641 r6040_free_txbufs(dev
);
643 /* Free Descriptor memory */
644 pci_free_consistent(pdev
, RX_DESC_SIZE
, lp
->rx_ring
, lp
->rx_ring_dma
);
645 pci_free_consistent(pdev
, TX_DESC_SIZE
, lp
->tx_ring
, lp
->tx_ring_dma
);
647 dbg(DBG_EXIT
, "EXIT\n");
650 int r6040_close(struct net_device
*dev
)
652 struct r6040_private
*lp
= netdev_priv(dev
);
654 dbg(DBG_EXIT
, "ENTER\n");
657 del_timer_sync(&lp
->timer
);
658 spin_lock_irq(&lp
->lock
);
659 napi_disable(&lp
->napi
);
660 netif_stop_queue(dev
);
662 spin_unlock_irq(&lp
->lock
);
664 dbg(DBG_EXIT
, "EXIT\n");
668 /* Status of PHY CHIP. Returns 0x8000 for full duplex, 0 for half duplex */
669 STATIC
int phy_mode_chk(struct net_device
*dev
)
671 struct r6040_private
*lp
= netdev_priv(dev
);
672 void __iomem
*ioaddr
= lp
->base
;
675 /* PHY Link Status Check */
676 phy_dat
= phy_read(ioaddr
, lp
->phy_addr
, 1);
677 if (!(phy_dat
& 0x4))
678 phy_dat
= 0x8000; /* Link Failed, full duplex */
680 /* PHY Chip Auto-Negotiation Status */
681 phy_dat
= phy_read(ioaddr
, lp
->phy_addr
, 1);
682 if (phy_dat
& 0x0020) {
683 /* Auto Negotiation Mode */
684 phy_dat
= phy_read(ioaddr
, lp
->phy_addr
, 5);
685 phy_dat
&= phy_read(ioaddr
, lp
->phy_addr
, 4);
687 /* Force full duplex */
693 phy_dat
= phy_read(ioaddr
, lp
->phy_addr
, 0);
700 dbg(DBG_PHY
, "RETURN x%x\n", phy_dat
);
704 void r6040_set_carrier(struct mii_if_info
*mii
)
706 if (phy_mode_chk(mii
->dev
)) {
707 /* autoneg is off: Link is always assumed to be up */
708 if (!netif_carrier_ok(mii
->dev
))
709 netif_carrier_on(mii
->dev
);
711 phy_mode_chk(mii
->dev
);
714 int r6040_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
716 struct r6040_private
*lp
= netdev_priv(dev
);
717 struct mii_ioctl_data
*data
= if_mii(rq
);
720 if (!netif_running(dev
))
722 spin_lock_irq(&lp
->lock
);
723 rc
= generic_mii_ioctl(&lp
->mii_if
, data
, cmd
, NULL
);
724 spin_unlock_irq(&lp
->lock
);
725 r6040_set_carrier(&lp
->mii_if
);
729 int r6040_rx(struct net_device
*dev
, int limit
)
731 struct r6040_private
*priv
= netdev_priv(dev
);
733 struct r6040_descriptor
*descptr
= priv
->rx_remove_ptr
;
734 struct sk_buff
*skb_ptr
, *new_skb
;
735 char obuf
[2*32+1] __attribute__ ((unused
)); /* for debugging */
737 while (count
< limit
&& !(descptr
->status
& DESC_STATUS_OWNER_MAC
)) {
738 /* limit not reached and the descriptor belongs to the CPU */
740 dbg(DBG_RX_DESCR
, "descptr %p status x%x data len x%x\n",
741 descptr
, descptr
->status
, descptr
->len
);
743 /* Check for errors */
744 if (descptr
->status
& DESC_STATUS_RX_ERR
) {
746 dev
->stats
.rx_errors
++;
748 if (descptr
->status
& (DESC_STATUS_RX_ERR_DRIBBLE
|
749 DESC_STATUS_RX_ERR_BUFLEN
|
750 DESC_STATUS_RX_ERR_LONG
|
751 DESC_STATUS_RX_ERR_RUNT
)) {
752 /* packet too long or too short*/
753 dev
->stats
.rx_length_errors
++;
756 if (descptr
->status
& DESC_STATUS_RX_ERR_CRC
) {
757 dev
->stats
.rx_crc_errors
++;
762 /* successful received packet */
764 /* first try to allocate new skb. If this fails
765 we drop the packet and leave the old skb there.*/
766 new_skb
= netdev_alloc_skb(dev
, MAX_BUF_SIZE
);
768 dev
->stats
.rx_dropped
++;
771 skb_ptr
= descptr
->skb_ptr
;
772 skb_ptr
->dev
= priv
->dev
;
773 /* Do not count the CRC */
774 skb_put(skb_ptr
, descptr
->len
- 4);
775 pci_unmap_single(priv
->pdev
, le32_to_cpu(descptr
->buf
),
776 MAX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
777 skb_ptr
->protocol
= eth_type_trans(skb_ptr
, priv
->dev
);
779 dbg(DBG_RX_DATA
, "rx len x%x: %s...\n",
781 hex2str(skb_ptr
->data
, obuf
, sizeof(obuf
)/2, '\0'));
783 /* Send to upper layer */
784 netif_receive_skb(skb_ptr
);
785 dev
->last_rx
= jiffies
;
786 dev
->stats
.rx_packets
++;
787 dev
->stats
.rx_bytes
+= (descptr
->len
-4);
789 /* put new skb into descriptor */
790 descptr
->skb_ptr
= new_skb
;
791 descptr
->buf
= cpu_to_le32(pci_map_single(priv
->pdev
,
792 descptr
->skb_ptr
->data
,
793 MAX_BUF_SIZE
, PCI_DMA_FROMDEVICE
));
796 /* put the descriptor back to the MAC */
797 descptr
->status
= DESC_STATUS_OWNER_MAC
;
798 descptr
= descptr
->vndescp
;
799 count
++; /* shall we count errors and dropped packets as well? */
800 } /* while (limit && !(descptr->status & DESC_STATUS_OWNER_MAC)) */
802 /* remember next descriptor to check for rx */
803 priv
->rx_remove_ptr
= descptr
;
808 void r6040_tx(struct net_device
*dev
)
810 struct r6040_private
*priv
= netdev_priv(dev
);
811 struct r6040_descriptor
*descptr
;
812 void __iomem
*ioaddr
= priv
->base
;
813 struct sk_buff
*skb_ptr
;
816 spin_lock(&priv
->lock
);
817 descptr
= priv
->tx_remove_ptr
;
818 while (priv
->tx_free_desc
< TX_DCNT
) {
819 /* Check for errors */
820 err
= ioread16(ioaddr
+ MLSR
);
823 dev
->stats
.rx_fifo_errors
++;
824 if (err
& (0x2000 | 0x4000))
825 dev
->stats
.tx_carrier_errors
++;
827 dbg(DBG_TX_DONE
, "descptr %p status x%x err x%x jiffies %lu\n",
828 descptr
, descptr
->status
, err
, jiffies
);
830 if (descptr
->status
& 0x8000)
831 break; /* Not complete */
832 skb_ptr
= descptr
->skb_ptr
;
833 pci_unmap_single(priv
->pdev
, le32_to_cpu(descptr
->buf
),
834 skb_ptr
->len
, PCI_DMA_TODEVICE
);
836 dev_kfree_skb_irq(skb_ptr
);
837 descptr
->skb_ptr
= NULL
;
838 /* To next descriptor */
839 descptr
= descptr
->vndescp
;
840 priv
->tx_free_desc
++;
842 priv
->tx_remove_ptr
= descptr
;
844 if (priv
->tx_free_desc
)
845 netif_wake_queue(dev
);
846 spin_unlock(&priv
->lock
);
849 int r6040_poll(struct napi_struct
*napi
, int budget
)
851 struct r6040_private
*priv
=
852 container_of(napi
, struct r6040_private
, napi
);
853 struct net_device
*dev
= priv
->dev
;
854 void __iomem
*ioaddr
= priv
->base
;
857 work_done
= r6040_rx(dev
, budget
);
859 dbg(DBG_POLL
, "budget x%x done x%x\n", budget
, work_done
);
861 if (work_done
< budget
) {
862 netif_rx_complete(dev
, napi
);
863 /* Enable RX interrupt */
864 iowrite16(ioread16(ioaddr
+ MIER
) | RX_INTS
, ioaddr
+ MIER
);
869 /* The RDC interrupt handler. */
870 irqreturn_t
r6040_interrupt(int irq
, void *dev_id
)
872 struct net_device
*dev
= dev_id
;
873 struct r6040_private
*lp
= netdev_priv(dev
);
874 void __iomem
*ioaddr
= lp
->base
;
877 /* Read MISR status and clear */
878 status
= ioread16(ioaddr
+ MISR
);
880 dbg(DBG_IRQ
, "status x%x jiffies %lu\n", status
, jiffies
);
882 if (status
== 0x0000 || status
== 0xffff)
885 /* rx early / rx finish interrupt
886 or rx descriptor unavail. */
887 if (status
& RX_INTS
) {
888 if (status
& RX_NO_DESC
) {
889 /* rx descriptor unavail. */
890 dev
->stats
.rx_dropped
++;
891 dev
->stats
.rx_missed_errors
++;
893 /* Mask off RX interrupts */
894 iowrite16(ioread16(ioaddr
+ MIER
) & ~RX_INTS
, ioaddr
+ MIER
);
895 netif_rx_schedule(dev
, &lp
->napi
);
899 if (status
& RX_FIFO_FULL
) {
900 dev
->stats
.rx_fifo_errors
++;
903 /* TX interrupt request */
910 #ifdef CONFIG_NET_POLL_CONTROLLER
911 void r6040_poll_controller(struct net_device
*dev
)
913 disable_irq(dev
->irq
);
914 r6040_interrupt(dev
->irq
, dev
);
915 enable_irq(dev
->irq
);
920 int r6040_up(struct net_device
*dev
)
922 struct r6040_private
*lp
= netdev_priv(dev
);
923 void __iomem
*ioaddr
= lp
->base
;
926 dbg(DBG_INIT
, "ENTER\n");
928 /* Initialise and alloc RX/TX buffers */
929 r6040_init_txbufs(dev
);
930 if ((rc
=r6040_alloc_rxbufs(dev
)))
933 /* Read the PHY ID */
934 lp
->switch_sig
= phy_read(ioaddr
, 0, 2);
936 if (lp
->switch_sig
== ICPLUS_PHY_ID
) {
937 phy_write(ioaddr
, 29, 31, 0x175C); /* Enable registers */
938 lp
->phy_mode
= 0x8000;
941 phy_write(ioaddr
, lp
->phy_addr
, 4, PHY_CAP
);
942 phy_write(ioaddr
, lp
->phy_addr
, 0, PHY_MODE
);
944 if (PHY_MODE
== 0x3100)
945 lp
->phy_mode
= phy_mode_chk(dev
);
947 lp
->phy_mode
= (PHY_MODE
& 0x0100) ? 0x8000:0x0;
950 /* configure duplex mode */
951 lp
->mcr0
|= lp
->phy_mode
;
953 /* improve performance (by RDC guys) */
954 phy_write(ioaddr
, 30, 17, (phy_read(ioaddr
, 30, 17) | 0x4000));
955 phy_write(ioaddr
, 30, 17, ~((~phy_read(ioaddr
, 30, 17)) | 0x2000));
956 phy_write(ioaddr
, 0, 19, 0x0000);
957 phy_write(ioaddr
, 0, 30, 0x01F0);
959 /* Reset MAC and init all registers */
960 r6040_init_mac_regs(lp
);
966 A periodic timer routine
967 Polling PHY Chip Link Status
969 void r6040_timer(unsigned long data
)
971 struct net_device
*dev
= (struct net_device
*)data
;
972 struct r6040_private
*lp
= netdev_priv(dev
);
973 void __iomem
*ioaddr
= lp
->base
;
976 /* Polling PHY Chip Status */
977 if (PHY_MODE
== 0x3100)
978 phy_mode
= phy_mode_chk(dev
);
980 phy_mode
= (PHY_MODE
& 0x0100) ? 0x8000:0x0;
982 if (phy_mode
!= lp
->phy_mode
) {
983 lp
->phy_mode
= phy_mode
;
984 lp
->mcr0
= (lp
->mcr0
& 0x7fff) | phy_mode
;
985 iowrite16(lp
->mcr0
, ioaddr
);
986 printk(KERN_INFO
"Link Change x%x \n", ioread16(ioaddr
));
989 /* Timer active again */
990 mod_timer(&lp
->timer
, jiffies
+ round_jiffies(HZ
));
993 int r6040_open(struct net_device
*dev
)
995 struct r6040_private
*lp
= netdev_priv(dev
);
998 dbg(DBG_OPEN
, "ENTER\n");
999 /* Request IRQ and Register interrupt handler */
1000 ret
= request_irq(dev
->irq
, &r6040_interrupt
,
1001 IRQF_SHARED
, dev
->name
, dev
);
1005 dbg(DBG_OPEN
, "got irq %d\n", dev
->irq
);
1007 /* Allocate Descriptor memory */
1009 pci_alloc_consistent(lp
->pdev
, RX_DESC_SIZE
, &lp
->rx_ring_dma
);
1013 dbg(DBG_OPEN
, "allocated rx ring\n");
1016 pci_alloc_consistent(lp
->pdev
, TX_DESC_SIZE
, &lp
->tx_ring_dma
);
1018 pci_free_consistent(lp
->pdev
, RX_DESC_SIZE
, lp
->rx_ring
,
1023 dbg(DBG_OPEN
, "allocated tx ring\n");
1025 if ((ret
=r6040_up(dev
))) {
1026 pci_free_consistent(lp
->pdev
, TX_DESC_SIZE
, lp
->tx_ring
,
1028 pci_free_consistent(lp
->pdev
, RX_DESC_SIZE
, lp
->rx_ring
,
1033 napi_enable(&lp
->napi
);
1034 netif_start_queue(dev
);
1036 /* set and active a timer process */
1037 setup_timer(&lp
->timer
, r6040_timer
, (unsigned long) dev
);
1038 if (lp
->switch_sig
!= ICPLUS_PHY_ID
)
1039 mod_timer(&lp
->timer
, jiffies
+ HZ
);
1043 int r6040_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1045 struct r6040_private
*lp
= netdev_priv(dev
);
1046 struct r6040_descriptor
*descptr
;
1047 void __iomem
*ioaddr
= lp
->base
;
1048 unsigned long flags
;
1049 int ret
= NETDEV_TX_OK
;
1051 /* Critical Section */
1052 spin_lock_irqsave(&lp
->lock
, flags
);
1054 /* TX resource check */
1055 if (!lp
->tx_free_desc
) {
1056 spin_unlock_irqrestore(&lp
->lock
, flags
);
1057 netif_stop_queue(dev
);
1058 printk(KERN_ERR DRV_NAME
": no tx descriptor\n");
1059 ret
= NETDEV_TX_BUSY
;
1063 /* Statistic Counter */
1064 dev
->stats
.tx_packets
++;
1065 dev
->stats
.tx_bytes
+= skb
->len
;
1066 /* Set TX descriptor & Transmit it */
1068 descptr
= lp
->tx_insert_ptr
;
1069 if (skb
->len
< MISR
)
1070 descptr
->len
= MISR
;
1072 descptr
->len
= skb
->len
;
1074 descptr
->skb_ptr
= skb
;
1075 descptr
->buf
= cpu_to_le32(pci_map_single(lp
->pdev
,
1076 skb
->data
, skb
->len
, PCI_DMA_TODEVICE
));
1078 dbg(DBG_TX_DESCR
, "desc @ %p: len x%x buf %08x skb->data %p skb->len x%x jiffies %lu\n",
1079 descptr
, descptr
->len
, descptr
->buf
, skb
->data
, skb
->len
, jiffies
);
1083 dbg(DBG_TX_DATA
, "tx len x%x: %s\n",
1084 descptr
->len
, hex2str(skb
->data
, obuf
, sizeof(obuf
)/2, '\0'));
1087 descptr
->status
= 0x8000;
1088 /* Trigger the MAC to check the TX descriptor */
1089 iowrite16(0x01, ioaddr
+ MTPR
);
1090 lp
->tx_insert_ptr
= descptr
->vndescp
;
1092 /* If no tx resource, stop */
1093 if (!lp
->tx_free_desc
)
1094 netif_stop_queue(dev
);
1096 dev
->trans_start
= jiffies
;
1097 spin_unlock_irqrestore(&lp
->lock
, flags
);
1101 /*! set MAC addresses and promiscous mode */
1102 void r6040_multicast_list(struct net_device
*dev
)
1104 struct r6040_private
*lp
= netdev_priv(dev
);
1105 void __iomem
*ioaddr
= lp
->base
;
1108 unsigned long flags
;
1109 struct dev_mc_list
*dmi
= dev
->mc_list
;
1111 char obuf
[3*ETH_ALEN
] __attribute__ ((unused
));
1114 adrp
= (u16
*)dev
->dev_addr
;
1115 iowrite16(adrp
[0], ioaddr
+ MID_0L
);
1116 iowrite16(adrp
[1], ioaddr
+ MID_0M
);
1117 iowrite16(adrp
[2], ioaddr
+ MID_0H
);
1119 dbg(DBG_MAC_ADDR
, "%s: set MAC addr %s\n",
1120 dev
->name
, hex2str(dev
->dev_addr
, obuf
, ETH_ALEN
, ':'));
1122 /* Promiscous Mode */
1123 spin_lock_irqsave(&lp
->lock
, flags
);
1125 /* Clear AMCP & PROM bits */
1126 reg
= ioread16(ioaddr
) & ~0x0120;
1127 if (dev
->flags
& IFF_PROMISC
) {
1131 /* Too many multicast addresses
1132 * accept all traffic */
1133 else if ((dev
->mc_count
> MCAST_MAX
)
1134 || (dev
->flags
& IFF_ALLMULTI
))
1137 iowrite16(reg
, ioaddr
);
1138 spin_unlock_irqrestore(&lp
->lock
, flags
);
1140 /* Build the hash table */
1141 if (dev
->mc_count
> MCAST_MAX
) {
1145 for (i
= 0; i
< 4; i
++)
1148 for (i
= 0; i
< dev
->mc_count
; i
++) {
1149 char *addrs
= dmi
->dmi_addr
;
1156 crc
= ether_crc_le(6, addrs
);
1158 hash_table
[crc
>> 4] |= 1 << (15 - (crc
& 0xf));
1160 /* Write the index of the hash table */
1161 for (i
= 0; i
< 4; i
++)
1162 iowrite16(hash_table
[i
] << 14, ioaddr
+ MCR1
);
1163 /* Fill the MAC hash tables with their values */
1164 iowrite16(hash_table
[0], ioaddr
+ MAR0
);
1165 iowrite16(hash_table
[1], ioaddr
+ MAR1
);
1166 iowrite16(hash_table
[2], ioaddr
+ MAR2
);
1167 iowrite16(hash_table
[3], ioaddr
+ MAR3
);
1169 /* Multicast Address 1~4 case */
1170 for (i
= 0, dmi
; (i
< dev
->mc_count
) && (i
< MCAST_MAX
); i
++) {
1171 adrp
= (u16
*)dmi
->dmi_addr
;
1172 iowrite16(adrp
[0], ioaddr
+ MID_1L
+ 8*i
);
1173 iowrite16(adrp
[1], ioaddr
+ MID_1M
+ 8*i
);
1174 iowrite16(adrp
[2], ioaddr
+ MID_1H
+ 8*i
);
1177 for (i
= dev
->mc_count
; i
< MCAST_MAX
; i
++) {
1178 iowrite16(0xffff, ioaddr
+ MID_0L
+ 8*i
);
1179 iowrite16(0xffff, ioaddr
+ MID_0M
+ 8*i
);
1180 iowrite16(0xffff, ioaddr
+ MID_0H
+ 8*i
);
1184 STATIC
void netdev_get_drvinfo(struct net_device
*dev
,
1185 struct ethtool_drvinfo
*info
)
1187 struct r6040_private
*rp
= netdev_priv(dev
);
1189 strcpy(info
->driver
, DRV_NAME
);
1190 strcpy(info
->version
, DRV_VERSION
);
1191 strcpy(info
->bus_info
, pci_name(rp
->pdev
));
1194 STATIC
int netdev_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1196 struct r6040_private
*rp
= netdev_priv(dev
);
1199 spin_lock_irq(&rp
->lock
);
1200 rc
= mii_ethtool_gset(&rp
->mii_if
, cmd
);
1201 spin_unlock_irq(&rp
->lock
);
1206 STATIC
int netdev_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
1208 struct r6040_private
*rp
= netdev_priv(dev
);
1211 spin_lock_irq(&rp
->lock
);
1212 rc
= mii_ethtool_sset(&rp
->mii_if
, cmd
);
1213 spin_unlock_irq(&rp
->lock
);
1214 r6040_set_carrier(&rp
->mii_if
);
1219 STATIC u32
netdev_get_link(struct net_device
*dev
)
1221 struct r6040_private
*rp
= netdev_priv(dev
);
1223 return mii_link_ok(&rp
->mii_if
);
1226 static struct ethtool_ops netdev_ethtool_ops
= {
1227 .get_drvinfo
= netdev_get_drvinfo
,
1228 .get_settings
= netdev_get_settings
,
1229 .set_settings
= netdev_set_settings
,
1230 .get_link
= netdev_get_link
,
1233 int __devinit
r6040_init_one(struct pci_dev
*pdev
,
1234 const struct pci_device_id
*ent
)
1236 struct net_device
*dev
, *parent_dev
;
1237 struct r6040_private
*lp
;
1238 void __iomem
*ioaddr
;
1239 int err
, io_size
= R6040_IO_SIZE
;
1240 static int card_idx
= -1;
1243 printk(KERN_INFO
"%s\n", version
);
1244 printk(KERN_INFO DRV_NAME
": debug %x\n", debug
);
1246 err
= pci_enable_device(pdev
);
1250 /* this should always be supported */
1251 if (pci_set_dma_mask(pdev
, DMA_32BIT_MASK
)) {
1252 printk(KERN_ERR DRV_NAME
"32-bit PCI DMA addresses"
1253 "not supported by the card\n");
1256 if (pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
)) {
1257 printk(KERN_ERR DRV_NAME
"32-bit PCI DMA addresses"
1258 "not supported by the card\n");
1263 if (pci_resource_len(pdev
, 0) < io_size
) {
1264 printk(KERN_ERR
"Insufficient PCI resources, aborting\n");
1268 pioaddr
= pci_resource_start(pdev
, 0); /* IO map base address */
1269 pci_set_master(pdev
);
1271 dev
= alloc_etherdev(sizeof(struct r6040_private
));
1273 printk(KERN_ERR
"Failed to allocate etherdev\n");
1276 SET_NETDEV_DEV(dev
, &pdev
->dev
);
1277 lp
= netdev_priv(dev
);
1279 if (pci_request_regions(pdev
, DRV_NAME
)) {
1280 printk(KERN_ERR DRV_NAME
": Failed to request PCI regions\n");
1282 goto err_out_disable
;
1285 ioaddr
= pci_iomap(pdev
, 0, io_size
);
1287 printk(KERN_ERR
"ioremap failed for device %s\n",
1292 /* Init system & device */
1294 dev
->irq
= pdev
->irq
;
1296 spin_lock_init(&lp
->lock
);
1297 pci_set_drvdata(pdev
, dev
);
1301 /* Link new device into r6040_root_dev */
1306 /* Init RDC private data */
1308 lp
->phy_addr
= phy_table
[card_idx
];
1311 /* The RDC-specific entries in the device structure. */
1312 dev
->open
= &r6040_open
;
1313 dev
->hard_start_xmit
= &r6040_start_xmit
;
1314 dev
->stop
= &r6040_close
;
1315 dev
->get_stats
= r6040_get_stats
;
1316 dev
->set_multicast_list
= &r6040_multicast_list
;
1317 dev
->do_ioctl
= &r6040_ioctl
;
1318 dev
->ethtool_ops
= &netdev_ethtool_ops
;
1319 dev
->tx_timeout
= &r6040_tx_timeout
;
1320 dev
->watchdog_timeo
= TX_TIMEOUT
;
1323 You must specify a netdevice with a "parent=" parameter, whose address
1324 is copied, or an array of bytes comprising a literal address; otherwise
1325 the (default) address of the Sitecom WL-153 bootloader is used.
1327 memcpy(dev
->dev_addr
, mac_base
, ETH_ALEN
);
1329 parent_dev
= __dev_get_by_name(&init_net
, parent
);
1331 memcpy(dev
->dev_addr
, parent_dev
->dev_addr
, ETH_ALEN
);
1333 dev
->dev_addr
[ETH_ALEN
-1] += card_idx
^ reverse
; /* + 0 or 1 */
1335 #ifdef CONFIG_NET_POLL_CONTROLLER
1336 dev
->poll_controller
= r6040_poll_controller
;
1338 netif_napi_add(dev
, &lp
->napi
, r6040_poll
, 64);
1339 lp
->mii_if
.dev
= dev
;
1340 lp
->mii_if
.mdio_read
= mdio_read
;
1341 lp
->mii_if
.mdio_write
= mdio_write
;
1342 lp
->mii_if
.phy_id
= lp
->phy_addr
;
1343 lp
->mii_if
.phy_id_mask
= 0x1f;
1344 lp
->mii_if
.reg_num_mask
= 0x1f;
1346 if (reverse
&& ((card_idx
& 1) == 0) && (dev_alloc_name(dev
, dev
->name
)
1348 for (err
= strlen(dev
->name
); err
; err
--) {
1349 if (dev
->name
[err
- 1]++ != '9')
1351 dev
->name
[err
- 1] = '0';
1354 /* Register net device. After this dev->name assign */
1355 err
= register_netdev(dev
);
1357 printk(KERN_ERR DRV_NAME
": Failed to register net device\n");
1361 dbg(DBG_INIT
, "%s successfully registered\n", dev
->name
);
1365 pci_release_regions(pdev
);
1367 pci_disable_device(pdev
);
1368 pci_set_drvdata(pdev
, NULL
);
1374 void __devexit
r6040_remove_one(struct pci_dev
*pdev
)
1376 struct net_device
*dev
= pci_get_drvdata(pdev
);
1378 unregister_netdev(dev
);
1379 pci_release_regions(pdev
);
1381 pci_disable_device(pdev
);
1382 pci_set_drvdata(pdev
, NULL
);
1386 static struct pci_device_id r6040_pci_tbl
[] = {
1387 { PCI_DEVICE(PCI_VENDOR_ID_RDC
, 0x6040) },
1390 MODULE_DEVICE_TABLE(pci
, r6040_pci_tbl
);
1392 static struct pci_driver r6040_driver
= {
1394 .id_table
= r6040_pci_tbl
,
1395 .probe
= r6040_init_one
,
1396 .remove
= __devexit_p(r6040_remove_one
),
1400 static int __init
r6040_init(void)
1402 return pci_register_driver(&r6040_driver
);
1406 static void __exit
r6040_cleanup(void)
1408 pci_unregister_driver(&r6040_driver
);
1411 module_init(r6040_init
);
1412 module_exit(r6040_cleanup
);