patch-2.4.5 linux/drivers/net/hamachi.c

Next file: linux/drivers/net/hp100.h
Previous file: linux/drivers/net/gmac.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.4/linux/drivers/net/hamachi.c linux/drivers/net/hamachi.c
@@ -23,10 +23,21 @@
 	or
 	http://www.parl.clemson.edu/~keithu/hamachi.html
 
-	For best viewing, set your tabs to 3.
+
+
+	Linux kernel changelog:
+
+	LK1.0.1:
+	- fix lack of pci_dev<->dev association
+	- ethtool support (jgarzik)
 
 */
 
+#define DRV_NAME	"hamachi"
+#define DRV_VERSION	"1.01+LK1.0.1"
+#define DRV_RELDATE	"5/18/2001"
+
+
 /* A few user-configurable values. */
 
 static int debug = 1;		/* 1 normal messages, 0 quiet .. 7 verbose.  */
@@ -116,7 +127,7 @@
 #define RX_RING_SIZE	512
 
 /*
- * Enable mii_ioctl.  Added interrupt coalescing parameter adjustment.
+ * Enable netdev_ioctl.  Added interrupt coalescing parameter adjustment.
  * 2/19/99 Pete Wyckoff <wyckoff@ca.sandia.gov>
  */
 
@@ -152,7 +163,9 @@
 #include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/init.h>
+#include <linux/ethtool.h>
 
+#include <asm/uaccess.h>
 #include <asm/processor.h>	/* Processor type for cache alignment. */
 #include <asm/bitops.h>
 #include <asm/io.h>
@@ -166,7 +179,7 @@
 #include <linux/delay.h>
 
 static char version[] __initdata =
-KERN_INFO "hamachi.c:v1.01 5/16/2000  Written by Donald Becker\n"
+KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE "  Written by Donald Becker\n"
 KERN_INFO "   Some modifications by Eric kasten <kasten@nscl.msu.edu>\n"
 KERN_INFO "   Further modifications by Keith Underwood <keithu@parl.clemson.edu>\n";
 
@@ -502,7 +515,7 @@
 	unsigned char phys[MII_CNT];		/* MII device addresses, only first one used. */
 	u_int32_t rx_int_var, tx_int_var;	/* interrupt control variables */
 	u_int32_t option;							/* Hold on to a copy of the options */
-	u_int8_t pad[16];							/* Used for 32-byte alignment */
+	struct pci_dev *pci_dev;
 };
 
 MODULE_AUTHOR("Donald Becker <becker@scyld.com>, Eric Kasten <kasten@nscl.msu.edu>, Keith Underwood <keithu@parl.clemson.edu>");
@@ -527,7 +540,7 @@
 static int mdio_read(long ioaddr, int phy_id, int location);
 static void mdio_write(long ioaddr, int phy_id, int location, int value);
 static int hamachi_open(struct net_device *dev);
-static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
+static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 static void hamachi_timer(unsigned long data);
 static void hamachi_tx_timeout(struct net_device *dev);
 static void hamachi_init_ring(struct net_device *dev);
@@ -569,7 +582,7 @@
 
 	pci_set_master(pdev);
 
-	i = pci_request_regions(pdev, "hamachi");
+	i = pci_request_regions(pdev, DRV_NAME);
 	if (i) return i;
 
 	irq = pdev->irq;
@@ -633,8 +646,10 @@
 
 	dev->base_addr = ioaddr;
 	dev->irq = irq;
+	pci_set_drvdata(pdev, dev);
 
 	hmp->chip_id = chip_id;
+	hmp->pci_dev = pdev;
 
 	/* The lower four bits are the media type. */
 	if (option > 0) {
@@ -676,7 +691,7 @@
 	dev->stop = &hamachi_close;
 	dev->get_stats = &hamachi_get_stats;
 	dev->set_multicast_list = &set_rx_mode;
-	dev->do_ioctl = &mii_ioctl;
+	dev->do_ioctl = &netdev_ioctl;
 	dev->tx_timeout = &hamachi_tx_timeout;
 	dev->watchdog_timeo = TX_TIMEOUT;
 	if (mtu)
@@ -687,6 +702,7 @@
 		kfree(dev);
 		iounmap((char *)ioaddr);
 		pci_release_regions(pdev);
+		pci_set_drvdata(pdev, NULL);
 		return i;
 	}
 
@@ -1815,12 +1831,38 @@
 	}
 }
 
-static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+static int netdev_ethtool_ioctl(struct net_device *dev, void *useraddr)
+{
+	struct hamachi_private *np = dev->priv;
+	u32 ethcmd;
+		
+	if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
+		return -EFAULT;
+
+        switch (ethcmd) {
+        case ETHTOOL_GDRVINFO: {
+		struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
+		strcpy(info.driver, DRV_NAME);
+		strcpy(info.version, DRV_VERSION);
+		strcpy(info.bus_info, np->pci_dev->slot_name);
+		if (copy_to_user(useraddr, &info, sizeof(info)))
+			return -EFAULT;
+		return 0;
+	}
+
+        }
+	
+	return -EOPNOTSUPP;
+}
+
+static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
 	long ioaddr = dev->base_addr;
 	u16 *data = (u16 *)&rq->ifr_data;
 
 	switch(cmd) {
+	case SIOCETHTOOL:
+		return netdev_ethtool_ioctl(dev, (void *) rq->ifr_data);
 	case SIOCDEVPRIVATE:		/* Get the address of the PHY in use. */
 		data[0] = ((struct hamachi_private *)dev->priv)->phys[0] & 0x1f;
 		/* Fall Through */
@@ -1878,7 +1920,7 @@
 MODULE_DEVICE_TABLE(pci, hamachi_pci_tbl);
 
 static struct pci_driver hamachi_driver = {
-	name:		"hamachi",
+	name:		DRV_NAME,
 	id_table:	hamachi_pci_tbl,
 	probe:		hamachi_init_one,
 	remove:		hamachi_remove_one,

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