patch-2.4.3 linux/drivers/net/sis900.c

Next file: linux/drivers/net/sk98lin/h/lm80.h
Previous file: linux/drivers/net/sgiseeq.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.2/linux/drivers/net/sis900.c linux/drivers/net/sis900.c
@@ -18,6 +18,7 @@
    preliminary Rev. 1.0 Jan. 18, 1998
    http://www.sis.com.tw/support/databook.htm
 
+   Rev 1.07.09 Feb.  9 2001 Dave Jones <davej@suse.de> PCI enable cleanup
    Rev 1.07.08 Jan.  8 2001 Lei-Chun Chang added RTL8201 PHY support
    Rev 1.07.07 Nov. 29 2000 Lei-Chun Chang added kernel-doc extractable documentation and 630 workaround fix
    Rev 1.07.06 Nov.  7 2000 Jeff Garzik <jgarzik@mandrakesoft.com> some bug fix and cleaning
@@ -60,7 +61,7 @@
 #include "sis900.h"
 
 static const char *version =
-"sis900.c: v1.07.08  1/8/2001\n";
+"sis900.c: v1.07.09  2/9/2001\n";
 
 static int max_interrupt_work = 20;
 static int multicast_filter_limit = 128;
@@ -252,34 +253,37 @@
 static int __devinit sis900_probe (struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
 {
 	struct sis900_private *sis_priv;
-	long ioaddr = pci_resource_start(pci_dev, 0);
+	long ioaddr;
 	struct net_device *net_dev;
-	int irq = pci_dev->irq;
-	int i, ret = 0;
+	int irq;
+	int i, ret;
 	u8 revision;
 	char *card_name = card_names[pci_id->driver_data];
 
-	if (!pci_dma_supported(pci_dev, SIS900_DMA_MASK)) {
+	/* setup various bits in PCI command register */
+	ret = pci_enable_device (pci_dev);
+	if (ret) return ret;
+
+	i = pci_set_dma_mask(pci_dev, SIS900_DMA_MASK);
+	if (i) {
 		printk(KERN_ERR "sis900.c: architecture does not support "
 		       "32bit PCI busmaster DMA\n");
-		return -ENODEV;
+		return i;
 	}
 
-	/* setup various bits in PCI command register */
-	if (pci_enable_device (pci_dev))
-		return -ENODEV;
 	pci_set_master(pci_dev);
 
-	net_dev = init_etherdev(NULL, sizeof(struct sis900_private));
+	irq = pci_dev->irq;
+	ioaddr = pci_resource_start(pci_dev, 0);
+
+	net_dev = alloc_etherdev(sizeof(struct sis900_private));
 	if (!net_dev)
 		return -ENOMEM;
 	SET_MODULE_OWNER(net_dev);
 
-	if (!request_region(ioaddr, SIS900_TOTAL_SIZE, net_dev->name)) {
-		printk(KERN_ERR "sis900.c: can't allocate I/O space at 0x%lX\n", ioaddr);
-		ret = -EBUSY;
+	ret = pci_request_regions(pci_dev, "sis900");
+	if (ret)
 		goto err_out;
-	}
 
 	pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &revision);
 	if (revision == SIS630E_900_REV || revision == SIS630EA1_900_REV)
@@ -294,13 +298,6 @@
 		goto err_out_region;
 	}
 
-	/* print some information about our NIC */
-	printk(KERN_INFO "%s: %s at %#lx, IRQ %d, ", net_dev->name,
-	       card_name, ioaddr, irq);
-	for (i = 0; i < 5; i++)
-		printk("%2.2x:", (u8)net_dev->dev_addr[i]);
-	printk("%2.2x.\n", net_dev->dev_addr[i]);
-
 	sis_priv = net_dev->priv;
 
 	/* We do a request_region() to register /proc/ioports info. */
@@ -315,8 +312,7 @@
 		goto err_out_region;
 	}
 
-	pci_dev->driver_data = net_dev;
-	pci_dev->dma_mask = SIS900_DMA_MASK;
+	pci_set_drvdata(pci_dev, net_dev);
 
 	/* The SiS900-specific entries in the device structure. */
 	net_dev->open = &sis900_open;
@@ -329,12 +325,24 @@
 	net_dev->tx_timeout = sis900_tx_timeout;
 	net_dev->watchdog_timeo = TX_TIMEOUT;
 
+	ret = register_netdev(net_dev);
+	if (ret)
+		goto err_out_cleardev;
+
+	/* print some information about our NIC */
+	printk(KERN_INFO "%s: %s at %#lx, IRQ %d, ", net_dev->name,
+	       card_name, ioaddr, irq);
+	for (i = 0; i < 5; i++)
+		printk("%2.2x:", (u8)net_dev->dev_addr[i]);
+	printk("%2.2x.\n", net_dev->dev_addr[i]);
+
 	return 0;
 
+err_out_cleardev:
+	pci_set_drvdata(pci_dev, NULL);
 err_out_region:
-	release_region(ioaddr, SIS900_TOTAL_SIZE);
+	pci_release_regions(pci_dev);
 err_out:
-	unregister_netdev(net_dev);
 	kfree(net_dev);
 	return ret;
 }
@@ -350,7 +358,7 @@
 
 static int __init sis900_mii_probe (struct net_device * net_dev)
 {
-	struct sis900_private * sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private * sis_priv = net_dev->priv;
 	int phy_addr;
 	u8 revision;
 
@@ -608,7 +616,7 @@
 static int
 sis900_open(struct net_device *net_dev)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	long ioaddr = net_dev->base_addr;
 	u8  revision;
 	int ret;
@@ -701,7 +709,7 @@
 static void
 sis900_init_tx_ring(struct net_device *net_dev)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	long ioaddr = net_dev->base_addr;
 	int i;
 
@@ -735,7 +743,7 @@
 static void 
 sis900_init_rx_ring(struct net_device *net_dev)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	long ioaddr = net_dev->base_addr;
 	int i;
 
@@ -806,7 +814,7 @@
 
 static void sis630_set_eq(struct net_device *net_dev, u8 revision)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	u16 reg14h, eq_value, max_value=0, min_value=0;
 	u8 host_bridge_rev;
 	int i, maxcount=10;
@@ -873,7 +881,7 @@
 static void sis900_timer(unsigned long data)
 {
 	struct net_device *net_dev = (struct net_device *)data;
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	struct mii_phy *mii_phy = sis_priv->mii;
 	static int next_tick = 5*HZ;
 	u16 status;
@@ -950,7 +958,7 @@
 
 static void sis900_check_mode (struct net_device *net_dev, struct mii_phy *mii_phy)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	long ioaddr = net_dev->base_addr;
 	int speed, duplex;
 	u32 tx_flags = 0, rx_flags = 0;
@@ -1169,7 +1177,7 @@
 
 static void sis900_tx_timeout(struct net_device *net_dev)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	long ioaddr = net_dev->base_addr;
 	unsigned long flags;
 	int i;
@@ -1222,7 +1230,7 @@
 static int
 sis900_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	long ioaddr = net_dev->base_addr;
 	unsigned int  entry;
 	unsigned long flags;
@@ -1271,8 +1279,8 @@
 
 static void sis900_interrupt(int irq, void *dev_instance, struct pt_regs *regs)
 {
-	struct net_device *net_dev = (struct net_device *)dev_instance;
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct net_device *net_dev = dev_instance;
+	struct sis900_private *sis_priv = net_dev->priv;
 	int boguscnt = max_interrupt_work;
 	long ioaddr = net_dev->base_addr;
 	u32 status;
@@ -1330,7 +1338,7 @@
 
 static int sis900_rx(struct net_device *net_dev)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	long ioaddr = net_dev->base_addr;
 	unsigned int entry = sis_priv->cur_rx % NUM_RX_DESC;
 	u32 rx_status = sis_priv->rx_ring[entry].cmdsts;
@@ -1459,7 +1467,7 @@
 
 static void sis900_finish_xmit (struct net_device *net_dev)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 
 	for (; sis_priv->dirty_tx < sis_priv->cur_tx; sis_priv->dirty_tx++) {
 		unsigned int entry;
@@ -1469,14 +1477,14 @@
 		tx_status = sis_priv->tx_ring[entry].cmdsts;
 
 		if (tx_status & OWN) {
-			/* The packet is not transmited yet (owned by hardware) !
+			/* The packet is not transmitted yet (owned by hardware) !
 			   Note: the interrupt is generated only when Tx Machine
 			   is idle, so this is an almost impossible case */
 			break;
 		}
 
 		if (tx_status & (ABORT | UNDERRUN | OWCOLL)) {
-			/* packet unsuccessfully transmited */
+			/* packet unsuccessfully transmitted */
 			if (sis900_debug > 3)
 				printk(KERN_INFO "%s: Transmit "
 				       "error, Tx status %8.8x.\n",
@@ -1491,7 +1499,7 @@
 			if (tx_status & OWCOLL)
 				sis_priv->stats.tx_window_errors++;
 		} else {
-			/* packet successfully transmited */
+			/* packet successfully transmitted */
 			sis_priv->stats.collisions += (tx_status & COLCNT) >> 16;
 			sis_priv->stats.tx_bytes += tx_status & DSIZE;
 			sis_priv->stats.tx_packets++;
@@ -1524,7 +1532,7 @@
 sis900_close(struct net_device *net_dev)
 {
 	long ioaddr = net_dev->base_addr;
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	int i;
 
 	netif_stop_queue(net_dev);
@@ -1568,7 +1576,7 @@
 
 static int mii_ioctl(struct net_device *net_dev, struct ifreq *rq, int cmd)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 	u16 *data = (u16 *)&rq->ifr_data;
 
 	switch(cmd) {
@@ -1598,7 +1606,7 @@
 static struct net_device_stats *
 sis900_get_stats(struct net_device *net_dev)
 {
-	struct sis900_private *sis_priv = (struct sis900_private *)net_dev->priv;
+	struct sis900_private *sis_priv = net_dev->priv;
 
 	return &sis_priv->stats;
 }
@@ -1615,7 +1623,7 @@
 
 static int sis900_set_config(struct net_device *dev, struct ifmap *map)
 {    
-	struct sis900_private *sis_priv = (struct sis900_private *)dev->priv;
+	struct sis900_private *sis_priv = dev->priv;
 	struct mii_phy *mii_phy = sis_priv->mii;
         
 	u16 status;
@@ -1838,11 +1846,12 @@
 
 static void __devexit sis900_remove(struct pci_dev *pci_dev)
 {
-	struct net_device *net_dev = pci_dev->driver_data;
+	struct net_device *net_dev = pci_get_drvdata(pci_dev);
 		
 	unregister_netdev(net_dev);
-	release_region(net_dev->base_addr, SIS900_TOTAL_SIZE);
 	kfree(net_dev);
+	pci_release_regions(pci_dev);
+	pci_set_drvdata(pci_dev, NULL);
 }
 
 #define SIS900_MODULE_NAME "sis900"

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)