struct e1000_adapter *adapter = netdev->priv;
struct e1000_adapter *adapter = netdev_priv(netdev);
e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd){	struct e1000_adapter *adapter = netdev->priv;	struct mii_ioctl_data *data = if_mii(ifr);	int retval;	uint16_t mii_reg;	uint16_t spddplx;	unsigned long flags;	if(adapter->hw.media_type != e1000_media_type_copper)		return -EOPNOTSUPP;	switch (cmd) {	case SIOCGMIIPHY:		data->phy_id = adapter->hw.phy_addr;		break;	case SIOCGMIIREG:		if(!capable(CAP_NET_ADMIN))			return -EPERM;		spin_lock_irqsave(&adapter->stats_lock, flags);		if(e1000_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,				   &data->val_out)) {			spin_unlock_irqrestore(&adapter->stats_lock, flags);			return -EIO;		}		spin_unlock_irqrestore(&adapter->stats_lock, flags);		break;	case SIOCSMIIREG:		if(!capable(CAP_NET_ADMIN))			return -EPERM;		if(data->reg_num & ~(0x1F))			return -EFAULT;		mii_reg = data->val_in;		spin_lock_irqsave(&adapter->stats_lock, flags);		if(e1000_write_phy_reg(&adapter->hw, data->reg_num,					mii_reg)) {			spin_unlock_irqrestore(&adapter->stats_lock, flags);			return -EIO;		}		if(adapter->hw.phy_type == e1000_phy_m88) {			switch (data->reg_num) {			case PHY_CTRL:				if(mii_reg & MII_CR_POWER_DOWN)					break;				if(mii_reg & MII_CR_AUTO_NEG_EN) {					adapter->hw.autoneg = 1;					adapter->hw.autoneg_advertised = 0x2F;				} else {					if (mii_reg & 0x40)						spddplx = SPEED_1000;					else if (mii_reg & 0x2000)						spddplx = SPEED_100;					else						spddplx = SPEED_10;					spddplx += (mii_reg & 0x100)						   ? FULL_DUPLEX :						   HALF_DUPLEX;					retval = e1000_set_spd_dplx(adapter,								    spddplx);					if(retval) {						spin_unlock_irqrestore(							&adapter->stats_lock, 							flags);						return retval;					}				}				if(netif_running(adapter->netdev)) {					e1000_down(adapter);					e1000_up(adapter);				} else					e1000_reset(adapter);				break;			case M88E1000_PHY_SPEC_CTRL:			case M88E1000_EXT_PHY_SPEC_CTRL:				if(e1000_phy_reset(&adapter->hw)) {					spin_unlock_irqrestore(						&adapter->stats_lock, flags);					return -EIO;				}				break;			}		} else {			switch (data->reg_num) {			case PHY_CTRL:				if(mii_reg & MII_CR_POWER_DOWN)					break;				if(netif_running(adapter->netdev)) {					e1000_down(adapter);					e1000_up(adapter);				} else					e1000_reset(adapter);				break;			}		}		spin_unlock_irqrestore(&adapter->stats_lock, flags);		break;	default:		return -EOPNOTSUPP;	}	return E1000_SUCCESS;}