diff options
Diffstat (limited to 'drivers/net/ethernet/intel/igb')
| -rw-r--r-- | drivers/net/ethernet/intel/igb/e1000_82575.c | 17 | ||||
| -rw-r--r-- | drivers/net/ethernet/intel/igb/e1000_defines.h | 11 | ||||
| -rw-r--r-- | drivers/net/ethernet/intel/igb/e1000_phy.c | 29 | ||||
| -rw-r--r-- | drivers/net/ethernet/intel/igb/e1000_phy.h | 5 | ||||
| -rw-r--r-- | drivers/net/ethernet/intel/igb/e1000_regs.h | 3 | ||||
| -rw-r--r-- | drivers/net/ethernet/intel/igb/igb.h | 41 | ||||
| -rw-r--r-- | drivers/net/ethernet/intel/igb/igb_ethtool.c | 198 | ||||
| -rw-r--r-- | drivers/net/ethernet/intel/igb/igb_main.c | 725 | ||||
| -rw-r--r-- | drivers/net/ethernet/intel/igb/igb_ptp.c | 677 | 
9 files changed, 967 insertions, 739 deletions
diff --git a/drivers/net/ethernet/intel/igb/e1000_82575.c b/drivers/net/ethernet/intel/igb/e1000_82575.c index ba994fb4cec..ca4641e2f74 100644 --- a/drivers/net/ethernet/intel/igb/e1000_82575.c +++ b/drivers/net/ethernet/intel/igb/e1000_82575.c @@ -2223,11 +2223,10 @@ out:  s32 igb_set_eee_i350(struct e1000_hw *hw)  {  	s32 ret_val = 0; -	u32 ipcnfg, eeer, ctrl_ext; +	u32 ipcnfg, eeer; -	ctrl_ext = rd32(E1000_CTRL_EXT); -	if ((hw->mac.type != e1000_i350) || -	    (ctrl_ext & E1000_CTRL_EXT_LINK_MODE_MASK)) +	if ((hw->mac.type < e1000_i350) || +	    (hw->phy.media_type != e1000_media_type_copper))  		goto out;  	ipcnfg = rd32(E1000_IPCNFG);  	eeer = rd32(E1000_EEER); @@ -2240,6 +2239,14 @@ s32 igb_set_eee_i350(struct e1000_hw *hw)  			E1000_EEER_RX_LPI_EN |  			E1000_EEER_LPI_FC); +		/* keep the LPI clock running before EEE is enabled */ +		if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) { +			u32 eee_su; +			eee_su = rd32(E1000_EEE_SU); +			eee_su &= ~E1000_EEE_SU_LPI_CLK_STP; +			wr32(E1000_EEE_SU, eee_su); +		} +  	} else {  		ipcnfg &= ~(E1000_IPCNFG_EEE_1G_AN |  			E1000_IPCNFG_EEE_100M_AN); @@ -2249,6 +2256,8 @@ s32 igb_set_eee_i350(struct e1000_hw *hw)  	}  	wr32(E1000_IPCNFG, ipcnfg);  	wr32(E1000_EEER, eeer); +	rd32(E1000_IPCNFG); +	rd32(E1000_EEER);  out:  	return ret_val; diff --git a/drivers/net/ethernet/intel/igb/e1000_defines.h b/drivers/net/ethernet/intel/igb/e1000_defines.h index ec7e4fe3e3e..de4b41ec3c4 100644 --- a/drivers/net/ethernet/intel/igb/e1000_defines.h +++ b/drivers/net/ethernet/intel/igb/e1000_defines.h @@ -322,6 +322,9 @@  #define E1000_FCRTC_RTH_COAL_SHIFT      4  #define E1000_PCIEMISC_LX_DECISION      0x00000080 /* Lx power decision */ +/* Timestamp in Rx buffer */ +#define E1000_RXPBS_CFG_TS_EN           0x80000000 +  /* SerDes Control */  #define E1000_SCTL_DISABLE_SERDES_LOOPBACK 0x0400 @@ -360,6 +363,7 @@  #define E1000_ICR_RXDMT0        0x00000010 /* rx desc min. threshold (0) */  #define E1000_ICR_RXT0          0x00000080 /* rx timer intr (ring 0) */  #define E1000_ICR_VMMB          0x00000100 /* VM MB event */ +#define E1000_ICR_TS            0x00080000 /* Time Sync Interrupt */  #define E1000_ICR_DRSTA         0x40000000 /* Device Reset Asserted */  /* If this bit asserted, the driver should claim the interrupt */  #define E1000_ICR_INT_ASSERTED  0x80000000 @@ -399,6 +403,7 @@  #define E1000_IMS_TXDW      E1000_ICR_TXDW      /* Transmit desc written back */  #define E1000_IMS_LSC       E1000_ICR_LSC       /* Link Status Change */  #define E1000_IMS_VMMB      E1000_ICR_VMMB      /* Mail box activity */ +#define E1000_IMS_TS        E1000_ICR_TS        /* Time Sync Interrupt */  #define E1000_IMS_RXSEQ     E1000_ICR_RXSEQ     /* rx sequence error */  #define E1000_IMS_RXDMT0    E1000_ICR_RXDMT0    /* rx desc min. threshold */  #define E1000_IMS_RXT0      E1000_ICR_RXT0      /* rx timer intr */ @@ -510,6 +515,9 @@  #define E1000_TIMINCA_16NS_SHIFT 24 +#define E1000_TSICR_TXTS 0x00000002 +#define E1000_TSIM_TXTS 0x00000002 +  #define E1000_MDICNFG_EXT_MDIO    0x80000000      /* MDI ext/int destination */  #define E1000_MDICNFG_COM_MDIO    0x40000000      /* MDI shared w/ lan 0 */  #define E1000_MDICNFG_PHY_MASK    0x03E00000 @@ -849,8 +857,9 @@  #define E1000_IPCNFG_EEE_100M_AN     0x00000004  /* EEE Enable 100M AN */  #define E1000_EEER_TX_LPI_EN         0x00010000  /* EEE Tx LPI Enable */  #define E1000_EEER_RX_LPI_EN         0x00020000  /* EEE Rx LPI Enable */ -#define E1000_EEER_FRC_AN            0x10000000 /* Enable EEE in loopback */ +#define E1000_EEER_FRC_AN            0x10000000  /* Enable EEE in loopback */  #define E1000_EEER_LPI_FC            0x00040000  /* EEE Enable on FC */ +#define E1000_EEE_SU_LPI_CLK_STP     0X00800000  /* EEE LPI Clock Stop */  /* SerDes Control */  #define E1000_GEN_CTL_READY             0x80000000 diff --git a/drivers/net/ethernet/intel/igb/e1000_phy.c b/drivers/net/ethernet/intel/igb/e1000_phy.c index 7be98b6f105..3404bc79f4c 100644 --- a/drivers/net/ethernet/intel/igb/e1000_phy.c +++ b/drivers/net/ethernet/intel/igb/e1000_phy.c @@ -464,6 +464,32 @@ s32 igb_copper_link_setup_82580(struct e1000_hw *hw)  	phy_data |= I82580_CFG_ENABLE_DOWNSHIFT;  	ret_val = phy->ops.write_reg(hw, I82580_CFG_REG, phy_data); +	if (ret_val) +		goto out; + +	/* Set MDI/MDIX mode */ +	ret_val = phy->ops.read_reg(hw, I82580_PHY_CTRL_2, &phy_data); +	if (ret_val) +		goto out; +	phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK; +	/* +	 * Options: +	 *   0 - Auto (default) +	 *   1 - MDI mode +	 *   2 - MDI-X mode +	 */ +	switch (hw->phy.mdix) { +	case 1: +		break; +	case 2: +		phy_data |= I82580_PHY_CTRL2_MANUAL_MDIX; +		break; +	case 0: +	default: +		phy_data |= I82580_PHY_CTRL2_AUTO_MDI_MDIX; +		break; +	} +	ret_val = hw->phy.ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);  out:  	return ret_val; @@ -2246,8 +2272,7 @@ s32 igb_phy_force_speed_duplex_82580(struct e1000_hw *hw)  	if (ret_val)  		goto out; -	phy_data &= ~I82580_PHY_CTRL2_AUTO_MDIX; -	phy_data &= ~I82580_PHY_CTRL2_FORCE_MDI_MDIX; +	phy_data &= ~I82580_PHY_CTRL2_MDIX_CFG_MASK;  	ret_val = phy->ops.write_reg(hw, I82580_PHY_CTRL_2, phy_data);  	if (ret_val) diff --git a/drivers/net/ethernet/intel/igb/e1000_phy.h b/drivers/net/ethernet/intel/igb/e1000_phy.h index 34e40619f16..6ac3299bfcb 100644 --- a/drivers/net/ethernet/intel/igb/e1000_phy.h +++ b/drivers/net/ethernet/intel/igb/e1000_phy.h @@ -111,8 +111,9 @@ s32  igb_check_polarity_m88(struct e1000_hw *hw);  #define I82580_PHY_STATUS2_SPEED_100MBPS  0x0100  /* I82580 PHY Control 2 */ -#define I82580_PHY_CTRL2_AUTO_MDIX        0x0400 -#define I82580_PHY_CTRL2_FORCE_MDI_MDIX   0x0200 +#define I82580_PHY_CTRL2_MANUAL_MDIX      0x0200 +#define I82580_PHY_CTRL2_AUTO_MDI_MDIX    0x0400 +#define I82580_PHY_CTRL2_MDIX_CFG_MASK    0x0600  /* I82580 PHY Diagnostics Status */  #define I82580_DSTATUS_CABLE_LENGTH       0x03FC diff --git a/drivers/net/ethernet/intel/igb/e1000_regs.h b/drivers/net/ethernet/intel/igb/e1000_regs.h index 28394bea525..e5db48594e8 100644 --- a/drivers/net/ethernet/intel/igb/e1000_regs.h +++ b/drivers/net/ethernet/intel/igb/e1000_regs.h @@ -91,6 +91,8 @@  #define E1000_TIMINCA    0x0B608 /* Increment attributes register - RW */  #define E1000_TSAUXC     0x0B640 /* Timesync Auxiliary Control register */  #define E1000_SYSTIMR    0x0B6F8 /* System time register Residue */ +#define E1000_TSICR      0x0B66C /* Interrupt Cause Register */ +#define E1000_TSIM       0x0B674 /* Interrupt Mask Register */  /* Filtering Registers */  #define E1000_SAQF(_n) (0x5980 + 4 * (_n)) @@ -347,6 +349,7 @@  /* Energy Efficient Ethernet "EEE" register */  #define E1000_IPCNFG  0x0E38  /* Internal PHY Configuration */  #define E1000_EEER    0x0E30  /* Energy Efficient Ethernet */ +#define E1000_EEE_SU  0X0E34  /* EEE Setup */  /* Thermal Sensor Register */  #define E1000_THSTAT    0x08110 /* Thermal Sensor Status */ diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h index 9e572dd29ab..8aad230c059 100644 --- a/drivers/net/ethernet/intel/igb/igb.h +++ b/drivers/net/ethernet/intel/igb/igb.h @@ -34,9 +34,11 @@  #include "e1000_mac.h"  #include "e1000_82575.h" +#ifdef CONFIG_IGB_PTP  #include <linux/clocksource.h>  #include <linux/net_tstamp.h>  #include <linux/ptp_clock_kernel.h> +#endif /* CONFIG_IGB_PTP */  #include <linux/bitops.h>  #include <linux/if_vlan.h> @@ -99,7 +101,6 @@ struct vf_data_storage {  	u16 pf_vlan; /* When set, guest VLAN config not allowed. */  	u16 pf_qos;  	u16 tx_rate; -	struct pci_dev *vfdev;  };  #define IGB_VF_FLAG_CTS            0x00000001 /* VF is clear to send data */ @@ -131,9 +132,9 @@ struct vf_data_storage {  #define MAXIMUM_ETHERNET_VLAN_SIZE 1522  /* Supported Rx Buffer Sizes */ -#define IGB_RXBUFFER_512   512 +#define IGB_RXBUFFER_256   256  #define IGB_RXBUFFER_16384 16384 -#define IGB_RX_HDR_LEN     IGB_RXBUFFER_512 +#define IGB_RX_HDR_LEN     IGB_RXBUFFER_256  /* How many Tx Descriptors do we need to call netif_wake_queue ? */  #define IGB_TX_QUEUE_WAKE	16 @@ -167,8 +168,8 @@ struct igb_tx_buffer {  	unsigned int bytecount;  	u16 gso_segs;  	__be16 protocol; -	dma_addr_t dma; -	u32 length; +	DEFINE_DMA_UNMAP_ADDR(dma); +	DEFINE_DMA_UNMAP_LEN(len);  	u32 tx_flags;  }; @@ -212,7 +213,6 @@ struct igb_q_vector {  	struct igb_ring_container rx, tx;  	struct napi_struct napi; -	int numa_node;  	u16 itr_val;  	u8 set_itr; @@ -257,7 +257,6 @@ struct igb_ring {  	};  	/* Items past this point are only used during ring alloc / free */  	dma_addr_t dma;                /* phys address of the ring */ -	int numa_node;                  /* node to alloc ring memory on */  };  enum e1000_ring_flags_t { @@ -342,7 +341,6 @@ struct igb_adapter {  	/* OS defined structs */  	struct pci_dev *pdev; -	struct hwtstamp_config hwtstamp_config;  	spinlock_t stats64_lock;  	struct rtnl_link_stats64 stats64; @@ -373,15 +371,19 @@ struct igb_adapter {  	int vf_rate_link_speed;  	u32 rss_queues;  	u32 wvbr; -	int node;  	u32 *shadow_vfta; +#ifdef CONFIG_IGB_PTP  	struct ptp_clock *ptp_clock; -	struct ptp_clock_info caps; -	struct delayed_work overflow_work; +	struct ptp_clock_info ptp_caps; +	struct delayed_work ptp_overflow_work; +	struct work_struct ptp_tx_work; +	struct sk_buff *ptp_tx_skb;  	spinlock_t tmreg_lock;  	struct cyclecounter cc;  	struct timecounter tc; +#endif /* CONFIG_IGB_PTP */ +  	char fw_version[32];  }; @@ -390,6 +392,7 @@ struct igb_adapter {  #define IGB_FLAG_QUAD_PORT_A       (1 << 2)  #define IGB_FLAG_QUEUE_PAIRS       (1 << 3)  #define IGB_FLAG_DMAC              (1 << 4) +#define IGB_FLAG_PTP               (1 << 5)  /* DMA Coalescing defines */  #define IGB_MIN_TXPBSIZE           20408 @@ -435,13 +438,17 @@ extern void igb_power_up_link(struct igb_adapter *);  extern void igb_set_fw_version(struct igb_adapter *);  #ifdef CONFIG_IGB_PTP  extern void igb_ptp_init(struct igb_adapter *adapter); -extern void igb_ptp_remove(struct igb_adapter *adapter); - -extern void igb_systim_to_hwtstamp(struct igb_adapter *adapter, -				   struct skb_shared_hwtstamps *hwtstamps, -				   u64 systim); +extern void igb_ptp_stop(struct igb_adapter *adapter); +extern void igb_ptp_reset(struct igb_adapter *adapter); +extern void igb_ptp_tx_work(struct work_struct *work); +extern void igb_ptp_tx_hwtstamp(struct igb_adapter *adapter); +extern void igb_ptp_rx_hwtstamp(struct igb_q_vector *q_vector, +				union e1000_adv_rx_desc *rx_desc, +				struct sk_buff *skb); +extern int igb_ptp_hwtstamp_ioctl(struct net_device *netdev, +				  struct ifreq *ifr, int cmd); +#endif /* CONFIG_IGB_PTP */ -#endif  static inline s32 igb_reset_phy(struct e1000_hw *hw)  {  	if (hw->phy.ops.reset) diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c index 70591117051..2ea01284982 100644 --- a/drivers/net/ethernet/intel/igb/igb_ethtool.c +++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c @@ -148,9 +148,9 @@ static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)  				   SUPPORTED_100baseT_Full |  				   SUPPORTED_1000baseT_Full|  				   SUPPORTED_Autoneg | -				   SUPPORTED_TP); -		ecmd->advertising = (ADVERTISED_TP | -				     ADVERTISED_Pause); +				   SUPPORTED_TP | +				   SUPPORTED_Pause); +		ecmd->advertising = ADVERTISED_TP;  		if (hw->mac.autoneg == 1) {  			ecmd->advertising |= ADVERTISED_Autoneg; @@ -158,6 +158,21 @@ static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)  			ecmd->advertising |= hw->phy.autoneg_advertised;  		} +		if (hw->mac.autoneg != 1) +			ecmd->advertising &= ~(ADVERTISED_Pause | +					       ADVERTISED_Asym_Pause); + +		if (hw->fc.requested_mode == e1000_fc_full) +			ecmd->advertising |= ADVERTISED_Pause; +		else if (hw->fc.requested_mode == e1000_fc_rx_pause) +			ecmd->advertising |= (ADVERTISED_Pause | +					      ADVERTISED_Asym_Pause); +		else if (hw->fc.requested_mode == e1000_fc_tx_pause) +			ecmd->advertising |=  ADVERTISED_Asym_Pause; +		else +			ecmd->advertising &= ~(ADVERTISED_Pause | +					       ADVERTISED_Asym_Pause); +  		ecmd->port = PORT_TP;  		ecmd->phy_address = hw->phy.addr;  	} else { @@ -198,6 +213,19 @@ static int igb_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)  	}  	ecmd->autoneg = hw->mac.autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE; + +	/* MDI-X => 2; MDI =>1; Invalid =>0 */ +	if (hw->phy.media_type == e1000_media_type_copper) +		ecmd->eth_tp_mdix = hw->phy.is_mdix ? ETH_TP_MDI_X : +						      ETH_TP_MDI; +	else +		ecmd->eth_tp_mdix = ETH_TP_MDI_INVALID; + +	if (hw->phy.mdix == AUTO_ALL_MODES) +		ecmd->eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO; +	else +		ecmd->eth_tp_mdix_ctrl = hw->phy.mdix; +  	return 0;  } @@ -214,6 +242,22 @@ static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)  		return -EINVAL;  	} +	/* +	 * MDI setting is only allowed when autoneg enabled because +	 * some hardware doesn't allow MDI setting when speed or +	 * duplex is forced. +	 */ +	if (ecmd->eth_tp_mdix_ctrl) { +		if (hw->phy.media_type != e1000_media_type_copper) +			return -EOPNOTSUPP; + +		if ((ecmd->eth_tp_mdix_ctrl != ETH_TP_MDI_AUTO) && +		    (ecmd->autoneg != AUTONEG_ENABLE)) { +			dev_err(&adapter->pdev->dev, "forcing MDI/MDI-X state is not supported when link speed and/or duplex are forced\n"); +			return -EINVAL; +		} +	} +  	while (test_and_set_bit(__IGB_RESETTING, &adapter->state))  		msleep(1); @@ -227,12 +271,25 @@ static int igb_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)  			hw->fc.requested_mode = e1000_fc_default;  	} else {  		u32 speed = ethtool_cmd_speed(ecmd); +		/* calling this overrides forced MDI setting */  		if (igb_set_spd_dplx(adapter, speed, ecmd->duplex)) {  			clear_bit(__IGB_RESETTING, &adapter->state);  			return -EINVAL;  		}  	} +	/* MDI-X => 2; MDI => 1; Auto => 3 */ +	if (ecmd->eth_tp_mdix_ctrl) { +		/* +		 * fix up the value for auto (3 => 0) as zero is mapped +		 * internally to auto +		 */ +		if (ecmd->eth_tp_mdix_ctrl == ETH_TP_MDI_AUTO) +			hw->phy.mdix = AUTO_ALL_MODES; +		else +			hw->phy.mdix = ecmd->eth_tp_mdix_ctrl; +	} +  	/* reset the link */  	if (netif_running(adapter->netdev)) {  		igb_down(adapter); @@ -1469,33 +1526,22 @@ static int igb_integrated_phy_loopback(struct igb_adapter *adapter)  {  	struct e1000_hw *hw = &adapter->hw;  	u32 ctrl_reg = 0; -	u16 phy_reg = 0;  	hw->mac.autoneg = false; -	switch (hw->phy.type) { -	case e1000_phy_m88: -		/* Auto-MDI/MDIX Off */ -		igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808); -		/* reset to update Auto-MDI/MDIX */ -		igb_write_phy_reg(hw, PHY_CONTROL, 0x9140); -		/* autoneg off */ -		igb_write_phy_reg(hw, PHY_CONTROL, 0x8140); -		break; -	case e1000_phy_82580: -		/* enable MII loopback */ -		igb_write_phy_reg(hw, I82580_PHY_LBK_CTRL, 0x8041); -		break; -	case e1000_phy_i210: -		/* set loopback speed in PHY */ -		igb_read_phy_reg(hw, (GS40G_PAGE_SELECT & GS40G_PAGE_2), -					&phy_reg); -		phy_reg |= GS40G_MAC_SPEED_1G; -		igb_write_phy_reg(hw, (GS40G_PAGE_SELECT & GS40G_PAGE_2), -					phy_reg); -		ctrl_reg = rd32(E1000_CTRL_EXT); -	default: -		break; +	if (hw->phy.type == e1000_phy_m88) { +		if (hw->phy.id != I210_I_PHY_ID) { +			/* Auto-MDI/MDIX Off */ +			igb_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, 0x0808); +			/* reset to update Auto-MDI/MDIX */ +			igb_write_phy_reg(hw, PHY_CONTROL, 0x9140); +			/* autoneg off */ +			igb_write_phy_reg(hw, PHY_CONTROL, 0x8140); +		} else { +			/* force 1000, set loopback  */ +			igb_write_phy_reg(hw, I347AT4_PAGE_SELECT, 0); +			igb_write_phy_reg(hw, PHY_CONTROL, 0x4140); +		}  	}  	/* add small delay to avoid loopback test failure */ @@ -1513,7 +1559,7 @@ static int igb_integrated_phy_loopback(struct igb_adapter *adapter)  		     E1000_CTRL_FD |	 /* Force Duplex to FULL */  		     E1000_CTRL_SLU);	 /* Set link up enable bit */ -	if ((hw->phy.type == e1000_phy_m88) || (hw->phy.type == e1000_phy_i210)) +	if (hw->phy.type == e1000_phy_m88)  		ctrl_reg |= E1000_CTRL_ILOS; /* Invert Loss of Signal */  	wr32(E1000_CTRL, ctrl_reg); @@ -1521,11 +1567,10 @@ static int igb_integrated_phy_loopback(struct igb_adapter *adapter)  	/* Disable the receiver on the PHY so when a cable is plugged in, the  	 * PHY does not begin to autoneg when a cable is reconnected to the NIC.  	 */ -	if ((hw->phy.type == e1000_phy_m88) || (hw->phy.type == e1000_phy_i210)) +	if (hw->phy.type == e1000_phy_m88)  		igb_phy_disable_receiver(adapter); -	udelay(500); - +	mdelay(500);  	return 0;  } @@ -1785,13 +1830,6 @@ static int igb_loopback_test(struct igb_adapter *adapter, u64 *data)  		*data = 0;  		goto out;  	} -	if ((adapter->hw.mac.type == e1000_i210) -		|| (adapter->hw.mac.type == e1000_i211)) { -		dev_err(&adapter->pdev->dev, -			"Loopback test not supported on this part at this time.\n"); -		*data = 0; -		goto out; -	}  	*data = igb_setup_desc_rings(adapter);  	if (*data)  		goto out; @@ -2257,6 +2295,54 @@ static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)  	}  } +static int igb_get_ts_info(struct net_device *dev, +			   struct ethtool_ts_info *info) +{ +	struct igb_adapter *adapter = netdev_priv(dev); + +	switch (adapter->hw.mac.type) { +#ifdef CONFIG_IGB_PTP +	case e1000_82576: +	case e1000_82580: +	case e1000_i350: +	case e1000_i210: +	case e1000_i211: +		info->so_timestamping = +			SOF_TIMESTAMPING_TX_HARDWARE | +			SOF_TIMESTAMPING_RX_HARDWARE | +			SOF_TIMESTAMPING_RAW_HARDWARE; + +		if (adapter->ptp_clock) +			info->phc_index = ptp_clock_index(adapter->ptp_clock); +		else +			info->phc_index = -1; + +		info->tx_types = +			(1 << HWTSTAMP_TX_OFF) | +			(1 << HWTSTAMP_TX_ON); + +		info->rx_filters = 1 << HWTSTAMP_FILTER_NONE; + +		/* 82576 does not support timestamping all packets. */ +		if (adapter->hw.mac.type >= e1000_82580) +			info->rx_filters |= 1 << HWTSTAMP_FILTER_ALL; +		else +			info->rx_filters |= +				(1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | +				(1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | +				(1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) | +				(1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | +				(1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) | +				(1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) | +				(1 << HWTSTAMP_FILTER_PTP_V2_EVENT); + +		return 0; +#endif /* CONFIG_IGB_PTP */ +	default: +		return -EOPNOTSUPP; +	} +} +  static int igb_ethtool_begin(struct net_device *netdev)  {  	struct igb_adapter *adapter = netdev_priv(netdev); @@ -2270,38 +2356,6 @@ static void igb_ethtool_complete(struct net_device *netdev)  	pm_runtime_put(&adapter->pdev->dev);  } -#ifdef CONFIG_IGB_PTP -static int igb_ethtool_get_ts_info(struct net_device *dev, -				   struct ethtool_ts_info *info) -{ -	struct igb_adapter *adapter = netdev_priv(dev); - -	info->so_timestamping = -		SOF_TIMESTAMPING_TX_HARDWARE | -		SOF_TIMESTAMPING_RX_HARDWARE | -		SOF_TIMESTAMPING_RAW_HARDWARE; - -	if (adapter->ptp_clock) -		info->phc_index = ptp_clock_index(adapter->ptp_clock); -	else -		info->phc_index = -1; - -	info->tx_types = -		(1 << HWTSTAMP_TX_OFF) | -		(1 << HWTSTAMP_TX_ON); - -	info->rx_filters = -		(1 << HWTSTAMP_FILTER_NONE) | -		(1 << HWTSTAMP_FILTER_ALL) | -		(1 << HWTSTAMP_FILTER_SOME) | -		(1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | -		(1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | -		(1 << HWTSTAMP_FILTER_PTP_V2_EVENT); - -	return 0; -} - -#endif  static const struct ethtool_ops igb_ethtool_ops = {  	.get_settings           = igb_get_settings,  	.set_settings           = igb_set_settings, @@ -2328,11 +2382,9 @@ static const struct ethtool_ops igb_ethtool_ops = {  	.get_ethtool_stats      = igb_get_ethtool_stats,  	.get_coalesce           = igb_get_coalesce,  	.set_coalesce           = igb_set_coalesce, +	.get_ts_info            = igb_get_ts_info,  	.begin			= igb_ethtool_begin,  	.complete		= igb_ethtool_complete, -#ifdef CONFIG_IGB_PTP -	.get_ts_info		= igb_ethtool_get_ts_info, -#endif  };  void igb_set_ethtool_ops(struct net_device *netdev) diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c index 48cc4fb1a30..e1ceb37ef12 100644 --- a/drivers/net/ethernet/intel/igb/igb_main.c +++ b/drivers/net/ethernet/intel/igb/igb_main.c @@ -172,8 +172,7 @@ static void igb_check_vf_rate_limit(struct igb_adapter *);  #ifdef CONFIG_PCI_IOV  static int igb_vf_configure(struct igb_adapter *adapter, int vf); -static int igb_find_enabled_vfs(struct igb_adapter *adapter); -static int igb_check_vf_assignment(struct igb_adapter *adapter); +static bool igb_vfs_are_assigned(struct igb_adapter *adapter);  #endif  #ifdef CONFIG_PM @@ -217,7 +216,7 @@ static pci_ers_result_t igb_io_error_detected(struct pci_dev *,  static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);  static void igb_io_resume(struct pci_dev *); -static struct pci_error_handlers igb_err_handler = { +static const struct pci_error_handlers igb_err_handler = {  	.error_detected = igb_io_error_detected,  	.slot_reset = igb_io_slot_reset,  	.resume = igb_io_resume, @@ -404,8 +403,8 @@ static void igb_dump(struct igb_adapter *adapter)  		buffer_info = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];  		pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",  			n, tx_ring->next_to_use, tx_ring->next_to_clean, -			(u64)buffer_info->dma, -			buffer_info->length, +			(u64)dma_unmap_addr(buffer_info, dma), +			dma_unmap_len(buffer_info, len),  			buffer_info->next_to_watch,  			(u64)buffer_info->time_stamp);  	} @@ -456,8 +455,8 @@ static void igb_dump(struct igb_adapter *adapter)  				" %04X  %p %016llX %p%s\n", i,  				le64_to_cpu(u0->a),  				le64_to_cpu(u0->b), -				(u64)buffer_info->dma, -				buffer_info->length, +				(u64)dma_unmap_addr(buffer_info, dma), +				dma_unmap_len(buffer_info, len),  				buffer_info->next_to_watch,  				(u64)buffer_info->time_stamp,  				buffer_info->skb, next_desc); @@ -466,7 +465,8 @@ static void igb_dump(struct igb_adapter *adapter)  				print_hex_dump(KERN_INFO, "",  					DUMP_PREFIX_ADDRESS,  					16, 1, buffer_info->skb->data, -					buffer_info->length, true); +					dma_unmap_len(buffer_info, len), +					true);  		}  	} @@ -683,52 +683,29 @@ static int igb_alloc_queues(struct igb_adapter *adapter)  {  	struct igb_ring *ring;  	int i; -	int orig_node = adapter->node;  	for (i = 0; i < adapter->num_tx_queues; i++) { -		if (orig_node == -1) { -			int cur_node = next_online_node(adapter->node); -			if (cur_node == MAX_NUMNODES) -				cur_node = first_online_node; -			adapter->node = cur_node; -		} -		ring = kzalloc_node(sizeof(struct igb_ring), GFP_KERNEL, -				    adapter->node); -		if (!ring) -			ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL); +		ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);  		if (!ring)  			goto err;  		ring->count = adapter->tx_ring_count;  		ring->queue_index = i;  		ring->dev = &adapter->pdev->dev;  		ring->netdev = adapter->netdev; -		ring->numa_node = adapter->node;  		/* For 82575, context index must be unique per ring. */  		if (adapter->hw.mac.type == e1000_82575)  			set_bit(IGB_RING_FLAG_TX_CTX_IDX, &ring->flags);  		adapter->tx_ring[i] = ring;  	} -	/* Restore the adapter's original node */ -	adapter->node = orig_node;  	for (i = 0; i < adapter->num_rx_queues; i++) { -		if (orig_node == -1) { -			int cur_node = next_online_node(adapter->node); -			if (cur_node == MAX_NUMNODES) -				cur_node = first_online_node; -			adapter->node = cur_node; -		} -		ring = kzalloc_node(sizeof(struct igb_ring), GFP_KERNEL, -				    adapter->node); -		if (!ring) -			ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL); +		ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);  		if (!ring)  			goto err;  		ring->count = adapter->rx_ring_count;  		ring->queue_index = i;  		ring->dev = &adapter->pdev->dev;  		ring->netdev = adapter->netdev; -		ring->numa_node = adapter->node;  		/* set flag indicating ring supports SCTP checksum offload */  		if (adapter->hw.mac.type >= e1000_82576)  			set_bit(IGB_RING_FLAG_RX_SCTP_CSUM, &ring->flags); @@ -742,16 +719,12 @@ static int igb_alloc_queues(struct igb_adapter *adapter)  		adapter->rx_ring[i] = ring;  	} -	/* Restore the adapter's original node */ -	adapter->node = orig_node;  	igb_cache_ring_register(adapter);  	return 0;  err: -	/* Restore the adapter's original node */ -	adapter->node = orig_node;  	igb_free_queues(adapter);  	return -ENOMEM; @@ -1117,24 +1090,10 @@ static int igb_alloc_q_vectors(struct igb_adapter *adapter)  	struct igb_q_vector *q_vector;  	struct e1000_hw *hw = &adapter->hw;  	int v_idx; -	int orig_node = adapter->node;  	for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) { -		if ((adapter->num_q_vectors == (adapter->num_rx_queues + -						adapter->num_tx_queues)) && -		    (adapter->num_rx_queues == v_idx)) -			adapter->node = orig_node; -		if (orig_node == -1) { -			int cur_node = next_online_node(adapter->node); -			if (cur_node == MAX_NUMNODES) -				cur_node = first_online_node; -			adapter->node = cur_node; -		} -		q_vector = kzalloc_node(sizeof(struct igb_q_vector), GFP_KERNEL, -					adapter->node); -		if (!q_vector) -			q_vector = kzalloc(sizeof(struct igb_q_vector), -					   GFP_KERNEL); +		q_vector = kzalloc(sizeof(struct igb_q_vector), +				   GFP_KERNEL);  		if (!q_vector)  			goto err_out;  		q_vector->adapter = adapter; @@ -1143,14 +1102,10 @@ static int igb_alloc_q_vectors(struct igb_adapter *adapter)  		netif_napi_add(adapter->netdev, &q_vector->napi, igb_poll, 64);  		adapter->q_vector[v_idx] = q_vector;  	} -	/* Restore the adapter's original node */ -	adapter->node = orig_node;  	return 0;  err_out: -	/* Restore the adapter's original node */ -	adapter->node = orig_node;  	igb_free_q_vectors(adapter);  	return -ENOMEM;  } @@ -1751,6 +1706,11 @@ void igb_reset(struct igb_adapter *adapter)  	/* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */  	wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE); +#ifdef CONFIG_IGB_PTP +	/* Re-enable PTP, where applicable. */ +	igb_ptp_reset(adapter); +#endif /* CONFIG_IGB_PTP */ +  	igb_get_phy_info(hw);  } @@ -2180,11 +2140,12 @@ static int __devinit igb_probe(struct pci_dev *pdev,  	}  #endif +  #ifdef CONFIG_IGB_PTP  	/* do hw tstamp init after resetting */  	igb_ptp_init(adapter); +#endif /* CONFIG_IGB_PTP */ -#endif  	dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");  	/* print bus type/speed/width info */  	dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n", @@ -2259,9 +2220,9 @@ static void __devexit igb_remove(struct pci_dev *pdev)  	pm_runtime_get_noresume(&pdev->dev);  #ifdef CONFIG_IGB_PTP -	igb_ptp_remove(adapter); +	igb_ptp_stop(adapter); +#endif /* CONFIG_IGB_PTP */ -#endif  	/*  	 * The watchdog timer may be rescheduled, so explicitly  	 * disable watchdog from being rescheduled. @@ -2294,11 +2255,11 @@ static void __devexit igb_remove(struct pci_dev *pdev)  	/* reclaim resources allocated to VFs */  	if (adapter->vf_data) {  		/* disable iov and allow time for transactions to clear */ -		if (!igb_check_vf_assignment(adapter)) { +		if (igb_vfs_are_assigned(adapter)) { +			dev_info(&pdev->dev, "Unloading driver while VFs are assigned - VFs will not be deallocated\n"); +		} else {  			pci_disable_sriov(pdev);  			msleep(500); -		} else { -			dev_info(&pdev->dev, "VF(s) assigned to guests!\n");  		}  		kfree(adapter->vf_data); @@ -2338,7 +2299,7 @@ static void __devinit igb_probe_vfs(struct igb_adapter * adapter)  #ifdef CONFIG_PCI_IOV  	struct pci_dev *pdev = adapter->pdev;  	struct e1000_hw *hw = &adapter->hw; -	int old_vfs = igb_find_enabled_vfs(adapter); +	int old_vfs = pci_num_vf(adapter->pdev);  	int i;  	/* Virtualization features not supported on i210 family. */ @@ -2418,8 +2379,6 @@ static int __devinit igb_sw_init(struct igb_adapter *adapter)  				  VLAN_HLEN;  	adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN; -	adapter->node = -1; -  	spin_lock_init(&adapter->stats64_lock);  #ifdef CONFIG_PCI_IOV  	switch (hw->mac.type) { @@ -2666,13 +2625,11 @@ static int igb_close(struct net_device *netdev)  int igb_setup_tx_resources(struct igb_ring *tx_ring)  {  	struct device *dev = tx_ring->dev; -	int orig_node = dev_to_node(dev);  	int size;  	size = sizeof(struct igb_tx_buffer) * tx_ring->count; -	tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node); -	if (!tx_ring->tx_buffer_info) -		tx_ring->tx_buffer_info = vzalloc(size); + +	tx_ring->tx_buffer_info = vzalloc(size);  	if (!tx_ring->tx_buffer_info)  		goto err; @@ -2680,18 +2637,10 @@ int igb_setup_tx_resources(struct igb_ring *tx_ring)  	tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);  	tx_ring->size = ALIGN(tx_ring->size, 4096); -	set_dev_node(dev, tx_ring->numa_node);  	tx_ring->desc = dma_alloc_coherent(dev,  					   tx_ring->size,  					   &tx_ring->dma,  					   GFP_KERNEL); -	set_dev_node(dev, orig_node); -	if (!tx_ring->desc) -		tx_ring->desc = dma_alloc_coherent(dev, -						   tx_ring->size, -						   &tx_ring->dma, -						   GFP_KERNEL); -  	if (!tx_ring->desc)  		goto err; @@ -2702,8 +2651,8 @@ int igb_setup_tx_resources(struct igb_ring *tx_ring)  err:  	vfree(tx_ring->tx_buffer_info); -	dev_err(dev, -		"Unable to allocate memory for the transmit descriptor ring\n"); +	tx_ring->tx_buffer_info = NULL; +	dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");  	return -ENOMEM;  } @@ -2820,34 +2769,23 @@ static void igb_configure_tx(struct igb_adapter *adapter)  int igb_setup_rx_resources(struct igb_ring *rx_ring)  {  	struct device *dev = rx_ring->dev; -	int orig_node = dev_to_node(dev); -	int size, desc_len; +	int size;  	size = sizeof(struct igb_rx_buffer) * rx_ring->count; -	rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node); -	if (!rx_ring->rx_buffer_info) -		rx_ring->rx_buffer_info = vzalloc(size); + +	rx_ring->rx_buffer_info = vzalloc(size);  	if (!rx_ring->rx_buffer_info)  		goto err; -	desc_len = sizeof(union e1000_adv_rx_desc);  	/* Round up to nearest 4K */ -	rx_ring->size = rx_ring->count * desc_len; +	rx_ring->size = rx_ring->count * sizeof(union e1000_adv_rx_desc);  	rx_ring->size = ALIGN(rx_ring->size, 4096); -	set_dev_node(dev, rx_ring->numa_node);  	rx_ring->desc = dma_alloc_coherent(dev,  					   rx_ring->size,  					   &rx_ring->dma,  					   GFP_KERNEL); -	set_dev_node(dev, orig_node); -	if (!rx_ring->desc) -		rx_ring->desc = dma_alloc_coherent(dev, -						   rx_ring->size, -						   &rx_ring->dma, -						   GFP_KERNEL); -  	if (!rx_ring->desc)  		goto err; @@ -2859,8 +2797,7 @@ int igb_setup_rx_resources(struct igb_ring *rx_ring)  err:  	vfree(rx_ring->rx_buffer_info);  	rx_ring->rx_buffer_info = NULL; -	dev_err(dev, "Unable to allocate memory for the receive descriptor" -		" ring\n"); +	dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");  	return -ENOMEM;  } @@ -2898,57 +2835,48 @@ static void igb_setup_mrqc(struct igb_adapter *adapter)  {  	struct e1000_hw *hw = &adapter->hw;  	u32 mrqc, rxcsum; -	u32 j, num_rx_queues, shift = 0, shift2 = 0; -	union e1000_reta { -		u32 dword; -		u8  bytes[4]; -	} reta; -	static const u8 rsshash[40] = { -		0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, 0x41, 0x67, -		0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, 0xd0, 0xca, 0x2b, 0xcb, -		0xae, 0x7b, 0x30, 0xb4,	0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, -		0xf2, 0x0c, 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa }; +	u32 j, num_rx_queues, shift = 0; +	static const u32 rsskey[10] = { 0xDA565A6D, 0xC20E5B25, 0x3D256741, +					0xB08FA343, 0xCB2BCAD0, 0xB4307BAE, +					0xA32DCB77, 0x0CF23080, 0x3BB7426A, +					0xFA01ACBE };  	/* Fill out hash function seeds */ -	for (j = 0; j < 10; j++) { -		u32 rsskey = rsshash[(j * 4)]; -		rsskey |= rsshash[(j * 4) + 1] << 8; -		rsskey |= rsshash[(j * 4) + 2] << 16; -		rsskey |= rsshash[(j * 4) + 3] << 24; -		array_wr32(E1000_RSSRK(0), j, rsskey); -	} +	for (j = 0; j < 10; j++) +		wr32(E1000_RSSRK(j), rsskey[j]);  	num_rx_queues = adapter->rss_queues; -	if (adapter->vfs_allocated_count) { -		/* 82575 and 82576 supports 2 RSS queues for VMDq */ -		switch (hw->mac.type) { -		case e1000_i350: -		case e1000_82580: -			num_rx_queues = 1; -			shift = 0; -			break; -		case e1000_82576: +	switch (hw->mac.type) { +	case e1000_82575: +		shift = 6; +		break; +	case e1000_82576: +		/* 82576 supports 2 RSS queues for SR-IOV */ +		if (adapter->vfs_allocated_count) {  			shift = 3;  			num_rx_queues = 2; -			break; -		case e1000_82575: -			shift = 2; -			shift2 = 6; -		default: -			break;  		} -	} else { -		if (hw->mac.type == e1000_82575) -			shift = 6; +		break; +	default: +		break;  	} -	for (j = 0; j < (32 * 4); j++) { -		reta.bytes[j & 3] = (j % num_rx_queues) << shift; -		if (shift2) -			reta.bytes[j & 3] |= num_rx_queues << shift2; -		if ((j & 3) == 3) -			wr32(E1000_RETA(j >> 2), reta.dword); +	/* +	 * Populate the indirection table 4 entries at a time.  To do this +	 * we are generating the results for n and n+2 and then interleaving +	 * those with the results with n+1 and n+3. +	 */ +	for (j = 0; j < 32; j++) { +		/* first pass generates n and n+2 */ +		u32 base = ((j * 0x00040004) + 0x00020000) * num_rx_queues; +		u32 reta = (base & 0x07800780) >> (7 - shift); + +		/* second pass generates n+1 and n+3 */ +		base += 0x00010001 * num_rx_queues; +		reta |= (base & 0x07800780) << (1 + shift); + +		wr32(E1000_RETA(j), reta);  	}  	/* @@ -3184,8 +3112,10 @@ void igb_configure_rx_ring(struct igb_adapter *adapter,  	srrctl |= (PAGE_SIZE / 2) >> E1000_SRRCTL_BSIZEPKT_SHIFT;  #endif  	srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; +#ifdef CONFIG_IGB_PTP  	if (hw->mac.type >= e1000_82580)  		srrctl |= E1000_SRRCTL_TIMESTAMP; +#endif /* CONFIG_IGB_PTP */  	/* Only set Drop Enable if we are supporting multiple queues */  	if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)  		srrctl |= E1000_SRRCTL_DROP_EN; @@ -3269,20 +3199,20 @@ void igb_unmap_and_free_tx_resource(struct igb_ring *ring,  {  	if (tx_buffer->skb) {  		dev_kfree_skb_any(tx_buffer->skb); -		if (tx_buffer->dma) +		if (dma_unmap_len(tx_buffer, len))  			dma_unmap_single(ring->dev, -					 tx_buffer->dma, -					 tx_buffer->length, +					 dma_unmap_addr(tx_buffer, dma), +					 dma_unmap_len(tx_buffer, len),  					 DMA_TO_DEVICE); -	} else if (tx_buffer->dma) { +	} else if (dma_unmap_len(tx_buffer, len)) {  		dma_unmap_page(ring->dev, -			       tx_buffer->dma, -			       tx_buffer->length, +			       dma_unmap_addr(tx_buffer, dma), +			       dma_unmap_len(tx_buffer, len),  			       DMA_TO_DEVICE);  	}  	tx_buffer->next_to_watch = NULL;  	tx_buffer->skb = NULL; -	tx_buffer->dma = 0; +	dma_unmap_len_set(tx_buffer, len, 0);  	/* buffer_info must be completely set up in the transmit path */  } @@ -4229,9 +4159,11 @@ static __le32 igb_tx_cmd_type(u32 tx_flags)  	if (tx_flags & IGB_TX_FLAGS_VLAN)  		cmd_type |= cpu_to_le32(E1000_ADVTXD_DCMD_VLE); +#ifdef CONFIG_IGB_PTP  	/* set timestamp bit if present */ -	if (tx_flags & IGB_TX_FLAGS_TSTAMP) +	if (unlikely(tx_flags & IGB_TX_FLAGS_TSTAMP))  		cmd_type |= cpu_to_le32(E1000_ADVTXD_MAC_TSTAMP); +#endif /* CONFIG_IGB_PTP */  	/* set segmentation bits for TSO */  	if (tx_flags & IGB_TX_FLAGS_TSO) @@ -4275,7 +4207,7 @@ static void igb_tx_map(struct igb_ring *tx_ring,  		       const u8 hdr_len)  {  	struct sk_buff *skb = first->skb; -	struct igb_tx_buffer *tx_buffer_info; +	struct igb_tx_buffer *tx_buffer;  	union e1000_adv_tx_desc *tx_desc;  	dma_addr_t dma;  	struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0]; @@ -4296,8 +4228,8 @@ static void igb_tx_map(struct igb_ring *tx_ring,  		goto dma_error;  	/* record length, and DMA address */ -	first->length = size; -	first->dma = dma; +	dma_unmap_len_set(first, len, size); +	dma_unmap_addr_set(first, dma, dma);  	tx_desc->read.buffer_addr = cpu_to_le64(dma);  	for (;;) { @@ -4339,9 +4271,9 @@ static void igb_tx_map(struct igb_ring *tx_ring,  		if (dma_mapping_error(tx_ring->dev, dma))  			goto dma_error; -		tx_buffer_info = &tx_ring->tx_buffer_info[i]; -		tx_buffer_info->length = size; -		tx_buffer_info->dma = dma; +		tx_buffer = &tx_ring->tx_buffer_info[i]; +		dma_unmap_len_set(tx_buffer, len, size); +		dma_unmap_addr_set(tx_buffer, dma, dma);  		tx_desc->read.olinfo_status = 0;  		tx_desc->read.buffer_addr = cpu_to_le64(dma); @@ -4392,9 +4324,9 @@ dma_error:  	/* clear dma mappings for failed tx_buffer_info map */  	for (;;) { -		tx_buffer_info = &tx_ring->tx_buffer_info[i]; -		igb_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); -		if (tx_buffer_info == first) +		tx_buffer = &tx_ring->tx_buffer_info[i]; +		igb_unmap_and_free_tx_resource(tx_ring, tx_buffer); +		if (tx_buffer == first)  			break;  		if (i == 0)  			i = tx_ring->count; @@ -4440,6 +4372,9 @@ static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, const u16 size)  netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,  				struct igb_ring *tx_ring)  { +#ifdef CONFIG_IGB_PTP +	struct igb_adapter *adapter = netdev_priv(tx_ring->netdev); +#endif /* CONFIG_IGB_PTP */  	struct igb_tx_buffer *first;  	int tso;  	u32 tx_flags = 0; @@ -4462,10 +4397,17 @@ netdev_tx_t igb_xmit_frame_ring(struct sk_buff *skb,  	first->bytecount = skb->len;  	first->gso_segs = 1; -	if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) { +#ifdef CONFIG_IGB_PTP +	if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) && +		     !(adapter->ptp_tx_skb))) {  		skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;  		tx_flags |= IGB_TX_FLAGS_TSTAMP; + +		adapter->ptp_tx_skb = skb_get(skb); +		if (adapter->hw.mac.type == e1000_82576) +			schedule_work(&adapter->ptp_tx_work);  	} +#endif /* CONFIG_IGB_PTP */  	if (vlan_tx_tag_present(skb)) {  		tx_flags |= IGB_TX_FLAGS_VLAN; @@ -4661,11 +4603,13 @@ void igb_update_stats(struct igb_adapter *adapter,  	bytes = 0;  	packets = 0;  	for (i = 0; i < adapter->num_rx_queues; i++) { -		u32 rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0x0FFF; +		u32 rqdpc = rd32(E1000_RQDPC(i));  		struct igb_ring *ring = adapter->rx_ring[i]; -		ring->rx_stats.drops += rqdpc_tmp; -		net_stats->rx_fifo_errors += rqdpc_tmp; +		if (rqdpc) { +			ring->rx_stats.drops += rqdpc; +			net_stats->rx_fifo_errors += rqdpc; +		}  		do {  			start = u64_stats_fetch_begin_bh(&ring->rx_syncp); @@ -4755,7 +4699,11 @@ void igb_update_stats(struct igb_adapter *adapter,  	reg = rd32(E1000_CTRL_EXT);  	if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {  		adapter->stats.rxerrc += rd32(E1000_RXERRC); -		adapter->stats.tncrs += rd32(E1000_TNCRS); + +		/* this stat has invalid values on i210/i211 */ +		if ((hw->mac.type != e1000_i210) && +		    (hw->mac.type != e1000_i211)) +			adapter->stats.tncrs += rd32(E1000_TNCRS);  	}  	adapter->stats.tsctc += rd32(E1000_TSCTC); @@ -4852,6 +4800,19 @@ static irqreturn_t igb_msix_other(int irq, void *data)  			mod_timer(&adapter->watchdog_timer, jiffies + 1);  	} +#ifdef CONFIG_IGB_PTP +	if (icr & E1000_ICR_TS) { +		u32 tsicr = rd32(E1000_TSICR); + +		if (tsicr & E1000_TSICR_TXTS) { +			/* acknowledge the interrupt */ +			wr32(E1000_TSICR, E1000_TSICR_TXTS); +			/* retrieve hardware timestamp */ +			schedule_work(&adapter->ptp_tx_work); +		} +	} +#endif /* CONFIG_IGB_PTP */ +  	wr32(E1000_EIMS, adapter->eims_other);  	return IRQ_HANDLED; @@ -5002,102 +4963,43 @@ static int igb_notify_dca(struct notifier_block *nb, unsigned long event,  static int igb_vf_configure(struct igb_adapter *adapter, int vf)  {  	unsigned char mac_addr[ETH_ALEN]; -	struct pci_dev *pdev = adapter->pdev; -	struct e1000_hw *hw = &adapter->hw; -	struct pci_dev *pvfdev; -	unsigned int device_id; -	u16 thisvf_devfn;  	eth_random_addr(mac_addr);  	igb_set_vf_mac(adapter, vf, mac_addr); -	switch (adapter->hw.mac.type) { -	case e1000_82576: -		device_id = IGB_82576_VF_DEV_ID; -		/* VF Stride for 82576 is 2 */ -		thisvf_devfn = (pdev->devfn + 0x80 + (vf << 1)) | -			(pdev->devfn & 1); -		break; -	case e1000_i350: -		device_id = IGB_I350_VF_DEV_ID; -		/* VF Stride for I350 is 4 */ -		thisvf_devfn = (pdev->devfn + 0x80 + (vf << 2)) | -				(pdev->devfn & 3); -		break; -	default: -		device_id = 0; -		thisvf_devfn = 0; -		break; -	} - -	pvfdev = pci_get_device(hw->vendor_id, device_id, NULL); -	while (pvfdev) { -		if (pvfdev->devfn == thisvf_devfn) -			break; -		pvfdev = pci_get_device(hw->vendor_id, -					device_id, pvfdev); -	} - -	if (pvfdev) -		adapter->vf_data[vf].vfdev = pvfdev; -	else -		dev_err(&pdev->dev, -			"Couldn't find pci dev ptr for VF %4.4x\n", -			thisvf_devfn); -	return pvfdev != NULL; +	return 0;  } -static int igb_find_enabled_vfs(struct igb_adapter *adapter) +static bool igb_vfs_are_assigned(struct igb_adapter *adapter)  { -	struct e1000_hw *hw = &adapter->hw;  	struct pci_dev *pdev = adapter->pdev; -	struct pci_dev *pvfdev; -	u16 vf_devfn = 0; -	u16 vf_stride; -	unsigned int device_id; -	int vfs_found = 0; +	struct pci_dev *vfdev; +	int dev_id;  	switch (adapter->hw.mac.type) {  	case e1000_82576: -		device_id = IGB_82576_VF_DEV_ID; -		/* VF Stride for 82576 is 2 */ -		vf_stride = 2; +		dev_id = IGB_82576_VF_DEV_ID;  		break;  	case e1000_i350: -		device_id = IGB_I350_VF_DEV_ID; -		/* VF Stride for I350 is 4 */ -		vf_stride = 4; +		dev_id = IGB_I350_VF_DEV_ID;  		break;  	default: -		device_id = 0; -		vf_stride = 0; -		break; -	} - -	vf_devfn = pdev->devfn + 0x80; -	pvfdev = pci_get_device(hw->vendor_id, device_id, NULL); -	while (pvfdev) { -		if (pvfdev->devfn == vf_devfn && -		    (pvfdev->bus->number >= pdev->bus->number)) -			vfs_found++; -		vf_devfn += vf_stride; -		pvfdev = pci_get_device(hw->vendor_id, -					device_id, pvfdev); +		return false;  	} -	return vfs_found; -} - -static int igb_check_vf_assignment(struct igb_adapter *adapter) -{ -	int i; -	for (i = 0; i < adapter->vfs_allocated_count; i++) { -		if (adapter->vf_data[i].vfdev) { -			if (adapter->vf_data[i].vfdev->dev_flags & -			    PCI_DEV_FLAGS_ASSIGNED) +	/* loop through all the VFs to see if we own any that are assigned */ +	vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, NULL); +	while (vfdev) { +		/* if we don't own it we don't care */ +		if (vfdev->is_virtfn && vfdev->physfn == pdev) { +			/* if it is assigned we cannot release it */ +			if (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED)  				return true;  		} + +		vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, dev_id, vfdev);  	} +  	return false;  } @@ -5643,6 +5545,19 @@ static irqreturn_t igb_intr_msi(int irq, void *data)  			mod_timer(&adapter->watchdog_timer, jiffies + 1);  	} +#ifdef CONFIG_IGB_PTP +	if (icr & E1000_ICR_TS) { +		u32 tsicr = rd32(E1000_TSICR); + +		if (tsicr & E1000_TSICR_TXTS) { +			/* acknowledge the interrupt */ +			wr32(E1000_TSICR, E1000_TSICR_TXTS); +			/* retrieve hardware timestamp */ +			schedule_work(&adapter->ptp_tx_work); +		} +	} +#endif /* CONFIG_IGB_PTP */ +  	napi_schedule(&q_vector->napi);  	return IRQ_HANDLED; @@ -5684,6 +5599,19 @@ static irqreturn_t igb_intr(int irq, void *data)  			mod_timer(&adapter->watchdog_timer, jiffies + 1);  	} +#ifdef CONFIG_IGB_PTP +	if (icr & E1000_ICR_TS) { +		u32 tsicr = rd32(E1000_TSICR); + +		if (tsicr & E1000_TSICR_TXTS) { +			/* acknowledge the interrupt */ +			wr32(E1000_TSICR, E1000_TSICR_TXTS); +			/* retrieve hardware timestamp */ +			schedule_work(&adapter->ptp_tx_work); +		} +	} +#endif /* CONFIG_IGB_PTP */ +  	napi_schedule(&q_vector->napi);  	return IRQ_HANDLED; @@ -5743,37 +5671,6 @@ static int igb_poll(struct napi_struct *napi, int budget)  	return 0;  } -#ifdef CONFIG_IGB_PTP -/** - * igb_tx_hwtstamp - utility function which checks for TX time stamp - * @q_vector: pointer to q_vector containing needed info - * @buffer: pointer to igb_tx_buffer structure - * - * If we were asked to do hardware stamping and such a time stamp is - * available, then it must have been for this skb here because we only - * allow only one such packet into the queue. - */ -static void igb_tx_hwtstamp(struct igb_q_vector *q_vector, -			    struct igb_tx_buffer *buffer_info) -{ -	struct igb_adapter *adapter = q_vector->adapter; -	struct e1000_hw *hw = &adapter->hw; -	struct skb_shared_hwtstamps shhwtstamps; -	u64 regval; - -	/* if skb does not support hw timestamp or TX stamp not valid exit */ -	if (likely(!(buffer_info->tx_flags & IGB_TX_FLAGS_TSTAMP)) || -	    !(rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID)) -		return; - -	regval = rd32(E1000_TXSTMPL); -	regval |= (u64)rd32(E1000_TXSTMPH) << 32; - -	igb_systim_to_hwtstamp(adapter, &shhwtstamps, regval); -	skb_tstamp_tx(buffer_info->skb, &shhwtstamps); -} - -#endif  /**   * igb_clean_tx_irq - Reclaim resources after transmit completes   * @q_vector: pointer to q_vector containing needed info @@ -5785,7 +5682,7 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)  	struct igb_adapter *adapter = q_vector->adapter;  	struct igb_ring *tx_ring = q_vector->tx.ring;  	struct igb_tx_buffer *tx_buffer; -	union e1000_adv_tx_desc *tx_desc, *eop_desc; +	union e1000_adv_tx_desc *tx_desc;  	unsigned int total_bytes = 0, total_packets = 0;  	unsigned int budget = q_vector->tx.work_limit;  	unsigned int i = tx_ring->next_to_clean; @@ -5797,16 +5694,16 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)  	tx_desc = IGB_TX_DESC(tx_ring, i);  	i -= tx_ring->count; -	for (; budget; budget--) { -		eop_desc = tx_buffer->next_to_watch; - -		/* prevent any other reads prior to eop_desc */ -		rmb(); +	do { +		union e1000_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;  		/* if next_to_watch is not set then there is no work pending */  		if (!eop_desc)  			break; +		/* prevent any other reads prior to eop_desc */ +		rmb(); +  		/* if DD is not set pending work has not been completed */  		if (!(eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)))  			break; @@ -5818,25 +5715,21 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)  		total_bytes += tx_buffer->bytecount;  		total_packets += tx_buffer->gso_segs; -#ifdef CONFIG_IGB_PTP -		/* retrieve hardware timestamp */ -		igb_tx_hwtstamp(q_vector, tx_buffer); - -#endif  		/* free the skb */  		dev_kfree_skb_any(tx_buffer->skb); -		tx_buffer->skb = NULL;  		/* unmap skb header data */  		dma_unmap_single(tx_ring->dev, -				 tx_buffer->dma, -				 tx_buffer->length, +				 dma_unmap_addr(tx_buffer, dma), +				 dma_unmap_len(tx_buffer, len),  				 DMA_TO_DEVICE); +		/* clear tx_buffer data */ +		tx_buffer->skb = NULL; +		dma_unmap_len_set(tx_buffer, len, 0); +  		/* clear last DMA location and unmap remaining buffers */  		while (tx_desc != eop_desc) { -			tx_buffer->dma = 0; -  			tx_buffer++;  			tx_desc++;  			i++; @@ -5847,17 +5740,15 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)  			}  			/* unmap any remaining paged data */ -			if (tx_buffer->dma) { +			if (dma_unmap_len(tx_buffer, len)) {  				dma_unmap_page(tx_ring->dev, -					       tx_buffer->dma, -					       tx_buffer->length, +					       dma_unmap_addr(tx_buffer, dma), +					       dma_unmap_len(tx_buffer, len),  					       DMA_TO_DEVICE); +				dma_unmap_len_set(tx_buffer, len, 0);  			}  		} -		/* clear last DMA location */ -		tx_buffer->dma = 0; -  		/* move us one more past the eop_desc for start of next pkt */  		tx_buffer++;  		tx_desc++; @@ -5867,7 +5758,13 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)  			tx_buffer = tx_ring->tx_buffer_info;  			tx_desc = IGB_TX_DESC(tx_ring, 0);  		} -	} + +		/* issue prefetch for next Tx descriptor */ +		prefetch(tx_desc); + +		/* update budget accounting */ +		budget--; +	} while (likely(budget));  	netdev_tx_completed_queue(txring_txq(tx_ring),  				  total_packets, total_bytes); @@ -5883,12 +5780,10 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)  	if (test_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags)) {  		struct e1000_hw *hw = &adapter->hw; -		eop_desc = tx_buffer->next_to_watch; -  		/* Detect a transmit hang in hardware, this serializes the  		 * check with the clearing of time_stamp and movement of i */  		clear_bit(IGB_RING_FLAG_TX_DETECT_HANG, &tx_ring->flags); -		if (eop_desc && +		if (tx_buffer->next_to_watch &&  		    time_after(jiffies, tx_buffer->time_stamp +  			       (adapter->tx_timeout_factor * HZ)) &&  		    !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) { @@ -5912,9 +5807,9 @@ static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)  				tx_ring->next_to_use,  				tx_ring->next_to_clean,  				tx_buffer->time_stamp, -				eop_desc, +				tx_buffer->next_to_watch,  				jiffies, -				eop_desc->wb.status); +				tx_buffer->next_to_watch->wb.status);  			netif_stop_subqueue(tx_ring->netdev,  					    tx_ring->queue_index); @@ -5994,47 +5889,6 @@ static inline void igb_rx_hash(struct igb_ring *ring,  		skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);  } -#ifdef CONFIG_IGB_PTP -static void igb_rx_hwtstamp(struct igb_q_vector *q_vector, -			    union e1000_adv_rx_desc *rx_desc, -			    struct sk_buff *skb) -{ -	struct igb_adapter *adapter = q_vector->adapter; -	struct e1000_hw *hw = &adapter->hw; -	u64 regval; - -	if (!igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP | -				       E1000_RXDADV_STAT_TS)) -		return; - -	/* -	 * If this bit is set, then the RX registers contain the time stamp. No -	 * other packet will be time stamped until we read these registers, so -	 * read the registers to make them available again. Because only one -	 * packet can be time stamped at a time, we know that the register -	 * values must belong to this one here and therefore we don't need to -	 * compare any of the additional attributes stored for it. -	 * -	 * If nothing went wrong, then it should have a shared tx_flags that we -	 * can turn into a skb_shared_hwtstamps. -	 */ -	if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) { -		u32 *stamp = (u32 *)skb->data; -		regval = le32_to_cpu(*(stamp + 2)); -		regval |= (u64)le32_to_cpu(*(stamp + 3)) << 32; -		skb_pull(skb, IGB_TS_HDR_LEN); -	} else { -		if(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) -			return; - -		regval = rd32(E1000_RXSTMPL); -		regval |= (u64)rd32(E1000_RXSTMPH) << 32; -	} - -	igb_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval); -} - -#endif  static void igb_rx_vlan(struct igb_ring *ring,  			union e1000_adv_rx_desc *rx_desc,  			struct sk_buff *skb) @@ -6146,8 +6000,8 @@ static bool igb_clean_rx_irq(struct igb_q_vector *q_vector, int budget)  		}  #ifdef CONFIG_IGB_PTP -		igb_rx_hwtstamp(q_vector, rx_desc, skb); -#endif +		igb_ptp_rx_hwtstamp(q_vector, rx_desc, skb); +#endif /* CONFIG_IGB_PTP */  		igb_rx_hash(rx_ring, rx_desc, skb);  		igb_rx_checksum(rx_ring, rx_desc, skb);  		igb_rx_vlan(rx_ring, rx_desc, skb); @@ -6341,181 +6195,6 @@ static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)  }  /** - * igb_hwtstamp_ioctl - control hardware time stamping - * @netdev: - * @ifreq: - * @cmd: - * - * Outgoing time stamping can be enabled and disabled. Play nice and - * disable it when requested, although it shouldn't case any overhead - * when no packet needs it. At most one packet in the queue may be - * marked for time stamping, otherwise it would be impossible to tell - * for sure to which packet the hardware time stamp belongs. - * - * Incoming time stamping has to be configured via the hardware - * filters. Not all combinations are supported, in particular event - * type has to be specified. Matching the kind of event packet is - * not supported, with the exception of "all V2 events regardless of - * level 2 or 4". - * - **/ -static int igb_hwtstamp_ioctl(struct net_device *netdev, -			      struct ifreq *ifr, int cmd) -{ -	struct igb_adapter *adapter = netdev_priv(netdev); -	struct e1000_hw *hw = &adapter->hw; -	struct hwtstamp_config config; -	u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; -	u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; -	u32 tsync_rx_cfg = 0; -	bool is_l4 = false; -	bool is_l2 = false; -	u32 regval; - -	if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) -		return -EFAULT; - -	/* reserved for future extensions */ -	if (config.flags) -		return -EINVAL; - -	switch (config.tx_type) { -	case HWTSTAMP_TX_OFF: -		tsync_tx_ctl = 0; -	case HWTSTAMP_TX_ON: -		break; -	default: -		return -ERANGE; -	} - -	switch (config.rx_filter) { -	case HWTSTAMP_FILTER_NONE: -		tsync_rx_ctl = 0; -		break; -	case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: -	case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: -	case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: -	case HWTSTAMP_FILTER_ALL: -		/* -		 * register TSYNCRXCFG must be set, therefore it is not -		 * possible to time stamp both Sync and Delay_Req messages -		 * => fall back to time stamping all packets -		 */ -		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; -		config.rx_filter = HWTSTAMP_FILTER_ALL; -		break; -	case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: -		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; -		tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE; -		is_l4 = true; -		break; -	case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: -		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; -		tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE; -		is_l4 = true; -		break; -	case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: -	case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: -		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; -		tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE; -		is_l2 = true; -		is_l4 = true; -		config.rx_filter = HWTSTAMP_FILTER_SOME; -		break; -	case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: -	case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: -		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; -		tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE; -		is_l2 = true; -		is_l4 = true; -		config.rx_filter = HWTSTAMP_FILTER_SOME; -		break; -	case HWTSTAMP_FILTER_PTP_V2_EVENT: -	case HWTSTAMP_FILTER_PTP_V2_SYNC: -	case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: -		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2; -		config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; -		is_l2 = true; -		is_l4 = true; -		break; -	default: -		return -ERANGE; -	} - -	if (hw->mac.type == e1000_82575) { -		if (tsync_rx_ctl | tsync_tx_ctl) -			return -EINVAL; -		return 0; -	} - -	/* -	 * Per-packet timestamping only works if all packets are -	 * timestamped, so enable timestamping in all packets as -	 * long as one rx filter was configured. -	 */ -	if ((hw->mac.type >= e1000_82580) && tsync_rx_ctl) { -		tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; -		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; -	} - -	/* enable/disable TX */ -	regval = rd32(E1000_TSYNCTXCTL); -	regval &= ~E1000_TSYNCTXCTL_ENABLED; -	regval |= tsync_tx_ctl; -	wr32(E1000_TSYNCTXCTL, regval); - -	/* enable/disable RX */ -	regval = rd32(E1000_TSYNCRXCTL); -	regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK); -	regval |= tsync_rx_ctl; -	wr32(E1000_TSYNCRXCTL, regval); - -	/* define which PTP packets are time stamped */ -	wr32(E1000_TSYNCRXCFG, tsync_rx_cfg); - -	/* define ethertype filter for timestamped packets */ -	if (is_l2) -		wr32(E1000_ETQF(3), -		                (E1000_ETQF_FILTER_ENABLE | /* enable filter */ -		                 E1000_ETQF_1588 | /* enable timestamping */ -		                 ETH_P_1588));     /* 1588 eth protocol type */ -	else -		wr32(E1000_ETQF(3), 0); - -#define PTP_PORT 319 -	/* L4 Queue Filter[3]: filter by destination port and protocol */ -	if (is_l4) { -		u32 ftqf = (IPPROTO_UDP /* UDP */ -			| E1000_FTQF_VF_BP /* VF not compared */ -			| E1000_FTQF_1588_TIME_STAMP /* Enable Timestamping */ -			| E1000_FTQF_MASK); /* mask all inputs */ -		ftqf &= ~E1000_FTQF_MASK_PROTO_BP; /* enable protocol check */ - -		wr32(E1000_IMIR(3), htons(PTP_PORT)); -		wr32(E1000_IMIREXT(3), -		     (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP)); -		if (hw->mac.type == e1000_82576) { -			/* enable source port check */ -			wr32(E1000_SPQF(3), htons(PTP_PORT)); -			ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP; -		} -		wr32(E1000_FTQF(3), ftqf); -	} else { -		wr32(E1000_FTQF(3), E1000_FTQF_MASK); -	} -	wrfl(); - -	adapter->hwtstamp_config = config; - -	/* clear TX/RX time stamp registers, just to be sure */ -	regval = rd32(E1000_TXSTMPH); -	regval = rd32(E1000_RXSTMPH); - -	return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -		-EFAULT : 0; -} - -/**   * igb_ioctl -   * @netdev:   * @ifreq: @@ -6528,8 +6207,10 @@ static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)  	case SIOCGMIIREG:  	case SIOCSMIIREG:  		return igb_mii_ioctl(netdev, ifr, cmd); +#ifdef CONFIG_IGB_PTP  	case SIOCSHWTSTAMP: -		return igb_hwtstamp_ioctl(netdev, ifr, cmd); +		return igb_ptp_hwtstamp_ioctl(netdev, ifr, cmd); +#endif /* CONFIG_IGB_PTP */  	default:  		return -EOPNOTSUPP;  	} @@ -6538,28 +6219,20 @@ static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)  s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)  {  	struct igb_adapter *adapter = hw->back; -	u16 cap_offset; -	cap_offset = adapter->pdev->pcie_cap; -	if (!cap_offset) +	if (pcie_capability_read_word(adapter->pdev, reg, value))  		return -E1000_ERR_CONFIG; -	pci_read_config_word(adapter->pdev, cap_offset + reg, value); -  	return 0;  }  s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)  {  	struct igb_adapter *adapter = hw->back; -	u16 cap_offset; -	cap_offset = adapter->pdev->pcie_cap; -	if (!cap_offset) +	if (pcie_capability_write_word(adapter->pdev, reg, *value))  		return -E1000_ERR_CONFIG; -	pci_write_config_word(adapter->pdev, cap_offset + reg, *value); -  	return 0;  } @@ -6675,6 +6348,10 @@ int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)  	default:  		goto err_inval;  	} + +	/* clear MDI, MDI(-X) override is only allowed when autoneg enabled */ +	adapter->hw.phy.mdix = AUTO_ALL_MODES; +  	return 0;  err_inval: diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c index c846ea9131a..ee21445157a 100644 --- a/drivers/net/ethernet/intel/igb/igb_ptp.c +++ b/drivers/net/ethernet/intel/igb/igb_ptp.c @@ -69,22 +69,22 @@   *   2^40 * 10^-9 /  60  = 18.3 minutes.   */ -#define IGB_OVERFLOW_PERIOD	(HZ * 60 * 9) -#define INCPERIOD_82576		(1 << E1000_TIMINCA_16NS_SHIFT) -#define INCVALUE_82576_MASK	((1 << E1000_TIMINCA_16NS_SHIFT) - 1) -#define INCVALUE_82576		(16 << IGB_82576_TSYNC_SHIFT) -#define IGB_NBITS_82580		40 +#define IGB_SYSTIM_OVERFLOW_PERIOD	(HZ * 60 * 9) +#define INCPERIOD_82576			(1 << E1000_TIMINCA_16NS_SHIFT) +#define INCVALUE_82576_MASK		((1 << E1000_TIMINCA_16NS_SHIFT) - 1) +#define INCVALUE_82576			(16 << IGB_82576_TSYNC_SHIFT) +#define IGB_NBITS_82580			40  /*   * SYSTIM read access for the 82576   */ -static cycle_t igb_82576_systim_read(const struct cyclecounter *cc) +static cycle_t igb_ptp_read_82576(const struct cyclecounter *cc)  { -	u64 val; -	u32 lo, hi;  	struct igb_adapter *igb = container_of(cc, struct igb_adapter, cc);  	struct e1000_hw *hw = &igb->hw; +	u64 val; +	u32 lo, hi;  	lo = rd32(E1000_SYSTIML);  	hi = rd32(E1000_SYSTIMH); @@ -99,12 +99,12 @@ static cycle_t igb_82576_systim_read(const struct cyclecounter *cc)   * SYSTIM read access for the 82580   */ -static cycle_t igb_82580_systim_read(const struct cyclecounter *cc) +static cycle_t igb_ptp_read_82580(const struct cyclecounter *cc)  { -	u64 val; -	u32 lo, hi, jk;  	struct igb_adapter *igb = container_of(cc, struct igb_adapter, cc);  	struct e1000_hw *hw = &igb->hw; +	u64 val; +	u32 lo, hi, jk;  	/*  	 * The timestamp latches on lowest register read. For the 82580 @@ -122,16 +122,101 @@ static cycle_t igb_82580_systim_read(const struct cyclecounter *cc)  }  /* + * SYSTIM read access for I210/I211 + */ + +static void igb_ptp_read_i210(struct igb_adapter *adapter, struct timespec *ts) +{ +	struct e1000_hw *hw = &adapter->hw; +	u32 sec, nsec, jk; + +	/* +	 * The timestamp latches on lowest register read. For I210/I211, the +	 * lowest register is SYSTIMR. Since we only need to provide nanosecond +	 * resolution, we can ignore it. +	 */ +	jk = rd32(E1000_SYSTIMR); +	nsec = rd32(E1000_SYSTIML); +	sec = rd32(E1000_SYSTIMH); + +	ts->tv_sec = sec; +	ts->tv_nsec = nsec; +} + +static void igb_ptp_write_i210(struct igb_adapter *adapter, +			       const struct timespec *ts) +{ +	struct e1000_hw *hw = &adapter->hw; + +	/* +	 * Writing the SYSTIMR register is not necessary as it only provides +	 * sub-nanosecond resolution. +	 */ +	wr32(E1000_SYSTIML, ts->tv_nsec); +	wr32(E1000_SYSTIMH, ts->tv_sec); +} + +/** + * igb_ptp_systim_to_hwtstamp - convert system time value to hw timestamp + * @adapter: board private structure + * @hwtstamps: timestamp structure to update + * @systim: unsigned 64bit system time value. + * + * We need to convert the system time value stored in the RX/TXSTMP registers + * into a hwtstamp which can be used by the upper level timestamping functions. + * + * The 'tmreg_lock' spinlock is used to protect the consistency of the + * system time value. This is needed because reading the 64 bit time + * value involves reading two (or three) 32 bit registers. The first + * read latches the value. Ditto for writing. + * + * In addition, here have extended the system time with an overflow + * counter in software. + **/ +static void igb_ptp_systim_to_hwtstamp(struct igb_adapter *adapter, +				       struct skb_shared_hwtstamps *hwtstamps, +				       u64 systim) +{ +	unsigned long flags; +	u64 ns; + +	switch (adapter->hw.mac.type) { +	case e1000_82576: +	case e1000_82580: +	case e1000_i350: +		spin_lock_irqsave(&adapter->tmreg_lock, flags); + +		ns = timecounter_cyc2time(&adapter->tc, systim); + +		spin_unlock_irqrestore(&adapter->tmreg_lock, flags); + +		memset(hwtstamps, 0, sizeof(*hwtstamps)); +		hwtstamps->hwtstamp = ns_to_ktime(ns); +		break; +	case e1000_i210: +	case e1000_i211: +		memset(hwtstamps, 0, sizeof(*hwtstamps)); +		/* Upper 32 bits contain s, lower 32 bits contain ns. */ +		hwtstamps->hwtstamp = ktime_set(systim >> 32, +						systim & 0xFFFFFFFF); +		break; +	default: +		break; +	} +} + +/*   * PTP clock operations   */ -static int ptp_82576_adjfreq(struct ptp_clock_info *ptp, s32 ppb) +static int igb_ptp_adjfreq_82576(struct ptp_clock_info *ptp, s32 ppb)  { +	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, +					       ptp_caps); +	struct e1000_hw *hw = &igb->hw; +	int neg_adj = 0;  	u64 rate;  	u32 incvalue; -	int neg_adj = 0; -	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, caps); -	struct e1000_hw *hw = &igb->hw;  	if (ppb < 0) {  		neg_adj = 1; @@ -153,13 +238,14 @@ static int ptp_82576_adjfreq(struct ptp_clock_info *ptp, s32 ppb)  	return 0;  } -static int ptp_82580_adjfreq(struct ptp_clock_info *ptp, s32 ppb) +static int igb_ptp_adjfreq_82580(struct ptp_clock_info *ptp, s32 ppb)  { +	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, +					       ptp_caps); +	struct e1000_hw *hw = &igb->hw; +	int neg_adj = 0;  	u64 rate;  	u32 inca; -	int neg_adj = 0; -	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, caps); -	struct e1000_hw *hw = &igb->hw;  	if (ppb < 0) {  		neg_adj = 1; @@ -178,11 +264,12 @@ static int ptp_82580_adjfreq(struct ptp_clock_info *ptp, s32 ppb)  	return 0;  } -static int igb_adjtime(struct ptp_clock_info *ptp, s64 delta) +static int igb_ptp_adjtime_82576(struct ptp_clock_info *ptp, s64 delta)  { -	s64 now; +	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, +					       ptp_caps);  	unsigned long flags; -	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, caps); +	s64 now;  	spin_lock_irqsave(&igb->tmreg_lock, flags); @@ -195,12 +282,32 @@ static int igb_adjtime(struct ptp_clock_info *ptp, s64 delta)  	return 0;  } -static int igb_gettime(struct ptp_clock_info *ptp, struct timespec *ts) +static int igb_ptp_adjtime_i210(struct ptp_clock_info *ptp, s64 delta) +{ +	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, +					       ptp_caps); +	unsigned long flags; +	struct timespec now, then = ns_to_timespec(delta); + +	spin_lock_irqsave(&igb->tmreg_lock, flags); + +	igb_ptp_read_i210(igb, &now); +	now = timespec_add(now, then); +	igb_ptp_write_i210(igb, (const struct timespec *)&now); + +	spin_unlock_irqrestore(&igb->tmreg_lock, flags); + +	return 0; +} + +static int igb_ptp_gettime_82576(struct ptp_clock_info *ptp, +				 struct timespec *ts)  { +	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, +					       ptp_caps); +	unsigned long flags;  	u64 ns;  	u32 remainder; -	unsigned long flags; -	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, caps);  	spin_lock_irqsave(&igb->tmreg_lock, flags); @@ -214,11 +321,29 @@ static int igb_gettime(struct ptp_clock_info *ptp, struct timespec *ts)  	return 0;  } -static int igb_settime(struct ptp_clock_info *ptp, const struct timespec *ts) +static int igb_ptp_gettime_i210(struct ptp_clock_info *ptp, +				struct timespec *ts)  { -	u64 ns; +	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, +					       ptp_caps);  	unsigned long flags; -	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, caps); + +	spin_lock_irqsave(&igb->tmreg_lock, flags); + +	igb_ptp_read_i210(igb, ts); + +	spin_unlock_irqrestore(&igb->tmreg_lock, flags); + +	return 0; +} + +static int igb_ptp_settime_82576(struct ptp_clock_info *ptp, +				 const struct timespec *ts) +{ +	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, +					       ptp_caps); +	unsigned long flags; +	u64 ns;  	ns = ts->tv_sec * 1000000000ULL;  	ns += ts->tv_nsec; @@ -232,77 +357,369 @@ static int igb_settime(struct ptp_clock_info *ptp, const struct timespec *ts)  	return 0;  } -static int ptp_82576_enable(struct ptp_clock_info *ptp, -			    struct ptp_clock_request *rq, int on) +static int igb_ptp_settime_i210(struct ptp_clock_info *ptp, +				const struct timespec *ts)  { -	return -EOPNOTSUPP; +	struct igb_adapter *igb = container_of(ptp, struct igb_adapter, +					       ptp_caps); +	unsigned long flags; + +	spin_lock_irqsave(&igb->tmreg_lock, flags); + +	igb_ptp_write_i210(igb, ts); + +	spin_unlock_irqrestore(&igb->tmreg_lock, flags); + +	return 0;  } -static int ptp_82580_enable(struct ptp_clock_info *ptp, -			    struct ptp_clock_request *rq, int on) +static int igb_ptp_enable(struct ptp_clock_info *ptp, +			  struct ptp_clock_request *rq, int on)  {  	return -EOPNOTSUPP;  } -static void igb_overflow_check(struct work_struct *work) +/** + * igb_ptp_tx_work + * @work: pointer to work struct + * + * This work function polls the TSYNCTXCTL valid bit to determine when a + * timestamp has been taken for the current stored skb. + */ +void igb_ptp_tx_work(struct work_struct *work) +{ +	struct igb_adapter *adapter = container_of(work, struct igb_adapter, +						   ptp_tx_work); +	struct e1000_hw *hw = &adapter->hw; +	u32 tsynctxctl; + +	if (!adapter->ptp_tx_skb) +		return; + +	tsynctxctl = rd32(E1000_TSYNCTXCTL); +	if (tsynctxctl & E1000_TSYNCTXCTL_VALID) +		igb_ptp_tx_hwtstamp(adapter); +	else +		/* reschedule to check later */ +		schedule_work(&adapter->ptp_tx_work); +} + +static void igb_ptp_overflow_check(struct work_struct *work)  { -	struct timespec ts;  	struct igb_adapter *igb = -		container_of(work, struct igb_adapter, overflow_work.work); +		container_of(work, struct igb_adapter, ptp_overflow_work.work); +	struct timespec ts; -	igb_gettime(&igb->caps, &ts); +	igb->ptp_caps.gettime(&igb->ptp_caps, &ts);  	pr_debug("igb overflow check at %ld.%09lu\n", ts.tv_sec, ts.tv_nsec); -	schedule_delayed_work(&igb->overflow_work, IGB_OVERFLOW_PERIOD); +	schedule_delayed_work(&igb->ptp_overflow_work, +			      IGB_SYSTIM_OVERFLOW_PERIOD); +} + +/** + * igb_ptp_tx_hwtstamp - utility function which checks for TX time stamp + * @adapter: Board private structure. + * + * If we were asked to do hardware stamping and such a time stamp is + * available, then it must have been for this skb here because we only + * allow only one such packet into the queue. + */ +void igb_ptp_tx_hwtstamp(struct igb_adapter *adapter) +{ +	struct e1000_hw *hw = &adapter->hw; +	struct skb_shared_hwtstamps shhwtstamps; +	u64 regval; + +	regval = rd32(E1000_TXSTMPL); +	regval |= (u64)rd32(E1000_TXSTMPH) << 32; + +	igb_ptp_systim_to_hwtstamp(adapter, &shhwtstamps, regval); +	skb_tstamp_tx(adapter->ptp_tx_skb, &shhwtstamps); +	dev_kfree_skb_any(adapter->ptp_tx_skb); +	adapter->ptp_tx_skb = NULL; +} + +void igb_ptp_rx_hwtstamp(struct igb_q_vector *q_vector, +			 union e1000_adv_rx_desc *rx_desc, +			 struct sk_buff *skb) +{ +	struct igb_adapter *adapter = q_vector->adapter; +	struct e1000_hw *hw = &adapter->hw; +	u64 regval; + +	if (!igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP | +				       E1000_RXDADV_STAT_TS)) +		return; + +	/* +	 * If this bit is set, then the RX registers contain the time stamp. No +	 * other packet will be time stamped until we read these registers, so +	 * read the registers to make them available again. Because only one +	 * packet can be time stamped at a time, we know that the register +	 * values must belong to this one here and therefore we don't need to +	 * compare any of the additional attributes stored for it. +	 * +	 * If nothing went wrong, then it should have a shared tx_flags that we +	 * can turn into a skb_shared_hwtstamps. +	 */ +	if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) { +		u32 *stamp = (u32 *)skb->data; +		regval = le32_to_cpu(*(stamp + 2)); +		regval |= (u64)le32_to_cpu(*(stamp + 3)) << 32; +		skb_pull(skb, IGB_TS_HDR_LEN); +	} else { +		if (!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) +			return; + +		regval = rd32(E1000_RXSTMPL); +		regval |= (u64)rd32(E1000_RXSTMPH) << 32; +	} + +	igb_ptp_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval); +} + +/** + * igb_ptp_hwtstamp_ioctl - control hardware time stamping + * @netdev: + * @ifreq: + * @cmd: + * + * Outgoing time stamping can be enabled and disabled. Play nice and + * disable it when requested, although it shouldn't case any overhead + * when no packet needs it. At most one packet in the queue may be + * marked for time stamping, otherwise it would be impossible to tell + * for sure to which packet the hardware time stamp belongs. + * + * Incoming time stamping has to be configured via the hardware + * filters. Not all combinations are supported, in particular event + * type has to be specified. Matching the kind of event packet is + * not supported, with the exception of "all V2 events regardless of + * level 2 or 4". + * + **/ +int igb_ptp_hwtstamp_ioctl(struct net_device *netdev, +			   struct ifreq *ifr, int cmd) +{ +	struct igb_adapter *adapter = netdev_priv(netdev); +	struct e1000_hw *hw = &adapter->hw; +	struct hwtstamp_config config; +	u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED; +	u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; +	u32 tsync_rx_cfg = 0; +	bool is_l4 = false; +	bool is_l2 = false; +	u32 regval; + +	if (copy_from_user(&config, ifr->ifr_data, sizeof(config))) +		return -EFAULT; + +	/* reserved for future extensions */ +	if (config.flags) +		return -EINVAL; + +	switch (config.tx_type) { +	case HWTSTAMP_TX_OFF: +		tsync_tx_ctl = 0; +	case HWTSTAMP_TX_ON: +		break; +	default: +		return -ERANGE; +	} + +	switch (config.rx_filter) { +	case HWTSTAMP_FILTER_NONE: +		tsync_rx_ctl = 0; +		break; +	case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: +	case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: +	case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: +	case HWTSTAMP_FILTER_ALL: +		/* +		 * register TSYNCRXCFG must be set, therefore it is not +		 * possible to time stamp both Sync and Delay_Req messages +		 * => fall back to time stamping all packets +		 */ +		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; +		config.rx_filter = HWTSTAMP_FILTER_ALL; +		break; +	case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: +		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; +		tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE; +		is_l4 = true; +		break; +	case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: +		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1; +		tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE; +		is_l4 = true; +		break; +	case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: +	case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: +		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; +		tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE; +		is_l2 = true; +		is_l4 = true; +		config.rx_filter = HWTSTAMP_FILTER_SOME; +		break; +	case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: +	case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: +		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2; +		tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE; +		is_l2 = true; +		is_l4 = true; +		config.rx_filter = HWTSTAMP_FILTER_SOME; +		break; +	case HWTSTAMP_FILTER_PTP_V2_EVENT: +	case HWTSTAMP_FILTER_PTP_V2_SYNC: +	case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: +		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2; +		config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT; +		is_l2 = true; +		is_l4 = true; +		break; +	default: +		return -ERANGE; +	} + +	if (hw->mac.type == e1000_82575) { +		if (tsync_rx_ctl | tsync_tx_ctl) +			return -EINVAL; +		return 0; +	} + +	/* +	 * Per-packet timestamping only works if all packets are +	 * timestamped, so enable timestamping in all packets as +	 * long as one rx filter was configured. +	 */ +	if ((hw->mac.type >= e1000_82580) && tsync_rx_ctl) { +		tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED; +		tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL; + +		if ((hw->mac.type == e1000_i210) || +		    (hw->mac.type == e1000_i211)) { +			regval = rd32(E1000_RXPBS); +			regval |= E1000_RXPBS_CFG_TS_EN; +			wr32(E1000_RXPBS, regval); +		} +	} + +	/* enable/disable TX */ +	regval = rd32(E1000_TSYNCTXCTL); +	regval &= ~E1000_TSYNCTXCTL_ENABLED; +	regval |= tsync_tx_ctl; +	wr32(E1000_TSYNCTXCTL, regval); + +	/* enable/disable RX */ +	regval = rd32(E1000_TSYNCRXCTL); +	regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK); +	regval |= tsync_rx_ctl; +	wr32(E1000_TSYNCRXCTL, regval); + +	/* define which PTP packets are time stamped */ +	wr32(E1000_TSYNCRXCFG, tsync_rx_cfg); + +	/* define ethertype filter for timestamped packets */ +	if (is_l2) +		wr32(E1000_ETQF(3), +		     (E1000_ETQF_FILTER_ENABLE | /* enable filter */ +		      E1000_ETQF_1588 | /* enable timestamping */ +		      ETH_P_1588));     /* 1588 eth protocol type */ +	else +		wr32(E1000_ETQF(3), 0); + +#define PTP_PORT 319 +	/* L4 Queue Filter[3]: filter by destination port and protocol */ +	if (is_l4) { +		u32 ftqf = (IPPROTO_UDP /* UDP */ +			| E1000_FTQF_VF_BP /* VF not compared */ +			| E1000_FTQF_1588_TIME_STAMP /* Enable Timestamping */ +			| E1000_FTQF_MASK); /* mask all inputs */ +		ftqf &= ~E1000_FTQF_MASK_PROTO_BP; /* enable protocol check */ + +		wr32(E1000_IMIR(3), htons(PTP_PORT)); +		wr32(E1000_IMIREXT(3), +		     (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP)); +		if (hw->mac.type == e1000_82576) { +			/* enable source port check */ +			wr32(E1000_SPQF(3), htons(PTP_PORT)); +			ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP; +		} +		wr32(E1000_FTQF(3), ftqf); +	} else { +		wr32(E1000_FTQF(3), E1000_FTQF_MASK); +	} +	wrfl(); + +	/* clear TX/RX time stamp registers, just to be sure */ +	regval = rd32(E1000_TXSTMPL); +	regval = rd32(E1000_TXSTMPH); +	regval = rd32(E1000_RXSTMPL); +	regval = rd32(E1000_RXSTMPH); + +	return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? +		-EFAULT : 0;  }  void igb_ptp_init(struct igb_adapter *adapter)  {  	struct e1000_hw *hw = &adapter->hw; +	struct net_device *netdev = adapter->netdev;  	switch (hw->mac.type) { -	case e1000_i210: -	case e1000_i211: -	case e1000_i350: +	case e1000_82576: +		snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); +		adapter->ptp_caps.owner = THIS_MODULE; +		adapter->ptp_caps.max_adj = 1000000000; +		adapter->ptp_caps.n_ext_ts = 0; +		adapter->ptp_caps.pps = 0; +		adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82576; +		adapter->ptp_caps.adjtime = igb_ptp_adjtime_82576; +		adapter->ptp_caps.gettime = igb_ptp_gettime_82576; +		adapter->ptp_caps.settime = igb_ptp_settime_82576; +		adapter->ptp_caps.enable = igb_ptp_enable; +		adapter->cc.read = igb_ptp_read_82576; +		adapter->cc.mask = CLOCKSOURCE_MASK(64); +		adapter->cc.mult = 1; +		adapter->cc.shift = IGB_82576_TSYNC_SHIFT; +		/* Dial the nominal frequency. */ +		wr32(E1000_TIMINCA, INCPERIOD_82576 | INCVALUE_82576); +		break;  	case e1000_82580: -		adapter->caps.owner	= THIS_MODULE; -		strcpy(adapter->caps.name, "igb-82580"); -		adapter->caps.max_adj	= 62499999; -		adapter->caps.n_ext_ts	= 0; -		adapter->caps.pps	= 0; -		adapter->caps.adjfreq	= ptp_82580_adjfreq; -		adapter->caps.adjtime	= igb_adjtime; -		adapter->caps.gettime	= igb_gettime; -		adapter->caps.settime	= igb_settime; -		adapter->caps.enable	= ptp_82580_enable; -		adapter->cc.read	= igb_82580_systim_read; -		adapter->cc.mask	= CLOCKSOURCE_MASK(IGB_NBITS_82580); -		adapter->cc.mult	= 1; -		adapter->cc.shift	= 0; +	case e1000_i350: +		snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); +		adapter->ptp_caps.owner = THIS_MODULE; +		adapter->ptp_caps.max_adj = 62499999; +		adapter->ptp_caps.n_ext_ts = 0; +		adapter->ptp_caps.pps = 0; +		adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82580; +		adapter->ptp_caps.adjtime = igb_ptp_adjtime_82576; +		adapter->ptp_caps.gettime = igb_ptp_gettime_82576; +		adapter->ptp_caps.settime = igb_ptp_settime_82576; +		adapter->ptp_caps.enable = igb_ptp_enable; +		adapter->cc.read = igb_ptp_read_82580; +		adapter->cc.mask = CLOCKSOURCE_MASK(IGB_NBITS_82580); +		adapter->cc.mult = 1; +		adapter->cc.shift = 0;  		/* Enable the timer functions by clearing bit 31. */  		wr32(E1000_TSAUXC, 0x0);  		break; - -	case e1000_82576: -		adapter->caps.owner	= THIS_MODULE; -		strcpy(adapter->caps.name, "igb-82576"); -		adapter->caps.max_adj	= 1000000000; -		adapter->caps.n_ext_ts	= 0; -		adapter->caps.pps	= 0; -		adapter->caps.adjfreq	= ptp_82576_adjfreq; -		adapter->caps.adjtime	= igb_adjtime; -		adapter->caps.gettime	= igb_gettime; -		adapter->caps.settime	= igb_settime; -		adapter->caps.enable	= ptp_82576_enable; -		adapter->cc.read	= igb_82576_systim_read; -		adapter->cc.mask	= CLOCKSOURCE_MASK(64); -		adapter->cc.mult	= 1; -		adapter->cc.shift	= IGB_82576_TSYNC_SHIFT; -		/* Dial the nominal frequency. */ -		wr32(E1000_TIMINCA, INCPERIOD_82576 | INCVALUE_82576); +	case e1000_i210: +	case e1000_i211: +		snprintf(adapter->ptp_caps.name, 16, "%pm", netdev->dev_addr); +		adapter->ptp_caps.owner = THIS_MODULE; +		adapter->ptp_caps.max_adj = 62499999; +		adapter->ptp_caps.n_ext_ts = 0; +		adapter->ptp_caps.pps = 0; +		adapter->ptp_caps.adjfreq = igb_ptp_adjfreq_82580; +		adapter->ptp_caps.adjtime = igb_ptp_adjtime_i210; +		adapter->ptp_caps.gettime = igb_ptp_gettime_i210; +		adapter->ptp_caps.settime = igb_ptp_settime_i210; +		adapter->ptp_caps.enable = igb_ptp_enable; +		/* Enable the timer functions by clearing bit 31. */ +		wr32(E1000_TSAUXC, 0x0);  		break; -  	default:  		adapter->ptp_clock = NULL;  		return; @@ -310,86 +727,114 @@ void igb_ptp_init(struct igb_adapter *adapter)  	wrfl(); -	timecounter_init(&adapter->tc, &adapter->cc, -			 ktime_to_ns(ktime_get_real())); +	spin_lock_init(&adapter->tmreg_lock); +	INIT_WORK(&adapter->ptp_tx_work, igb_ptp_tx_work); -	INIT_DELAYED_WORK(&adapter->overflow_work, igb_overflow_check); +	/* Initialize the clock and overflow work for devices that need it. */ +	if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211)) { +		struct timespec ts = ktime_to_timespec(ktime_get_real()); -	spin_lock_init(&adapter->tmreg_lock); +		igb_ptp_settime_i210(&adapter->ptp_caps, &ts); +	} else { +		timecounter_init(&adapter->tc, &adapter->cc, +				 ktime_to_ns(ktime_get_real())); + +		INIT_DELAYED_WORK(&adapter->ptp_overflow_work, +				  igb_ptp_overflow_check); + +		schedule_delayed_work(&adapter->ptp_overflow_work, +				      IGB_SYSTIM_OVERFLOW_PERIOD); +	} -	schedule_delayed_work(&adapter->overflow_work, IGB_OVERFLOW_PERIOD); +	/* Initialize the time sync interrupts for devices that support it. */ +	if (hw->mac.type >= e1000_82580) { +		wr32(E1000_TSIM, E1000_TSIM_TXTS); +		wr32(E1000_IMS, E1000_IMS_TS); +	} -	adapter->ptp_clock = ptp_clock_register(&adapter->caps); +	adapter->ptp_clock = ptp_clock_register(&adapter->ptp_caps, +						&adapter->pdev->dev);  	if (IS_ERR(adapter->ptp_clock)) {  		adapter->ptp_clock = NULL;  		dev_err(&adapter->pdev->dev, "ptp_clock_register failed\n"); -	} else +	} else {  		dev_info(&adapter->pdev->dev, "added PHC on %s\n",  			 adapter->netdev->name); +		adapter->flags |= IGB_FLAG_PTP; +	}  } -void igb_ptp_remove(struct igb_adapter *adapter) +/** + * igb_ptp_stop - Disable PTP device and stop the overflow check. + * @adapter: Board private structure. + * + * This function stops the PTP support and cancels the delayed work. + **/ +void igb_ptp_stop(struct igb_adapter *adapter)  {  	switch (adapter->hw.mac.type) { -	case e1000_i211: -	case e1000_i210: -	case e1000_i350: -	case e1000_82580:  	case e1000_82576: -		cancel_delayed_work_sync(&adapter->overflow_work); +	case e1000_82580: +	case e1000_i350: +		cancel_delayed_work_sync(&adapter->ptp_overflow_work); +		break; +	case e1000_i210: +	case e1000_i211: +		/* No delayed work to cancel. */  		break;  	default:  		return;  	} +	cancel_work_sync(&adapter->ptp_tx_work); +  	if (adapter->ptp_clock) {  		ptp_clock_unregister(adapter->ptp_clock);  		dev_info(&adapter->pdev->dev, "removed PHC on %s\n",  			 adapter->netdev->name); +		adapter->flags &= ~IGB_FLAG_PTP;  	}  }  /** - * igb_systim_to_hwtstamp - convert system time value to hw timestamp - * @adapter: board private structure - * @hwtstamps: timestamp structure to update - * @systim: unsigned 64bit system time value. - * - * We need to convert the system time value stored in the RX/TXSTMP registers - * into a hwtstamp which can be used by the upper level timestamping functions. - * - * The 'tmreg_lock' spinlock is used to protect the consistency of the - * system time value. This is needed because reading the 64 bit time - * value involves reading two (or three) 32 bit registers. The first - * read latches the value. Ditto for writing. + * igb_ptp_reset - Re-enable the adapter for PTP following a reset. + * @adapter: Board private structure.   * - * In addition, here have extended the system time with an overflow - * counter in software. + * This function handles the reset work required to re-enable the PTP device.   **/ -void igb_systim_to_hwtstamp(struct igb_adapter *adapter, -			    struct skb_shared_hwtstamps *hwtstamps, -			    u64 systim) +void igb_ptp_reset(struct igb_adapter *adapter)  { -	u64 ns; -	unsigned long flags; +	struct e1000_hw *hw = &adapter->hw; + +	if (!(adapter->flags & IGB_FLAG_PTP)) +		return;  	switch (adapter->hw.mac.type) { +	case e1000_82576: +		/* Dial the nominal frequency. */ +		wr32(E1000_TIMINCA, INCPERIOD_82576 | INCVALUE_82576); +		break; +	case e1000_82580: +	case e1000_i350:  	case e1000_i210:  	case e1000_i211: -	case e1000_i350: -	case e1000_82580: -	case e1000_82576: +		/* Enable the timer functions and interrupts. */ +		wr32(E1000_TSAUXC, 0x0); +		wr32(E1000_TSIM, E1000_TSIM_TXTS); +		wr32(E1000_IMS, E1000_IMS_TS);  		break;  	default: +		/* No work to do. */  		return;  	} -	spin_lock_irqsave(&adapter->tmreg_lock, flags); +	/* Re-initialize the timer. */ +	if ((hw->mac.type == e1000_i210) || (hw->mac.type == e1000_i211)) { +		struct timespec ts = ktime_to_timespec(ktime_get_real()); -	ns = timecounter_cyc2time(&adapter->tc, systim); - -	spin_unlock_irqrestore(&adapter->tmreg_lock, flags); - -	memset(hwtstamps, 0, sizeof(*hwtstamps)); -	hwtstamps->hwtstamp = ns_to_ktime(ns); +		igb_ptp_settime_i210(&adapter->ptp_caps, &ts); +	} else { +		timecounter_init(&adapter->tc, &adapter->cc, +				 ktime_to_ns(ktime_get_real())); +	}  }  |