Fixing the VIA rhine a bit

Alan Cox (alan@lxorguk.ukuu.org.uk)
Fri, 15 Oct 1999 02:48:49 +0100


Can someone with 2.3.22pre and a via rhine card test this out

It should fix the memory allocation checks and also reserve memory space
in MMIO mode

diff -u --new-file --recursive --exclude-from ../exclude linux.22p2/drivers/net/via-rhine.c linux.ac/drivers/net/via-rhine.c
--- linux.22p2/drivers/net/via-rhine.c Fri Oct 15 02:43:46 1999
+++ linux.ac/drivers/net/via-rhine.c Thu Oct 14 15:24:57 1999
@@ -110,14 +110,9 @@
#define RUN_AT(x) (jiffies + (x))

#ifdef MODULE
-char kernel_version[] = UTS_RELEASE;
-#else
-#ifndef __alpha__
-#define ioremap vremap
-#define iounmap vfree
-#endif
+static char kernel_version[] = UTS_RELEASE;
#endif
-#if defined(MODULE) && LINUX_VERSION_CODE > 0x20115
+
MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");
MODULE_DESCRIPTION("VIA Rhine PCI Fast Ethernet driver");
MODULE_PARM(max_interrupt_work, "i");
@@ -126,15 +121,7 @@
MODULE_PARM(rx_copybreak, "i");
MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
-#endif
-#if LINUX_VERSION_CODE < 0x20123
-#define test_and_set_bit(val, addr) set_bit(val, addr)
-#endif
-#if LINUX_VERSION_CODE <= 0x20139
-#define net_device_stats enet_statistics
-#else
-#define NETSTATS_VER2
-#endif
+
#if LINUX_VERSION_CODE < 0x20155 || defined(CARDBUS)
/* Grrrr, the PCI code changed, but did not consider CardBus... */
#include <linux/bios32.h>
@@ -142,11 +129,8 @@
#else
#define PCI_SUPPORT_VER2
#endif
-#if LINUX_VERSION_CODE < 0x20159
-#define dev_free_skb(skb) dev_kfree_skb(skb, FREE_WRITE);
-#else
+
#define dev_free_skb(skb) dev_kfree_skb(skb);
-#endif


/*
@@ -254,12 +238,12 @@
u16 vendor_id, device_id, device_id_mask, flags;
int io_size;
struct net_device *(*probe1)(int pci_bus, int pci_devfn, struct net_device *dev,
- long ioaddr, int irq, int chip_idx, int fnd_cnt);
+ long ioaddr, int irq, int chip_idx, int fnd_cnt, unsigned long pciaddr);
};

static struct net_device *via_probe1(int pci_bus, int pci_devfn,
struct net_device *dev, long ioaddr, int irq,
- int chp_idx, int fnd_cnt);
+ int chp_idx, int fnd_cnt, unsigned long pciaddr);

static struct pci_id_info pci_tbl[] = {
{ "VIA VT86C100A Rhine-II", 0x1106, 0x6100, 0xffff,
@@ -370,6 +354,7 @@
int mii_cnt; /* MII device addresses. */
u16 advertising; /* NWay media advertisement */
unsigned char phys[2]; /* MII device addresses. */
+ unsigned long physaddr; /* Physical address if MMIO */
};

static int mdio_read(struct net_device *dev, int phy_id, int location);
@@ -465,11 +450,16 @@
ioaddr = pciaddr & ~3;
if (check_region(ioaddr, pci_tbl[chip_idx].io_size))
continue;
- } else if ((ioaddr = (long)ioremap(pciaddr & ~0xf,
- pci_tbl[chip_idx].io_size)) == 0) {
- printk(KERN_INFO "Failed to map PCI address %#lx.\n",
- pciaddr);
- continue;
+ }
+ else
+ {
+ if(check_mem_region(pciaddr, pci_tbl[chip_idx].io_size))
+ continue;
+ if ((ioaddr = (long)ioremap(pciaddr & ~0xf, pci_tbl[chip_idx].io_size)) == 0) {
+ printk(KERN_INFO "Failed to map PCI address %#lx.\n",
+ pciaddr);
+ continue;
+ }
}

pcibios_read_config_word(pci_bus, pci_device_fn,
@@ -484,7 +474,7 @@
}

dev = pci_tbl[chip_idx].probe1(pci_bus, pci_device_fn, dev, ioaddr,
- irq, chip_idx, cards_found);
+ irq, chip_idx, cards_found, pciaddr);

if (dev && (pci_tbl[chip_idx].flags & PCI_COMMAND_MASTER)) {
u8 pci_latency;
@@ -513,14 +503,17 @@
}
#endif

+
static struct net_device *via_probe1(int pci_bus, int pci_devfn,
struct net_device *dev, long ioaddr, int irq,
- int chip_id, int card_idx)
+ int chip_id, int card_idx, unsigned long pciaddr)
{
struct netdev_private *np;
int i, option = card_idx < MAX_UNITS ? options[card_idx] : 0;

dev = init_etherdev(dev, 0);
+ if(dev==NULL)
+ return NULL;

printk(KERN_INFO "%s: %s at 0x%lx, ",
dev->name, pci_tbl[chip_id].name, ioaddr);
@@ -532,8 +525,19 @@
printk("%2.2x:", dev->dev_addr[i]);
printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);

+ /* Make certain the descriptor lists are cache-aligned. */
+ np = (void *)(((long)kmalloc(sizeof(*np), GFP_KERNEL) + 31) & ~31);
+ if(np==NULL)
+ {
+ printk(KERN_ERR "%s: No memory for descriptor buffers.\n",
+ dev->name);
+ return NULL;
+ }
+
#ifdef VIA_USE_IO
request_region(ioaddr, pci_tbl[chip_id].io_size, dev->name);
+#else
+ request_mem_region(pciaddr, pci_tbl[chip_id].io_size, dev->name);
#endif

/* Reset the chip to erase previous misconfiguration. */
@@ -542,8 +546,6 @@
dev->base_addr = ioaddr;
dev->irq = irq;

- /* Make certain the descriptor lists are cache-aligned. */
- np = (void *)(((long)kmalloc(sizeof(*np), GFP_KERNEL) + 31) & ~31);
memset(np, 0, sizeof(*np));
dev->priv = np;

@@ -553,6 +555,7 @@
np->pci_bus = pci_bus;
np->pci_devfn = pci_devfn;
np->chip_id = chip_id;
+ np->physaddr = pciaddr;

if (dev->mem_start)
option = dev->mem_start;
@@ -761,15 +764,14 @@
dev->name, readw(ioaddr + IntrStatus),
mdio_read(dev, np->phys[0], 1));

- /* Perhaps we should reinitialize the hardware here. */
- dev->if_port = 0;
- /* Stop and restart the chip's Tx processes . */
-
- /* Trigger an immediate transmit demand. */
-
- dev->trans_start = jiffies;
- np->stats.tx_errors++;
- return;
+ /* Perhaps we should reinitialize the hardware here. */
+ dev->if_port = 0;
+ /* Stop and restart the chip's Tx processes . */
+
+ /* Trigger an immediate transmit demand. */
+
+ dev->trans_start = jiffies;
+ np->stats.tx_errors++;
}


@@ -947,9 +949,7 @@
if (txstatus & 0x0001) np->stats.tx_deferred++;
#endif
np->stats.collisions += (txstatus >> 3) & 15;
-#if defined(NETSTATS_VER2)
np->stats.tx_bytes += np->tx_ring[entry].desc_length & 0x7ff;
-#endif
np->stats.tx_packets++;
}
/* Free the original skb. */
@@ -1288,6 +1288,7 @@
#ifdef VIA_USE_IO
release_region(root_net_dev->base_addr, pci_tbl[np->chip_id].io_size);
#else
+ release_mem_region(np->physaddr, pci_tbl[np->chip_id].io_size);
iounmap((char *)(root_net_dev->base_addr));
#endif
kfree(root_net_dev);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/