aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2013-12-10 21:30:16 -0500
committerDavid S. Miller <davem@davemloft.net>2013-12-10 21:30:16 -0500
commitf00ac4ba035a5a9e73df39ad2f46e203b179367b (patch)
tree86f1ff9a546c3a4b7976a79d5d469b79eee55792
parent4e34da4d4252f93a7bc66017a7577afb03c3cb8e (diff)
parente6e25bba9b8a343af6b5e281a0378d3c8ae52165 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/net-next
Jeff Kirsher says: ==================== Intel Wired LAN Driver Updates This series contains updates to i40e, igb, ixgbe and ixgbevf. Shannon provides a couple of i40e patches, first restricts the ethtool diag test messages by using netif_info() macro to when the hardware bit is enabled in the message level netdev message mask. Second provides a fix for when there is an out-of-range descriptor request. Kamil provides a fix for i40e by updating the loopback enum types and add information about the current loopback mode to data returned from get_link_info(). Jesse provides a fix for i40e define name that was being mis-used. I40E_ITR_NONE was being used as an ITRN register index by accident because it was easily associated with the i40e Rx ITR and friends defines, when it should be associated with the DYN_CTL register sets. Jacob provides an update for ixgbevf Kconfig description since the VF driver supports more than just the 82599 device. Don and Alex provide a cleanup patch for ixgbe to make it where head, tail, next to clean and next to use are all reset in a single function for both Tx and Rx path. Before, the code for this was spread out over several areas which made it difficult to track what the values were for each of the values. Carolyn provides two igb patches to add a media switching feature for i354 PHY's and new Media Auto Sense for 82580 devices only. Aaron Sierra provides a fix for igb to resolve an issue with the 64-bit PCI addresses being truncated because the return values of pci_resource_start() and pci_resouce_end() were being cast to unsigned long. Guenter Roeck provides two igb patches, first simplifies the code by attaching the hwmon sysfs attributes to hwmon device instead of the PCI device. Second fixes the temperature sensor attribute index by setting it to 1 instead of 0 (per hwmon ABI). ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/intel/Kconfig8
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_common.c1
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_diag.h8
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_ethtool.c41
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_main.c2
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_txrx.h21
-rw-r--r--drivers/net/ethernet/intel/i40e/i40e_type.h1
-rw-r--r--drivers/net/ethernet/intel/igb/e1000_82575.c89
-rw-r--r--drivers/net/ethernet/intel/igb/e1000_defines.h16
-rw-r--r--drivers/net/ethernet/intel/igb/e1000_hw.h3
-rw-r--r--drivers/net/ethernet/intel/igb/igb.h19
-rw-r--r--drivers/net/ethernet/intel/igb/igb_ethtool.c4
-rw-r--r--drivers/net/ethernet/intel/igb/igb_hwmon.c108
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c209
-rw-r--r--drivers/net/ethernet/intel/ixgbevf/ixgbevf.h4
-rw-r--r--drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c55
16 files changed, 453 insertions, 136 deletions
diff --git a/drivers/net/ethernet/intel/Kconfig b/drivers/net/ethernet/intel/Kconfig
index 149ac85b5f9e..41a2fa2fc67d 100644
--- a/drivers/net/ethernet/intel/Kconfig
+++ b/drivers/net/ethernet/intel/Kconfig
@@ -220,12 +220,12 @@ config IXGBE_DCB
220 If unsure, say N. 220 If unsure, say N.
221 221
222config IXGBEVF 222config IXGBEVF
223 tristate "Intel(R) 82599 Virtual Function Ethernet support" 223 tristate "Intel(R) 10GbE PCI Express Virtual Function Ethernet support"
224 depends on PCI_MSI 224 depends on PCI_MSI
225 ---help--- 225 ---help---
226 This driver supports Intel(R) 82599 virtual functions. For more 226 This driver supports Intel(R) PCI Express virtual functions for the
227 information on how to identify your adapter, go to the Adapter & 227 Intel(R) ixgbe driver. For more information on how to identify your
228 Driver ID Guide at: 228 adapter, go to the Adapter & Driver ID Guide at:
229 229
230 <http://support.intel.com/support/network/sb/CS-008441.htm> 230 <http://support.intel.com/support/network/sb/CS-008441.htm>
231 231
diff --git a/drivers/net/ethernet/intel/i40e/i40e_common.c b/drivers/net/ethernet/intel/i40e/i40e_common.c
index 0b52fbc7d56d..e526d40e9cf8 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_common.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_common.c
@@ -562,6 +562,7 @@ i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
562 hw_link_info->link_info = resp->link_info; 562 hw_link_info->link_info = resp->link_info;
563 hw_link_info->an_info = resp->an_info; 563 hw_link_info->an_info = resp->an_info;
564 hw_link_info->ext_info = resp->ext_info; 564 hw_link_info->ext_info = resp->ext_info;
565 hw_link_info->loopback = resp->loopback;
565 566
566 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE)) 567 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
567 hw_link_info->lse_enable = true; 568 hw_link_info->lse_enable = true;
diff --git a/drivers/net/ethernet/intel/i40e/i40e_diag.h b/drivers/net/ethernet/intel/i40e/i40e_diag.h
index 3d98277f4526..d1fc68cd6c94 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_diag.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_diag.h
@@ -31,10 +31,10 @@
31#include "i40e_type.h" 31#include "i40e_type.h"
32 32
33enum i40e_lb_mode { 33enum i40e_lb_mode {
34 I40E_LB_MODE_NONE = 0, 34 I40E_LB_MODE_NONE = 0x0,
35 I40E_LB_MODE_PHY_LOCAL, 35 I40E_LB_MODE_PHY_LOCAL = I40E_AQ_LB_PHY_LOCAL,
36 I40E_LB_MODE_PHY_REMOTE, 36 I40E_LB_MODE_PHY_REMOTE = I40E_AQ_LB_PHY_REMOTE,
37 I40E_LB_MODE_MAC_LOCAL, 37 I40E_LB_MODE_MAC_LOCAL = I40E_AQ_LB_MAC_LOCAL,
38}; 38};
39 39
40struct i40e_diag_reg_test_info { 40struct i40e_diag_reg_test_info {
diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
index f0bab1704dd1..fd3e379de6da 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
@@ -422,15 +422,19 @@ static int i40e_set_ringparam(struct net_device *netdev,
422 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 422 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
423 return -EINVAL; 423 return -EINVAL;
424 424
425 new_tx_count = clamp_t(u32, ring->tx_pending, 425 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
426 I40E_MIN_NUM_DESCRIPTORS, 426 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
427 I40E_MAX_NUM_DESCRIPTORS); 427 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
428 new_tx_count = ALIGN(new_tx_count, I40E_REQ_DESCRIPTOR_MULTIPLE); 428 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
429 netdev_info(netdev,
430 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
431 ring->tx_pending, ring->rx_pending,
432 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
433 return -EINVAL;
434 }
429 435
430 new_rx_count = clamp_t(u32, ring->rx_pending, 436 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
431 I40E_MIN_NUM_DESCRIPTORS, 437 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
432 I40E_MAX_NUM_DESCRIPTORS);
433 new_rx_count = ALIGN(new_rx_count, I40E_REQ_DESCRIPTOR_MULTIPLE);
434 438
435 /* if nothing to do return success */ 439 /* if nothing to do return success */
436 if ((new_tx_count == vsi->tx_rings[0]->count) && 440 if ((new_tx_count == vsi->tx_rings[0]->count) &&
@@ -711,7 +715,7 @@ static int i40e_link_test(struct net_device *netdev, u64 *data)
711 struct i40e_netdev_priv *np = netdev_priv(netdev); 715 struct i40e_netdev_priv *np = netdev_priv(netdev);
712 struct i40e_pf *pf = np->vsi->back; 716 struct i40e_pf *pf = np->vsi->back;
713 717
714 netdev_info(netdev, "link test\n"); 718 netif_info(pf, hw, netdev, "link test\n");
715 if (i40e_get_link_status(&pf->hw)) 719 if (i40e_get_link_status(&pf->hw))
716 *data = 0; 720 *data = 0;
717 else 721 else
@@ -725,7 +729,7 @@ static int i40e_reg_test(struct net_device *netdev, u64 *data)
725 struct i40e_netdev_priv *np = netdev_priv(netdev); 729 struct i40e_netdev_priv *np = netdev_priv(netdev);
726 struct i40e_pf *pf = np->vsi->back; 730 struct i40e_pf *pf = np->vsi->back;
727 731
728 netdev_info(netdev, "register test\n"); 732 netif_info(pf, hw, netdev, "register test\n");
729 *data = i40e_diag_reg_test(&pf->hw); 733 *data = i40e_diag_reg_test(&pf->hw);
730 734
731 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); 735 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
@@ -737,7 +741,7 @@ static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
737 struct i40e_netdev_priv *np = netdev_priv(netdev); 741 struct i40e_netdev_priv *np = netdev_priv(netdev);
738 struct i40e_pf *pf = np->vsi->back; 742 struct i40e_pf *pf = np->vsi->back;
739 743
740 netdev_info(netdev, "eeprom test\n"); 744 netif_info(pf, hw, netdev, "eeprom test\n");
741 *data = i40e_diag_eeprom_test(&pf->hw); 745 *data = i40e_diag_eeprom_test(&pf->hw);
742 746
743 return *data; 747 return *data;
@@ -749,7 +753,7 @@ static int i40e_intr_test(struct net_device *netdev, u64 *data)
749 struct i40e_pf *pf = np->vsi->back; 753 struct i40e_pf *pf = np->vsi->back;
750 u16 swc_old = pf->sw_int_count; 754 u16 swc_old = pf->sw_int_count;
751 755
752 netdev_info(netdev, "interrupt test\n"); 756 netif_info(pf, hw, netdev, "interrupt test\n");
753 wr32(&pf->hw, I40E_PFINT_DYN_CTL0, 757 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
754 (I40E_PFINT_DYN_CTL0_INTENA_MASK | 758 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
755 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK)); 759 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
@@ -761,7 +765,10 @@ static int i40e_intr_test(struct net_device *netdev, u64 *data)
761 765
762static int i40e_loopback_test(struct net_device *netdev, u64 *data) 766static int i40e_loopback_test(struct net_device *netdev, u64 *data)
763{ 767{
764 netdev_info(netdev, "loopback test not implemented\n"); 768 struct i40e_netdev_priv *np = netdev_priv(netdev);
769 struct i40e_pf *pf = np->vsi->back;
770
771 netif_info(pf, hw, netdev, "loopback test not implemented\n");
765 *data = 0; 772 *data = 0;
766 773
767 return *data; 774 return *data;
@@ -776,8 +783,7 @@ static void i40e_diag_test(struct net_device *netdev,
776 set_bit(__I40E_TESTING, &pf->state); 783 set_bit(__I40E_TESTING, &pf->state);
777 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 784 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
778 /* Offline tests */ 785 /* Offline tests */
779 786 netif_info(pf, drv, netdev, "offline testing starting\n");
780 netdev_info(netdev, "offline testing starting\n");
781 787
782 /* Link test performed before hardware reset 788 /* Link test performed before hardware reset
783 * so autoneg doesn't interfere with test result 789 * so autoneg doesn't interfere with test result
@@ -798,8 +804,9 @@ static void i40e_diag_test(struct net_device *netdev,
798 eth_test->flags |= ETH_TEST_FL_FAILED; 804 eth_test->flags |= ETH_TEST_FL_FAILED;
799 805
800 } else { 806 } else {
801 netdev_info(netdev, "online test starting\n");
802 /* Online tests */ 807 /* Online tests */
808 netif_info(pf, drv, netdev, "online testing starting\n");
809
803 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) 810 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
804 eth_test->flags |= ETH_TEST_FL_FAILED; 811 eth_test->flags |= ETH_TEST_FL_FAILED;
805 812
@@ -811,7 +818,7 @@ static void i40e_diag_test(struct net_device *netdev,
811 } 818 }
812 clear_bit(__I40E_TESTING, &pf->state); 819 clear_bit(__I40E_TESTING, &pf->state);
813 820
814 netdev_info(netdev, "testing finished\n"); 821 netif_info(pf, drv, netdev, "testing finished\n");
815} 822}
816 823
817static void i40e_get_wol(struct net_device *netdev, 824static void i40e_get_wol(struct net_device *netdev,
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index d2b48bb237fd..a6291e23fe5f 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -36,7 +36,7 @@ static const char i40e_driver_string[] =
36 36
37#define DRV_VERSION_MAJOR 0 37#define DRV_VERSION_MAJOR 0
38#define DRV_VERSION_MINOR 3 38#define DRV_VERSION_MINOR 3
39#define DRV_VERSION_BUILD 12 39#define DRV_VERSION_BUILD 13
40#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \ 40#define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
41 __stringify(DRV_VERSION_MINOR) "." \ 41 __stringify(DRV_VERSION_MINOR) "." \
42 __stringify(DRV_VERSION_BUILD) DRV_KERN 42 __stringify(DRV_VERSION_BUILD) DRV_KERN
diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.h b/drivers/net/ethernet/intel/i40e/i40e_txrx.h
index db55d9947f15..faabf22fbd20 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_txrx.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.h
@@ -49,10 +49,23 @@
49 49
50#define I40E_QUEUE_END_OF_LIST 0x7FF 50#define I40E_QUEUE_END_OF_LIST 0x7FF
51 51
52#define I40E_ITR_NONE 3 52/* this enum matches hardware bits and is meant to be used by DYN_CTLN
53#define I40E_RX_ITR 0 53 * registers and QINT registers or more generally anywhere in the manual
54#define I40E_TX_ITR 1 54 * mentioning ITR_INDX, ITR_NONE cannot be used as an index 'n' into any
55#define I40E_PE_ITR 2 55 * register but instead is a special value meaning "don't update" ITR0/1/2.
56 */
57enum i40e_dyn_idx_t {
58 I40E_IDX_ITR0 = 0,
59 I40E_IDX_ITR1 = 1,
60 I40E_IDX_ITR2 = 2,
61 I40E_ITR_NONE = 3 /* ITR_NONE must not be used as an index */
62};
63
64/* these are indexes into ITRN registers */
65#define I40E_RX_ITR I40E_IDX_ITR0
66#define I40E_TX_ITR I40E_IDX_ITR1
67#define I40E_PE_ITR I40E_IDX_ITR2
68
56/* Supported Rx Buffer Sizes */ 69/* Supported Rx Buffer Sizes */
57#define I40E_RXBUFFER_512 512 /* Used for packet split */ 70#define I40E_RXBUFFER_512 512 /* Used for packet split */
58#define I40E_RXBUFFER_2048 2048 71#define I40E_RXBUFFER_2048 2048
diff --git a/drivers/net/ethernet/intel/i40e/i40e_type.h b/drivers/net/ethernet/intel/i40e/i40e_type.h
index 88b37e07b255..8ae644570263 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_type.h
+++ b/drivers/net/ethernet/intel/i40e/i40e_type.h
@@ -172,6 +172,7 @@ struct i40e_link_status {
172 u8 link_info; 172 u8 link_info;
173 u8 an_info; 173 u8 an_info;
174 u8 ext_info; 174 u8 ext_info;
175 u8 loopback;
175 /* is Link Status Event notification to SW enabled */ 176 /* is Link Status Event notification to SW enabled */
176 bool lse_enable; 177 bool lse_enable;
177}; 178};
diff --git a/drivers/net/ethernet/intel/igb/e1000_82575.c b/drivers/net/ethernet/intel/igb/e1000_82575.c
index 47c2d10df826..06df6928f44c 100644
--- a/drivers/net/ethernet/intel/igb/e1000_82575.c
+++ b/drivers/net/ethernet/intel/igb/e1000_82575.c
@@ -113,6 +113,59 @@ static bool igb_sgmii_uses_mdio_82575(struct e1000_hw *hw)
113} 113}
114 114
115/** 115/**
116 * igb_check_for_link_media_swap - Check which M88E1112 interface linked
117 * @hw: pointer to the HW structure
118 *
119 * Poll the M88E1112 interfaces to see which interface achieved link.
120 */
121static s32 igb_check_for_link_media_swap(struct e1000_hw *hw)
122{
123 struct e1000_phy_info *phy = &hw->phy;
124 s32 ret_val;
125 u16 data;
126 u8 port = 0;
127
128 /* Check the copper medium. */
129 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
130 if (ret_val)
131 return ret_val;
132
133 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
134 if (ret_val)
135 return ret_val;
136
137 if (data & E1000_M88E1112_STATUS_LINK)
138 port = E1000_MEDIA_PORT_COPPER;
139
140 /* Check the other medium. */
141 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 1);
142 if (ret_val)
143 return ret_val;
144
145 ret_val = phy->ops.read_reg(hw, E1000_M88E1112_STATUS, &data);
146 if (ret_val)
147 return ret_val;
148
149 /* reset page to 0 */
150 ret_val = phy->ops.write_reg(hw, E1000_M88E1112_PAGE_ADDR, 0);
151 if (ret_val)
152 return ret_val;
153
154 if (data & E1000_M88E1112_STATUS_LINK)
155 port = E1000_MEDIA_PORT_OTHER;
156
157 /* Determine if a swap needs to happen. */
158 if (port && (hw->dev_spec._82575.media_port != port)) {
159 hw->dev_spec._82575.media_port = port;
160 hw->dev_spec._82575.media_changed = true;
161 } else {
162 ret_val = igb_check_for_link_82575(hw);
163 }
164
165 return E1000_SUCCESS;
166}
167
168/**
116 * igb_init_phy_params_82575 - Init PHY func ptrs. 169 * igb_init_phy_params_82575 - Init PHY func ptrs.
117 * @hw: pointer to the HW structure 170 * @hw: pointer to the HW structure
118 **/ 171 **/
@@ -189,6 +242,29 @@ static s32 igb_init_phy_params_82575(struct e1000_hw *hw)
189 else 242 else
190 phy->ops.get_cable_length = igb_get_cable_length_m88; 243 phy->ops.get_cable_length = igb_get_cable_length_m88;
191 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88; 244 phy->ops.force_speed_duplex = igb_phy_force_speed_duplex_m88;
245 /* Check if this PHY is confgured for media swap. */
246 if (phy->id == M88E1112_E_PHY_ID) {
247 u16 data;
248
249 ret_val = phy->ops.write_reg(hw,
250 E1000_M88E1112_PAGE_ADDR,
251 2);
252 if (ret_val)
253 goto out;
254
255 ret_val = phy->ops.read_reg(hw,
256 E1000_M88E1112_MAC_CTRL_1,
257 &data);
258 if (ret_val)
259 goto out;
260
261 data = (data & E1000_M88E1112_MAC_CTRL_1_MODE_MASK) >>
262 E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT;
263 if (data == E1000_M88E1112_AUTO_COPPER_SGMII ||
264 data == E1000_M88E1112_AUTO_COPPER_BASEX)
265 hw->mac.ops.check_for_link =
266 igb_check_for_link_media_swap;
267 }
192 break; 268 break;
193 case IGP03E1000_E_PHY_ID: 269 case IGP03E1000_E_PHY_ID:
194 phy->type = e1000_phy_igp_3; 270 phy->type = e1000_phy_igp_3;
@@ -365,6 +441,19 @@ static s32 igb_init_mac_params_82575(struct e1000_hw *hw)
365 ? igb_setup_copper_link_82575 441 ? igb_setup_copper_link_82575
366 : igb_setup_serdes_link_82575; 442 : igb_setup_serdes_link_82575;
367 443
444 if (mac->type == e1000_82580) {
445 switch (hw->device_id) {
446 /* feature not supported on these id's */
447 case E1000_DEV_ID_DH89XXCC_SGMII:
448 case E1000_DEV_ID_DH89XXCC_SERDES:
449 case E1000_DEV_ID_DH89XXCC_BACKPLANE:
450 case E1000_DEV_ID_DH89XXCC_SFP:
451 break;
452 default:
453 hw->dev_spec._82575.mas_capable = true;
454 break;
455 }
456 }
368 return 0; 457 return 0;
369} 458}
370 459
diff --git a/drivers/net/ethernet/intel/igb/e1000_defines.h b/drivers/net/ethernet/intel/igb/e1000_defines.h
index 978eca31ceda..0571b973be80 100644
--- a/drivers/net/ethernet/intel/igb/e1000_defines.h
+++ b/drivers/net/ethernet/intel/igb/e1000_defines.h
@@ -205,6 +205,11 @@
205 */ 205 */
206 206
207#define E1000_CONNSW_ENRGSRC 0x4 207#define E1000_CONNSW_ENRGSRC 0x4
208#define E1000_CONNSW_PHYSD 0x400
209#define E1000_CONNSW_PHY_PDN 0x800
210#define E1000_CONNSW_SERDESD 0x200
211#define E1000_CONNSW_AUTOSENSE_CONF 0x2
212#define E1000_CONNSW_AUTOSENSE_EN 0x1
208#define E1000_PCS_CFG_PCS_EN 8 213#define E1000_PCS_CFG_PCS_EN 8
209#define E1000_PCS_LCTL_FLV_LINK_UP 1 214#define E1000_PCS_LCTL_FLV_LINK_UP 1
210#define E1000_PCS_LCTL_FSV_100 2 215#define E1000_PCS_LCTL_FSV_100 2
@@ -532,6 +537,17 @@
532#define E1000_MDICNFG_PHY_MASK 0x03E00000 537#define E1000_MDICNFG_PHY_MASK 0x03E00000
533#define E1000_MDICNFG_PHY_SHIFT 21 538#define E1000_MDICNFG_PHY_SHIFT 21
534 539
540#define E1000_MEDIA_PORT_COPPER 1
541#define E1000_MEDIA_PORT_OTHER 2
542#define E1000_M88E1112_AUTO_COPPER_SGMII 0x2
543#define E1000_M88E1112_AUTO_COPPER_BASEX 0x3
544#define E1000_M88E1112_STATUS_LINK 0x0004 /* Interface Link Bit */
545#define E1000_M88E1112_MAC_CTRL_1 0x10
546#define E1000_M88E1112_MAC_CTRL_1_MODE_MASK 0x0380 /* Mode Select */
547#define E1000_M88E1112_MAC_CTRL_1_MODE_SHIFT 7
548#define E1000_M88E1112_PAGE_ADDR 0x16
549#define E1000_M88E1112_STATUS 0x01
550
535/* PCI Express Control */ 551/* PCI Express Control */
536#define E1000_GCR_CMPL_TMOUT_MASK 0x0000F000 552#define E1000_GCR_CMPL_TMOUT_MASK 0x0000F000
537#define E1000_GCR_CMPL_TMOUT_10ms 0x00001000 553#define E1000_GCR_CMPL_TMOUT_10ms 0x00001000
diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
index 2e166b22d52b..ab99e2b582a8 100644
--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
@@ -533,6 +533,9 @@ struct e1000_dev_spec_82575 {
533 bool clear_semaphore_once; 533 bool clear_semaphore_once;
534 struct e1000_sfp_flags eth_flags; 534 struct e1000_sfp_flags eth_flags;
535 bool module_plugged; 535 bool module_plugged;
536 u8 media_port;
537 bool media_changed;
538 bool mas_capable;
536}; 539};
537 540
538struct e1000_hw { 541struct e1000_hw {
diff --git a/drivers/net/ethernet/intel/igb/igb.h b/drivers/net/ethernet/intel/igb/igb.h
index 5e9ed89403aa..8aaca0a1dca0 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -337,8 +337,10 @@ struct hwmon_attr {
337 }; 337 };
338 338
339struct hwmon_buff { 339struct hwmon_buff {
340 struct device *device; 340 struct attribute_group group;
341 struct hwmon_attr *hwmon_list; 341 const struct attribute_group *groups[2];
342 struct attribute *attrs[E1000_MAX_SENSORS * 4 + 1];
343 struct hwmon_attr hwmon_list[E1000_MAX_SENSORS * 4];
342 unsigned int n_hwmon; 344 unsigned int n_hwmon;
343 }; 345 };
344#endif 346#endif
@@ -440,7 +442,7 @@ struct igb_adapter {
440 442
441 char fw_version[32]; 443 char fw_version[32];
442#ifdef CONFIG_IGB_HWMON 444#ifdef CONFIG_IGB_HWMON
443 struct hwmon_buff igb_hwmon_buff; 445 struct hwmon_buff *igb_hwmon_buff;
444 bool ets; 446 bool ets;
445#endif 447#endif
446 struct i2c_algo_bit_data i2c_algo; 448 struct i2c_algo_bit_data i2c_algo;
@@ -450,6 +452,8 @@ struct igb_adapter {
450 u8 rss_indir_tbl[IGB_RETA_SIZE]; 452 u8 rss_indir_tbl[IGB_RETA_SIZE];
451 453
452 unsigned long link_check_timeout; 454 unsigned long link_check_timeout;
455 int copper_tries;
456 struct e1000_info ei;
453}; 457};
454 458
455#define IGB_FLAG_HAS_MSI (1 << 0) 459#define IGB_FLAG_HAS_MSI (1 << 0)
@@ -462,6 +466,15 @@ struct igb_adapter {
462#define IGB_FLAG_RSS_FIELD_IPV6_UDP (1 << 7) 466#define IGB_FLAG_RSS_FIELD_IPV6_UDP (1 << 7)
463#define IGB_FLAG_WOL_SUPPORTED (1 << 8) 467#define IGB_FLAG_WOL_SUPPORTED (1 << 8)
464#define IGB_FLAG_NEED_LINK_UPDATE (1 << 9) 468#define IGB_FLAG_NEED_LINK_UPDATE (1 << 9)
469#define IGB_FLAG_MEDIA_RESET (1 << 10)
470#define IGB_FLAG_MAS_CAPABLE (1 << 11)
471#define IGB_FLAG_MAS_ENABLE (1 << 12)
472
473/* Media Auto Sense */
474#define IGB_MAS_ENABLE_0 0X0001
475#define IGB_MAS_ENABLE_1 0X0002
476#define IGB_MAS_ENABLE_2 0X0004
477#define IGB_MAS_ENABLE_3 0X0008
465 478
466/* DMA Coalescing defines */ 479/* DMA Coalescing defines */
467#define IGB_MIN_TXPBSIZE 20408 480#define IGB_MIN_TXPBSIZE 20408
diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index c3143da497c8..1c7d2381af8c 100644
--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -1983,6 +1983,10 @@ static void igb_diag_test(struct net_device *netdev,
1983 bool if_running = netif_running(netdev); 1983 bool if_running = netif_running(netdev);
1984 1984
1985 set_bit(__IGB_TESTING, &adapter->state); 1985 set_bit(__IGB_TESTING, &adapter->state);
1986
1987 /* can't do offline tests on media switching devices */
1988 if (adapter->hw.dev_spec._82575.mas_capable)
1989 eth_test->flags &= ~ETH_TEST_FL_OFFLINE;
1986 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 1990 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1987 /* Offline tests */ 1991 /* Offline tests */
1988 1992
diff --git a/drivers/net/ethernet/intel/igb/igb_hwmon.c b/drivers/net/ethernet/intel/igb/igb_hwmon.c
index 58f1ce967aeb..e0af5bc61613 100644
--- a/drivers/net/ethernet/intel/igb/igb_hwmon.c
+++ b/drivers/net/ethernet/intel/igb/igb_hwmon.c
@@ -117,29 +117,29 @@ static int igb_add_hwmon_attr(struct igb_adapter *adapter,
117 unsigned int n_attr; 117 unsigned int n_attr;
118 struct hwmon_attr *igb_attr; 118 struct hwmon_attr *igb_attr;
119 119
120 n_attr = adapter->igb_hwmon_buff.n_hwmon; 120 n_attr = adapter->igb_hwmon_buff->n_hwmon;
121 igb_attr = &adapter->igb_hwmon_buff.hwmon_list[n_attr]; 121 igb_attr = &adapter->igb_hwmon_buff->hwmon_list[n_attr];
122 122
123 switch (type) { 123 switch (type) {
124 case IGB_HWMON_TYPE_LOC: 124 case IGB_HWMON_TYPE_LOC:
125 igb_attr->dev_attr.show = igb_hwmon_show_location; 125 igb_attr->dev_attr.show = igb_hwmon_show_location;
126 snprintf(igb_attr->name, sizeof(igb_attr->name), 126 snprintf(igb_attr->name, sizeof(igb_attr->name),
127 "temp%u_label", offset); 127 "temp%u_label", offset + 1);
128 break; 128 break;
129 case IGB_HWMON_TYPE_TEMP: 129 case IGB_HWMON_TYPE_TEMP:
130 igb_attr->dev_attr.show = igb_hwmon_show_temp; 130 igb_attr->dev_attr.show = igb_hwmon_show_temp;
131 snprintf(igb_attr->name, sizeof(igb_attr->name), 131 snprintf(igb_attr->name, sizeof(igb_attr->name),
132 "temp%u_input", offset); 132 "temp%u_input", offset + 1);
133 break; 133 break;
134 case IGB_HWMON_TYPE_CAUTION: 134 case IGB_HWMON_TYPE_CAUTION:
135 igb_attr->dev_attr.show = igb_hwmon_show_cautionthresh; 135 igb_attr->dev_attr.show = igb_hwmon_show_cautionthresh;
136 snprintf(igb_attr->name, sizeof(igb_attr->name), 136 snprintf(igb_attr->name, sizeof(igb_attr->name),
137 "temp%u_max", offset); 137 "temp%u_max", offset + 1);
138 break; 138 break;
139 case IGB_HWMON_TYPE_MAX: 139 case IGB_HWMON_TYPE_MAX:
140 igb_attr->dev_attr.show = igb_hwmon_show_maxopthresh; 140 igb_attr->dev_attr.show = igb_hwmon_show_maxopthresh;
141 snprintf(igb_attr->name, sizeof(igb_attr->name), 141 snprintf(igb_attr->name, sizeof(igb_attr->name),
142 "temp%u_crit", offset); 142 "temp%u_crit", offset + 1);
143 break; 143 break;
144 default: 144 default:
145 rc = -EPERM; 145 rc = -EPERM;
@@ -154,30 +154,16 @@ static int igb_add_hwmon_attr(struct igb_adapter *adapter,
154 igb_attr->dev_attr.attr.mode = S_IRUGO; 154 igb_attr->dev_attr.attr.mode = S_IRUGO;
155 igb_attr->dev_attr.attr.name = igb_attr->name; 155 igb_attr->dev_attr.attr.name = igb_attr->name;
156 sysfs_attr_init(&igb_attr->dev_attr.attr); 156 sysfs_attr_init(&igb_attr->dev_attr.attr);
157 rc = device_create_file(&adapter->pdev->dev,
158 &igb_attr->dev_attr);
159 if (rc == 0)
160 ++adapter->igb_hwmon_buff.n_hwmon;
161 157
162 return rc; 158 adapter->igb_hwmon_buff->attrs[n_attr] = &igb_attr->dev_attr.attr;
159
160 ++adapter->igb_hwmon_buff->n_hwmon;
161
162 return 0;
163} 163}
164 164
165static void igb_sysfs_del_adapter(struct igb_adapter *adapter) 165static void igb_sysfs_del_adapter(struct igb_adapter *adapter)
166{ 166{
167 int i;
168
169 if (adapter == NULL)
170 return;
171
172 for (i = 0; i < adapter->igb_hwmon_buff.n_hwmon; i++) {
173 device_remove_file(&adapter->pdev->dev,
174 &adapter->igb_hwmon_buff.hwmon_list[i].dev_attr);
175 }
176
177 kfree(adapter->igb_hwmon_buff.hwmon_list);
178
179 if (adapter->igb_hwmon_buff.device)
180 hwmon_device_unregister(adapter->igb_hwmon_buff.device);
181} 167}
182 168
183/* called from igb_main.c */ 169/* called from igb_main.c */
@@ -189,11 +175,11 @@ void igb_sysfs_exit(struct igb_adapter *adapter)
189/* called from igb_main.c */ 175/* called from igb_main.c */
190int igb_sysfs_init(struct igb_adapter *adapter) 176int igb_sysfs_init(struct igb_adapter *adapter)
191{ 177{
192 struct hwmon_buff *igb_hwmon = &adapter->igb_hwmon_buff; 178 struct hwmon_buff *igb_hwmon;
179 struct i2c_client *client;
180 struct device *hwmon_dev;
193 unsigned int i; 181 unsigned int i;
194 int n_attrs;
195 int rc = 0; 182 int rc = 0;
196 struct i2c_client *client = NULL;
197 183
198 /* If this method isn't defined we don't support thermals */ 184 /* If this method isn't defined we don't support thermals */
199 if (adapter->hw.mac.ops.init_thermal_sensor_thresh == NULL) 185 if (adapter->hw.mac.ops.init_thermal_sensor_thresh == NULL)
@@ -201,34 +187,16 @@ int igb_sysfs_init(struct igb_adapter *adapter)
201 187
202 /* Don't create thermal hwmon interface if no sensors present */ 188 /* Don't create thermal hwmon interface if no sensors present */
203 rc = (adapter->hw.mac.ops.init_thermal_sensor_thresh(&adapter->hw)); 189 rc = (adapter->hw.mac.ops.init_thermal_sensor_thresh(&adapter->hw));
204 if (rc) 190 if (rc)
205 goto exit;
206
207 /* init i2c_client */
208 client = i2c_new_device(&adapter->i2c_adap, &i350_sensor_info);
209 if (client == NULL) {
210 dev_info(&adapter->pdev->dev,
211 "Failed to create new i2c device..\n");
212 goto exit; 191 goto exit;
213 }
214 adapter->i2c_client = client;
215 192
216 /* Allocation space for max attributes 193 igb_hwmon = devm_kzalloc(&adapter->pdev->dev, sizeof(*igb_hwmon),
217 * max num sensors * values (loc, temp, max, caution) 194 GFP_KERNEL);
218 */ 195 if (!igb_hwmon) {
219 n_attrs = E1000_MAX_SENSORS * 4;
220 igb_hwmon->hwmon_list = kcalloc(n_attrs, sizeof(struct hwmon_attr),
221 GFP_KERNEL);
222 if (!igb_hwmon->hwmon_list) {
223 rc = -ENOMEM; 196 rc = -ENOMEM;
224 goto err; 197 goto exit;
225 }
226
227 igb_hwmon->device = hwmon_device_register(&adapter->pdev->dev);
228 if (IS_ERR(igb_hwmon->device)) {
229 rc = PTR_ERR(igb_hwmon->device);
230 goto err;
231 } 198 }
199 adapter->igb_hwmon_buff = igb_hwmon;
232 200
233 for (i = 0; i < E1000_MAX_SENSORS; i++) { 201 for (i = 0; i < E1000_MAX_SENSORS; i++) {
234 202
@@ -240,11 +208,39 @@ int igb_sysfs_init(struct igb_adapter *adapter)
240 208
241 /* Bail if any hwmon attr struct fails to initialize */ 209 /* Bail if any hwmon attr struct fails to initialize */
242 rc = igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_CAUTION); 210 rc = igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_CAUTION);
243 rc |= igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_LOC);
244 rc |= igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_TEMP);
245 rc |= igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_MAX);
246 if (rc) 211 if (rc)
247 goto err; 212 goto exit;
213 rc = igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_LOC);
214 if (rc)
215 goto exit;
216 rc = igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_TEMP);
217 if (rc)
218 goto exit;
219 rc = igb_add_hwmon_attr(adapter, i, IGB_HWMON_TYPE_MAX);
220 if (rc)
221 goto exit;
222 }
223
224 /* init i2c_client */
225 client = i2c_new_device(&adapter->i2c_adap, &i350_sensor_info);
226 if (client == NULL) {
227 dev_info(&adapter->pdev->dev,
228 "Failed to create new i2c device.\n");
229 rc = -ENODEV;
230 goto exit;
231 }
232 adapter->i2c_client = client;
233
234 igb_hwmon->groups[0] = &igb_hwmon->group;
235 igb_hwmon->group.attrs = igb_hwmon->attrs;
236
237 hwmon_dev = devm_hwmon_device_register_with_groups(&adapter->pdev->dev,
238 client->name,
239 igb_hwmon,
240 igb_hwmon->groups);
241 if (IS_ERR(hwmon_dev)) {
242 rc = PTR_ERR(hwmon_dev);
243 goto err;
248 } 244 }
249 245
250 goto exit; 246 goto exit;
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 025e5f4b7481..3bc10bd5bbc1 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -1607,6 +1607,73 @@ static void igb_power_down_link(struct igb_adapter *adapter)
1607} 1607}
1608 1608
1609/** 1609/**
1610 * Detect and switch function for Media Auto Sense
1611 * @adapter: address of the board private structure
1612 **/
1613static void igb_check_swap_media(struct igb_adapter *adapter)
1614{
1615 struct e1000_hw *hw = &adapter->hw;
1616 u32 ctrl_ext, connsw;
1617 bool swap_now = false;
1618
1619 ctrl_ext = rd32(E1000_CTRL_EXT);
1620 connsw = rd32(E1000_CONNSW);
1621
1622 /* need to live swap if current media is copper and we have fiber/serdes
1623 * to go to.
1624 */
1625
1626 if ((hw->phy.media_type == e1000_media_type_copper) &&
1627 (!(connsw & E1000_CONNSW_AUTOSENSE_EN))) {
1628 swap_now = true;
1629 } else if (!(connsw & E1000_CONNSW_SERDESD)) {
1630 /* copper signal takes time to appear */
1631 if (adapter->copper_tries < 4) {
1632 adapter->copper_tries++;
1633 connsw |= E1000_CONNSW_AUTOSENSE_CONF;
1634 wr32(E1000_CONNSW, connsw);
1635 return;
1636 } else {
1637 adapter->copper_tries = 0;
1638 if ((connsw & E1000_CONNSW_PHYSD) &&
1639 (!(connsw & E1000_CONNSW_PHY_PDN))) {
1640 swap_now = true;
1641 connsw &= ~E1000_CONNSW_AUTOSENSE_CONF;
1642 wr32(E1000_CONNSW, connsw);
1643 }
1644 }
1645 }
1646
1647 if (!swap_now)
1648 return;
1649
1650 switch (hw->phy.media_type) {
1651 case e1000_media_type_copper:
1652 netdev_info(adapter->netdev,
1653 "MAS: changing media to fiber/serdes\n");
1654 ctrl_ext |=
1655 E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1656 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1657 adapter->copper_tries = 0;
1658 break;
1659 case e1000_media_type_internal_serdes:
1660 case e1000_media_type_fiber:
1661 netdev_info(adapter->netdev,
1662 "MAS: changing media to copper\n");
1663 ctrl_ext &=
1664 ~E1000_CTRL_EXT_LINK_MODE_PCIE_SERDES;
1665 adapter->flags |= IGB_FLAG_MEDIA_RESET;
1666 break;
1667 default:
1668 /* shouldn't get here during regular operation */
1669 netdev_err(adapter->netdev,
1670 "AMS: Invalid media type found, returning\n");
1671 break;
1672 }
1673 wr32(E1000_CTRL_EXT, ctrl_ext);
1674}
1675
1676/**
1610 * igb_up - Open the interface and prepare it to handle traffic 1677 * igb_up - Open the interface and prepare it to handle traffic
1611 * @adapter: board private structure 1678 * @adapter: board private structure
1612 **/ 1679 **/
@@ -1719,6 +1786,37 @@ void igb_reinit_locked(struct igb_adapter *adapter)
1719 clear_bit(__IGB_RESETTING, &adapter->state); 1786 clear_bit(__IGB_RESETTING, &adapter->state);
1720} 1787}
1721 1788
1789/** igb_enable_mas - Media Autosense re-enable after swap
1790 *
1791 * @adapter: adapter struct
1792 **/
1793static s32 igb_enable_mas(struct igb_adapter *adapter)
1794{
1795 struct e1000_hw *hw = &adapter->hw;
1796 u32 connsw;
1797 s32 ret_val = 0;
1798
1799 connsw = rd32(E1000_CONNSW);
1800 if (!(hw->phy.media_type == e1000_media_type_copper))
1801 return ret_val;
1802
1803 /* configure for SerDes media detect */
1804 if (!(connsw & E1000_CONNSW_SERDESD)) {
1805 connsw |= E1000_CONNSW_ENRGSRC;
1806 connsw |= E1000_CONNSW_AUTOSENSE_EN;
1807 wr32(E1000_CONNSW, connsw);
1808 wrfl();
1809 } else if (connsw & E1000_CONNSW_SERDESD) {
1810 /* already SerDes, no need to enable anything */
1811 return ret_val;
1812 } else {
1813 netdev_info(adapter->netdev,
1814 "MAS: Unable to configure feature, disabling..\n");
1815 adapter->flags &= ~IGB_FLAG_MAS_ENABLE;
1816 }
1817 return ret_val;
1818}
1819
1722void igb_reset(struct igb_adapter *adapter) 1820void igb_reset(struct igb_adapter *adapter)
1723{ 1821{
1724 struct pci_dev *pdev = adapter->pdev; 1822 struct pci_dev *pdev = adapter->pdev;
@@ -1830,6 +1928,16 @@ void igb_reset(struct igb_adapter *adapter)
1830 hw->mac.ops.reset_hw(hw); 1928 hw->mac.ops.reset_hw(hw);
1831 wr32(E1000_WUC, 0); 1929 wr32(E1000_WUC, 0);
1832 1930
1931 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
1932 /* need to resetup here after media swap */
1933 adapter->ei.get_invariants(hw);
1934 adapter->flags &= ~IGB_FLAG_MEDIA_RESET;
1935 }
1936 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
1937 if (igb_enable_mas(adapter))
1938 dev_err(&pdev->dev,
1939 "Error enabling Media Auto Sense\n");
1940 }
1833 if (hw->mac.ops.init_hw(hw)) 1941 if (hw->mac.ops.init_hw(hw))
1834 dev_err(&pdev->dev, "Hardware Error\n"); 1942 dev_err(&pdev->dev, "Hardware Error\n");
1835 1943
@@ -1976,6 +2084,58 @@ void igb_set_fw_version(struct igb_adapter *adapter)
1976} 2084}
1977 2085
1978/** 2086/**
2087 * igb_init_mas - init Media Autosense feature if enabled in the NVM
2088 *
2089 * @adapter: adapter struct
2090 **/
2091static void igb_init_mas(struct igb_adapter *adapter)
2092{
2093 struct e1000_hw *hw = &adapter->hw;
2094 u16 eeprom_data;
2095
2096 hw->nvm.ops.read(hw, NVM_COMPAT, 1, &eeprom_data);
2097 switch (hw->bus.func) {
2098 case E1000_FUNC_0:
2099 if (eeprom_data & IGB_MAS_ENABLE_0) {
2100 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2101 netdev_info(adapter->netdev,
2102 "MAS: Enabling Media Autosense for port %d\n",
2103 hw->bus.func);
2104 }
2105 break;
2106 case E1000_FUNC_1:
2107 if (eeprom_data & IGB_MAS_ENABLE_1) {
2108 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2109 netdev_info(adapter->netdev,
2110 "MAS: Enabling Media Autosense for port %d\n",
2111 hw->bus.func);
2112 }
2113 break;
2114 case E1000_FUNC_2:
2115 if (eeprom_data & IGB_MAS_ENABLE_2) {
2116 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2117 netdev_info(adapter->netdev,
2118 "MAS: Enabling Media Autosense for port %d\n",
2119 hw->bus.func);
2120 }
2121 break;
2122 case E1000_FUNC_3:
2123 if (eeprom_data & IGB_MAS_ENABLE_3) {
2124 adapter->flags |= IGB_FLAG_MAS_ENABLE;
2125 netdev_info(adapter->netdev,
2126 "MAS: Enabling Media Autosense for port %d\n",
2127 hw->bus.func);
2128 }
2129 break;
2130 default:
2131 /* Shouldn't get here */
2132 netdev_err(adapter->netdev,
2133 "MAS: Invalid port configuration, returning\n");
2134 break;
2135 }
2136}
2137
2138/**
1979 * igb_init_i2c - Init I2C interface 2139 * igb_init_i2c - Init I2C interface
1980 * @adapter: pointer to adapter structure 2140 * @adapter: pointer to adapter structure
1981 **/ 2141 **/
@@ -2022,7 +2182,6 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2022 s32 ret_val; 2182 s32 ret_val;
2023 static int global_quad_port_a; /* global quad port a indication */ 2183 static int global_quad_port_a; /* global quad port a indication */
2024 const struct e1000_info *ei = igb_info_tbl[ent->driver_data]; 2184 const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
2025 unsigned long mmio_start, mmio_len;
2026 int err, pci_using_dac; 2185 int err, pci_using_dac;
2027 u8 part_str[E1000_PBANUM_LENGTH]; 2186 u8 part_str[E1000_PBANUM_LENGTH];
2028 2187
@@ -2079,11 +2238,8 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2079 hw->back = adapter; 2238 hw->back = adapter;
2080 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); 2239 adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
2081 2240
2082 mmio_start = pci_resource_start(pdev, 0);
2083 mmio_len = pci_resource_len(pdev, 0);
2084
2085 err = -EIO; 2241 err = -EIO;
2086 hw->hw_addr = ioremap(mmio_start, mmio_len); 2242 hw->hw_addr = pci_iomap(pdev, 0, 0);
2087 if (!hw->hw_addr) 2243 if (!hw->hw_addr)
2088 goto err_ioremap; 2244 goto err_ioremap;
2089 2245
@@ -2093,8 +2249,8 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2093 2249
2094 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1); 2250 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
2095 2251
2096 netdev->mem_start = mmio_start; 2252 netdev->mem_start = pci_resource_start(pdev, 0);
2097 netdev->mem_end = mmio_start + mmio_len; 2253 netdev->mem_end = pci_resource_end(pdev, 0);
2098 2254
2099 /* PCI config space info */ 2255 /* PCI config space info */
2100 hw->vendor_id = pdev->vendor; 2256 hw->vendor_id = pdev->vendor;
@@ -2350,6 +2506,11 @@ static int igb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2350 adapter->ets = false; 2506 adapter->ets = false;
2351 } 2507 }
2352#endif 2508#endif
2509 /* Check if Media Autosense is enabled */
2510 adapter->ei = *ei;
2511 if (hw->dev_spec._82575.mas_capable)
2512 igb_init_mas(adapter);
2513
2353 /* do hw tstamp init after resetting */ 2514 /* do hw tstamp init after resetting */
2354 igb_ptp_init(adapter); 2515 igb_ptp_init(adapter);
2355 2516
@@ -3935,6 +4096,7 @@ static void igb_watchdog_task(struct work_struct *work)
3935 struct net_device *netdev = adapter->netdev; 4096 struct net_device *netdev = adapter->netdev;
3936 u32 link; 4097 u32 link;
3937 int i; 4098 int i;
4099 u32 connsw;
3938 4100
3939 link = igb_has_link(adapter); 4101 link = igb_has_link(adapter);
3940 4102
@@ -3945,7 +4107,21 @@ static void igb_watchdog_task(struct work_struct *work)
3945 link = false; 4107 link = false;
3946 } 4108 }
3947 4109
4110 /* Force link down if we have fiber to swap to */
4111 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4112 if (hw->phy.media_type == e1000_media_type_copper) {
4113 connsw = rd32(E1000_CONNSW);
4114 if (!(connsw & E1000_CONNSW_AUTOSENSE_EN))
4115 link = 0;
4116 }
4117 }
3948 if (link) { 4118 if (link) {
4119 /* Perform a reset if the media type changed. */
4120 if (hw->dev_spec._82575.media_changed) {
4121 hw->dev_spec._82575.media_changed = false;
4122 adapter->flags |= IGB_FLAG_MEDIA_RESET;
4123 igb_reset(adapter);
4124 }
3949 /* Cancel scheduled suspend requests. */ 4125 /* Cancel scheduled suspend requests. */
3950 pm_runtime_resume(netdev->dev.parent); 4126 pm_runtime_resume(netdev->dev.parent);
3951 4127
@@ -4026,8 +4202,27 @@ static void igb_watchdog_task(struct work_struct *work)
4026 mod_timer(&adapter->phy_info_timer, 4202 mod_timer(&adapter->phy_info_timer,
4027 round_jiffies(jiffies + 2 * HZ)); 4203 round_jiffies(jiffies + 2 * HZ));
4028 4204
4205 /* link is down, time to check for alternate media */
4206 if (adapter->flags & IGB_FLAG_MAS_ENABLE) {
4207 igb_check_swap_media(adapter);
4208 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4209 schedule_work(&adapter->reset_task);
4210 /* return immediately */
4211 return;
4212 }
4213 }
4029 pm_schedule_suspend(netdev->dev.parent, 4214 pm_schedule_suspend(netdev->dev.parent,
4030 MSEC_PER_SEC * 5); 4215 MSEC_PER_SEC * 5);
4216
4217 /* also check for alternate media here */
4218 } else if (!netif_carrier_ok(netdev) &&
4219 (adapter->flags & IGB_FLAG_MAS_ENABLE)) {
4220 igb_check_swap_media(adapter);
4221 if (adapter->flags & IGB_FLAG_MEDIA_RESET) {
4222 schedule_work(&adapter->reset_task);
4223 /* return immediately */
4224 return;
4225 }
4031 } 4226 }
4032 } 4227 }
4033 4228
diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf.h b/drivers/net/ethernet/intel/ixgbevf/ixgbevf.h
index 8971e2d0a984..eaaa3ecacfd7 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf.h
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf.h
@@ -86,9 +86,7 @@ struct ixgbevf_ring {
86 u64 bp_misses; 86 u64 bp_misses;
87 u64 bp_cleaned; 87 u64 bp_cleaned;
88#endif 88#endif
89 89 u8 __iomem *tail;
90 u16 head;
91 u16 tail;
92 90
93 u16 reg_idx; /* holds the special value that gets the hardware register 91 u16 reg_idx; /* holds the special value that gets the hardware register
94 * offset associated with this ring, which is different 92 * offset associated with this ring, which is different
diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index 92ef4cb5a8e8..84b55fe71546 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -98,10 +98,11 @@ MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
98static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector); 98static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector);
99static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter); 99static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter);
100 100
101static inline void ixgbevf_release_rx_desc(struct ixgbe_hw *hw, 101static inline void ixgbevf_release_rx_desc(struct ixgbevf_ring *rx_ring,
102 struct ixgbevf_ring *rx_ring,
103 u32 val) 102 u32 val)
104{ 103{
104 rx_ring->next_to_use = val;
105
105 /* 106 /*
106 * Force memory writes to complete before letting h/w 107 * Force memory writes to complete before letting h/w
107 * know there are new descriptors to fetch. (Only 108 * know there are new descriptors to fetch. (Only
@@ -109,7 +110,7 @@ static inline void ixgbevf_release_rx_desc(struct ixgbe_hw *hw,
109 * such as IA-64). 110 * such as IA-64).
110 */ 111 */
111 wmb(); 112 wmb();
112 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rx_ring->reg_idx), val); 113 writel(val, rx_ring->tail);
113} 114}
114 115
115/** 116/**
@@ -406,10 +407,8 @@ static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter *adapter,
406 } 407 }
407 408
408no_buffers: 409no_buffers:
409 if (rx_ring->next_to_use != i) { 410 if (rx_ring->next_to_use != i)
410 rx_ring->next_to_use = i; 411 ixgbevf_release_rx_desc(rx_ring, i);
411 ixgbevf_release_rx_desc(&adapter->hw, rx_ring, i);
412 }
413} 412}
414 413
415static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter *adapter, 414static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter *adapter,
@@ -1110,8 +1109,9 @@ static void ixgbevf_configure_tx(struct ixgbevf_adapter *adapter)
1110 IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(j), tdlen); 1109 IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(j), tdlen);
1111 IXGBE_WRITE_REG(hw, IXGBE_VFTDH(j), 0); 1110 IXGBE_WRITE_REG(hw, IXGBE_VFTDH(j), 0);
1112 IXGBE_WRITE_REG(hw, IXGBE_VFTDT(j), 0); 1111 IXGBE_WRITE_REG(hw, IXGBE_VFTDT(j), 0);
1113 adapter->tx_ring[i].head = IXGBE_VFTDH(j); 1112 ring->tail = hw->hw_addr + IXGBE_VFTDT(j);
1114 adapter->tx_ring[i].tail = IXGBE_VFTDT(j); 1113 ring->next_to_clean = 0;
1114 ring->next_to_use = 0;
1115 /* Disable Tx Head Writeback RO bit, since this hoses 1115 /* Disable Tx Head Writeback RO bit, since this hoses
1116 * bookkeeping if things aren't delivered in order. 1116 * bookkeeping if things aren't delivered in order.
1117 */ 1117 */
@@ -1208,20 +1208,22 @@ static void ixgbevf_configure_rx(struct ixgbevf_adapter *adapter)
1208 /* set_rx_buffer_len must be called before ring initialization */ 1208 /* set_rx_buffer_len must be called before ring initialization */
1209 ixgbevf_set_rx_buffer_len(adapter); 1209 ixgbevf_set_rx_buffer_len(adapter);
1210 1210
1211 rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc);
1212 /* Setup the HW Rx Head and Tail Descriptor Pointers and 1211 /* Setup the HW Rx Head and Tail Descriptor Pointers and
1213 * the Base and Length of the Rx Descriptor Ring */ 1212 * the Base and Length of the Rx Descriptor Ring */
1214 for (i = 0; i < adapter->num_rx_queues; i++) { 1213 for (i = 0; i < adapter->num_rx_queues; i++) {
1215 rdba = adapter->rx_ring[i].dma; 1214 struct ixgbevf_ring *ring = &adapter->rx_ring[i];
1216 j = adapter->rx_ring[i].reg_idx; 1215 rdba = ring->dma;
1216 j = ring->reg_idx;
1217 rdlen = ring->count * sizeof(union ixgbe_adv_rx_desc);
1217 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(j), 1218 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(j),
1218 (rdba & DMA_BIT_MASK(32))); 1219 (rdba & DMA_BIT_MASK(32)));
1219 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(j), (rdba >> 32)); 1220 IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(j), (rdba >> 32));
1220 IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(j), rdlen); 1221 IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(j), rdlen);
1221 IXGBE_WRITE_REG(hw, IXGBE_VFRDH(j), 0); 1222 IXGBE_WRITE_REG(hw, IXGBE_VFRDH(j), 0);
1222 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(j), 0); 1223 IXGBE_WRITE_REG(hw, IXGBE_VFRDT(j), 0);
1223 adapter->rx_ring[i].head = IXGBE_VFRDH(j); 1224 ring->tail = hw->hw_addr + IXGBE_VFRDT(j);
1224 adapter->rx_ring[i].tail = IXGBE_VFRDT(j); 1225 ring->next_to_clean = 0;
1226 ring->next_to_use = 0;
1225 1227
1226 ixgbevf_configure_srrctl(adapter, j); 1228 ixgbevf_configure_srrctl(adapter, j);
1227 } 1229 }
@@ -1402,7 +1404,7 @@ static void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter *adapter,
1402 hw_dbg(hw, "RXDCTL.ENABLE queue %d not set while polling\n", 1404 hw_dbg(hw, "RXDCTL.ENABLE queue %d not set while polling\n",
1403 rxr); 1405 rxr);
1404 1406
1405 ixgbevf_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], 1407 ixgbevf_release_rx_desc(&adapter->rx_ring[rxr],
1406 (adapter->rx_ring[rxr].count - 1)); 1408 (adapter->rx_ring[rxr].count - 1));
1407} 1409}
1408 1410
@@ -1680,14 +1682,6 @@ static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter *adapter,
1680 1682
1681 /* Zero out the descriptor ring */ 1683 /* Zero out the descriptor ring */
1682 memset(rx_ring->desc, 0, rx_ring->size); 1684 memset(rx_ring->desc, 0, rx_ring->size);
1683
1684 rx_ring->next_to_clean = 0;
1685 rx_ring->next_to_use = 0;
1686
1687 if (rx_ring->head)
1688 writel(0, adapter->hw.hw_addr + rx_ring->head);
1689 if (rx_ring->tail)
1690 writel(0, adapter->hw.hw_addr + rx_ring->tail);
1691} 1685}
1692 1686
1693/** 1687/**
@@ -1715,14 +1709,6 @@ static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter *adapter,
1715 memset(tx_ring->tx_buffer_info, 0, size); 1709 memset(tx_ring->tx_buffer_info, 0, size);
1716 1710
1717 memset(tx_ring->desc, 0, tx_ring->size); 1711 memset(tx_ring->desc, 0, tx_ring->size);
1718
1719 tx_ring->next_to_use = 0;
1720 tx_ring->next_to_clean = 0;
1721
1722 if (tx_ring->head)
1723 writel(0, adapter->hw.hw_addr + tx_ring->head);
1724 if (tx_ring->tail)
1725 writel(0, adapter->hw.hw_addr + tx_ring->tail);
1726} 1712}
1727 1713
1728/** 1714/**
@@ -2473,8 +2459,6 @@ int ixgbevf_setup_tx_resources(struct ixgbevf_adapter *adapter,
2473 if (!tx_ring->desc) 2459 if (!tx_ring->desc)
2474 goto err; 2460 goto err;
2475 2461
2476 tx_ring->next_to_use = 0;
2477 tx_ring->next_to_clean = 0;
2478 return 0; 2462 return 0;
2479 2463
2480err: 2464err:
@@ -2542,9 +2526,6 @@ int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter,
2542 goto alloc_failed; 2526 goto alloc_failed;
2543 } 2527 }
2544 2528
2545 rx_ring->next_to_clean = 0;
2546 rx_ring->next_to_use = 0;
2547
2548 return 0; 2529 return 0;
2549alloc_failed: 2530alloc_failed:
2550 return -ENOMEM; 2531 return -ENOMEM;
@@ -3181,7 +3162,7 @@ static int ixgbevf_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
3181 ixgbevf_tx_map(tx_ring, skb, tx_flags), 3162 ixgbevf_tx_map(tx_ring, skb, tx_flags),
3182 first, skb->len, hdr_len); 3163 first, skb->len, hdr_len);
3183 3164
3184 writel(tx_ring->next_to_use, adapter->hw.hw_addr + tx_ring->tail); 3165 writel(tx_ring->next_to_use, tx_ring->tail);
3185 3166
3186 ixgbevf_maybe_stop_tx(tx_ring, DESC_NEEDED); 3167 ixgbevf_maybe_stop_tx(tx_ring, DESC_NEEDED);
3187 3168