1 diff -urN linux-2.6.17/drivers/net/Kconfig linux-2.6.17.new/drivers/net/Kconfig
2 --- linux-2.6.17/drivers/net/Kconfig 2006-06-18 03:49:35.000000000 +0200
3 +++ linux-2.6.17.new/drivers/net/Kconfig 2006-09-25 13:14:27.000000000 +0200
5 <file:Documentation/networking/net-modules.txt>. The module will be
9 + tristate "RDC Fast-Ethernet support (EXPERIMENTAL)"
10 + depends on NET_PCI && EXPERIMENTAL
13 + If you have a network (Ethernet) controller of this type, say Y and
14 + read the Ethernet-HOWTO, available from
15 + <http://www.tldp.org/docs.html#howto>.
17 + To compile this driver as a module, choose M here and read
18 + <file:Documentation/networking/net-modules.txt>. The module will be
22 tristate "Broadcom 4400 ethernet support (EXPERIMENTAL)"
23 depends on NET_PCI && PCI && EXPERIMENTAL
24 diff -urN linux-2.6.17/drivers/net/Makefile linux-2.6.17.new/drivers/net/Makefile
25 --- linux-2.6.17/drivers/net/Makefile 2006-06-18 03:49:35.000000000 +0200
26 +++ linux-2.6.17.new/drivers/net/Makefile 2006-09-25 13:14:45.000000000 +0200
28 obj-$(CONFIG_NE3210) += ne3210.o 8390.o
29 obj-$(CONFIG_NET_SB1250_MAC) += sb1250-mac.o
30 obj-$(CONFIG_B44) += b44.o
31 +obj-$(CONFIG_R6040) += r6040.o
32 obj-$(CONFIG_FORCEDETH) += forcedeth.o
33 obj-$(CONFIG_NE_H8300) += ne-h8300.o 8390.o
35 diff -urN linux-2.6.17/drivers/net/r6040.c linux-2.6.17.new/drivers/net/r6040.c
36 --- linux-2.6.17/drivers/net/r6040.c 1970-01-01 01:00:00.000000000 +0100
37 +++ linux-2.6.17.new/drivers/net/r6040.c 2006-09-25 13:12:41.000000000 +0200
39 +/* rdc.c: A RDC FastEthernet driver for linux. */
41 + Re-written 2004 by Sten Wang.
43 + Copyright 1994-2000 by Donald Becker.
44 + Copyright 1993 United States Government as represented by the
45 + Director, National Security Agency. This software may be used and
46 + distributed according to the terms of the GNU General Public License,
47 + incorporated herein by reference.
49 + This driver is for RDC FastEthernet MAC series.
50 + For kernel version after 2.4.22
53 + ---------- ------------------------------------------------
54 + 12-22-2004 Sten Init MAC MBCR register=0x012A
58 +#define FORICPLUS /* Supports ICPlus IP175C switch chip */
59 +#define BOOSTRDC /* Accelerate Ethernet performance */
61 +#define DRV_NAME "rdc"
62 +#define DRV_VERSION "0.6"
63 +#define DRV_RELDATE "9July2004"
65 +/* PHY CHIP Address */
66 +#define PHY1_ADDR 1 /* For MAC1 */
67 +#define PHY2_ADDR 2 /* For MAC2 */
68 +#define PHY_MODE 0x3100 /* PHY CHIP Register 0 */
69 +#define PHY_CAP 0x01E1 /* PHY CHIP Register 4 */
71 +/* Time in jiffies before concluding the transmitter is hung. */
72 +#define TX_TIMEOUT (400 * HZ / 1000)
73 +#define TIMER_WUT (jiffies + HZ * 1)/* timer wakeup time : 1 second */
76 +#define RDC_MAC_ID 0x6040
78 +/* RDC MAC I/O Size */
79 +#define R6040_IO_SIZE 256
81 +/* RDC Chip PCI Command */
82 +#define R6040_PCI_CMD 0x0005 /* IO, Master */
89 +#define TX_DCNT 32 /* TX descriptor count */
90 +#define RX_DCNT 32 /* RX descriptor count */
92 +#define TX_DCNT 0x8 /* TX descriptor count */
93 +#define RX_DCNT 0x8 /* RX descriptor count */
95 +#define MAX_BUF_SIZE 0x600
96 +#define ALLOC_DESC_SIZE ((TX_DCNT+RX_DCNT)*sizeof(struct rdc_descriptor)+0x10)
97 +#define MBCR_DEFAULT 0x012A /* MAC Control Register */
99 +/* Debug enable or not */
103 +#define RDC_DBUG(msg, value) printk("%s %x\n", msg, value);
105 +#define RDC_DBUG(msg, value)
109 +#include <linux/module.h>
110 +#include <linux/kernel.h>
111 +#include <linux/string.h>
112 +#include <linux/timer.h>
113 +#include <linux/errno.h>
114 +#include <linux/ioport.h>
115 +#include <linux/slab.h>
116 +#include <linux/interrupt.h>
117 +#include <linux/pci.h>
118 +#include <linux/netdevice.h>
119 +#include <linux/etherdevice.h>
120 +#include <linux/skbuff.h>
121 +#include <linux/init.h>
122 +#include <linux/delay.h> /* for udelay() */
123 +#include <linux/mii.h>
124 +#include <linux/ethtool.h>
125 +#include <linux/crc32.h>
126 +#include <linux/spinlock.h>
128 +#include <asm/processor.h>
129 +#include <asm/bitops.h>
131 +#include <asm/irq.h>
132 +#include <asm/uaccess.h>
134 +MODULE_AUTHOR("Sten Wang <sten.wang@rdc.com.tw>");
135 +MODULE_DESCRIPTION("RDC R6040 PCI FastEthernet Driver");
136 +MODULE_LICENSE("GPL");
138 +//MODULE_PARM(adr_table, "2-4i");
139 +MODULE_PARM_DESC(adr_table, "MAC Address (assigned)");
141 +struct rdc_descriptor {
142 + u16 status, len; /* 0-3 */
144 + u32 ndesc; /* 8-B */
145 + u32 rev1; /* C-F */
146 + char *vbufp; /* 10-13 */
147 + struct rdc_descriptor *vndescp; /* 14-17 */
148 + struct sk_buff *skb_ptr; /* 18-1B */
149 + u32 rev2; /* 1C-1F */
150 +} __attribute__(( aligned(32) ));
152 +struct rdc_private {
153 + struct net_device_stats stats;
155 + struct timer_list timer;
156 + struct pci_dev *pdev;
158 + struct rdc_descriptor *rx_insert_ptr;
159 + struct rdc_descriptor *rx_remove_ptr;
160 + struct rdc_descriptor *tx_insert_ptr;
161 + struct rdc_descriptor *tx_remove_ptr;
162 + u16 tx_free_desc, rx_free_desc, phy_addr, phy_mode;
164 + dma_addr_t desc_dma;
168 +struct rdc_chip_info {
175 +static int __devinitdata printed_version;
176 +static char version[] __devinitdata =
177 + KERN_INFO DRV_NAME ": RDC R6040 net driver, version "
178 + DRV_VERSION " (" DRV_RELDATE ")\n";
180 +static struct rdc_chip_info rdc_chip_info[] __devinitdata =
182 + { "RDC R6040 Knight", R6040_PCI_CMD, R6040_IO_SIZE, 0}
185 +static int phy_table[] = { 0x1, 0x2};
186 +static u8 adr_table[2][8] = {{0x00, 0x00, 0x60, 0x00, 0x00, 0x01}, {0x00, 0x00, 0x60, 0x00, 0x00, 0x02}};
188 +static int rdc_open(struct net_device *dev);
189 +static int rdc_start_xmit(struct sk_buff *skb, struct net_device *dev);
190 +static irqreturn_t rdc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
191 +static struct net_device_stats *rdc_get_stats(struct net_device *dev);
192 +static int rdc_close(struct net_device *dev);
193 +static void set_multicast_list(struct net_device *dev);
194 +static struct ethtool_ops netdev_ethtool_ops;
195 +static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
196 +static void rdc_down(struct net_device *dev);
197 +static void rdc_up(struct net_device *dev);
198 +static void rdc_tx_timeout (struct net_device *dev);
199 +static void rdc_timer(unsigned long);
201 +static int phy_mode_chk(struct net_device *dev);
202 +static int phy_read(int ioaddr, int phy_adr, int reg_idx);
203 +static void phy_write(int ioaddr, int phy_adr, int reg_idx, int dat);
206 +#define rx_buf_alloc(lp) \
208 + struct rdc_descriptor *descptr; \
209 + descptr = lp->rx_insert_ptr; \
210 + while(lp->rx_free_desc < RX_DCNT){ \
211 + descptr->skb_ptr = dev_alloc_skb(MAX_BUF_SIZE); \
212 + if (!descptr->skb_ptr) break; \
213 + descptr->buf = cpu_to_le32(pci_map_single(lp->pdev, descptr->skb_ptr->tail, MAX_BUF_SIZE, PCI_DMA_FROMDEVICE)); \
214 + descptr->status = 0x8000; \
215 + descptr = descptr->vndescp; \
216 + lp->rx_free_desc++; \
218 + lp->rx_insert_ptr = descptr; \
222 +static void rx_buf_alloc(struct rdc_private *lp);
226 +static void process_ioctl(struct net_device*, unsigned long* );
229 +static int __devinit rdc_init_one (struct pci_dev *pdev,
230 + const struct pci_device_id *ent)
232 + struct net_device *dev;
233 + struct rdc_private *lp;
234 + int ioaddr, io_size, err;
235 + static int card_idx = -1;
236 + int chip_id = (int)ent->driver_data;
238 + RDC_DBUG("rdc_init_one()", 0);
240 + if (printed_version++)
243 + if ((err = pci_enable_device (pdev)))
246 + /* this should always be supported */
247 + if (pci_set_dma_mask(pdev, 0xffffffff)) {
248 + printk(KERN_ERR DRV_NAME "32-bit PCI DMA addresses not supported by the card!?\n");
252 + /* IO Size check */
253 + io_size = rdc_chip_info[chip_id].io_size;
254 + if (pci_resource_len (pdev, 0) < io_size) {
258 + ioaddr = pci_resource_start (pdev, 0); /* IO map base address */
259 + pci_set_master(pdev);
261 + dev = alloc_etherdev(sizeof(struct rdc_private));
264 + SET_MODULE_OWNER(dev);
266 + if (pci_request_regions(pdev, DRV_NAME)) {
267 + printk(KERN_ERR DRV_NAME ": Failed to request PCI regions\n");
269 + goto err_out_disable;
272 + /* Init system & device */
274 + dev->base_addr = ioaddr;
275 + dev->irq = pdev->irq;
277 + spin_lock_init(&lp->lock);
278 + pci_set_drvdata(pdev, dev);
280 + /* Set MAC address */
282 + memcpy(dev->dev_addr, (u8 *)&adr_table[card_idx][0], 6);
284 + /* Link new device into rdc_root_dev */
287 + /* Init RDC private data */
289 + lp->phy_addr = phy_table[card_idx];
291 + /* The RDC-specific entries in the device structure. */
292 + dev->open = &rdc_open;
293 + dev->hard_start_xmit = &rdc_start_xmit;
294 + dev->stop = &rdc_close;
295 + dev->get_stats = &rdc_get_stats;
296 + dev->set_multicast_list = &set_multicast_list;
297 + dev->do_ioctl = &netdev_ioctl;
298 + dev->ethtool_ops = &netdev_ethtool_ops;
299 + dev->tx_timeout = &rdc_tx_timeout;
300 + dev->watchdog_timeo = TX_TIMEOUT;
302 + /* Register net device. After this dev->name assign */
303 + if ((err = register_netdev(dev))) {
304 + printk(KERN_ERR DRV_NAME ": Failed to register net device\n");
308 + netif_carrier_on(dev);
312 + pci_release_regions(pdev);
314 + pci_disable_device(pdev);
315 + pci_set_drvdata(pdev, NULL);
321 +static void __devexit rdc_remove_one (struct pci_dev *pdev)
323 + struct net_device *dev = pci_get_drvdata(pdev);
325 + unregister_netdev(dev);
326 + pci_release_regions(pdev);
328 + pci_disable_device(pdev);
329 + pci_set_drvdata(pdev, NULL);
333 +rdc_open(struct net_device *dev)
335 + struct rdc_private *lp = dev->priv;
338 + RDC_DBUG("rdc_open()", 0);
340 + /* Request IRQ and Register interrupt handler */
341 + i = request_irq(dev->irq, &rdc_interrupt, SA_SHIRQ, dev->name, dev);
344 + /* Allocate Descriptor memory */
345 + lp->desc_pool = pci_alloc_consistent(lp->pdev, ALLOC_DESC_SIZE, &lp->desc_dma);
346 + if (!lp->desc_pool) return -ENOMEM;
350 + netif_start_queue(dev);
353 + /* set and active a timer process */
354 + init_timer(&lp->timer);
355 + lp->timer.expires = TIMER_WUT;
356 + lp->timer.data = (unsigned long)dev;
357 + lp->timer.function = &rdc_timer;
358 + add_timer(&lp->timer);
365 +rdc_tx_timeout (struct net_device *dev)
367 + struct rdc_private *lp = dev->priv;
368 + //int ioaddr = dev->base_addr;
369 + //struct rdc_descriptor *descptr = lp->tx_remove_ptr;
371 + RDC_DBUG("rdc_tx_timeout()", 0);
373 + /* Transmitter timeout, serious problems. */
374 + /* Sten: Nothing need to do so far. */
375 + printk(KERN_ERR DRV_NAME ": Big Trobule, transmit timeout/n");
376 + lp->stats.tx_errors++;
377 + netif_stop_queue(dev);
379 +//printk("<RDC> XMT timedout: CR0 %x, CR40 %x, CR3C %x, CR2C %x, CR30 %x, CR34 %x, CR38 %x\n", inw(ioaddr), inw(ioaddr+0x40), inw(ioaddr+0x3c), inw(ioaddr+0x2c), inw(ioaddr+0x30), inw(ioaddr+0x34), inw(ioaddr+0x38));
381 +//printk("<RDC> XMT_TO: %08lx:%04x %04x %08lx %08lx %08lx %08lx\n", descptr, descptr->status, descptr->len, descptr->buf, descptr->skb_ptr, descptr->ndesc, descptr->vndescp);
386 +rdc_start_xmit(struct sk_buff *skb, struct net_device *dev)
388 + struct rdc_private *lp = dev->priv;
389 + struct rdc_descriptor *descptr;
390 + int ioaddr = dev->base_addr;
391 + unsigned long flags;
393 + RDC_DBUG("rdc_start_xmit()", 0);
395 + if (skb == NULL) /* NULL skb directly return */
397 + if (skb->len >= MAX_BUF_SIZE) { /* Packet too long, drop it */
398 + dev_kfree_skb(skb);
402 + /* Critical Section */
403 + spin_lock_irqsave(&lp->lock, flags);
405 + /* TX resource check */
406 + if (!lp->tx_free_desc) {
407 + spin_unlock_irqrestore(&lp->lock, flags);
408 + printk(KERN_ERR DRV_NAME ": NO TX DESC ");
412 + /* Statistic Counter */
413 + lp->stats.tx_packets++;
414 + lp->stats.tx_bytes += skb->len;
416 + /* Set TX descriptor & Transmit it */
417 + lp->tx_free_desc--;
418 + descptr = lp->tx_insert_ptr;
419 + if (skb->len < 0x3c) descptr->len = 0x3c;
420 + else descptr->len = skb->len;
421 + descptr->skb_ptr = skb;
422 + descptr->buf = cpu_to_le32(pci_map_single(lp->pdev, skb->data, skb->len, PCI_DMA_TODEVICE));
423 + descptr->status = 0x8000;
424 + outw(0x01, ioaddr + 0x14);
425 + lp->tx_insert_ptr = descptr->vndescp;
428 + printk("Xmit(): %08lx:%04x %04x %08lx %08lx %08lx %08lx\n", descptr, descptr->status, descptr->len, descptr->buf, descptr->skb_ptr, descptr->ndesc, descptr->vndescp);
431 + /* If no tx resource, stop */
432 + if (!lp->tx_free_desc)
433 + netif_stop_queue(dev);
435 + dev->trans_start = jiffies;
436 + spin_unlock_irqrestore(&lp->lock, flags);
440 +/* The RDC interrupt handler. */
442 +rdc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
444 + struct net_device *dev = dev_id;
445 + struct rdc_private *lp;
446 + struct rdc_descriptor *descptr;
447 + struct sk_buff *skb_ptr;
448 + int ioaddr, status;
449 + unsigned long flags;
452 + RDC_DBUG("rdc_interrupt()", 0);
454 + printk (KERN_ERR DRV_NAME ": INT() unknown device.\n");
455 + return IRQ_RETVAL(handled);
458 + lp = (struct rdc_private *)dev->priv;
459 + spin_lock_irqsave(&lp->lock, flags);
461 + /* Check MAC Interrupt status */
462 + ioaddr = dev->base_addr;
463 + outw(0x0, ioaddr + 0x40); /* Mask Off RDC MAC interrupt */
464 + status = inw(ioaddr + 0x3c); /* Read INTR status and clear */
466 + /* TX interrupt request */
467 + if (status & 0x10) {
469 + descptr = lp->tx_remove_ptr;
470 + while(lp->tx_free_desc < TX_DCNT) {
471 + if (descptr->status & 0x8000) break; /* Not complte */
472 + skb_ptr = descptr->skb_ptr;
473 + pci_unmap_single(lp->pdev, descptr->buf, skb_ptr->len, PCI_DMA_TODEVICE);
474 + dev_kfree_skb_irq(skb_ptr); /* Free buffer */
475 + descptr->skb_ptr = 0;
476 + descptr = descptr->vndescp; /* To next descriptor */
477 + lp->tx_free_desc++;
479 + lp->tx_remove_ptr = descptr;
480 + if (lp->tx_free_desc) netif_wake_queue(dev);
483 + /* RX interrupt request */
484 + if (status & 0x01) {
486 + descptr = lp->rx_remove_ptr;
487 + while(lp->rx_free_desc) {
488 + if (descptr->status & 0x8000) break; /* No Rx packet */
489 + skb_ptr = descptr->skb_ptr;
490 + descptr->skb_ptr = 0;
491 + skb_ptr->dev = dev;
492 + skb_put(skb_ptr, descptr->len - 4);
493 + pci_unmap_single(lp->pdev, descptr->buf, MAX_BUF_SIZE, PCI_DMA_FROMDEVICE);
494 + skb_ptr->protocol = eth_type_trans(skb_ptr, dev);
495 + netif_rx(skb_ptr); /* Send to upper layer */
496 + lp->stats.rx_packets++;
497 + lp->stats.rx_bytes += descptr->len;
498 + descptr = descptr->vndescp; /* To next descriptor */
499 + lp->rx_free_desc--;
501 + lp->rx_remove_ptr = descptr;
504 + /* Allocate new RX buffer */
505 + if (lp->rx_free_desc < RX_DCNT) rx_buf_alloc(lp);
507 + outw(0x0011, ioaddr + 0x40); /* TX/RX interrupt enable */
508 + spin_unlock_irqrestore(&lp->lock, flags);
510 + return IRQ_RETVAL(handled);
514 +static struct net_device_stats *
515 +rdc_get_stats(struct net_device *dev)
517 + struct rdc_private *lp = dev->priv;
519 + RDC_DBUG("rdc_get_stats()", 0);
524 + * Set or clear the multicast filter for this adaptor.
527 +set_multicast_list(struct net_device *dev)
529 + struct rdc_private *lp = dev->priv;
530 + struct dev_mc_list *mcptr;
531 + int ioaddr = dev->base_addr;
533 + unsigned long flags;
535 + RDC_DBUG("set_multicast_list()", 0);
539 + adrp = (u16 *) dev->dev_addr;
540 + outw(adrp[0], ioaddr); ioaddr += 2;
541 + outw(adrp[1], ioaddr); ioaddr += 2;
542 + outw(adrp[2], ioaddr); ioaddr += 2;
545 + printk("MAC ADDR: %04x %04x %04x\n", adrp[0], adrp[1], adrp[2]);
548 + /* Promiscous Mode */
549 + spin_lock_irqsave(lp->lock, flags);
550 + i = inw(ioaddr) & ~0x0120; /* Clear AMCP & PROM */
551 + if (dev->flags & IFF_PROMISC) i |= 0x0020;
552 + if (dev->mc_count > 4) i |= 0x0100; /* Too many multicast address */
554 + spin_unlock_irqrestore(lp->lock, flags);
556 + /* Multicast Address */
557 + if (dev->mc_count > 4) /* Wait to do: Hash Table for multicast */
560 + /* Multicast Address 1~4 case */
561 + for (i = 0, mcptr = dev->mc_list; (i<dev->mc_count) && (i<4); i++) {
562 + adrp = (u16 *)mcptr->dmi_addr;
563 + outw(adrp[0], ioaddr); ioaddr += 2;
564 + outw(adrp[1], ioaddr); ioaddr += 2;
565 + outw(adrp[2], ioaddr); ioaddr += 2;
566 + mcptr = mcptr->next;
568 + printk("M_ADDR: %04x %04x %04x\n", adrp[0], adrp[1], adrp[2]);
571 + for (i = dev->mc_count; i < 4; i++) {
572 + outw(0xffff, ioaddr); ioaddr += 2;
573 + outw(0xffff, ioaddr); ioaddr += 2;
574 + outw(0xffff, ioaddr); ioaddr += 2;
578 +static void netdev_get_drvinfo (struct net_device *dev, struct ethtool_drvinfo *info)
580 + struct rdc_private *rp = dev->priv;
582 + strcpy (info->driver, DRV_NAME);
583 + strcpy (info->version, DRV_VERSION);
584 + strcpy (info->bus_info, pci_name(rp->pdev));
587 +static struct ethtool_ops netdev_ethtool_ops = {
588 + .get_drvinfo = netdev_get_drvinfo,
592 +rdc_close(struct net_device *dev)
594 + struct rdc_private *lp = dev->priv;
596 + RDC_DBUG("rdc_close()", 0);
598 + /* deleted timer */
599 + del_timer_sync(&lp->timer);
601 + spin_lock_irq(&lp->lock);
603 + netif_stop_queue(dev);
607 + spin_unlock_irq(&lp->lock);
614 +static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd)
616 + RDC_DBUG("netdev_ioctl()", 0);
621 + case SIOCDEVPRIVATE:
623 + //printk(KERN_INFO"Ethernet IOCTL: cmd SIOCDEVPRIVATE\n");
625 + unsigned long *data;
626 + unsigned long args[4];
628 + data = (unsigned long *)rq->ifr_data;
629 + if (copy_from_user(args, data, 4*sizeof(unsigned long)))
632 + process_ioctl(dev, args);
644 + Stop RDC MAC and Free the allocated resource
646 +static void rdc_down(struct net_device *dev)
648 + struct rdc_private *lp = dev->priv;
650 + int ioaddr = dev->base_addr;
652 + RDC_DBUG("rdc_down()", 0);
655 + outw(0x0000, ioaddr + 0x40); /* Mask Off Interrupt */
656 + outw(0x0001, ioaddr + 0x04); /* Reset RDC MAC */
658 + do{}while((i++ < 2048) && (inw(ioaddr + 0x04) & 0x1));
660 + free_irq(dev->irq, dev);
662 + /* Free RX buffer */
663 + for (i = 0; i < RX_DCNT; i++) {
664 + if (lp->rx_insert_ptr->skb_ptr) {
665 + pci_unmap_single(lp->pdev, lp->rx_insert_ptr->buf, MAX_BUF_SIZE, PCI_DMA_FROMDEVICE);
666 + dev_kfree_skb(lp->rx_insert_ptr->skb_ptr);
667 + lp->rx_insert_ptr->skb_ptr = 0;
669 + lp->rx_insert_ptr = lp->rx_insert_ptr->vndescp;
672 + /* Free TX buffer */
673 + for (i = 0; i < TX_DCNT; i++) {
674 + if (lp->tx_insert_ptr->skb_ptr) {
675 + pci_unmap_single(lp->pdev, lp->tx_insert_ptr->buf, MAX_BUF_SIZE, PCI_DMA_TODEVICE);
676 + dev_kfree_skb(lp->tx_insert_ptr->skb_ptr);
677 + lp->rx_insert_ptr->skb_ptr = 0;
679 + lp->tx_insert_ptr = lp->tx_insert_ptr->vndescp;
682 + /* Free Descriptor memory */
683 + pci_free_consistent(lp->pdev, ALLOC_DESC_SIZE, lp->desc_pool, lp->desc_dma);
687 +static void rdc_up(struct net_device *dev)
689 + struct rdc_private *lp = dev->priv;
690 + struct rdc_descriptor *descptr;
692 + int ioaddr = dev->base_addr;
694 + dma_addr_t desc_dma, start_dma;
696 + RDC_DBUG("rdc_up()", 0);
699 + lp->tx_free_desc = TX_DCNT;
700 + lp->rx_free_desc = 0;
702 + /* Init descriptor */
703 + memset(lp->desc_pool, 0, ALLOC_DESC_SIZE); /* Let all descriptor = 0 */
704 + lp->tx_insert_ptr = (struct rdc_descriptor *)lp->desc_pool;
705 + lp->tx_remove_ptr = lp->tx_insert_ptr;
706 + lp->rx_insert_ptr = (struct rdc_descriptor *)lp->tx_insert_ptr+TX_DCNT;
707 + lp->rx_remove_ptr = lp->rx_insert_ptr;
709 + /* Init TX descriptor */
710 + descptr = lp->tx_insert_ptr;
711 + desc_dma = lp->desc_dma;
712 + start_dma = desc_dma;
713 + for (i = 0; i < TX_DCNT; i++) {
714 + descptr->ndesc = cpu_to_le32(desc_dma + sizeof(struct rdc_descriptor));
715 + descptr->vndescp = (descptr + 1);
716 + descptr = (descptr + 1);
717 + desc_dma += sizeof(struct rdc_descriptor);
719 + (descptr - 1)->ndesc = cpu_to_le32(start_dma);
720 + (descptr - 1)->vndescp = lp->tx_insert_ptr;
722 + /* Init RX descriptor */
723 + start_dma = desc_dma;
724 + descptr = lp->rx_insert_ptr;
725 + for (i = 0; i < RX_DCNT; i++) {
726 + descptr->ndesc = cpu_to_le32(desc_dma + sizeof(struct rdc_descriptor));
727 + descptr->vndescp = (descptr + 1);
728 + descptr = (descptr + 1);
729 + desc_dma += sizeof(struct rdc_descriptor);
731 + (descptr - 1)->ndesc = cpu_to_le32(start_dma);
732 + (descptr - 1)->vndescp = lp->rx_insert_ptr;
734 + /* Allocate buffer for RX descriptor */
738 +descptr = lp->tx_insert_ptr;
739 +for (i = 0; i < TX_DCNT; i++) {
740 + printk("%08lx:%04x %04x %08lx %08lx %08lx %08lx\n", descptr, descptr->status, descptr->len, descptr->buf, descptr->skb_ptr, descptr->ndesc, descptr->vndescp);
741 + descptr = descptr->vndescp;
743 +descptr = lp->rx_insert_ptr;
744 +for (i = 0; i < RX_DCNT; i++) {
745 + printk("%08lx:%04x %04x %08lx %08lx %08lx %08lx\n", descptr, descptr->status, descptr->len, descptr->buf, descptr->skb_ptr, descptr->ndesc, descptr->vndescp);
746 + descptr = descptr->vndescp;
750 + /* MAC operation register */
751 + outw(0x01, ioaddr); /* Reset MAC */
752 + outw(2 , ioaddr+0xAC);
753 + outw(0 , ioaddr+0xAC);
756 + /* TX and RX descriptor start Register */
757 + tmp_addr = cpu_to_le32(lp->tx_insert_ptr);
759 + tmp_addr = virt_to_bus((volatile void *)tmp_addr);
760 + outw((u16) tmp_addr, ioaddr+0x2c);
761 + outw(tmp_addr >> 16, ioaddr+0x30);
762 + tmp_addr = cpu_to_le32(lp->rx_insert_ptr);
764 + tmp_addr = virt_to_bus((volatile void *)tmp_addr);
765 + outw((u16) tmp_addr, ioaddr+0x34);
766 + outw(tmp_addr >> 16, ioaddr+0x38);
768 + /* Buffer Size Register */
769 + outw(MAX_BUF_SIZE, ioaddr+0x18);
773 + if(phy_read(ioaddr, 0, 2) == 0x0243) // ICPlus IP175C Signature
775 + phy_write(ioaddr, 29,31, 0x175C); //Enable registers
777 + lp->phy_mode = 0x8000;
780 + /* PHY Mode Check */
781 + phy_write(ioaddr, lp->phy_addr, 4, PHY_CAP);
782 + phy_write(ioaddr, lp->phy_addr, 0, PHY_MODE);
784 + if (PHY_MODE == 0x3100)
785 + lp->phy_mode = phy_mode_chk(dev);
786 + else lp->phy_mode = (PHY_MODE & 0x0100) ? 0x8000:0x0;
788 + /* MAC Bus Control Register */
789 + outw(MBCR_DEFAULT, ioaddr+0x8);
791 + /* MAC TX/RX Enable */
792 + lp->mcr0 |= lp->phy_mode;
795 + // BIT15 | BIT12 | BIT5 | BIT1
796 + lp->mcr0 |= 0x0020;
797 + //Xavier, only set promiscuous mode with eth1 (LAN i/f)
798 + //This is a very bad hard code...
799 + //if(ioaddr == 0xe900)lp->mcr0 |= 0x0020;
801 + outw(lp->mcr0, ioaddr);
804 + /* set interrupt waiting time and packet numbers */
805 + outw(0x0802, ioaddr + 0x0C);
806 + outw(0x0802, ioaddr + 0x10);
809 + /* upgrade performance (by RDC guys) */
810 + phy_write(ioaddr,30,17,(phy_read(ioaddr,30,17)|0x4000)); //bit 14=1
811 + phy_write(ioaddr,30,17,~((~phy_read(ioaddr,30,17))|0x2000)); //bit 13=0
812 + phy_write(ioaddr,0,19,0x0000);
813 + phy_write(ioaddr,0,30,0x01F0);
817 + /* Interrupt Mask Register */
818 + outw(0x0011, ioaddr + 0x40);
822 + A periodic timer routine
823 + Polling PHY Chip Link Status
825 +static void rdc_timer(unsigned long data)
827 + struct net_device *dev=(struct net_device *)data;
828 + struct rdc_private *lp = dev->priv;
829 + u16 ioaddr = dev->base_addr, phy_mode;
831 + RDC_DBUG("rdc_timer()", 0);
833 + /* Polling PHY Chip Status */
834 + if (PHY_MODE == 0x3100)
835 + phy_mode = phy_mode_chk(dev);
836 + else phy_mode = (PHY_MODE & 0x0100) ? 0x8000:0x0;
838 + if (phy_mode != lp->phy_mode) {
839 + lp->phy_mode = phy_mode;
840 + lp->mcr0 = (lp->mcr0 & 0x7fff) | phy_mode;
841 + outw(lp->mcr0, ioaddr);
842 + printk("<RDC> Link Change %x \n", inw(ioaddr));
846 +// printk("<RDC> Timer: CR0 %x CR40 %x CR3C %x\n", inw(ioaddr), inw(ioaddr+0x40), inw(ioaddr+0x3c));
848 + /* Timer active again */
849 + lp->timer.expires = TIMER_WUT;
850 + add_timer(&lp->timer);
854 +/* Allocate skb buffer for rx descriptor */
855 +static void rx_buf_alloc(struct rdc_private *lp)
857 + struct rdc_descriptor *descptr;
859 + RDC_DBUG("rx_buf_alloc()", 0);
860 + descptr = lp->rx_insert_ptr;
861 + while(lp->rx_free_desc < RX_DCNT){
862 + descptr->skb_ptr = dev_alloc_skb(MAX_BUF_SIZE);
863 + if (!descptr->skb_ptr) break;
864 + descptr->buf = cpu_to_le32(pci_map_single(lp->pdev, descptr->skb_ptr->tail, MAX_BUF_SIZE, PCI_DMA_FROMDEVICE));
865 + descptr->status = 0x8000;
866 + descptr = descptr->vndescp;
867 + lp->rx_free_desc++;
869 + lp->rx_insert_ptr = descptr;
873 +/* Status of PHY CHIP */
874 +static int phy_mode_chk(struct net_device *dev)
877 + struct rdc_private *lp = dev->priv;
878 + int ioaddr = dev->base_addr, phy_dat;
880 + RDC_DBUG("phy_mode_chk()", 0);
882 + /* PHY Link Status Check */
883 + phy_dat = phy_read(ioaddr, lp->phy_addr, 1);
884 + if (!(phy_dat & 0x4)) return 0x8000; /* Link Failed, full duplex */
886 + /* PHY Chip Auto-Negotiation Status */
887 + phy_dat = phy_read(ioaddr, lp->phy_addr, 1);
888 + if (phy_dat & 0x0020) {
889 + /* Auto Negotiation Mode */
890 + phy_dat = phy_read(ioaddr, lp->phy_addr, 5);
891 + phy_dat &= phy_read(ioaddr, lp->phy_addr, 4);
892 + if (phy_dat & 0x140) phy_dat = 0x8000;
896 + phy_dat = phy_read(ioaddr, lp->phy_addr, 0);
897 + if (phy_dat & 0x100) phy_dat = 0x8000;
898 + else phy_dat = 0x0000;
905 +/* Read a word data from PHY Chip */
906 +static int phy_read(int ioaddr, int phy_addr, int reg_idx)
910 + RDC_DBUG("phy_read()", 0);
911 + outw(0x2000 + reg_idx + (phy_addr << 8), ioaddr + 0x20);
912 + do{}while( (i++ < 2048) && (inw(ioaddr + 0x20) & 0x2000) );
914 + return inw(ioaddr + 0x24);
917 +/* Write a word data from PHY Chip */
918 +static void phy_write(int ioaddr, int phy_addr, int reg_idx, int dat)
922 + RDC_DBUG("phy_write()", 0);
923 + outw(dat, ioaddr + 0x28);
924 + outw(0x4000 + reg_idx + (phy_addr << 8), ioaddr + 0x20);
925 + do{}while( (i++ < 2048) && (inw(ioaddr + 0x20) & 0x4000) );
932 +static struct pci_device_id rdc_pci_tbl[] = {
933 + {0x17F3, 0x6040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RDC_6040},
934 + //{0x1106, 0x3065, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RDC_6040},
935 + {0,} /* terminate list */
937 +MODULE_DEVICE_TABLE(pci, rdc_pci_tbl);
939 +static struct pci_driver rdc_driver = {
941 + .id_table = rdc_pci_tbl,
942 + .probe = rdc_init_one,
943 + .remove = __devexit_p(rdc_remove_one),
947 +static int __init rdc_init (void)
949 + RDC_DBUG("rdc_init()", 0);
952 + printed_version = 1;
954 + return pci_module_init (&rdc_driver);
958 +static void __exit rdc_cleanup (void)
960 + RDC_DBUG("rdc_cleanup()", 0);
961 + pci_unregister_driver (&rdc_driver);
964 +module_init(rdc_init);
965 +module_exit(rdc_cleanup);
970 + * compile-command: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c rdc.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`"
971 + * c-indent-level: 4
972 + * c-basic-offset: 4
979 +#define RDC3210_CFGREG_ADDR 0x0CF8
980 +#define RDC3210_CFGREG_DATA 0x0CFC
981 +static void process_ioctl(struct net_device *dev, unsigned long* args)
983 + int ioaddr = dev->base_addr;
985 + /* port priority */
986 + if(args[0]&(1<<31))phy_write(ioaddr,29,19,(phy_read(ioaddr,29,19)|0x2000)); /* port 0 */
987 + if(args[0]&(1<<29))phy_write(ioaddr,29,19,(phy_read(ioaddr,29,19)|0x0020)); /* port 1 */
988 + if(args[0]&(1<<27))phy_write(ioaddr,29,20,(phy_read(ioaddr,29,20)|0x2000)); /* port 2 */
989 + if(args[0]&(1<<25))phy_write(ioaddr,29,20,(phy_read(ioaddr,29,20)|0x0020)); /* port 3 */
996 + val = 0x80000000 | (7 << 11) | ((0x48));
997 + outl(val, RDC3210_CFGREG_ADDR);
999 + val = inl(RDC3210_CFGREG_DATA);
1001 + val |= (0x1 << DMZ_GPIO);
1002 + outl(val, RDC3210_CFGREG_DATA);
1005 + val = 0x80000000 | (7 << 11) | ((0x4C));
1006 + outl(val, RDC3210_CFGREG_ADDR);
1008 + val = inl(RDC3210_CFGREG_DATA);
1009 + if(args[0]&(1<<23)) /* DMZ enabled */
1010 + val &= ~(0x1 << DMZ_GPIO); /* low activated */
1011 + else val |= (0x1 << DMZ_GPIO);
1012 + outl(val, RDC3210_CFGREG_DATA);
1018 +#endif /* FORICPLUS */