<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
From: Steffen Klassert &lt;klassert@mathematik.tu-chemnitz.de&gt;

With this patch the driver makes use of the MII lib helper function
generic_mii_ioctl.  Patch is tested with the mii-diag tool and a 3c905-TX,
3c905B-TX NIC.

Signed-off-by: Steffen Klassert &lt;klassert@mathematik.tu-chemnitz.de&gt;
Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
---

 25-akpm/drivers/net/3c59x.c |   46 +++++++++-----------------------------------
 1 files changed, 10 insertions(+), 36 deletions(-)

diff -puN drivers/net/3c59x.c~3c59x-make-use-of-generic_mii_ioctl drivers/net/3c59x.c
--- 25/drivers/net/3c59x.c~3c59x-make-use-of-generic_mii_ioctl	2004-10-16 01:31:10.660758576 -0700
+++ 25-akpm/drivers/net/3c59x.c	2004-10-16 01:31:10.666757664 -0700
@@ -834,6 +834,7 @@ struct vortex_private {
 	u16 io_size;						/* Size of PCI region (for release_region) */
 	spinlock_t lock;					/* Serialise access to device &amp; its vortex_private */
 	spinlock_t mdio_lock;				/* Serialise access to mdio hardware */
+	struct mii_if_info mii;				/* MII lib hooks/info */
 };
 
 #ifdef CONFIG_PCI
@@ -1218,6 +1219,11 @@ static int __devinit vortex_probe1(struc
 	spin_lock_init(&amp;vp-&gt;lock);
 	spin_lock_init(&amp;vp-&gt;mdio_lock);
 	vp-&gt;gendev = gendev;
+	vp-&gt;mii.dev = dev;
+	vp-&gt;mii.mdio_read = mdio_read;
+	vp-&gt;mii.mdio_write = mdio_write;
+	vp-&gt;mii.phy_id_mask = 0x1f;
+	vp-&gt;mii.reg_num_mask = 0x1f;
 
 	/* Makes sure rings are at least 16 byte aligned. */
 	vp-&gt;rx_ring = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE
@@ -1452,6 +1458,7 @@ static int __devinit vortex_probe1(struc
 				mdio_write(dev, vp-&gt;phys[0], 4, vp-&gt;advertising);
 			}
 		}
+		vp-&gt;mii.phy_id = vp-&gt;phys[0];
 	}
 
 	if (vp-&gt;capabilities &amp; CapBusMaster) {
@@ -2898,41 +2905,6 @@ static struct ethtool_ops vortex_ethtool
 };
 
 #ifdef CONFIG_PCI
-static int vortex_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
-{
-	struct vortex_private *vp = netdev_priv(dev);
-	long ioaddr = dev-&gt;base_addr;
-	struct mii_ioctl_data *data = if_mii(rq);
-	int phy = vp-&gt;phys[0] &amp; 0x1f;
-	int retval;
-
-	switch(cmd) {
-	case SIOCGMIIPHY:		/* Get address of MII PHY in use. */
-		data-&gt;phy_id = phy;
-
-	case SIOCGMIIREG:		/* Read MII PHY register. */
-		EL3WINDOW(4);
-		data-&gt;val_out = mdio_read(dev, data-&gt;phy_id &amp; 0x1f, data-&gt;reg_num &amp; 0x1f);
-		retval = 0;
-		break;
-
-	case SIOCSMIIREG:		/* Write MII PHY register. */
-		if (!capable(CAP_NET_ADMIN)) {
-			retval = -EPERM;
-		} else {
-			EL3WINDOW(4);
-			mdio_write(dev, data-&gt;phy_id &amp; 0x1f, data-&gt;reg_num &amp; 0x1f, data-&gt;val_in);
-			retval = 0;
-		}
-		break;
-	default:
-		retval = -EOPNOTSUPP;
-		break;
-	}
-
-	return retval;
-}
-
 /*
  *	Must power the device up to do MDIO operations
  */
@@ -2940,6 +2912,7 @@ static int vortex_ioctl(struct net_devic
 {
 	int err;
 	struct vortex_private *vp = netdev_priv(dev);
+	long ioaddr = dev-&gt;base_addr;
 	int state = 0;
 
 	if(VORTEX_PCI(vp))
@@ -2949,7 +2922,8 @@ static int vortex_ioctl(struct net_devic
 
 	if(state != 0)
 		pci_set_power_state(VORTEX_PCI(vp), 0);
-	err = vortex_do_ioctl(dev, rq, cmd);
+	EL3WINDOW(4);
+	err = generic_mii_ioctl(&amp;vp-&gt;mii, if_mii(rq), cmd, NULL);
 	if(state != 0)
 		pci_set_power_state(VORTEX_PCI(vp), state);
 
_
</pre></body></html>