Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2014 Intel Corporation. |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
| 27 | /* ethtool support for i40e */ |
| 28 | |
| 29 | #include "i40e.h" |
| 30 | #include "i40e_diag.h" |
| 31 | |
| 32 | struct i40e_stats { |
| 33 | char stat_string[ETH_GSTRING_LEN]; |
| 34 | int sizeof_stat; |
| 35 | int stat_offset; |
| 36 | }; |
| 37 | |
| 38 | #define I40E_STAT(_type, _name, _stat) { \ |
| 39 | .stat_string = _name, \ |
| 40 | .sizeof_stat = FIELD_SIZEOF(_type, _stat), \ |
| 41 | .stat_offset = offsetof(_type, _stat) \ |
| 42 | } |
| 43 | #define I40E_NETDEV_STAT(_net_stat) \ |
| 44 | I40E_STAT(struct net_device_stats, #_net_stat, _net_stat) |
| 45 | #define I40E_PF_STAT(_name, _stat) \ |
| 46 | I40E_STAT(struct i40e_pf, _name, _stat) |
| 47 | #define I40E_VSI_STAT(_name, _stat) \ |
| 48 | I40E_STAT(struct i40e_vsi, _name, _stat) |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 49 | #define I40E_VEB_STAT(_name, _stat) \ |
| 50 | I40E_STAT(struct i40e_veb, _name, _stat) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 51 | |
| 52 | static const struct i40e_stats i40e_gstrings_net_stats[] = { |
| 53 | I40E_NETDEV_STAT(rx_packets), |
| 54 | I40E_NETDEV_STAT(tx_packets), |
| 55 | I40E_NETDEV_STAT(rx_bytes), |
| 56 | I40E_NETDEV_STAT(tx_bytes), |
| 57 | I40E_NETDEV_STAT(rx_errors), |
| 58 | I40E_NETDEV_STAT(tx_errors), |
| 59 | I40E_NETDEV_STAT(rx_dropped), |
| 60 | I40E_NETDEV_STAT(tx_dropped), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 61 | I40E_NETDEV_STAT(collisions), |
| 62 | I40E_NETDEV_STAT(rx_length_errors), |
| 63 | I40E_NETDEV_STAT(rx_crc_errors), |
| 64 | }; |
| 65 | |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 66 | static const struct i40e_stats i40e_gstrings_veb_stats[] = { |
| 67 | I40E_VEB_STAT("rx_bytes", stats.rx_bytes), |
| 68 | I40E_VEB_STAT("tx_bytes", stats.tx_bytes), |
| 69 | I40E_VEB_STAT("rx_unicast", stats.rx_unicast), |
| 70 | I40E_VEB_STAT("tx_unicast", stats.tx_unicast), |
| 71 | I40E_VEB_STAT("rx_multicast", stats.rx_multicast), |
| 72 | I40E_VEB_STAT("tx_multicast", stats.tx_multicast), |
| 73 | I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast), |
| 74 | I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast), |
| 75 | I40E_VEB_STAT("rx_discards", stats.rx_discards), |
| 76 | I40E_VEB_STAT("tx_discards", stats.tx_discards), |
| 77 | I40E_VEB_STAT("tx_errors", stats.tx_errors), |
| 78 | I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol), |
| 79 | }; |
| 80 | |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 81 | static const struct i40e_stats i40e_gstrings_misc_stats[] = { |
Shannon Nelson | 418631d | 2014-04-23 04:50:07 +0000 | [diff] [blame] | 82 | I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast), |
| 83 | I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast), |
| 84 | I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast), |
| 85 | I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast), |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 86 | I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast), |
| 87 | I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast), |
Shannon Nelson | 418631d | 2014-04-23 04:50:07 +0000 | [diff] [blame] | 88 | I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol), |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 91 | static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, |
| 92 | struct ethtool_rxnfc *cmd); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 93 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 94 | /* These PF_STATs might look like duplicates of some NETDEV_STATs, |
| 95 | * but they are separate. This device supports Virtualization, and |
| 96 | * as such might have several netdevs supporting VMDq and FCoE going |
| 97 | * through a single port. The NETDEV_STATs are for individual netdevs |
| 98 | * seen at the top of the stack, and the PF_STATs are for the physical |
| 99 | * function at the bottom of the stack hosting those netdevs. |
| 100 | * |
| 101 | * The PF_STATs are appended to the netdev stats only when ethtool -S |
| 102 | * is queried on the base PF netdev, not on the VMDq or FCoE netdev. |
| 103 | */ |
| 104 | static struct i40e_stats i40e_gstrings_stats[] = { |
| 105 | I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes), |
| 106 | I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes), |
Shannon Nelson | 532d283 | 2014-04-23 04:50:09 +0000 | [diff] [blame] | 107 | I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast), |
| 108 | I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast), |
| 109 | I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast), |
| 110 | I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast), |
| 111 | I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast), |
| 112 | I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 113 | I40E_PF_STAT("tx_errors", stats.eth.tx_errors), |
| 114 | I40E_PF_STAT("rx_dropped", stats.eth.rx_discards), |
| 115 | I40E_PF_STAT("tx_dropped", stats.eth.tx_discards), |
| 116 | I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down), |
| 117 | I40E_PF_STAT("crc_errors", stats.crc_errors), |
| 118 | I40E_PF_STAT("illegal_bytes", stats.illegal_bytes), |
| 119 | I40E_PF_STAT("mac_local_faults", stats.mac_local_faults), |
| 120 | I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults), |
Jesse Brandeburg | a47a15f | 2014-02-06 05:51:09 +0000 | [diff] [blame] | 121 | I40E_PF_STAT("tx_timeout", tx_timeout_count), |
Jesse Brandeburg | 8a3c91c | 2014-05-20 08:01:43 +0000 | [diff] [blame] | 122 | I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 123 | I40E_PF_STAT("rx_length_errors", stats.rx_length_errors), |
| 124 | I40E_PF_STAT("link_xon_rx", stats.link_xon_rx), |
| 125 | I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx), |
| 126 | I40E_PF_STAT("link_xon_tx", stats.link_xon_tx), |
| 127 | I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx), |
| 128 | I40E_PF_STAT("rx_size_64", stats.rx_size_64), |
| 129 | I40E_PF_STAT("rx_size_127", stats.rx_size_127), |
| 130 | I40E_PF_STAT("rx_size_255", stats.rx_size_255), |
| 131 | I40E_PF_STAT("rx_size_511", stats.rx_size_511), |
| 132 | I40E_PF_STAT("rx_size_1023", stats.rx_size_1023), |
| 133 | I40E_PF_STAT("rx_size_1522", stats.rx_size_1522), |
| 134 | I40E_PF_STAT("rx_size_big", stats.rx_size_big), |
| 135 | I40E_PF_STAT("tx_size_64", stats.tx_size_64), |
| 136 | I40E_PF_STAT("tx_size_127", stats.tx_size_127), |
| 137 | I40E_PF_STAT("tx_size_255", stats.tx_size_255), |
| 138 | I40E_PF_STAT("tx_size_511", stats.tx_size_511), |
| 139 | I40E_PF_STAT("tx_size_1023", stats.tx_size_1023), |
| 140 | I40E_PF_STAT("tx_size_1522", stats.tx_size_1522), |
| 141 | I40E_PF_STAT("tx_size_big", stats.tx_size_big), |
| 142 | I40E_PF_STAT("rx_undersize", stats.rx_undersize), |
| 143 | I40E_PF_STAT("rx_fragments", stats.rx_fragments), |
| 144 | I40E_PF_STAT("rx_oversize", stats.rx_oversize), |
| 145 | I40E_PF_STAT("rx_jabber", stats.rx_jabber), |
| 146 | I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests), |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 147 | I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared), |
Anjali Singhai Jain | 60793f4a | 2014-07-09 07:46:23 +0000 | [diff] [blame] | 148 | I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt), |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 149 | I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match), |
| 150 | I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match), |
| 151 | |
Anjali Singhai Jain | bee5af7 | 2014-03-06 08:59:50 +0000 | [diff] [blame] | 152 | /* LPI stats */ |
| 153 | I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status), |
| 154 | I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status), |
| 155 | I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count), |
| 156 | I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 159 | #ifdef I40E_FCOE |
| 160 | static const struct i40e_stats i40e_gstrings_fcoe_stats[] = { |
| 161 | I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc), |
| 162 | I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped), |
| 163 | I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets), |
| 164 | I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords), |
| 165 | I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count), |
| 166 | I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error), |
| 167 | I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets), |
| 168 | I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords), |
| 169 | }; |
| 170 | |
| 171 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 172 | #define I40E_QUEUE_STATS_LEN(n) \ |
Shannon Nelson | 31cd840 | 2014-04-04 04:43:12 +0000 | [diff] [blame] | 173 | (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \ |
| 174 | * 2 /* Tx and Rx together */ \ |
| 175 | * (sizeof(struct i40e_queue_stats) / sizeof(u64))) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 176 | #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats) |
| 177 | #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats) |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 178 | #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 179 | #ifdef I40E_FCOE |
| 180 | #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats) |
| 181 | #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \ |
| 182 | I40E_FCOE_STATS_LEN + \ |
| 183 | I40E_MISC_STATS_LEN + \ |
| 184 | I40E_QUEUE_STATS_LEN((n))) |
| 185 | #else |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 186 | #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \ |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 187 | I40E_MISC_STATS_LEN + \ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 188 | I40E_QUEUE_STATS_LEN((n))) |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 189 | #endif /* I40E_FCOE */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 190 | #define I40E_PFC_STATS_LEN ( \ |
| 191 | (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \ |
| 192 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \ |
| 193 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \ |
| 194 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \ |
| 195 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \ |
| 196 | / sizeof(u64)) |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 197 | #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 198 | #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \ |
| 199 | I40E_PFC_STATS_LEN + \ |
| 200 | I40E_VSI_STATS_LEN((n))) |
| 201 | |
| 202 | enum i40e_ethtool_test_id { |
| 203 | I40E_ETH_TEST_REG = 0, |
| 204 | I40E_ETH_TEST_EEPROM, |
| 205 | I40E_ETH_TEST_INTR, |
| 206 | I40E_ETH_TEST_LOOPBACK, |
| 207 | I40E_ETH_TEST_LINK, |
| 208 | }; |
| 209 | |
| 210 | static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = { |
| 211 | "Register test (offline)", |
| 212 | "Eeprom test (offline)", |
| 213 | "Interrupt test (offline)", |
| 214 | "Loopback test (offline)", |
| 215 | "Link test (on/offline)" |
| 216 | }; |
| 217 | |
| 218 | #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN) |
| 219 | |
| 220 | /** |
| 221 | * i40e_get_settings - Get Link Speed and Duplex settings |
| 222 | * @netdev: network interface device structure |
| 223 | * @ecmd: ethtool command |
| 224 | * |
| 225 | * Reports speed/duplex settings based on media_type |
| 226 | **/ |
| 227 | static int i40e_get_settings(struct net_device *netdev, |
| 228 | struct ethtool_cmd *ecmd) |
| 229 | { |
| 230 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 231 | struct i40e_pf *pf = np->vsi->back; |
| 232 | struct i40e_hw *hw = &pf->hw; |
| 233 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 234 | bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; |
| 235 | u32 link_speed = hw_link_info->link_speed; |
| 236 | |
| 237 | /* hardware is either in 40G mode or 10G mode |
| 238 | * NOTE: this section initializes supported and advertising |
| 239 | */ |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 240 | if (!link_up) { |
| 241 | /* link is down and the driver needs to fall back on |
| 242 | * device ID to determine what kinds of info to display, |
| 243 | * it's mostly a guess that may change when link is up |
| 244 | */ |
| 245 | switch (hw->device_id) { |
| 246 | case I40E_DEV_ID_QSFP_A: |
| 247 | case I40E_DEV_ID_QSFP_B: |
| 248 | case I40E_DEV_ID_QSFP_C: |
| 249 | /* pluggable QSFP */ |
| 250 | ecmd->supported = SUPPORTED_40000baseSR4_Full | |
| 251 | SUPPORTED_40000baseCR4_Full | |
| 252 | SUPPORTED_40000baseLR4_Full; |
| 253 | ecmd->advertising = ADVERTISED_40000baseSR4_Full | |
| 254 | ADVERTISED_40000baseCR4_Full | |
| 255 | ADVERTISED_40000baseLR4_Full; |
| 256 | break; |
| 257 | case I40E_DEV_ID_KX_B: |
| 258 | /* backplane 40G */ |
| 259 | ecmd->supported = SUPPORTED_40000baseKR4_Full; |
| 260 | ecmd->advertising = ADVERTISED_40000baseKR4_Full; |
| 261 | break; |
| 262 | case I40E_DEV_ID_KX_C: |
| 263 | /* backplane 10G */ |
| 264 | ecmd->supported = SUPPORTED_10000baseKR_Full; |
| 265 | ecmd->advertising = ADVERTISED_10000baseKR_Full; |
| 266 | break; |
| 267 | default: |
| 268 | /* all the rest are 10G/1G */ |
| 269 | ecmd->supported = SUPPORTED_10000baseT_Full | |
| 270 | SUPPORTED_1000baseT_Full; |
| 271 | ecmd->advertising = ADVERTISED_10000baseT_Full | |
| 272 | ADVERTISED_1000baseT_Full; |
| 273 | break; |
| 274 | } |
| 275 | |
| 276 | /* skip phy_type use as it is zero when link is down */ |
| 277 | goto no_valid_phy_type; |
| 278 | } |
| 279 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 280 | switch (hw_link_info->phy_type) { |
| 281 | case I40E_PHY_TYPE_40GBASE_CR4: |
| 282 | case I40E_PHY_TYPE_40GBASE_CR4_CU: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 283 | ecmd->supported = SUPPORTED_Autoneg | |
| 284 | SUPPORTED_40000baseCR4_Full; |
| 285 | ecmd->advertising = ADVERTISED_Autoneg | |
| 286 | ADVERTISED_40000baseCR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 287 | break; |
| 288 | case I40E_PHY_TYPE_40GBASE_KR4: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 289 | ecmd->supported = SUPPORTED_Autoneg | |
| 290 | SUPPORTED_40000baseKR4_Full; |
| 291 | ecmd->advertising = ADVERTISED_Autoneg | |
| 292 | ADVERTISED_40000baseKR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 293 | break; |
| 294 | case I40E_PHY_TYPE_40GBASE_SR4: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 295 | case I40E_PHY_TYPE_XLPPI: |
| 296 | case I40E_PHY_TYPE_XLAUI: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 297 | ecmd->supported = SUPPORTED_40000baseSR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 298 | break; |
| 299 | case I40E_PHY_TYPE_40GBASE_LR4: |
| 300 | ecmd->supported = SUPPORTED_40000baseLR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 301 | break; |
| 302 | case I40E_PHY_TYPE_10GBASE_KX4: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 303 | ecmd->supported = SUPPORTED_Autoneg | |
| 304 | SUPPORTED_10000baseKX4_Full; |
| 305 | ecmd->advertising = ADVERTISED_Autoneg | |
| 306 | ADVERTISED_10000baseKX4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 307 | break; |
| 308 | case I40E_PHY_TYPE_10GBASE_KR: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 309 | ecmd->supported = SUPPORTED_Autoneg | |
| 310 | SUPPORTED_10000baseKR_Full; |
| 311 | ecmd->advertising = ADVERTISED_Autoneg | |
| 312 | ADVERTISED_10000baseKR_Full; |
| 313 | break; |
| 314 | case I40E_PHY_TYPE_10GBASE_SR: |
| 315 | case I40E_PHY_TYPE_10GBASE_LR: |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame^] | 316 | case I40E_PHY_TYPE_1000BASE_SX: |
| 317 | case I40E_PHY_TYPE_1000BASE_LX: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 318 | ecmd->supported = SUPPORTED_10000baseT_Full; |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame^] | 319 | ecmd->supported |= SUPPORTED_1000baseT_Full; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 320 | break; |
| 321 | case I40E_PHY_TYPE_10GBASE_CR1_CU: |
| 322 | case I40E_PHY_TYPE_10GBASE_CR1: |
| 323 | case I40E_PHY_TYPE_10GBASE_T: |
| 324 | ecmd->supported = SUPPORTED_Autoneg | |
| 325 | SUPPORTED_10000baseT_Full; |
| 326 | ecmd->advertising = ADVERTISED_Autoneg | |
| 327 | ADVERTISED_10000baseT_Full; |
| 328 | break; |
| 329 | case I40E_PHY_TYPE_XAUI: |
| 330 | case I40E_PHY_TYPE_XFI: |
| 331 | case I40E_PHY_TYPE_SFI: |
| 332 | case I40E_PHY_TYPE_10GBASE_SFPP_CU: |
| 333 | ecmd->supported = SUPPORTED_10000baseT_Full; |
| 334 | break; |
| 335 | case I40E_PHY_TYPE_1000BASE_KX: |
| 336 | case I40E_PHY_TYPE_1000BASE_T: |
| 337 | ecmd->supported = SUPPORTED_Autoneg | |
| 338 | SUPPORTED_1000baseT_Full; |
| 339 | ecmd->advertising = ADVERTISED_Autoneg | |
| 340 | ADVERTISED_1000baseT_Full; |
| 341 | break; |
| 342 | case I40E_PHY_TYPE_100BASE_TX: |
| 343 | ecmd->supported = SUPPORTED_Autoneg | |
| 344 | SUPPORTED_100baseT_Full; |
| 345 | ecmd->advertising = ADVERTISED_Autoneg | |
| 346 | ADVERTISED_100baseT_Full; |
| 347 | break; |
| 348 | case I40E_PHY_TYPE_SGMII: |
| 349 | ecmd->supported = SUPPORTED_Autoneg | |
| 350 | SUPPORTED_1000baseT_Full | |
| 351 | SUPPORTED_100baseT_Full; |
| 352 | ecmd->advertising = ADVERTISED_Autoneg | |
| 353 | ADVERTISED_1000baseT_Full | |
| 354 | ADVERTISED_100baseT_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 355 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 356 | default: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 357 | /* if we got here and link is up something bad is afoot */ |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame^] | 358 | netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n", |
| 359 | hw_link_info->phy_type); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 360 | } |
| 361 | |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 362 | no_valid_phy_type: |
| 363 | /* this is if autoneg is enabled or disabled */ |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 364 | ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
| 365 | AUTONEG_ENABLE : AUTONEG_DISABLE); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 366 | |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 367 | switch (hw->phy.media_type) { |
| 368 | case I40E_MEDIA_TYPE_BACKPLANE: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 369 | ecmd->supported |= SUPPORTED_Autoneg | |
| 370 | SUPPORTED_Backplane; |
| 371 | ecmd->advertising |= ADVERTISED_Autoneg | |
| 372 | ADVERTISED_Backplane; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 373 | ecmd->port = PORT_NONE; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 374 | break; |
| 375 | case I40E_MEDIA_TYPE_BASET: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 376 | ecmd->supported |= SUPPORTED_TP; |
| 377 | ecmd->advertising |= ADVERTISED_TP; |
| 378 | ecmd->port = PORT_TP; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 379 | break; |
| 380 | case I40E_MEDIA_TYPE_DA: |
| 381 | case I40E_MEDIA_TYPE_CX4: |
Jesse Brandeburg | be405eb | 2013-11-20 10:02:50 +0000 | [diff] [blame] | 382 | ecmd->supported |= SUPPORTED_FIBRE; |
| 383 | ecmd->advertising |= ADVERTISED_FIBRE; |
| 384 | ecmd->port = PORT_DA; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 385 | break; |
| 386 | case I40E_MEDIA_TYPE_FIBER: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 387 | ecmd->supported |= SUPPORTED_FIBRE; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 388 | ecmd->port = PORT_FIBRE; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 389 | break; |
| 390 | case I40E_MEDIA_TYPE_UNKNOWN: |
| 391 | default: |
| 392 | ecmd->port = PORT_OTHER; |
| 393 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | ecmd->transceiver = XCVR_EXTERNAL; |
| 397 | |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 398 | ecmd->supported |= SUPPORTED_Pause; |
| 399 | |
| 400 | switch (hw->fc.current_mode) { |
| 401 | case I40E_FC_FULL: |
| 402 | ecmd->advertising |= ADVERTISED_Pause; |
| 403 | break; |
| 404 | case I40E_FC_TX_PAUSE: |
| 405 | ecmd->advertising |= ADVERTISED_Asym_Pause; |
| 406 | break; |
| 407 | case I40E_FC_RX_PAUSE: |
| 408 | ecmd->advertising |= (ADVERTISED_Pause | |
| 409 | ADVERTISED_Asym_Pause); |
| 410 | break; |
| 411 | default: |
| 412 | ecmd->advertising &= ~(ADVERTISED_Pause | |
| 413 | ADVERTISED_Asym_Pause); |
| 414 | break; |
| 415 | } |
| 416 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 417 | if (link_up) { |
| 418 | switch (link_speed) { |
| 419 | case I40E_LINK_SPEED_40GB: |
| 420 | /* need a SPEED_40000 in ethtool.h */ |
| 421 | ethtool_cmd_speed_set(ecmd, 40000); |
| 422 | break; |
| 423 | case I40E_LINK_SPEED_10GB: |
| 424 | ethtool_cmd_speed_set(ecmd, SPEED_10000); |
| 425 | break; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 426 | case I40E_LINK_SPEED_1GB: |
| 427 | ethtool_cmd_speed_set(ecmd, SPEED_1000); |
| 428 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 429 | default: |
| 430 | break; |
| 431 | } |
| 432 | ecmd->duplex = DUPLEX_FULL; |
| 433 | } else { |
| 434 | ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN); |
| 435 | ecmd->duplex = DUPLEX_UNKNOWN; |
| 436 | } |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 441 | /** |
| 442 | * i40e_set_settings - Set Speed and Duplex |
| 443 | * @netdev: network interface device structure |
| 444 | * @ecmd: ethtool command |
| 445 | * |
| 446 | * Set speed/duplex per media_types advertised/forced |
| 447 | **/ |
| 448 | static int i40e_set_settings(struct net_device *netdev, |
| 449 | struct ethtool_cmd *ecmd) |
| 450 | { |
| 451 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 452 | struct i40e_aq_get_phy_abilities_resp abilities; |
| 453 | struct i40e_aq_set_phy_config config; |
| 454 | struct i40e_pf *pf = np->vsi->back; |
| 455 | struct i40e_vsi *vsi = np->vsi; |
| 456 | struct i40e_hw *hw = &pf->hw; |
| 457 | struct ethtool_cmd safe_ecmd; |
| 458 | i40e_status status = 0; |
| 459 | bool change = false; |
| 460 | int err = 0; |
| 461 | u8 autoneg; |
| 462 | u32 advertise; |
| 463 | |
| 464 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 465 | return -EOPNOTSUPP; |
| 466 | |
| 467 | if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET && |
| 468 | hw->phy.media_type != I40E_MEDIA_TYPE_FIBER && |
| 469 | hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE) |
| 470 | return -EOPNOTSUPP; |
| 471 | |
| 472 | /* get our own copy of the bits to check against */ |
| 473 | memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd)); |
| 474 | i40e_get_settings(netdev, &safe_ecmd); |
| 475 | |
| 476 | /* save autoneg and speed out of ecmd */ |
| 477 | autoneg = ecmd->autoneg; |
| 478 | advertise = ecmd->advertising; |
| 479 | |
| 480 | /* set autoneg and speed back to what they currently are */ |
| 481 | ecmd->autoneg = safe_ecmd.autoneg; |
| 482 | ecmd->advertising = safe_ecmd.advertising; |
| 483 | |
| 484 | ecmd->cmd = safe_ecmd.cmd; |
| 485 | /* If ecmd and safe_ecmd are not the same now, then they are |
| 486 | * trying to set something that we do not support |
| 487 | */ |
| 488 | if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd))) |
| 489 | return -EOPNOTSUPP; |
| 490 | |
| 491 | while (test_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 492 | usleep_range(1000, 2000); |
| 493 | |
| 494 | /* Get the current phy config */ |
| 495 | status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, |
| 496 | NULL); |
| 497 | if (status) |
| 498 | return -EAGAIN; |
| 499 | |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame^] | 500 | /* Copy abilities to config in case autoneg is not |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 501 | * set below |
| 502 | */ |
| 503 | memset(&config, 0, sizeof(struct i40e_aq_set_phy_config)); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 504 | config.abilities = abilities.abilities; |
| 505 | |
| 506 | /* Check autoneg */ |
| 507 | if (autoneg == AUTONEG_ENABLE) { |
| 508 | /* If autoneg is not supported, return error */ |
| 509 | if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) { |
| 510 | netdev_info(netdev, "Autoneg not supported on this phy\n"); |
| 511 | return -EINVAL; |
| 512 | } |
| 513 | /* If autoneg was not already enabled */ |
| 514 | if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) { |
| 515 | config.abilities = abilities.abilities | |
| 516 | I40E_AQ_PHY_ENABLE_AN; |
| 517 | change = true; |
| 518 | } |
| 519 | } else { |
| 520 | /* If autoneg is supported 10GBASE_T is the only phy that |
| 521 | * can disable it, so otherwise return error |
| 522 | */ |
| 523 | if (safe_ecmd.supported & SUPPORTED_Autoneg && |
| 524 | hw->phy.link_info.phy_type != I40E_PHY_TYPE_10GBASE_T) { |
| 525 | netdev_info(netdev, "Autoneg cannot be disabled on this phy\n"); |
| 526 | return -EINVAL; |
| 527 | } |
| 528 | /* If autoneg is currently enabled */ |
| 529 | if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) { |
| 530 | config.abilities = abilities.abilities | |
| 531 | ~I40E_AQ_PHY_ENABLE_AN; |
| 532 | change = true; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | if (advertise & ~safe_ecmd.supported) |
| 537 | return -EINVAL; |
| 538 | |
| 539 | if (advertise & ADVERTISED_100baseT_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame^] | 540 | config.link_speed |= I40E_LINK_SPEED_100MB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 541 | if (advertise & ADVERTISED_1000baseT_Full || |
| 542 | advertise & ADVERTISED_1000baseKX_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame^] | 543 | config.link_speed |= I40E_LINK_SPEED_1GB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 544 | if (advertise & ADVERTISED_10000baseT_Full || |
| 545 | advertise & ADVERTISED_10000baseKX4_Full || |
| 546 | advertise & ADVERTISED_10000baseKR_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame^] | 547 | config.link_speed |= I40E_LINK_SPEED_10GB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 548 | if (advertise & ADVERTISED_40000baseKR4_Full || |
| 549 | advertise & ADVERTISED_40000baseCR4_Full || |
| 550 | advertise & ADVERTISED_40000baseSR4_Full || |
| 551 | advertise & ADVERTISED_40000baseLR4_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame^] | 552 | config.link_speed |= I40E_LINK_SPEED_40GB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 553 | |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame^] | 554 | if (change || (abilities.link_speed != config.link_speed)) { |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 555 | /* copy over the rest of the abilities */ |
| 556 | config.phy_type = abilities.phy_type; |
| 557 | config.eee_capability = abilities.eee_capability; |
| 558 | config.eeer = abilities.eeer_val; |
| 559 | config.low_power_ctrl = abilities.d3_lpan; |
| 560 | |
| 561 | /* If link is up set link and an so changes take effect */ |
| 562 | if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) |
| 563 | config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK; |
| 564 | |
| 565 | /* make the aq call */ |
| 566 | status = i40e_aq_set_phy_config(hw, &config, NULL); |
| 567 | if (status) { |
| 568 | netdev_info(netdev, "Set phy config failed with error %d.\n", |
| 569 | status); |
| 570 | return -EAGAIN; |
| 571 | } |
| 572 | |
| 573 | status = i40e_update_link_info(hw, true); |
| 574 | if (status) |
| 575 | netdev_info(netdev, "Updating link info failed with error %d\n", |
| 576 | status); |
| 577 | |
| 578 | } else { |
| 579 | netdev_info(netdev, "Nothing changed, exiting without setting anything.\n"); |
| 580 | } |
| 581 | |
| 582 | return err; |
| 583 | } |
| 584 | |
Jesse Brandeburg | a659972 | 2014-06-04 08:45:25 +0000 | [diff] [blame] | 585 | static int i40e_nway_reset(struct net_device *netdev) |
| 586 | { |
| 587 | /* restart autonegotiation */ |
| 588 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 589 | struct i40e_pf *pf = np->vsi->back; |
| 590 | struct i40e_hw *hw = &pf->hw; |
| 591 | bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP; |
| 592 | i40e_status ret = 0; |
| 593 | |
| 594 | ret = i40e_aq_set_link_restart_an(hw, link_up, NULL); |
| 595 | if (ret) { |
| 596 | netdev_info(netdev, "link restart failed, aq_err=%d\n", |
| 597 | pf->hw.aq.asq_last_status); |
| 598 | return -EIO; |
| 599 | } |
| 600 | |
| 601 | return 0; |
| 602 | } |
| 603 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 604 | /** |
| 605 | * i40e_get_pauseparam - Get Flow Control status |
| 606 | * Return tx/rx-pause status |
| 607 | **/ |
| 608 | static void i40e_get_pauseparam(struct net_device *netdev, |
| 609 | struct ethtool_pauseparam *pause) |
| 610 | { |
| 611 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 612 | struct i40e_pf *pf = np->vsi->back; |
| 613 | struct i40e_hw *hw = &pf->hw; |
| 614 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 615 | |
| 616 | pause->autoneg = |
| 617 | ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
| 618 | AUTONEG_ENABLE : AUTONEG_DISABLE); |
| 619 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 620 | if (hw->fc.current_mode == I40E_FC_RX_PAUSE) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 621 | pause->rx_pause = 1; |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 622 | } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 623 | pause->tx_pause = 1; |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 624 | } else if (hw->fc.current_mode == I40E_FC_FULL) { |
| 625 | pause->rx_pause = 1; |
| 626 | pause->tx_pause = 1; |
| 627 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 630 | /** |
| 631 | * i40e_set_pauseparam - Set Flow Control parameter |
| 632 | * @netdev: network interface device structure |
| 633 | * @pause: return tx/rx flow control status |
| 634 | **/ |
| 635 | static int i40e_set_pauseparam(struct net_device *netdev, |
| 636 | struct ethtool_pauseparam *pause) |
| 637 | { |
| 638 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 639 | struct i40e_pf *pf = np->vsi->back; |
| 640 | struct i40e_vsi *vsi = np->vsi; |
| 641 | struct i40e_hw *hw = &pf->hw; |
| 642 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 643 | bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; |
| 644 | i40e_status status; |
| 645 | u8 aq_failures; |
Catherine Sullivan | 7d62dac | 2014-07-09 07:46:18 +0000 | [diff] [blame] | 646 | int err = 0; |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 647 | |
| 648 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 649 | return -EOPNOTSUPP; |
| 650 | |
| 651 | if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
| 652 | AUTONEG_ENABLE : AUTONEG_DISABLE)) { |
| 653 | netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n"); |
| 654 | return -EOPNOTSUPP; |
| 655 | } |
| 656 | |
| 657 | /* If we have link and don't have autoneg */ |
| 658 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 659 | !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) { |
| 660 | /* Send message that it might not necessarily work*/ |
| 661 | netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n"); |
| 662 | } |
| 663 | |
| 664 | if (hw->fc.current_mode == I40E_FC_PFC) { |
| 665 | netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n"); |
| 666 | return -EOPNOTSUPP; |
| 667 | } |
| 668 | |
| 669 | if (pause->rx_pause && pause->tx_pause) |
| 670 | hw->fc.requested_mode = I40E_FC_FULL; |
| 671 | else if (pause->rx_pause && !pause->tx_pause) |
| 672 | hw->fc.requested_mode = I40E_FC_RX_PAUSE; |
| 673 | else if (!pause->rx_pause && pause->tx_pause) |
| 674 | hw->fc.requested_mode = I40E_FC_TX_PAUSE; |
| 675 | else if (!pause->rx_pause && !pause->tx_pause) |
| 676 | hw->fc.requested_mode = I40E_FC_NONE; |
| 677 | else |
| 678 | return -EINVAL; |
| 679 | |
| 680 | /* Set the fc mode and only restart an if link is up*/ |
| 681 | status = i40e_set_fc(hw, &aq_failures, link_up); |
| 682 | |
| 683 | if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) { |
| 684 | netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with error %d and status %d\n", |
| 685 | status, hw->aq.asq_last_status); |
| 686 | err = -EAGAIN; |
| 687 | } |
| 688 | if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) { |
| 689 | netdev_info(netdev, "Set fc failed on the set_phy_config call with error %d and status %d\n", |
| 690 | status, hw->aq.asq_last_status); |
| 691 | err = -EAGAIN; |
| 692 | } |
| 693 | if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) { |
| 694 | netdev_info(netdev, "Set fc failed on the update_link_info call with error %d and status %d\n", |
| 695 | status, hw->aq.asq_last_status); |
| 696 | err = -EAGAIN; |
| 697 | } |
| 698 | |
Catherine Sullivan | 7d62dac | 2014-07-09 07:46:18 +0000 | [diff] [blame] | 699 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 700 | /* Give it a little more time to try to come back */ |
| 701 | msleep(75); |
| 702 | if (!test_bit(__I40E_DOWN, &pf->state)) |
| 703 | return i40e_nway_reset(netdev); |
| 704 | } |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 705 | |
| 706 | return err; |
| 707 | } |
| 708 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 709 | static u32 i40e_get_msglevel(struct net_device *netdev) |
| 710 | { |
| 711 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 712 | struct i40e_pf *pf = np->vsi->back; |
| 713 | |
| 714 | return pf->msg_enable; |
| 715 | } |
| 716 | |
| 717 | static void i40e_set_msglevel(struct net_device *netdev, u32 data) |
| 718 | { |
| 719 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 720 | struct i40e_pf *pf = np->vsi->back; |
| 721 | |
| 722 | if (I40E_DEBUG_USER & data) |
| 723 | pf->hw.debug_mask = data; |
| 724 | pf->msg_enable = data; |
| 725 | } |
| 726 | |
| 727 | static int i40e_get_regs_len(struct net_device *netdev) |
| 728 | { |
| 729 | int reg_count = 0; |
| 730 | int i; |
| 731 | |
| 732 | for (i = 0; i40e_reg_list[i].offset != 0; i++) |
| 733 | reg_count += i40e_reg_list[i].elements; |
| 734 | |
| 735 | return reg_count * sizeof(u32); |
| 736 | } |
| 737 | |
| 738 | static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs, |
| 739 | void *p) |
| 740 | { |
| 741 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 742 | struct i40e_pf *pf = np->vsi->back; |
| 743 | struct i40e_hw *hw = &pf->hw; |
| 744 | u32 *reg_buf = p; |
| 745 | int i, j, ri; |
| 746 | u32 reg; |
| 747 | |
| 748 | /* Tell ethtool which driver-version-specific regs output we have. |
| 749 | * |
| 750 | * At some point, if we have ethtool doing special formatting of |
| 751 | * this data, it will rely on this version number to know how to |
| 752 | * interpret things. Hence, this needs to be updated if/when the |
| 753 | * diags register table is changed. |
| 754 | */ |
| 755 | regs->version = 1; |
| 756 | |
| 757 | /* loop through the diags reg table for what to print */ |
| 758 | ri = 0; |
| 759 | for (i = 0; i40e_reg_list[i].offset != 0; i++) { |
| 760 | for (j = 0; j < i40e_reg_list[i].elements; j++) { |
| 761 | reg = i40e_reg_list[i].offset |
| 762 | + (j * i40e_reg_list[i].stride); |
| 763 | reg_buf[ri++] = rd32(hw, reg); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | } |
| 768 | |
| 769 | static int i40e_get_eeprom(struct net_device *netdev, |
| 770 | struct ethtool_eeprom *eeprom, u8 *bytes) |
| 771 | { |
| 772 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 773 | struct i40e_hw *hw = &np->vsi->back->hw; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 774 | struct i40e_pf *pf = np->vsi->back; |
| 775 | int ret_val = 0, len; |
| 776 | u8 *eeprom_buff; |
| 777 | u16 i, sectors; |
| 778 | bool last; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 779 | u32 magic; |
| 780 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 781 | #define I40E_NVM_SECTOR_SIZE 4096 |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 782 | if (eeprom->len == 0) |
| 783 | return -EINVAL; |
| 784 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 785 | /* check for NVMUpdate access method */ |
| 786 | magic = hw->vendor_id | (hw->device_id << 16); |
| 787 | if (eeprom->magic && eeprom->magic != magic) { |
| 788 | int errno; |
| 789 | |
| 790 | /* make sure it is the right magic for NVMUpdate */ |
| 791 | if ((eeprom->magic >> 16) != hw->device_id) |
| 792 | return -EINVAL; |
| 793 | |
| 794 | ret_val = i40e_nvmupd_command(hw, |
| 795 | (struct i40e_nvm_access *)eeprom, |
| 796 | bytes, &errno); |
| 797 | if (ret_val) |
| 798 | dev_info(&pf->pdev->dev, |
| 799 | "NVMUpdate read failed err=%d status=0x%x\n", |
| 800 | ret_val, hw->aq.asq_last_status); |
| 801 | |
| 802 | return errno; |
| 803 | } |
| 804 | |
| 805 | /* normal ethtool get_eeprom support */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 806 | eeprom->magic = hw->vendor_id | (hw->device_id << 16); |
| 807 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 808 | eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 809 | if (!eeprom_buff) |
| 810 | return -ENOMEM; |
| 811 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 812 | ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ); |
| 813 | if (ret_val) { |
| 814 | dev_info(&pf->pdev->dev, |
| 815 | "Failed Acquiring NVM resource for read err=%d status=0x%x\n", |
| 816 | ret_val, hw->aq.asq_last_status); |
| 817 | goto free_buff; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 820 | sectors = eeprom->len / I40E_NVM_SECTOR_SIZE; |
| 821 | sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0; |
| 822 | len = I40E_NVM_SECTOR_SIZE; |
| 823 | last = false; |
| 824 | for (i = 0; i < sectors; i++) { |
| 825 | if (i == (sectors - 1)) { |
| 826 | len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i); |
| 827 | last = true; |
| 828 | } |
| 829 | ret_val = i40e_aq_read_nvm(hw, 0x0, |
| 830 | eeprom->offset + (I40E_NVM_SECTOR_SIZE * i), |
| 831 | len, |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 832 | (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i), |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 833 | last, NULL); |
| 834 | if (ret_val) { |
| 835 | dev_info(&pf->pdev->dev, |
| 836 | "read NVM failed err=%d status=0x%x\n", |
| 837 | ret_val, hw->aq.asq_last_status); |
| 838 | goto release_nvm; |
| 839 | } |
| 840 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 841 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 842 | release_nvm: |
| 843 | i40e_release_nvm(hw); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 844 | memcpy(bytes, (u8 *)eeprom_buff, eeprom->len); |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 845 | free_buff: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 846 | kfree(eeprom_buff); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 847 | return ret_val; |
| 848 | } |
| 849 | |
| 850 | static int i40e_get_eeprom_len(struct net_device *netdev) |
| 851 | { |
| 852 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 853 | struct i40e_hw *hw = &np->vsi->back->hw; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 854 | u32 val; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 855 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 856 | val = (rd32(hw, I40E_GLPCI_LBARCTRL) |
| 857 | & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK) |
| 858 | >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT; |
| 859 | /* register returns value in power of 2, 64Kbyte chunks. */ |
| 860 | val = (64 * 1024) * (1 << val); |
| 861 | return val; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 864 | static int i40e_set_eeprom(struct net_device *netdev, |
| 865 | struct ethtool_eeprom *eeprom, u8 *bytes) |
| 866 | { |
| 867 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 868 | struct i40e_hw *hw = &np->vsi->back->hw; |
| 869 | struct i40e_pf *pf = np->vsi->back; |
| 870 | int ret_val = 0; |
| 871 | int errno; |
| 872 | u32 magic; |
| 873 | |
| 874 | /* normal ethtool set_eeprom is not supported */ |
| 875 | magic = hw->vendor_id | (hw->device_id << 16); |
| 876 | if (eeprom->magic == magic) |
| 877 | return -EOPNOTSUPP; |
| 878 | |
| 879 | /* check for NVMUpdate access method */ |
| 880 | if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id) |
| 881 | return -EINVAL; |
| 882 | |
| 883 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 884 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 885 | return -EBUSY; |
| 886 | |
| 887 | ret_val = i40e_nvmupd_command(hw, (struct i40e_nvm_access *)eeprom, |
| 888 | bytes, &errno); |
| 889 | if (ret_val) |
| 890 | dev_info(&pf->pdev->dev, |
| 891 | "NVMUpdate write failed err=%d status=0x%x\n", |
| 892 | ret_val, hw->aq.asq_last_status); |
| 893 | |
| 894 | return errno; |
| 895 | } |
| 896 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 897 | static void i40e_get_drvinfo(struct net_device *netdev, |
| 898 | struct ethtool_drvinfo *drvinfo) |
| 899 | { |
| 900 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 901 | struct i40e_vsi *vsi = np->vsi; |
| 902 | struct i40e_pf *pf = vsi->back; |
| 903 | |
| 904 | strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver)); |
| 905 | strlcpy(drvinfo->version, i40e_driver_version_str, |
| 906 | sizeof(drvinfo->version)); |
| 907 | strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw), |
| 908 | sizeof(drvinfo->fw_version)); |
| 909 | strlcpy(drvinfo->bus_info, pci_name(pf->pdev), |
| 910 | sizeof(drvinfo->bus_info)); |
| 911 | } |
| 912 | |
| 913 | static void i40e_get_ringparam(struct net_device *netdev, |
| 914 | struct ethtool_ringparam *ring) |
| 915 | { |
| 916 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 917 | struct i40e_pf *pf = np->vsi->back; |
| 918 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 919 | |
| 920 | ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS; |
| 921 | ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS; |
| 922 | ring->rx_mini_max_pending = 0; |
| 923 | ring->rx_jumbo_max_pending = 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 924 | ring->rx_pending = vsi->rx_rings[0]->count; |
| 925 | ring->tx_pending = vsi->tx_rings[0]->count; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 926 | ring->rx_mini_pending = 0; |
| 927 | ring->rx_jumbo_pending = 0; |
| 928 | } |
| 929 | |
| 930 | static int i40e_set_ringparam(struct net_device *netdev, |
| 931 | struct ethtool_ringparam *ring) |
| 932 | { |
| 933 | struct i40e_ring *tx_rings = NULL, *rx_rings = NULL; |
| 934 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 935 | struct i40e_vsi *vsi = np->vsi; |
| 936 | struct i40e_pf *pf = vsi->back; |
| 937 | u32 new_rx_count, new_tx_count; |
| 938 | int i, err = 0; |
| 939 | |
| 940 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 941 | return -EINVAL; |
| 942 | |
Shannon Nelson | 1fa1837 | 2013-11-20 10:03:08 +0000 | [diff] [blame] | 943 | if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS || |
| 944 | ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS || |
| 945 | ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS || |
| 946 | ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) { |
| 947 | netdev_info(netdev, |
| 948 | "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n", |
| 949 | ring->tx_pending, ring->rx_pending, |
| 950 | I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS); |
| 951 | return -EINVAL; |
| 952 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 953 | |
Shannon Nelson | 1fa1837 | 2013-11-20 10:03:08 +0000 | [diff] [blame] | 954 | new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 955 | new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 956 | |
| 957 | /* if nothing to do return success */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 958 | if ((new_tx_count == vsi->tx_rings[0]->count) && |
| 959 | (new_rx_count == vsi->rx_rings[0]->count)) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 960 | return 0; |
| 961 | |
| 962 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 963 | usleep_range(1000, 2000); |
| 964 | |
| 965 | if (!netif_running(vsi->netdev)) { |
| 966 | /* simple case - set for the next time the netdev is started */ |
| 967 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 968 | vsi->tx_rings[i]->count = new_tx_count; |
| 969 | vsi->rx_rings[i]->count = new_rx_count; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 970 | } |
| 971 | goto done; |
| 972 | } |
| 973 | |
| 974 | /* We can't just free everything and then setup again, |
| 975 | * because the ISRs in MSI-X mode get passed pointers |
| 976 | * to the Tx and Rx ring structs. |
| 977 | */ |
| 978 | |
| 979 | /* alloc updated Tx resources */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 980 | if (new_tx_count != vsi->tx_rings[0]->count) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 981 | netdev_info(netdev, |
| 982 | "Changing Tx descriptor count from %d to %d.\n", |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 983 | vsi->tx_rings[0]->count, new_tx_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 984 | tx_rings = kcalloc(vsi->alloc_queue_pairs, |
| 985 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 986 | if (!tx_rings) { |
| 987 | err = -ENOMEM; |
| 988 | goto done; |
| 989 | } |
| 990 | |
| 991 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 992 | /* clone ring and setup updated count */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 993 | tx_rings[i] = *vsi->tx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 994 | tx_rings[i].count = new_tx_count; |
| 995 | err = i40e_setup_tx_descriptors(&tx_rings[i]); |
| 996 | if (err) { |
| 997 | while (i) { |
| 998 | i--; |
| 999 | i40e_free_tx_resources(&tx_rings[i]); |
| 1000 | } |
| 1001 | kfree(tx_rings); |
| 1002 | tx_rings = NULL; |
| 1003 | |
| 1004 | goto done; |
| 1005 | } |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | /* alloc updated Rx resources */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1010 | if (new_rx_count != vsi->rx_rings[0]->count) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1011 | netdev_info(netdev, |
| 1012 | "Changing Rx descriptor count from %d to %d\n", |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1013 | vsi->rx_rings[0]->count, new_rx_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1014 | rx_rings = kcalloc(vsi->alloc_queue_pairs, |
| 1015 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 1016 | if (!rx_rings) { |
| 1017 | err = -ENOMEM; |
| 1018 | goto free_tx; |
| 1019 | } |
| 1020 | |
| 1021 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 1022 | /* clone ring and setup updated count */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1023 | rx_rings[i] = *vsi->rx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1024 | rx_rings[i].count = new_rx_count; |
| 1025 | err = i40e_setup_rx_descriptors(&rx_rings[i]); |
| 1026 | if (err) { |
| 1027 | while (i) { |
| 1028 | i--; |
| 1029 | i40e_free_rx_resources(&rx_rings[i]); |
| 1030 | } |
| 1031 | kfree(rx_rings); |
| 1032 | rx_rings = NULL; |
| 1033 | |
| 1034 | goto free_tx; |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | /* Bring interface down, copy in the new ring info, |
| 1040 | * then restore the interface |
| 1041 | */ |
| 1042 | i40e_down(vsi); |
| 1043 | |
| 1044 | if (tx_rings) { |
| 1045 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1046 | i40e_free_tx_resources(vsi->tx_rings[i]); |
| 1047 | *vsi->tx_rings[i] = tx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1048 | } |
| 1049 | kfree(tx_rings); |
| 1050 | tx_rings = NULL; |
| 1051 | } |
| 1052 | |
| 1053 | if (rx_rings) { |
| 1054 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1055 | i40e_free_rx_resources(vsi->rx_rings[i]); |
| 1056 | *vsi->rx_rings[i] = rx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1057 | } |
| 1058 | kfree(rx_rings); |
| 1059 | rx_rings = NULL; |
| 1060 | } |
| 1061 | |
| 1062 | i40e_up(vsi); |
| 1063 | |
| 1064 | free_tx: |
| 1065 | /* error cleanup if the Rx allocations failed after getting Tx */ |
| 1066 | if (tx_rings) { |
| 1067 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1068 | i40e_free_tx_resources(&tx_rings[i]); |
| 1069 | kfree(tx_rings); |
| 1070 | tx_rings = NULL; |
| 1071 | } |
| 1072 | |
| 1073 | done: |
| 1074 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 1075 | |
| 1076 | return err; |
| 1077 | } |
| 1078 | |
| 1079 | static int i40e_get_sset_count(struct net_device *netdev, int sset) |
| 1080 | { |
| 1081 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1082 | struct i40e_vsi *vsi = np->vsi; |
| 1083 | struct i40e_pf *pf = vsi->back; |
| 1084 | |
| 1085 | switch (sset) { |
| 1086 | case ETH_SS_TEST: |
| 1087 | return I40E_TEST_LEN; |
| 1088 | case ETH_SS_STATS: |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1089 | if (vsi == pf->vsi[pf->lan_vsi]) { |
| 1090 | int len = I40E_PF_STATS_LEN(netdev); |
| 1091 | |
| 1092 | if (pf->lan_veb != I40E_NO_VEB) |
| 1093 | len += I40E_VEB_STATS_LEN; |
| 1094 | return len; |
| 1095 | } else { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1096 | return I40E_VSI_STATS_LEN(netdev); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1097 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1098 | default: |
| 1099 | return -EOPNOTSUPP; |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | static void i40e_get_ethtool_stats(struct net_device *netdev, |
| 1104 | struct ethtool_stats *stats, u64 *data) |
| 1105 | { |
| 1106 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 1107 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1108 | struct i40e_vsi *vsi = np->vsi; |
| 1109 | struct i40e_pf *pf = vsi->back; |
| 1110 | int i = 0; |
| 1111 | char *p; |
| 1112 | int j; |
| 1113 | struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1114 | unsigned int start; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1115 | |
| 1116 | i40e_update_stats(vsi); |
| 1117 | |
| 1118 | for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) { |
| 1119 | p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset; |
| 1120 | data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat == |
| 1121 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1122 | } |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 1123 | for (j = 0; j < I40E_MISC_STATS_LEN; j++) { |
| 1124 | p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset; |
| 1125 | data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat == |
| 1126 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1127 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1128 | #ifdef I40E_FCOE |
| 1129 | for (j = 0; j < I40E_FCOE_STATS_LEN; j++) { |
| 1130 | p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset; |
| 1131 | data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat == |
| 1132 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1133 | } |
| 1134 | #endif |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1135 | rcu_read_lock(); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1136 | for (j = 0; j < vsi->num_queue_pairs; j++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 1137 | tx_ring = ACCESS_ONCE(vsi->tx_rings[j]); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1138 | |
| 1139 | if (!tx_ring) |
| 1140 | continue; |
| 1141 | |
| 1142 | /* process Tx ring statistics */ |
| 1143 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1144 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1145 | data[i] = tx_ring->stats.packets; |
| 1146 | data[i + 1] = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1147 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1148 | i += 2; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1149 | |
| 1150 | /* Rx ring is the 2nd half of the queue pair */ |
| 1151 | rx_ring = &tx_ring[1]; |
| 1152 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1153 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1154 | data[i] = rx_ring->stats.packets; |
| 1155 | data[i + 1] = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1156 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1157 | i += 2; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1158 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1159 | rcu_read_unlock(); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1160 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 1161 | return; |
| 1162 | |
| 1163 | if (pf->lan_veb != I40E_NO_VEB) { |
| 1164 | struct i40e_veb *veb = pf->veb[pf->lan_veb]; |
| 1165 | for (j = 0; j < I40E_VEB_STATS_LEN; j++) { |
| 1166 | p = (char *)veb; |
| 1167 | p += i40e_gstrings_veb_stats[j].stat_offset; |
| 1168 | data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat == |
| 1169 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1170 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1171 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1172 | for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) { |
| 1173 | p = (char *)pf + i40e_gstrings_stats[j].stat_offset; |
| 1174 | data[i++] = (i40e_gstrings_stats[j].sizeof_stat == |
| 1175 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1176 | } |
| 1177 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { |
| 1178 | data[i++] = pf->stats.priority_xon_tx[j]; |
| 1179 | data[i++] = pf->stats.priority_xoff_tx[j]; |
| 1180 | } |
| 1181 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { |
| 1182 | data[i++] = pf->stats.priority_xon_rx[j]; |
| 1183 | data[i++] = pf->stats.priority_xoff_rx[j]; |
| 1184 | } |
| 1185 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) |
| 1186 | data[i++] = pf->stats.priority_xon_2_xoff[j]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | static void i40e_get_strings(struct net_device *netdev, u32 stringset, |
| 1190 | u8 *data) |
| 1191 | { |
| 1192 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1193 | struct i40e_vsi *vsi = np->vsi; |
| 1194 | struct i40e_pf *pf = vsi->back; |
| 1195 | char *p = (char *)data; |
| 1196 | int i; |
| 1197 | |
| 1198 | switch (stringset) { |
| 1199 | case ETH_SS_TEST: |
| 1200 | for (i = 0; i < I40E_TEST_LEN; i++) { |
| 1201 | memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN); |
| 1202 | data += ETH_GSTRING_LEN; |
| 1203 | } |
| 1204 | break; |
| 1205 | case ETH_SS_STATS: |
| 1206 | for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) { |
| 1207 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 1208 | i40e_gstrings_net_stats[i].stat_string); |
| 1209 | p += ETH_GSTRING_LEN; |
| 1210 | } |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 1211 | for (i = 0; i < I40E_MISC_STATS_LEN; i++) { |
| 1212 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 1213 | i40e_gstrings_misc_stats[i].stat_string); |
| 1214 | p += ETH_GSTRING_LEN; |
| 1215 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1216 | #ifdef I40E_FCOE |
| 1217 | for (i = 0; i < I40E_FCOE_STATS_LEN; i++) { |
| 1218 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 1219 | i40e_gstrings_fcoe_stats[i].stat_string); |
| 1220 | p += ETH_GSTRING_LEN; |
| 1221 | } |
| 1222 | #endif |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1223 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 1224 | snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i); |
| 1225 | p += ETH_GSTRING_LEN; |
| 1226 | snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i); |
| 1227 | p += ETH_GSTRING_LEN; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1228 | snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i); |
| 1229 | p += ETH_GSTRING_LEN; |
| 1230 | snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i); |
| 1231 | p += ETH_GSTRING_LEN; |
| 1232 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1233 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 1234 | return; |
| 1235 | |
| 1236 | if (pf->lan_veb != I40E_NO_VEB) { |
| 1237 | for (i = 0; i < I40E_VEB_STATS_LEN; i++) { |
| 1238 | snprintf(p, ETH_GSTRING_LEN, "veb.%s", |
| 1239 | i40e_gstrings_veb_stats[i].stat_string); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1240 | p += ETH_GSTRING_LEN; |
| 1241 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1242 | } |
| 1243 | for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) { |
| 1244 | snprintf(p, ETH_GSTRING_LEN, "port.%s", |
| 1245 | i40e_gstrings_stats[i].stat_string); |
| 1246 | p += ETH_GSTRING_LEN; |
| 1247 | } |
| 1248 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 1249 | snprintf(p, ETH_GSTRING_LEN, |
| 1250 | "port.tx_priority_%u_xon", i); |
| 1251 | p += ETH_GSTRING_LEN; |
| 1252 | snprintf(p, ETH_GSTRING_LEN, |
| 1253 | "port.tx_priority_%u_xoff", i); |
| 1254 | p += ETH_GSTRING_LEN; |
| 1255 | } |
| 1256 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 1257 | snprintf(p, ETH_GSTRING_LEN, |
| 1258 | "port.rx_priority_%u_xon", i); |
| 1259 | p += ETH_GSTRING_LEN; |
| 1260 | snprintf(p, ETH_GSTRING_LEN, |
| 1261 | "port.rx_priority_%u_xoff", i); |
| 1262 | p += ETH_GSTRING_LEN; |
| 1263 | } |
| 1264 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 1265 | snprintf(p, ETH_GSTRING_LEN, |
| 1266 | "port.rx_priority_%u_xon_2_xoff", i); |
| 1267 | p += ETH_GSTRING_LEN; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1268 | } |
| 1269 | /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */ |
| 1270 | break; |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | static int i40e_get_ts_info(struct net_device *dev, |
| 1275 | struct ethtool_ts_info *info) |
| 1276 | { |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1277 | struct i40e_pf *pf = i40e_netdev_to_pf(dev); |
| 1278 | |
| 1279 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 1280 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1281 | SOF_TIMESTAMPING_SOFTWARE | |
| 1282 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 1283 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 1284 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 1285 | |
| 1286 | if (pf->ptp_clock) |
| 1287 | info->phc_index = ptp_clock_index(pf->ptp_clock); |
| 1288 | else |
| 1289 | info->phc_index = -1; |
| 1290 | |
| 1291 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); |
| 1292 | |
| 1293 | info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 1294 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | |
| 1295 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | |
| 1296 | (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) | |
| 1297 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | |
| 1298 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | |
| 1299 | (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) | |
| 1300 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) | |
| 1301 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | |
| 1302 | (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | |
| 1303 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) | |
| 1304 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ); |
| 1305 | |
| 1306 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1309 | static int i40e_link_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1310 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1311 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1312 | struct i40e_pf *pf = np->vsi->back; |
| 1313 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1314 | netif_info(pf, hw, netdev, "link test\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1315 | if (i40e_get_link_status(&pf->hw)) |
| 1316 | *data = 0; |
| 1317 | else |
| 1318 | *data = 1; |
| 1319 | |
| 1320 | return *data; |
| 1321 | } |
| 1322 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1323 | static int i40e_reg_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1324 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1325 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1326 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1327 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1328 | netif_info(pf, hw, netdev, "register test\n"); |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1329 | *data = i40e_diag_reg_test(&pf->hw); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1330 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1331 | return *data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1334 | static int i40e_eeprom_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1335 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1336 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1337 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1338 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1339 | netif_info(pf, hw, netdev, "eeprom test\n"); |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1340 | *data = i40e_diag_eeprom_test(&pf->hw); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1341 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1342 | return *data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1345 | static int i40e_intr_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1346 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1347 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1348 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1349 | u16 swc_old = pf->sw_int_count; |
| 1350 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1351 | netif_info(pf, hw, netdev, "interrupt test\n"); |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1352 | wr32(&pf->hw, I40E_PFINT_DYN_CTL0, |
| 1353 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 1354 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK)); |
| 1355 | usleep_range(1000, 2000); |
| 1356 | *data = (swc_old == pf->sw_int_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1357 | |
| 1358 | return *data; |
| 1359 | } |
| 1360 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1361 | static int i40e_loopback_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1362 | { |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1363 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1364 | struct i40e_pf *pf = np->vsi->back; |
| 1365 | |
| 1366 | netif_info(pf, hw, netdev, "loopback test not implemented\n"); |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1367 | *data = 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1368 | |
| 1369 | return *data; |
| 1370 | } |
| 1371 | |
| 1372 | static void i40e_diag_test(struct net_device *netdev, |
| 1373 | struct ethtool_test *eth_test, u64 *data) |
| 1374 | { |
| 1375 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1376 | struct i40e_pf *pf = np->vsi->back; |
| 1377 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1378 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
| 1379 | /* Offline tests */ |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1380 | netif_info(pf, drv, netdev, "offline testing starting\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1381 | |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1382 | set_bit(__I40E_TESTING, &pf->state); |
| 1383 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1384 | /* Link test performed before hardware reset |
| 1385 | * so autoneg doesn't interfere with test result |
| 1386 | */ |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1387 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1388 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1389 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1390 | if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1391 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1392 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1393 | if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1394 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1395 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1396 | if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1397 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1398 | |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1399 | /* run reg test last, a reset is required after it */ |
| 1400 | if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG])) |
| 1401 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1402 | |
| 1403 | clear_bit(__I40E_TESTING, &pf->state); |
| 1404 | i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1405 | } else { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1406 | /* Online tests */ |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1407 | netif_info(pf, drv, netdev, "online testing starting\n"); |
| 1408 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1409 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1410 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1411 | |
| 1412 | /* Offline only tests, not run in online; pass by default */ |
| 1413 | data[I40E_ETH_TEST_REG] = 0; |
| 1414 | data[I40E_ETH_TEST_EEPROM] = 0; |
| 1415 | data[I40E_ETH_TEST_INTR] = 0; |
| 1416 | data[I40E_ETH_TEST_LOOPBACK] = 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1417 | } |
Shannon Nelson | c140c17 | 2013-11-20 10:02:58 +0000 | [diff] [blame] | 1418 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1419 | netif_info(pf, drv, netdev, "testing finished\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | static void i40e_get_wol(struct net_device *netdev, |
| 1423 | struct ethtool_wolinfo *wol) |
| 1424 | { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1425 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1426 | struct i40e_pf *pf = np->vsi->back; |
| 1427 | struct i40e_hw *hw = &pf->hw; |
| 1428 | u16 wol_nvm_bits; |
| 1429 | |
| 1430 | /* NVM bit on means WoL disabled for the port */ |
| 1431 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); |
| 1432 | if ((1 << hw->port) & wol_nvm_bits) { |
| 1433 | wol->supported = 0; |
| 1434 | wol->wolopts = 0; |
| 1435 | } else { |
| 1436 | wol->supported = WAKE_MAGIC; |
| 1437 | wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0); |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 1442 | { |
| 1443 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1444 | struct i40e_pf *pf = np->vsi->back; |
| 1445 | struct i40e_hw *hw = &pf->hw; |
| 1446 | u16 wol_nvm_bits; |
| 1447 | |
| 1448 | /* NVM bit on means WoL disabled for the port */ |
| 1449 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); |
| 1450 | if (((1 << hw->port) & wol_nvm_bits)) |
| 1451 | return -EOPNOTSUPP; |
| 1452 | |
| 1453 | /* only magic packet is supported */ |
| 1454 | if (wol->wolopts && (wol->wolopts != WAKE_MAGIC)) |
| 1455 | return -EOPNOTSUPP; |
| 1456 | |
| 1457 | /* is this a new value? */ |
| 1458 | if (pf->wol_en != !!wol->wolopts) { |
| 1459 | pf->wol_en = !!wol->wolopts; |
| 1460 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 1461 | } |
| 1462 | |
| 1463 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1466 | static int i40e_set_phys_id(struct net_device *netdev, |
| 1467 | enum ethtool_phys_id_state state) |
| 1468 | { |
| 1469 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1470 | struct i40e_pf *pf = np->vsi->back; |
| 1471 | struct i40e_hw *hw = &pf->hw; |
| 1472 | int blink_freq = 2; |
| 1473 | |
| 1474 | switch (state) { |
| 1475 | case ETHTOOL_ID_ACTIVE: |
| 1476 | pf->led_status = i40e_led_get(hw); |
| 1477 | return blink_freq; |
| 1478 | case ETHTOOL_ID_ON: |
Jesse Brandeburg | 0556a9e | 2013-11-28 06:39:33 +0000 | [diff] [blame] | 1479 | i40e_led_set(hw, 0xF, false); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1480 | break; |
| 1481 | case ETHTOOL_ID_OFF: |
Jesse Brandeburg | 0556a9e | 2013-11-28 06:39:33 +0000 | [diff] [blame] | 1482 | i40e_led_set(hw, 0x0, false); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1483 | break; |
| 1484 | case ETHTOOL_ID_INACTIVE: |
Jesse Brandeburg | 0556a9e | 2013-11-28 06:39:33 +0000 | [diff] [blame] | 1485 | i40e_led_set(hw, pf->led_status, false); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1486 | break; |
| 1487 | } |
| 1488 | |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt |
| 1493 | * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also |
| 1494 | * 125us (8000 interrupts per second) == ITR(62) |
| 1495 | */ |
| 1496 | |
| 1497 | static int i40e_get_coalesce(struct net_device *netdev, |
| 1498 | struct ethtool_coalesce *ec) |
| 1499 | { |
| 1500 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1501 | struct i40e_vsi *vsi = np->vsi; |
| 1502 | |
| 1503 | ec->tx_max_coalesced_frames_irq = vsi->work_limit; |
| 1504 | ec->rx_max_coalesced_frames_irq = vsi->work_limit; |
| 1505 | |
| 1506 | if (ITR_IS_DYNAMIC(vsi->rx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1507 | ec->use_adaptive_rx_coalesce = 1; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1508 | |
| 1509 | if (ITR_IS_DYNAMIC(vsi->tx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1510 | ec->use_adaptive_tx_coalesce = 1; |
| 1511 | |
| 1512 | ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC; |
| 1513 | ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1514 | |
| 1515 | return 0; |
| 1516 | } |
| 1517 | |
| 1518 | static int i40e_set_coalesce(struct net_device *netdev, |
| 1519 | struct ethtool_coalesce *ec) |
| 1520 | { |
| 1521 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1522 | struct i40e_q_vector *q_vector; |
| 1523 | struct i40e_vsi *vsi = np->vsi; |
| 1524 | struct i40e_pf *pf = vsi->back; |
| 1525 | struct i40e_hw *hw = &pf->hw; |
| 1526 | u16 vector; |
| 1527 | int i; |
| 1528 | |
| 1529 | if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq) |
| 1530 | vsi->work_limit = ec->tx_max_coalesced_frames_irq; |
| 1531 | |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1532 | vector = vsi->base_vector; |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1533 | if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) && |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1534 | (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1535 | vsi->rx_itr_setting = ec->rx_coalesce_usecs; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1536 | } else if (ec->rx_coalesce_usecs == 0) { |
| 1537 | vsi->rx_itr_setting = ec->rx_coalesce_usecs; |
| 1538 | i40e_irq_dynamic_disable(vsi, vector); |
| 1539 | if (ec->use_adaptive_rx_coalesce) |
| 1540 | netif_info(pf, drv, netdev, |
| 1541 | "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n"); |
| 1542 | } else { |
| 1543 | netif_info(pf, drv, netdev, |
| 1544 | "Invalid value, Rx-usecs range is 0, 8-8160\n"); |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1545 | return -EINVAL; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1546 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1547 | |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1548 | if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) && |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1549 | (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1550 | vsi->tx_itr_setting = ec->tx_coalesce_usecs; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1551 | } else if (ec->tx_coalesce_usecs == 0) { |
| 1552 | vsi->tx_itr_setting = ec->tx_coalesce_usecs; |
| 1553 | i40e_irq_dynamic_disable(vsi, vector); |
| 1554 | if (ec->use_adaptive_tx_coalesce) |
| 1555 | netif_info(pf, drv, netdev, |
| 1556 | "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n"); |
| 1557 | } else { |
| 1558 | netif_info(pf, drv, netdev, |
| 1559 | "Invalid value, Tx-usecs range is 0, 8-8160\n"); |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1560 | return -EINVAL; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1561 | } |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1562 | |
| 1563 | if (ec->use_adaptive_rx_coalesce) |
| 1564 | vsi->rx_itr_setting |= I40E_ITR_DYNAMIC; |
| 1565 | else |
| 1566 | vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC; |
| 1567 | |
| 1568 | if (ec->use_adaptive_tx_coalesce) |
| 1569 | vsi->tx_itr_setting |= I40E_ITR_DYNAMIC; |
| 1570 | else |
| 1571 | vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1572 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 1573 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
| 1574 | q_vector = vsi->q_vectors[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1575 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 1576 | wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr); |
| 1577 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 1578 | wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr); |
| 1579 | i40e_flush(hw); |
| 1580 | } |
| 1581 | |
| 1582 | return 0; |
| 1583 | } |
| 1584 | |
| 1585 | /** |
| 1586 | * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type |
| 1587 | * @pf: pointer to the physical function struct |
| 1588 | * @cmd: ethtool rxnfc command |
| 1589 | * |
| 1590 | * Returns Success if the flow is supported, else Invalid Input. |
| 1591 | **/ |
| 1592 | static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd) |
| 1593 | { |
| 1594 | cmd->data = 0; |
| 1595 | |
| 1596 | /* Report default options for RSS on i40e */ |
| 1597 | switch (cmd->flow_type) { |
| 1598 | case TCP_V4_FLOW: |
| 1599 | case UDP_V4_FLOW: |
| 1600 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 1601 | /* fall through to add IP fields */ |
| 1602 | case SCTP_V4_FLOW: |
| 1603 | case AH_ESP_V4_FLOW: |
| 1604 | case AH_V4_FLOW: |
| 1605 | case ESP_V4_FLOW: |
| 1606 | case IPV4_FLOW: |
| 1607 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; |
| 1608 | break; |
| 1609 | case TCP_V6_FLOW: |
| 1610 | case UDP_V6_FLOW: |
| 1611 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 1612 | /* fall through to add IP fields */ |
| 1613 | case SCTP_V6_FLOW: |
| 1614 | case AH_ESP_V6_FLOW: |
| 1615 | case AH_V6_FLOW: |
| 1616 | case ESP_V6_FLOW: |
| 1617 | case IPV6_FLOW: |
| 1618 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; |
| 1619 | break; |
| 1620 | default: |
| 1621 | return -EINVAL; |
| 1622 | } |
| 1623 | |
| 1624 | return 0; |
| 1625 | } |
| 1626 | |
| 1627 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1628 | * i40e_get_ethtool_fdir_all - Populates the rule count of a command |
| 1629 | * @pf: Pointer to the physical function struct |
| 1630 | * @cmd: The command to get or set Rx flow classification rules |
| 1631 | * @rule_locs: Array of used rule locations |
| 1632 | * |
| 1633 | * This function populates both the total and actual rule count of |
| 1634 | * the ethtool flow classification command |
| 1635 | * |
| 1636 | * Returns 0 on success or -EMSGSIZE if entry not found |
| 1637 | **/ |
| 1638 | static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf, |
| 1639 | struct ethtool_rxnfc *cmd, |
| 1640 | u32 *rule_locs) |
| 1641 | { |
| 1642 | struct i40e_fdir_filter *rule; |
| 1643 | struct hlist_node *node2; |
| 1644 | int cnt = 0; |
| 1645 | |
| 1646 | /* report total rule count */ |
Anjali Singhai Jain | 082def1 | 2014-04-09 05:59:00 +0000 | [diff] [blame] | 1647 | cmd->data = i40e_get_fd_cnt_all(pf); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1648 | |
| 1649 | hlist_for_each_entry_safe(rule, node2, |
| 1650 | &pf->fdir_filter_list, fdir_node) { |
| 1651 | if (cnt == cmd->rule_cnt) |
| 1652 | return -EMSGSIZE; |
| 1653 | |
| 1654 | rule_locs[cnt] = rule->fd_id; |
| 1655 | cnt++; |
| 1656 | } |
| 1657 | |
| 1658 | cmd->rule_cnt = cnt; |
| 1659 | |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
| 1663 | /** |
| 1664 | * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow |
| 1665 | * @pf: Pointer to the physical function struct |
| 1666 | * @cmd: The command to get or set Rx flow classification rules |
| 1667 | * |
| 1668 | * This function looks up a filter based on the Rx flow classification |
| 1669 | * command and fills the flow spec info for it if found |
| 1670 | * |
| 1671 | * Returns 0 on success or -EINVAL if filter not found |
| 1672 | **/ |
| 1673 | static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf, |
| 1674 | struct ethtool_rxnfc *cmd) |
| 1675 | { |
| 1676 | struct ethtool_rx_flow_spec *fsp = |
| 1677 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 1678 | struct i40e_fdir_filter *rule = NULL; |
| 1679 | struct hlist_node *node2; |
| 1680 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1681 | hlist_for_each_entry_safe(rule, node2, |
| 1682 | &pf->fdir_filter_list, fdir_node) { |
| 1683 | if (fsp->location <= rule->fd_id) |
| 1684 | break; |
| 1685 | } |
| 1686 | |
| 1687 | if (!rule || fsp->location != rule->fd_id) |
| 1688 | return -EINVAL; |
| 1689 | |
| 1690 | fsp->flow_type = rule->flow_type; |
Anjali Singhai Jain | 7d54eb2 | 2014-03-14 07:32:21 +0000 | [diff] [blame] | 1691 | if (fsp->flow_type == IP_USER_FLOW) { |
| 1692 | fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; |
| 1693 | fsp->h_u.usr_ip4_spec.proto = 0; |
| 1694 | fsp->m_u.usr_ip4_spec.proto = 0; |
| 1695 | } |
| 1696 | |
Anjali Singhai Jain | 04b73bd | 2014-05-22 06:31:41 +0000 | [diff] [blame] | 1697 | /* Reverse the src and dest notion, since the HW views them from |
| 1698 | * Tx perspective where as the user expects it from Rx filter view. |
| 1699 | */ |
| 1700 | fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port; |
| 1701 | fsp->h_u.tcp_ip4_spec.pdst = rule->src_port; |
| 1702 | fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0]; |
| 1703 | fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0]; |
Anjali Singhai Jain | 387ce1a | 2014-05-22 06:32:23 +0000 | [diff] [blame] | 1704 | |
| 1705 | if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET) |
| 1706 | fsp->ring_cookie = RX_CLS_FLOW_DISC; |
| 1707 | else |
| 1708 | fsp->ring_cookie = rule->q_index; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1709 | |
| 1710 | return 0; |
| 1711 | } |
| 1712 | |
| 1713 | /** |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1714 | * i40e_get_rxnfc - command to get RX flow classification rules |
| 1715 | * @netdev: network interface device structure |
| 1716 | * @cmd: ethtool rxnfc command |
| 1717 | * |
| 1718 | * Returns Success if the command is supported. |
| 1719 | **/ |
| 1720 | static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, |
| 1721 | u32 *rule_locs) |
| 1722 | { |
| 1723 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1724 | struct i40e_vsi *vsi = np->vsi; |
| 1725 | struct i40e_pf *pf = vsi->back; |
| 1726 | int ret = -EOPNOTSUPP; |
| 1727 | |
| 1728 | switch (cmd->cmd) { |
| 1729 | case ETHTOOL_GRXRINGS: |
| 1730 | cmd->data = vsi->alloc_queue_pairs; |
| 1731 | ret = 0; |
| 1732 | break; |
| 1733 | case ETHTOOL_GRXFH: |
| 1734 | ret = i40e_get_rss_hash_opts(pf, cmd); |
| 1735 | break; |
| 1736 | case ETHTOOL_GRXCLSRLCNT: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1737 | cmd->rule_cnt = pf->fdir_pf_active_filters; |
Anjali Singhai Jain | 082def1 | 2014-04-09 05:59:00 +0000 | [diff] [blame] | 1738 | /* report total rule count */ |
| 1739 | cmd->data = i40e_get_fd_cnt_all(pf); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1740 | ret = 0; |
| 1741 | break; |
| 1742 | case ETHTOOL_GRXCLSRULE: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1743 | ret = i40e_get_ethtool_fdir_entry(pf, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1744 | break; |
| 1745 | case ETHTOOL_GRXCLSRLALL: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1746 | ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs); |
| 1747 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1748 | default: |
| 1749 | break; |
| 1750 | } |
| 1751 | |
| 1752 | return ret; |
| 1753 | } |
| 1754 | |
| 1755 | /** |
| 1756 | * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash |
| 1757 | * @pf: pointer to the physical function struct |
| 1758 | * @cmd: ethtool rxnfc command |
| 1759 | * |
| 1760 | * Returns Success if the flow input set is supported. |
| 1761 | **/ |
| 1762 | static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc) |
| 1763 | { |
| 1764 | struct i40e_hw *hw = &pf->hw; |
| 1765 | u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | |
| 1766 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); |
| 1767 | |
| 1768 | /* RSS does not support anything other than hashing |
| 1769 | * to queues on src and dst IPs and ports |
| 1770 | */ |
| 1771 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | |
| 1772 | RXH_L4_B_0_1 | RXH_L4_B_2_3)) |
| 1773 | return -EINVAL; |
| 1774 | |
| 1775 | /* We need at least the IP SRC and DEST fields for hashing */ |
| 1776 | if (!(nfc->data & RXH_IP_SRC) || |
| 1777 | !(nfc->data & RXH_IP_DST)) |
| 1778 | return -EINVAL; |
| 1779 | |
| 1780 | switch (nfc->flow_type) { |
| 1781 | case TCP_V4_FLOW: |
| 1782 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 1783 | case 0: |
| 1784 | hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP); |
| 1785 | break; |
| 1786 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 1787 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP); |
| 1788 | break; |
| 1789 | default: |
| 1790 | return -EINVAL; |
| 1791 | } |
| 1792 | break; |
| 1793 | case TCP_V6_FLOW: |
| 1794 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 1795 | case 0: |
| 1796 | hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP); |
| 1797 | break; |
| 1798 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 1799 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP); |
| 1800 | break; |
| 1801 | default: |
| 1802 | return -EINVAL; |
| 1803 | } |
| 1804 | break; |
| 1805 | case UDP_V4_FLOW: |
| 1806 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 1807 | case 0: |
Kevin Scott | b2d36c0 | 2014-04-09 05:58:59 +0000 | [diff] [blame] | 1808 | hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | |
| 1809 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1810 | break; |
| 1811 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
Kevin Scott | b2d36c0 | 2014-04-09 05:58:59 +0000 | [diff] [blame] | 1812 | hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | |
| 1813 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1814 | break; |
| 1815 | default: |
| 1816 | return -EINVAL; |
| 1817 | } |
| 1818 | break; |
| 1819 | case UDP_V6_FLOW: |
| 1820 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 1821 | case 0: |
Kevin Scott | b2d36c0 | 2014-04-09 05:58:59 +0000 | [diff] [blame] | 1822 | hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | |
| 1823 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1824 | break; |
| 1825 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
Kevin Scott | b2d36c0 | 2014-04-09 05:58:59 +0000 | [diff] [blame] | 1826 | hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | |
| 1827 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1828 | break; |
| 1829 | default: |
| 1830 | return -EINVAL; |
| 1831 | } |
| 1832 | break; |
| 1833 | case AH_ESP_V4_FLOW: |
| 1834 | case AH_V4_FLOW: |
| 1835 | case ESP_V4_FLOW: |
| 1836 | case SCTP_V4_FLOW: |
| 1837 | if ((nfc->data & RXH_L4_B_0_1) || |
| 1838 | (nfc->data & RXH_L4_B_2_3)) |
| 1839 | return -EINVAL; |
| 1840 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER); |
| 1841 | break; |
| 1842 | case AH_ESP_V6_FLOW: |
| 1843 | case AH_V6_FLOW: |
| 1844 | case ESP_V6_FLOW: |
| 1845 | case SCTP_V6_FLOW: |
| 1846 | if ((nfc->data & RXH_L4_B_0_1) || |
| 1847 | (nfc->data & RXH_L4_B_2_3)) |
| 1848 | return -EINVAL; |
| 1849 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER); |
| 1850 | break; |
| 1851 | case IPV4_FLOW: |
| 1852 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | |
| 1853 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4); |
| 1854 | break; |
| 1855 | case IPV6_FLOW: |
| 1856 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | |
| 1857 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6); |
| 1858 | break; |
| 1859 | default: |
| 1860 | return -EINVAL; |
| 1861 | } |
| 1862 | |
| 1863 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 1864 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
| 1865 | i40e_flush(hw); |
| 1866 | |
| 1867 | return 0; |
| 1868 | } |
| 1869 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1870 | /** |
Anjali Singhai Jain | 43fddb7 | 2014-02-11 08:24:09 +0000 | [diff] [blame] | 1871 | * i40e_match_fdir_input_set - Match a new filter against an existing one |
| 1872 | * @rule: The filter already added |
| 1873 | * @input: The new filter to comapre against |
| 1874 | * |
| 1875 | * Returns true if the two input set match |
| 1876 | **/ |
| 1877 | static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule, |
| 1878 | struct i40e_fdir_filter *input) |
| 1879 | { |
| 1880 | if ((rule->dst_ip[0] != input->dst_ip[0]) || |
| 1881 | (rule->src_ip[0] != input->src_ip[0]) || |
| 1882 | (rule->dst_port != input->dst_port) || |
| 1883 | (rule->src_port != input->src_port)) |
| 1884 | return false; |
| 1885 | return true; |
| 1886 | } |
| 1887 | |
| 1888 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1889 | * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry |
| 1890 | * @vsi: Pointer to the targeted VSI |
| 1891 | * @input: The filter to update or NULL to indicate deletion |
| 1892 | * @sw_idx: Software index to the filter |
| 1893 | * @cmd: The command to get or set Rx flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1894 | * |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1895 | * This function updates (or deletes) a Flow Director entry from |
| 1896 | * the hlist of the corresponding PF |
| 1897 | * |
| 1898 | * Returns 0 on success |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1899 | **/ |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1900 | static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi, |
| 1901 | struct i40e_fdir_filter *input, |
| 1902 | u16 sw_idx, |
| 1903 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1904 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1905 | struct i40e_fdir_filter *rule, *parent; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1906 | struct i40e_pf *pf = vsi->back; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1907 | struct hlist_node *node2; |
| 1908 | int err = -EINVAL; |
Jesse Brandeburg | c35a1d7 | 2013-12-18 13:46:02 +0000 | [diff] [blame] | 1909 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1910 | parent = NULL; |
| 1911 | rule = NULL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1912 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1913 | hlist_for_each_entry_safe(rule, node2, |
| 1914 | &pf->fdir_filter_list, fdir_node) { |
| 1915 | /* hash found, or no matching entry */ |
| 1916 | if (rule->fd_id >= sw_idx) |
| 1917 | break; |
| 1918 | parent = rule; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1921 | /* if there is an old rule occupying our place remove it */ |
| 1922 | if (rule && (rule->fd_id == sw_idx)) { |
Anjali Singhai Jain | 43fddb7 | 2014-02-11 08:24:09 +0000 | [diff] [blame] | 1923 | if (input && !i40e_match_fdir_input_set(rule, input)) |
| 1924 | err = i40e_add_del_fdir(vsi, rule, false); |
| 1925 | else if (!input) |
| 1926 | err = i40e_add_del_fdir(vsi, rule, false); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1927 | hlist_del(&rule->fdir_node); |
| 1928 | kfree(rule); |
| 1929 | pf->fdir_pf_active_filters--; |
| 1930 | } |
| 1931 | |
| 1932 | /* If no input this was a delete, err should be 0 if a rule was |
| 1933 | * successfully found and removed from the list else -EINVAL |
| 1934 | */ |
| 1935 | if (!input) |
| 1936 | return err; |
| 1937 | |
| 1938 | /* initialize node and set software index */ |
| 1939 | INIT_HLIST_NODE(&input->fdir_node); |
| 1940 | |
| 1941 | /* add filter to the list */ |
| 1942 | if (parent) |
Ken Helias | 1d02328 | 2014-08-06 16:09:16 -0700 | [diff] [blame] | 1943 | hlist_add_behind(&input->fdir_node, &parent->fdir_node); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1944 | else |
| 1945 | hlist_add_head(&input->fdir_node, |
| 1946 | &pf->fdir_filter_list); |
| 1947 | |
| 1948 | /* update counts */ |
| 1949 | pf->fdir_pf_active_filters++; |
| 1950 | |
| 1951 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1955 | * i40e_del_fdir_entry - Deletes a Flow Director filter entry |
| 1956 | * @vsi: Pointer to the targeted VSI |
| 1957 | * @cmd: The command to get or set Rx flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1958 | * |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1959 | * The function removes a Flow Director filter entry from the |
| 1960 | * hlist of the corresponding PF |
| 1961 | * |
| 1962 | * Returns 0 on success |
| 1963 | */ |
| 1964 | static int i40e_del_fdir_entry(struct i40e_vsi *vsi, |
| 1965 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1966 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1967 | struct ethtool_rx_flow_spec *fsp = |
| 1968 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1969 | struct i40e_pf *pf = vsi->back; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1970 | int ret = 0; |
Jesse Brandeburg | c35a1d7 | 2013-12-18 13:46:02 +0000 | [diff] [blame] | 1971 | |
Anjali Singhai Jain | 60793f4a | 2014-07-09 07:46:23 +0000 | [diff] [blame] | 1972 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 1973 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 1974 | return -EBUSY; |
| 1975 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 1976 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 1977 | return -EBUSY; |
| 1978 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1979 | ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1980 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 1981 | i40e_fdir_check_and_reenable(pf); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1982 | return ret; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | /** |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1986 | * i40e_add_fdir_ethtool - Add/Remove Flow Director filters |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1987 | * @vsi: pointer to the targeted VSI |
| 1988 | * @cmd: command to get or set RX flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1989 | * |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1990 | * Add Flow Director filters for a specific flow spec based on their |
| 1991 | * protocol. Returns 0 if the filters were successfully added. |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1992 | **/ |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1993 | static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, |
| 1994 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1995 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1996 | struct ethtool_rx_flow_spec *fsp; |
| 1997 | struct i40e_fdir_filter *input; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1998 | struct i40e_pf *pf; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1999 | int ret = -EINVAL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2000 | |
| 2001 | if (!vsi) |
| 2002 | return -EINVAL; |
| 2003 | |
| 2004 | pf = vsi->back; |
| 2005 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2006 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 2007 | return -EOPNOTSUPP; |
| 2008 | |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 2009 | if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2010 | return -ENOSPC; |
| 2011 | |
Anjali Singhai Jain | 60793f4a | 2014-07-09 07:46:23 +0000 | [diff] [blame] | 2012 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 2013 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 2014 | return -EBUSY; |
| 2015 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 2016 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 2017 | return -EBUSY; |
| 2018 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2019 | fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 2020 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2021 | if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort + |
| 2022 | pf->hw.func_caps.fd_filters_guaranteed)) { |
| 2023 | return -EINVAL; |
| 2024 | } |
| 2025 | |
Anjali Singhai Jain | 387ce1a | 2014-05-22 06:32:23 +0000 | [diff] [blame] | 2026 | if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) && |
| 2027 | (fsp->ring_cookie >= vsi->num_queue_pairs)) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2028 | return -EINVAL; |
| 2029 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2030 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2031 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2032 | if (!input) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2033 | return -ENOMEM; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2034 | |
| 2035 | input->fd_id = fsp->location; |
| 2036 | |
Anjali Singhai Jain | 35a91fd | 2014-03-06 09:00:00 +0000 | [diff] [blame] | 2037 | if (fsp->ring_cookie == RX_CLS_FLOW_DISC) |
| 2038 | input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET; |
| 2039 | else |
| 2040 | input->dest_ctl = |
| 2041 | I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX; |
| 2042 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2043 | input->q_index = fsp->ring_cookie; |
| 2044 | input->flex_off = 0; |
| 2045 | input->pctype = 0; |
| 2046 | input->dest_vsi = vsi->id; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2047 | input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID; |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 2048 | input->cnt_index = pf->fd_sb_cnt_idx; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2049 | input->flow_type = fsp->flow_type; |
| 2050 | input->ip4_proto = fsp->h_u.usr_ip4_spec.proto; |
Anjali Singhai Jain | 04b73bd | 2014-05-22 06:31:41 +0000 | [diff] [blame] | 2051 | |
| 2052 | /* Reverse the src and dest notion, since the HW expects them to be from |
| 2053 | * Tx perspective where as the input from user is from Rx filter view. |
| 2054 | */ |
| 2055 | input->dst_port = fsp->h_u.tcp_ip4_spec.psrc; |
| 2056 | input->src_port = fsp->h_u.tcp_ip4_spec.pdst; |
| 2057 | input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src; |
| 2058 | input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2059 | |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 2060 | ret = i40e_add_del_fdir(vsi, input, true); |
| 2061 | if (ret) |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2062 | kfree(input); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2063 | else |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 2064 | i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2065 | |
| 2066 | return ret; |
| 2067 | } |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 2068 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2069 | /** |
| 2070 | * i40e_set_rxnfc - command to set RX flow classification rules |
| 2071 | * @netdev: network interface device structure |
| 2072 | * @cmd: ethtool rxnfc command |
| 2073 | * |
| 2074 | * Returns Success if the command is supported. |
| 2075 | **/ |
| 2076 | static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) |
| 2077 | { |
| 2078 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2079 | struct i40e_vsi *vsi = np->vsi; |
| 2080 | struct i40e_pf *pf = vsi->back; |
| 2081 | int ret = -EOPNOTSUPP; |
| 2082 | |
| 2083 | switch (cmd->cmd) { |
| 2084 | case ETHTOOL_SRXFH: |
| 2085 | ret = i40e_set_rss_hash_opt(pf, cmd); |
| 2086 | break; |
| 2087 | case ETHTOOL_SRXCLSRLINS: |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 2088 | ret = i40e_add_fdir_ethtool(vsi, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2089 | break; |
| 2090 | case ETHTOOL_SRXCLSRLDEL: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2091 | ret = i40e_del_fdir_entry(vsi, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2092 | break; |
| 2093 | default: |
| 2094 | break; |
| 2095 | } |
| 2096 | |
| 2097 | return ret; |
| 2098 | } |
| 2099 | |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2100 | /** |
| 2101 | * i40e_max_channels - get Max number of combined channels supported |
| 2102 | * @vsi: vsi pointer |
| 2103 | **/ |
| 2104 | static unsigned int i40e_max_channels(struct i40e_vsi *vsi) |
| 2105 | { |
| 2106 | /* TODO: This code assumes DCB and FD is disabled for now. */ |
| 2107 | return vsi->alloc_queue_pairs; |
| 2108 | } |
| 2109 | |
| 2110 | /** |
| 2111 | * i40e_get_channels - Get the current channels enabled and max supported etc. |
| 2112 | * @netdev: network interface device structure |
| 2113 | * @ch: ethtool channels structure |
| 2114 | * |
| 2115 | * We don't support separate tx and rx queues as channels. The other count |
| 2116 | * represents how many queues are being used for control. max_combined counts |
| 2117 | * how many queue pairs we can support. They may not be mapped 1 to 1 with |
| 2118 | * q_vectors since we support a lot more queue pairs than q_vectors. |
| 2119 | **/ |
| 2120 | static void i40e_get_channels(struct net_device *dev, |
| 2121 | struct ethtool_channels *ch) |
| 2122 | { |
| 2123 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 2124 | struct i40e_vsi *vsi = np->vsi; |
| 2125 | struct i40e_pf *pf = vsi->back; |
| 2126 | |
| 2127 | /* report maximum channels */ |
| 2128 | ch->max_combined = i40e_max_channels(vsi); |
| 2129 | |
| 2130 | /* report info for other vector */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2131 | ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0; |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2132 | ch->max_other = ch->other_count; |
| 2133 | |
| 2134 | /* Note: This code assumes DCB is disabled for now. */ |
| 2135 | ch->combined_count = vsi->num_queue_pairs; |
| 2136 | } |
| 2137 | |
| 2138 | /** |
| 2139 | * i40e_set_channels - Set the new channels count. |
| 2140 | * @netdev: network interface device structure |
| 2141 | * @ch: ethtool channels structure |
| 2142 | * |
| 2143 | * The new channels count may not be the same as requested by the user |
| 2144 | * since it gets rounded down to a power of 2 value. |
| 2145 | **/ |
| 2146 | static int i40e_set_channels(struct net_device *dev, |
| 2147 | struct ethtool_channels *ch) |
| 2148 | { |
| 2149 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 2150 | unsigned int count = ch->combined_count; |
| 2151 | struct i40e_vsi *vsi = np->vsi; |
| 2152 | struct i40e_pf *pf = vsi->back; |
| 2153 | int new_count; |
| 2154 | |
| 2155 | /* We do not support setting channels for any other VSI at present */ |
| 2156 | if (vsi->type != I40E_VSI_MAIN) |
| 2157 | return -EINVAL; |
| 2158 | |
| 2159 | /* verify they are not requesting separate vectors */ |
| 2160 | if (!count || ch->rx_count || ch->tx_count) |
| 2161 | return -EINVAL; |
| 2162 | |
| 2163 | /* verify other_count has not changed */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 2164 | if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0)) |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2165 | return -EINVAL; |
| 2166 | |
| 2167 | /* verify the number of channels does not exceed hardware limits */ |
| 2168 | if (count > i40e_max_channels(vsi)) |
| 2169 | return -EINVAL; |
| 2170 | |
| 2171 | /* update feature limits from largest to smallest supported values */ |
| 2172 | /* TODO: Flow director limit, DCB etc */ |
| 2173 | |
| 2174 | /* cap RSS limit */ |
| 2175 | if (count > pf->rss_size_max) |
| 2176 | count = pf->rss_size_max; |
| 2177 | |
| 2178 | /* use rss_reconfig to rebuild with new queue count and update traffic |
| 2179 | * class queue mapping |
| 2180 | */ |
| 2181 | new_count = i40e_reconfig_rss_queues(pf, count); |
Anjali Singhai Jain | 5f90f42 | 2013-12-21 05:44:43 +0000 | [diff] [blame] | 2182 | if (new_count > 0) |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2183 | return 0; |
| 2184 | else |
| 2185 | return -EINVAL; |
| 2186 | } |
| 2187 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2188 | static const struct ethtool_ops i40e_ethtool_ops = { |
| 2189 | .get_settings = i40e_get_settings, |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 2190 | .set_settings = i40e_set_settings, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2191 | .get_drvinfo = i40e_get_drvinfo, |
| 2192 | .get_regs_len = i40e_get_regs_len, |
| 2193 | .get_regs = i40e_get_regs, |
| 2194 | .nway_reset = i40e_nway_reset, |
| 2195 | .get_link = ethtool_op_get_link, |
| 2196 | .get_wol = i40e_get_wol, |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 2197 | .set_wol = i40e_set_wol, |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 2198 | .set_eeprom = i40e_set_eeprom, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2199 | .get_eeprom_len = i40e_get_eeprom_len, |
| 2200 | .get_eeprom = i40e_get_eeprom, |
| 2201 | .get_ringparam = i40e_get_ringparam, |
| 2202 | .set_ringparam = i40e_set_ringparam, |
| 2203 | .get_pauseparam = i40e_get_pauseparam, |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 2204 | .set_pauseparam = i40e_set_pauseparam, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2205 | .get_msglevel = i40e_get_msglevel, |
| 2206 | .set_msglevel = i40e_set_msglevel, |
| 2207 | .get_rxnfc = i40e_get_rxnfc, |
| 2208 | .set_rxnfc = i40e_set_rxnfc, |
| 2209 | .self_test = i40e_diag_test, |
| 2210 | .get_strings = i40e_get_strings, |
| 2211 | .set_phys_id = i40e_set_phys_id, |
| 2212 | .get_sset_count = i40e_get_sset_count, |
| 2213 | .get_ethtool_stats = i40e_get_ethtool_stats, |
| 2214 | .get_coalesce = i40e_get_coalesce, |
| 2215 | .set_coalesce = i40e_set_coalesce, |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 2216 | .get_channels = i40e_get_channels, |
| 2217 | .set_channels = i40e_set_channels, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2218 | .get_ts_info = i40e_get_ts_info, |
| 2219 | }; |
| 2220 | |
| 2221 | void i40e_set_ethtool_ops(struct net_device *netdev) |
| 2222 | { |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 2223 | netdev->ethtool_ops = &i40e_ethtool_ops; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2224 | } |