From: Steffen Klassert 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 Signed-off-by: Andrew Morton --- 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-11-03 20:26:18.785772824 -0800 +++ 25-akpm/drivers/net/3c59x.c 2004-11-03 20:26:18.791771912 -0800 @@ -835,6 +835,7 @@ struct vortex_private { u16 io_size; /* Size of PCI region (for release_region) */ spinlock_t lock; /* Serialise access to device & its vortex_private */ spinlock_t mdio_lock; /* Serialise access to mdio hardware */ + struct mii_if_info mii; /* MII lib hooks/info */ }; #ifdef CONFIG_PCI @@ -1219,6 +1220,11 @@ static int __devinit vortex_probe1(struc spin_lock_init(&vp->lock); spin_lock_init(&vp->mdio_lock); vp->gendev = gendev; + vp->mii.dev = dev; + vp->mii.mdio_read = mdio_read; + vp->mii.mdio_write = mdio_write; + vp->mii.phy_id_mask = 0x1f; + vp->mii.reg_num_mask = 0x1f; /* Makes sure rings are at least 16 byte aligned. */ vp->rx_ring = pci_alloc_consistent(pdev, sizeof(struct boom_rx_desc) * RX_RING_SIZE @@ -1453,6 +1459,7 @@ static int __devinit vortex_probe1(struc mdio_write(dev, vp->phys[0], 4, vp->advertising); } } + vp->mii.phy_id = vp->phys[0]; } if (vp->capabilities & CapBusMaster) { @@ -2899,41 +2906,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->base_addr; - struct mii_ioctl_data *data = if_mii(rq); - int phy = vp->phys[0] & 0x1f; - int retval; - - switch(cmd) { - case SIOCGMIIPHY: /* Get address of MII PHY in use. */ - data->phy_id = phy; - - case SIOCGMIIREG: /* Read MII PHY register. */ - EL3WINDOW(4); - data->val_out = mdio_read(dev, data->phy_id & 0x1f, data->reg_num & 0x1f); - retval = 0; - break; - - case SIOCSMIIREG: /* Write MII PHY register. */ - if (!capable(CAP_NET_ADMIN)) { - retval = -EPERM; - } else { - EL3WINDOW(4); - mdio_write(dev, data->phy_id & 0x1f, data->reg_num & 0x1f, data->val_in); - retval = 0; - } - break; - default: - retval = -EOPNOTSUPP; - break; - } - - return retval; -} - /* * Must power the device up to do MDIO operations */ @@ -2941,6 +2913,7 @@ static int vortex_ioctl(struct net_devic { int err; struct vortex_private *vp = netdev_priv(dev); + long ioaddr = dev->base_addr; int state = 0; if(VORTEX_PCI(vp)) @@ -2950,7 +2923,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(&vp->mii, if_mii(rq), cmd, NULL); if(state != 0) pci_set_power_state(VORTEX_PCI(vp), state); _