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 | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 148 | I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match), |
| 149 | I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match), |
| 150 | |
Anjali Singhai Jain | bee5af7 | 2014-03-06 08:59:50 +0000 | [diff] [blame] | 151 | /* LPI stats */ |
| 152 | I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status), |
| 153 | I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status), |
| 154 | I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count), |
| 155 | I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | #define I40E_QUEUE_STATS_LEN(n) \ |
Shannon Nelson | 31cd840 | 2014-04-04 04:43:12 +0000 | [diff] [blame] | 159 | (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \ |
| 160 | * 2 /* Tx and Rx together */ \ |
| 161 | * (sizeof(struct i40e_queue_stats) / sizeof(u64))) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 162 | #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats) |
| 163 | #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats) |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 164 | #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 165 | #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \ |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 166 | I40E_MISC_STATS_LEN + \ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 167 | I40E_QUEUE_STATS_LEN((n))) |
| 168 | #define I40E_PFC_STATS_LEN ( \ |
| 169 | (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \ |
| 170 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \ |
| 171 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \ |
| 172 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \ |
| 173 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \ |
| 174 | / sizeof(u64)) |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 175 | #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 176 | #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \ |
| 177 | I40E_PFC_STATS_LEN + \ |
| 178 | I40E_VSI_STATS_LEN((n))) |
| 179 | |
| 180 | enum i40e_ethtool_test_id { |
| 181 | I40E_ETH_TEST_REG = 0, |
| 182 | I40E_ETH_TEST_EEPROM, |
| 183 | I40E_ETH_TEST_INTR, |
| 184 | I40E_ETH_TEST_LOOPBACK, |
| 185 | I40E_ETH_TEST_LINK, |
| 186 | }; |
| 187 | |
| 188 | static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = { |
| 189 | "Register test (offline)", |
| 190 | "Eeprom test (offline)", |
| 191 | "Interrupt test (offline)", |
| 192 | "Loopback test (offline)", |
| 193 | "Link test (on/offline)" |
| 194 | }; |
| 195 | |
| 196 | #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN) |
| 197 | |
| 198 | /** |
| 199 | * i40e_get_settings - Get Link Speed and Duplex settings |
| 200 | * @netdev: network interface device structure |
| 201 | * @ecmd: ethtool command |
| 202 | * |
| 203 | * Reports speed/duplex settings based on media_type |
| 204 | **/ |
| 205 | static int i40e_get_settings(struct net_device *netdev, |
| 206 | struct ethtool_cmd *ecmd) |
| 207 | { |
| 208 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 209 | struct i40e_pf *pf = np->vsi->back; |
| 210 | struct i40e_hw *hw = &pf->hw; |
| 211 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 212 | bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; |
| 213 | u32 link_speed = hw_link_info->link_speed; |
| 214 | |
| 215 | /* hardware is either in 40G mode or 10G mode |
| 216 | * NOTE: this section initializes supported and advertising |
| 217 | */ |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 218 | if (!link_up) { |
| 219 | /* link is down and the driver needs to fall back on |
| 220 | * device ID to determine what kinds of info to display, |
| 221 | * it's mostly a guess that may change when link is up |
| 222 | */ |
| 223 | switch (hw->device_id) { |
| 224 | case I40E_DEV_ID_QSFP_A: |
| 225 | case I40E_DEV_ID_QSFP_B: |
| 226 | case I40E_DEV_ID_QSFP_C: |
| 227 | /* pluggable QSFP */ |
| 228 | ecmd->supported = SUPPORTED_40000baseSR4_Full | |
| 229 | SUPPORTED_40000baseCR4_Full | |
| 230 | SUPPORTED_40000baseLR4_Full; |
| 231 | ecmd->advertising = ADVERTISED_40000baseSR4_Full | |
| 232 | ADVERTISED_40000baseCR4_Full | |
| 233 | ADVERTISED_40000baseLR4_Full; |
| 234 | break; |
| 235 | case I40E_DEV_ID_KX_B: |
| 236 | /* backplane 40G */ |
| 237 | ecmd->supported = SUPPORTED_40000baseKR4_Full; |
| 238 | ecmd->advertising = ADVERTISED_40000baseKR4_Full; |
| 239 | break; |
| 240 | case I40E_DEV_ID_KX_C: |
| 241 | /* backplane 10G */ |
| 242 | ecmd->supported = SUPPORTED_10000baseKR_Full; |
| 243 | ecmd->advertising = ADVERTISED_10000baseKR_Full; |
| 244 | break; |
| 245 | default: |
| 246 | /* all the rest are 10G/1G */ |
| 247 | ecmd->supported = SUPPORTED_10000baseT_Full | |
| 248 | SUPPORTED_1000baseT_Full; |
| 249 | ecmd->advertising = ADVERTISED_10000baseT_Full | |
| 250 | ADVERTISED_1000baseT_Full; |
| 251 | break; |
| 252 | } |
| 253 | |
| 254 | /* skip phy_type use as it is zero when link is down */ |
| 255 | goto no_valid_phy_type; |
| 256 | } |
| 257 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 258 | switch (hw_link_info->phy_type) { |
| 259 | case I40E_PHY_TYPE_40GBASE_CR4: |
| 260 | case I40E_PHY_TYPE_40GBASE_CR4_CU: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 261 | ecmd->supported = SUPPORTED_Autoneg | |
| 262 | SUPPORTED_40000baseCR4_Full; |
| 263 | ecmd->advertising = ADVERTISED_Autoneg | |
| 264 | ADVERTISED_40000baseCR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 265 | break; |
| 266 | case I40E_PHY_TYPE_40GBASE_KR4: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 267 | ecmd->supported = SUPPORTED_Autoneg | |
| 268 | SUPPORTED_40000baseKR4_Full; |
| 269 | ecmd->advertising = ADVERTISED_Autoneg | |
| 270 | ADVERTISED_40000baseKR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 271 | break; |
| 272 | case I40E_PHY_TYPE_40GBASE_SR4: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 273 | case I40E_PHY_TYPE_XLPPI: |
| 274 | case I40E_PHY_TYPE_XLAUI: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 275 | ecmd->supported = SUPPORTED_40000baseSR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 276 | break; |
| 277 | case I40E_PHY_TYPE_40GBASE_LR4: |
| 278 | ecmd->supported = SUPPORTED_40000baseLR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 279 | break; |
| 280 | case I40E_PHY_TYPE_10GBASE_KX4: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 281 | ecmd->supported = SUPPORTED_Autoneg | |
| 282 | SUPPORTED_10000baseKX4_Full; |
| 283 | ecmd->advertising = ADVERTISED_Autoneg | |
| 284 | ADVERTISED_10000baseKX4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 285 | break; |
| 286 | case I40E_PHY_TYPE_10GBASE_KR: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 287 | ecmd->supported = SUPPORTED_Autoneg | |
| 288 | SUPPORTED_10000baseKR_Full; |
| 289 | ecmd->advertising = ADVERTISED_Autoneg | |
| 290 | ADVERTISED_10000baseKR_Full; |
| 291 | break; |
| 292 | case I40E_PHY_TYPE_10GBASE_SR: |
| 293 | case I40E_PHY_TYPE_10GBASE_LR: |
| 294 | ecmd->supported = SUPPORTED_10000baseT_Full; |
| 295 | break; |
| 296 | case I40E_PHY_TYPE_10GBASE_CR1_CU: |
| 297 | case I40E_PHY_TYPE_10GBASE_CR1: |
| 298 | case I40E_PHY_TYPE_10GBASE_T: |
| 299 | ecmd->supported = SUPPORTED_Autoneg | |
| 300 | SUPPORTED_10000baseT_Full; |
| 301 | ecmd->advertising = ADVERTISED_Autoneg | |
| 302 | ADVERTISED_10000baseT_Full; |
| 303 | break; |
| 304 | case I40E_PHY_TYPE_XAUI: |
| 305 | case I40E_PHY_TYPE_XFI: |
| 306 | case I40E_PHY_TYPE_SFI: |
| 307 | case I40E_PHY_TYPE_10GBASE_SFPP_CU: |
| 308 | ecmd->supported = SUPPORTED_10000baseT_Full; |
| 309 | break; |
| 310 | case I40E_PHY_TYPE_1000BASE_KX: |
| 311 | case I40E_PHY_TYPE_1000BASE_T: |
| 312 | ecmd->supported = SUPPORTED_Autoneg | |
| 313 | SUPPORTED_1000baseT_Full; |
| 314 | ecmd->advertising = ADVERTISED_Autoneg | |
| 315 | ADVERTISED_1000baseT_Full; |
| 316 | break; |
| 317 | case I40E_PHY_TYPE_100BASE_TX: |
| 318 | ecmd->supported = SUPPORTED_Autoneg | |
| 319 | SUPPORTED_100baseT_Full; |
| 320 | ecmd->advertising = ADVERTISED_Autoneg | |
| 321 | ADVERTISED_100baseT_Full; |
| 322 | break; |
| 323 | case I40E_PHY_TYPE_SGMII: |
| 324 | ecmd->supported = SUPPORTED_Autoneg | |
| 325 | SUPPORTED_1000baseT_Full | |
| 326 | SUPPORTED_100baseT_Full; |
| 327 | ecmd->advertising = ADVERTISED_Autoneg | |
| 328 | ADVERTISED_1000baseT_Full | |
| 329 | ADVERTISED_100baseT_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 330 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 331 | default: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 332 | /* if we got here and link is up something bad is afoot */ |
| 333 | WARN_ON(link_up); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 336 | no_valid_phy_type: |
| 337 | /* this is if autoneg is enabled or disabled */ |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 338 | ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
| 339 | AUTONEG_ENABLE : AUTONEG_DISABLE); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 340 | |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 341 | switch (hw->phy.media_type) { |
| 342 | case I40E_MEDIA_TYPE_BACKPLANE: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 343 | ecmd->supported |= SUPPORTED_Autoneg | |
| 344 | SUPPORTED_Backplane; |
| 345 | ecmd->advertising |= ADVERTISED_Autoneg | |
| 346 | ADVERTISED_Backplane; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 347 | ecmd->port = PORT_NONE; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 348 | break; |
| 349 | case I40E_MEDIA_TYPE_BASET: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 350 | ecmd->supported |= SUPPORTED_TP; |
| 351 | ecmd->advertising |= ADVERTISED_TP; |
| 352 | ecmd->port = PORT_TP; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 353 | break; |
| 354 | case I40E_MEDIA_TYPE_DA: |
| 355 | case I40E_MEDIA_TYPE_CX4: |
Jesse Brandeburg | be405eb | 2013-11-20 10:02:50 +0000 | [diff] [blame] | 356 | ecmd->supported |= SUPPORTED_FIBRE; |
| 357 | ecmd->advertising |= ADVERTISED_FIBRE; |
| 358 | ecmd->port = PORT_DA; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 359 | break; |
| 360 | case I40E_MEDIA_TYPE_FIBER: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 361 | ecmd->supported |= SUPPORTED_FIBRE; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 362 | ecmd->port = PORT_FIBRE; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 363 | break; |
| 364 | case I40E_MEDIA_TYPE_UNKNOWN: |
| 365 | default: |
| 366 | ecmd->port = PORT_OTHER; |
| 367 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | ecmd->transceiver = XCVR_EXTERNAL; |
| 371 | |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 372 | ecmd->supported |= SUPPORTED_Pause; |
| 373 | |
| 374 | switch (hw->fc.current_mode) { |
| 375 | case I40E_FC_FULL: |
| 376 | ecmd->advertising |= ADVERTISED_Pause; |
| 377 | break; |
| 378 | case I40E_FC_TX_PAUSE: |
| 379 | ecmd->advertising |= ADVERTISED_Asym_Pause; |
| 380 | break; |
| 381 | case I40E_FC_RX_PAUSE: |
| 382 | ecmd->advertising |= (ADVERTISED_Pause | |
| 383 | ADVERTISED_Asym_Pause); |
| 384 | break; |
| 385 | default: |
| 386 | ecmd->advertising &= ~(ADVERTISED_Pause | |
| 387 | ADVERTISED_Asym_Pause); |
| 388 | break; |
| 389 | } |
| 390 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 391 | if (link_up) { |
| 392 | switch (link_speed) { |
| 393 | case I40E_LINK_SPEED_40GB: |
| 394 | /* need a SPEED_40000 in ethtool.h */ |
| 395 | ethtool_cmd_speed_set(ecmd, 40000); |
| 396 | break; |
| 397 | case I40E_LINK_SPEED_10GB: |
| 398 | ethtool_cmd_speed_set(ecmd, SPEED_10000); |
| 399 | break; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame^] | 400 | case I40E_LINK_SPEED_1GB: |
| 401 | ethtool_cmd_speed_set(ecmd, SPEED_1000); |
| 402 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 403 | default: |
| 404 | break; |
| 405 | } |
| 406 | ecmd->duplex = DUPLEX_FULL; |
| 407 | } else { |
| 408 | ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN); |
| 409 | ecmd->duplex = DUPLEX_UNKNOWN; |
| 410 | } |
| 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * i40e_get_pauseparam - Get Flow Control status |
| 417 | * Return tx/rx-pause status |
| 418 | **/ |
| 419 | static void i40e_get_pauseparam(struct net_device *netdev, |
| 420 | struct ethtool_pauseparam *pause) |
| 421 | { |
| 422 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 423 | struct i40e_pf *pf = np->vsi->back; |
| 424 | struct i40e_hw *hw = &pf->hw; |
| 425 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 426 | |
| 427 | pause->autoneg = |
| 428 | ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
| 429 | AUTONEG_ENABLE : AUTONEG_DISABLE); |
| 430 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 431 | if (hw->fc.current_mode == I40E_FC_RX_PAUSE) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 432 | pause->rx_pause = 1; |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 433 | } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 434 | pause->tx_pause = 1; |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 435 | } else if (hw->fc.current_mode == I40E_FC_FULL) { |
| 436 | pause->rx_pause = 1; |
| 437 | pause->tx_pause = 1; |
| 438 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | static u32 i40e_get_msglevel(struct net_device *netdev) |
| 442 | { |
| 443 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 444 | struct i40e_pf *pf = np->vsi->back; |
| 445 | |
| 446 | return pf->msg_enable; |
| 447 | } |
| 448 | |
| 449 | static void i40e_set_msglevel(struct net_device *netdev, u32 data) |
| 450 | { |
| 451 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 452 | struct i40e_pf *pf = np->vsi->back; |
| 453 | |
| 454 | if (I40E_DEBUG_USER & data) |
| 455 | pf->hw.debug_mask = data; |
| 456 | pf->msg_enable = data; |
| 457 | } |
| 458 | |
| 459 | static int i40e_get_regs_len(struct net_device *netdev) |
| 460 | { |
| 461 | int reg_count = 0; |
| 462 | int i; |
| 463 | |
| 464 | for (i = 0; i40e_reg_list[i].offset != 0; i++) |
| 465 | reg_count += i40e_reg_list[i].elements; |
| 466 | |
| 467 | return reg_count * sizeof(u32); |
| 468 | } |
| 469 | |
| 470 | static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs, |
| 471 | void *p) |
| 472 | { |
| 473 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 474 | struct i40e_pf *pf = np->vsi->back; |
| 475 | struct i40e_hw *hw = &pf->hw; |
| 476 | u32 *reg_buf = p; |
| 477 | int i, j, ri; |
| 478 | u32 reg; |
| 479 | |
| 480 | /* Tell ethtool which driver-version-specific regs output we have. |
| 481 | * |
| 482 | * At some point, if we have ethtool doing special formatting of |
| 483 | * this data, it will rely on this version number to know how to |
| 484 | * interpret things. Hence, this needs to be updated if/when the |
| 485 | * diags register table is changed. |
| 486 | */ |
| 487 | regs->version = 1; |
| 488 | |
| 489 | /* loop through the diags reg table for what to print */ |
| 490 | ri = 0; |
| 491 | for (i = 0; i40e_reg_list[i].offset != 0; i++) { |
| 492 | for (j = 0; j < i40e_reg_list[i].elements; j++) { |
| 493 | reg = i40e_reg_list[i].offset |
| 494 | + (j * i40e_reg_list[i].stride); |
| 495 | reg_buf[ri++] = rd32(hw, reg); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | } |
| 500 | |
| 501 | static int i40e_get_eeprom(struct net_device *netdev, |
| 502 | struct ethtool_eeprom *eeprom, u8 *bytes) |
| 503 | { |
| 504 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 505 | struct i40e_hw *hw = &np->vsi->back->hw; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 506 | struct i40e_pf *pf = np->vsi->back; |
| 507 | int ret_val = 0, len; |
| 508 | u8 *eeprom_buff; |
| 509 | u16 i, sectors; |
| 510 | bool last; |
| 511 | #define I40E_NVM_SECTOR_SIZE 4096 |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 512 | if (eeprom->len == 0) |
| 513 | return -EINVAL; |
| 514 | |
| 515 | eeprom->magic = hw->vendor_id | (hw->device_id << 16); |
| 516 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 517 | eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 518 | if (!eeprom_buff) |
| 519 | return -ENOMEM; |
| 520 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 521 | ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ); |
| 522 | if (ret_val) { |
| 523 | dev_info(&pf->pdev->dev, |
| 524 | "Failed Acquiring NVM resource for read err=%d status=0x%x\n", |
| 525 | ret_val, hw->aq.asq_last_status); |
| 526 | goto free_buff; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 529 | sectors = eeprom->len / I40E_NVM_SECTOR_SIZE; |
| 530 | sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0; |
| 531 | len = I40E_NVM_SECTOR_SIZE; |
| 532 | last = false; |
| 533 | for (i = 0; i < sectors; i++) { |
| 534 | if (i == (sectors - 1)) { |
| 535 | len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i); |
| 536 | last = true; |
| 537 | } |
| 538 | ret_val = i40e_aq_read_nvm(hw, 0x0, |
| 539 | eeprom->offset + (I40E_NVM_SECTOR_SIZE * i), |
| 540 | len, |
Joe Perches | 3dbb7fd | 2014-03-25 04:30:38 +0000 | [diff] [blame] | 541 | eeprom_buff + (I40E_NVM_SECTOR_SIZE * i), |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 542 | last, NULL); |
| 543 | if (ret_val) { |
| 544 | dev_info(&pf->pdev->dev, |
| 545 | "read NVM failed err=%d status=0x%x\n", |
| 546 | ret_val, hw->aq.asq_last_status); |
| 547 | goto release_nvm; |
| 548 | } |
| 549 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 550 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 551 | release_nvm: |
| 552 | i40e_release_nvm(hw); |
Joe Perches | 3dbb7fd | 2014-03-25 04:30:38 +0000 | [diff] [blame] | 553 | memcpy(bytes, eeprom_buff, eeprom->len); |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 554 | free_buff: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 555 | kfree(eeprom_buff); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 556 | return ret_val; |
| 557 | } |
| 558 | |
| 559 | static int i40e_get_eeprom_len(struct net_device *netdev) |
| 560 | { |
| 561 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 562 | struct i40e_hw *hw = &np->vsi->back->hw; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 563 | u32 val; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 564 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 565 | val = (rd32(hw, I40E_GLPCI_LBARCTRL) |
| 566 | & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK) |
| 567 | >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT; |
| 568 | /* register returns value in power of 2, 64Kbyte chunks. */ |
| 569 | val = (64 * 1024) * (1 << val); |
| 570 | return val; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | static void i40e_get_drvinfo(struct net_device *netdev, |
| 574 | struct ethtool_drvinfo *drvinfo) |
| 575 | { |
| 576 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 577 | struct i40e_vsi *vsi = np->vsi; |
| 578 | struct i40e_pf *pf = vsi->back; |
| 579 | |
| 580 | strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver)); |
| 581 | strlcpy(drvinfo->version, i40e_driver_version_str, |
| 582 | sizeof(drvinfo->version)); |
| 583 | strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw), |
| 584 | sizeof(drvinfo->fw_version)); |
| 585 | strlcpy(drvinfo->bus_info, pci_name(pf->pdev), |
| 586 | sizeof(drvinfo->bus_info)); |
| 587 | } |
| 588 | |
| 589 | static void i40e_get_ringparam(struct net_device *netdev, |
| 590 | struct ethtool_ringparam *ring) |
| 591 | { |
| 592 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 593 | struct i40e_pf *pf = np->vsi->back; |
| 594 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 595 | |
| 596 | ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS; |
| 597 | ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS; |
| 598 | ring->rx_mini_max_pending = 0; |
| 599 | ring->rx_jumbo_max_pending = 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 600 | ring->rx_pending = vsi->rx_rings[0]->count; |
| 601 | ring->tx_pending = vsi->tx_rings[0]->count; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 602 | ring->rx_mini_pending = 0; |
| 603 | ring->rx_jumbo_pending = 0; |
| 604 | } |
| 605 | |
| 606 | static int i40e_set_ringparam(struct net_device *netdev, |
| 607 | struct ethtool_ringparam *ring) |
| 608 | { |
| 609 | struct i40e_ring *tx_rings = NULL, *rx_rings = NULL; |
| 610 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 611 | struct i40e_vsi *vsi = np->vsi; |
| 612 | struct i40e_pf *pf = vsi->back; |
| 613 | u32 new_rx_count, new_tx_count; |
| 614 | int i, err = 0; |
| 615 | |
| 616 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 617 | return -EINVAL; |
| 618 | |
Shannon Nelson | 1fa1837 | 2013-11-20 10:03:08 +0000 | [diff] [blame] | 619 | if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS || |
| 620 | ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS || |
| 621 | ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS || |
| 622 | ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) { |
| 623 | netdev_info(netdev, |
| 624 | "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n", |
| 625 | ring->tx_pending, ring->rx_pending, |
| 626 | I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS); |
| 627 | return -EINVAL; |
| 628 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 629 | |
Shannon Nelson | 1fa1837 | 2013-11-20 10:03:08 +0000 | [diff] [blame] | 630 | new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 631 | new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 632 | |
| 633 | /* if nothing to do return success */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 634 | if ((new_tx_count == vsi->tx_rings[0]->count) && |
| 635 | (new_rx_count == vsi->rx_rings[0]->count)) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 636 | return 0; |
| 637 | |
| 638 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 639 | usleep_range(1000, 2000); |
| 640 | |
| 641 | if (!netif_running(vsi->netdev)) { |
| 642 | /* simple case - set for the next time the netdev is started */ |
| 643 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 644 | vsi->tx_rings[i]->count = new_tx_count; |
| 645 | vsi->rx_rings[i]->count = new_rx_count; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 646 | } |
| 647 | goto done; |
| 648 | } |
| 649 | |
| 650 | /* We can't just free everything and then setup again, |
| 651 | * because the ISRs in MSI-X mode get passed pointers |
| 652 | * to the Tx and Rx ring structs. |
| 653 | */ |
| 654 | |
| 655 | /* alloc updated Tx resources */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 656 | if (new_tx_count != vsi->tx_rings[0]->count) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 657 | netdev_info(netdev, |
| 658 | "Changing Tx descriptor count from %d to %d.\n", |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 659 | vsi->tx_rings[0]->count, new_tx_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 660 | tx_rings = kcalloc(vsi->alloc_queue_pairs, |
| 661 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 662 | if (!tx_rings) { |
| 663 | err = -ENOMEM; |
| 664 | goto done; |
| 665 | } |
| 666 | |
| 667 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 668 | /* clone ring and setup updated count */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 669 | tx_rings[i] = *vsi->tx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 670 | tx_rings[i].count = new_tx_count; |
| 671 | err = i40e_setup_tx_descriptors(&tx_rings[i]); |
| 672 | if (err) { |
| 673 | while (i) { |
| 674 | i--; |
| 675 | i40e_free_tx_resources(&tx_rings[i]); |
| 676 | } |
| 677 | kfree(tx_rings); |
| 678 | tx_rings = NULL; |
| 679 | |
| 680 | goto done; |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | /* alloc updated Rx resources */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 686 | if (new_rx_count != vsi->rx_rings[0]->count) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 687 | netdev_info(netdev, |
| 688 | "Changing Rx descriptor count from %d to %d\n", |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 689 | vsi->rx_rings[0]->count, new_rx_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 690 | rx_rings = kcalloc(vsi->alloc_queue_pairs, |
| 691 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 692 | if (!rx_rings) { |
| 693 | err = -ENOMEM; |
| 694 | goto free_tx; |
| 695 | } |
| 696 | |
| 697 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 698 | /* clone ring and setup updated count */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 699 | rx_rings[i] = *vsi->rx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 700 | rx_rings[i].count = new_rx_count; |
| 701 | err = i40e_setup_rx_descriptors(&rx_rings[i]); |
| 702 | if (err) { |
| 703 | while (i) { |
| 704 | i--; |
| 705 | i40e_free_rx_resources(&rx_rings[i]); |
| 706 | } |
| 707 | kfree(rx_rings); |
| 708 | rx_rings = NULL; |
| 709 | |
| 710 | goto free_tx; |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | /* Bring interface down, copy in the new ring info, |
| 716 | * then restore the interface |
| 717 | */ |
| 718 | i40e_down(vsi); |
| 719 | |
| 720 | if (tx_rings) { |
| 721 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 722 | i40e_free_tx_resources(vsi->tx_rings[i]); |
| 723 | *vsi->tx_rings[i] = tx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 724 | } |
| 725 | kfree(tx_rings); |
| 726 | tx_rings = NULL; |
| 727 | } |
| 728 | |
| 729 | if (rx_rings) { |
| 730 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 731 | i40e_free_rx_resources(vsi->rx_rings[i]); |
| 732 | *vsi->rx_rings[i] = rx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 733 | } |
| 734 | kfree(rx_rings); |
| 735 | rx_rings = NULL; |
| 736 | } |
| 737 | |
| 738 | i40e_up(vsi); |
| 739 | |
| 740 | free_tx: |
| 741 | /* error cleanup if the Rx allocations failed after getting Tx */ |
| 742 | if (tx_rings) { |
| 743 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 744 | i40e_free_tx_resources(&tx_rings[i]); |
| 745 | kfree(tx_rings); |
| 746 | tx_rings = NULL; |
| 747 | } |
| 748 | |
| 749 | done: |
| 750 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 751 | |
| 752 | return err; |
| 753 | } |
| 754 | |
| 755 | static int i40e_get_sset_count(struct net_device *netdev, int sset) |
| 756 | { |
| 757 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 758 | struct i40e_vsi *vsi = np->vsi; |
| 759 | struct i40e_pf *pf = vsi->back; |
| 760 | |
| 761 | switch (sset) { |
| 762 | case ETH_SS_TEST: |
| 763 | return I40E_TEST_LEN; |
| 764 | case ETH_SS_STATS: |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 765 | if (vsi == pf->vsi[pf->lan_vsi]) { |
| 766 | int len = I40E_PF_STATS_LEN(netdev); |
| 767 | |
| 768 | if (pf->lan_veb != I40E_NO_VEB) |
| 769 | len += I40E_VEB_STATS_LEN; |
| 770 | return len; |
| 771 | } else { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 772 | return I40E_VSI_STATS_LEN(netdev); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 773 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 774 | default: |
| 775 | return -EOPNOTSUPP; |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | static void i40e_get_ethtool_stats(struct net_device *netdev, |
| 780 | struct ethtool_stats *stats, u64 *data) |
| 781 | { |
| 782 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 783 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 784 | struct i40e_vsi *vsi = np->vsi; |
| 785 | struct i40e_pf *pf = vsi->back; |
| 786 | int i = 0; |
| 787 | char *p; |
| 788 | int j; |
| 789 | struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 790 | unsigned int start; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 791 | |
| 792 | i40e_update_stats(vsi); |
| 793 | |
| 794 | for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) { |
| 795 | p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset; |
| 796 | data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat == |
| 797 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 798 | } |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 799 | for (j = 0; j < I40E_MISC_STATS_LEN; j++) { |
| 800 | p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset; |
| 801 | data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat == |
| 802 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 803 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 804 | rcu_read_lock(); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 805 | for (j = 0; j < vsi->num_queue_pairs; j++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 806 | tx_ring = ACCESS_ONCE(vsi->tx_rings[j]); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 807 | |
| 808 | if (!tx_ring) |
| 809 | continue; |
| 810 | |
| 811 | /* process Tx ring statistics */ |
| 812 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 813 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 814 | data[i] = tx_ring->stats.packets; |
| 815 | data[i + 1] = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 816 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 817 | i += 2; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 818 | |
| 819 | /* Rx ring is the 2nd half of the queue pair */ |
| 820 | rx_ring = &tx_ring[1]; |
| 821 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 822 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 823 | data[i] = rx_ring->stats.packets; |
| 824 | data[i + 1] = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 825 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 826 | i += 2; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 827 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 828 | rcu_read_unlock(); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 829 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 830 | return; |
| 831 | |
| 832 | if (pf->lan_veb != I40E_NO_VEB) { |
| 833 | struct i40e_veb *veb = pf->veb[pf->lan_veb]; |
| 834 | for (j = 0; j < I40E_VEB_STATS_LEN; j++) { |
| 835 | p = (char *)veb; |
| 836 | p += i40e_gstrings_veb_stats[j].stat_offset; |
| 837 | data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat == |
| 838 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 839 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 840 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 841 | for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) { |
| 842 | p = (char *)pf + i40e_gstrings_stats[j].stat_offset; |
| 843 | data[i++] = (i40e_gstrings_stats[j].sizeof_stat == |
| 844 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 845 | } |
| 846 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { |
| 847 | data[i++] = pf->stats.priority_xon_tx[j]; |
| 848 | data[i++] = pf->stats.priority_xoff_tx[j]; |
| 849 | } |
| 850 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { |
| 851 | data[i++] = pf->stats.priority_xon_rx[j]; |
| 852 | data[i++] = pf->stats.priority_xoff_rx[j]; |
| 853 | } |
| 854 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) |
| 855 | data[i++] = pf->stats.priority_xon_2_xoff[j]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | static void i40e_get_strings(struct net_device *netdev, u32 stringset, |
| 859 | u8 *data) |
| 860 | { |
| 861 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 862 | struct i40e_vsi *vsi = np->vsi; |
| 863 | struct i40e_pf *pf = vsi->back; |
| 864 | char *p = (char *)data; |
| 865 | int i; |
| 866 | |
| 867 | switch (stringset) { |
| 868 | case ETH_SS_TEST: |
| 869 | for (i = 0; i < I40E_TEST_LEN; i++) { |
| 870 | memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN); |
| 871 | data += ETH_GSTRING_LEN; |
| 872 | } |
| 873 | break; |
| 874 | case ETH_SS_STATS: |
| 875 | for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) { |
| 876 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 877 | i40e_gstrings_net_stats[i].stat_string); |
| 878 | p += ETH_GSTRING_LEN; |
| 879 | } |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 880 | for (i = 0; i < I40E_MISC_STATS_LEN; i++) { |
| 881 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 882 | i40e_gstrings_misc_stats[i].stat_string); |
| 883 | p += ETH_GSTRING_LEN; |
| 884 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 885 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 886 | snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i); |
| 887 | p += ETH_GSTRING_LEN; |
| 888 | snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i); |
| 889 | p += ETH_GSTRING_LEN; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 890 | snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i); |
| 891 | p += ETH_GSTRING_LEN; |
| 892 | snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i); |
| 893 | p += ETH_GSTRING_LEN; |
| 894 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 895 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 896 | return; |
| 897 | |
| 898 | if (pf->lan_veb != I40E_NO_VEB) { |
| 899 | for (i = 0; i < I40E_VEB_STATS_LEN; i++) { |
| 900 | snprintf(p, ETH_GSTRING_LEN, "veb.%s", |
| 901 | i40e_gstrings_veb_stats[i].stat_string); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 902 | p += ETH_GSTRING_LEN; |
| 903 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 904 | } |
| 905 | for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) { |
| 906 | snprintf(p, ETH_GSTRING_LEN, "port.%s", |
| 907 | i40e_gstrings_stats[i].stat_string); |
| 908 | p += ETH_GSTRING_LEN; |
| 909 | } |
| 910 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 911 | snprintf(p, ETH_GSTRING_LEN, |
| 912 | "port.tx_priority_%u_xon", i); |
| 913 | p += ETH_GSTRING_LEN; |
| 914 | snprintf(p, ETH_GSTRING_LEN, |
| 915 | "port.tx_priority_%u_xoff", i); |
| 916 | p += ETH_GSTRING_LEN; |
| 917 | } |
| 918 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 919 | snprintf(p, ETH_GSTRING_LEN, |
| 920 | "port.rx_priority_%u_xon", i); |
| 921 | p += ETH_GSTRING_LEN; |
| 922 | snprintf(p, ETH_GSTRING_LEN, |
| 923 | "port.rx_priority_%u_xoff", i); |
| 924 | p += ETH_GSTRING_LEN; |
| 925 | } |
| 926 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 927 | snprintf(p, ETH_GSTRING_LEN, |
| 928 | "port.rx_priority_%u_xon_2_xoff", i); |
| 929 | p += ETH_GSTRING_LEN; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 930 | } |
| 931 | /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */ |
| 932 | break; |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | static int i40e_get_ts_info(struct net_device *dev, |
| 937 | struct ethtool_ts_info *info) |
| 938 | { |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 939 | struct i40e_pf *pf = i40e_netdev_to_pf(dev); |
| 940 | |
| 941 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 942 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 943 | SOF_TIMESTAMPING_SOFTWARE | |
| 944 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 945 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 946 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 947 | |
| 948 | if (pf->ptp_clock) |
| 949 | info->phc_index = ptp_clock_index(pf->ptp_clock); |
| 950 | else |
| 951 | info->phc_index = -1; |
| 952 | |
| 953 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); |
| 954 | |
| 955 | info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | |
| 956 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | |
| 957 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | |
| 958 | (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) | |
| 959 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | |
| 960 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | |
| 961 | (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) | |
| 962 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) | |
| 963 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | |
| 964 | (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | |
| 965 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) | |
| 966 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ); |
| 967 | |
| 968 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 971 | static int i40e_link_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 972 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 973 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 974 | struct i40e_pf *pf = np->vsi->back; |
| 975 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 976 | netif_info(pf, hw, netdev, "link test\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 977 | if (i40e_get_link_status(&pf->hw)) |
| 978 | *data = 0; |
| 979 | else |
| 980 | *data = 1; |
| 981 | |
| 982 | return *data; |
| 983 | } |
| 984 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 985 | static int i40e_reg_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 986 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 987 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 988 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 989 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 990 | netif_info(pf, hw, netdev, "register test\n"); |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 991 | *data = i40e_diag_reg_test(&pf->hw); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 992 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 993 | return *data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 996 | static int i40e_eeprom_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 997 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 998 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 999 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1000 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1001 | netif_info(pf, hw, netdev, "eeprom test\n"); |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1002 | *data = i40e_diag_eeprom_test(&pf->hw); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1003 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1004 | return *data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1007 | static int i40e_intr_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1008 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1009 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1010 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1011 | u16 swc_old = pf->sw_int_count; |
| 1012 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1013 | netif_info(pf, hw, netdev, "interrupt test\n"); |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1014 | wr32(&pf->hw, I40E_PFINT_DYN_CTL0, |
| 1015 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | |
| 1016 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK)); |
| 1017 | usleep_range(1000, 2000); |
| 1018 | *data = (swc_old == pf->sw_int_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1019 | |
| 1020 | return *data; |
| 1021 | } |
| 1022 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1023 | static int i40e_loopback_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1024 | { |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1025 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1026 | struct i40e_pf *pf = np->vsi->back; |
| 1027 | |
| 1028 | netif_info(pf, hw, netdev, "loopback test not implemented\n"); |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1029 | *data = 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1030 | |
| 1031 | return *data; |
| 1032 | } |
| 1033 | |
| 1034 | static void i40e_diag_test(struct net_device *netdev, |
| 1035 | struct ethtool_test *eth_test, u64 *data) |
| 1036 | { |
| 1037 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1038 | struct i40e_pf *pf = np->vsi->back; |
| 1039 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1040 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
| 1041 | /* Offline tests */ |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1042 | netif_info(pf, drv, netdev, "offline testing starting\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1043 | |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1044 | set_bit(__I40E_TESTING, &pf->state); |
| 1045 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1046 | /* Link test performed before hardware reset |
| 1047 | * so autoneg doesn't interfere with test result |
| 1048 | */ |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1049 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1050 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1051 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1052 | if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1053 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1054 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1055 | if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1056 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1057 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1058 | if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1059 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1060 | |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1061 | /* run reg test last, a reset is required after it */ |
| 1062 | if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG])) |
| 1063 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1064 | |
| 1065 | clear_bit(__I40E_TESTING, &pf->state); |
| 1066 | i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1067 | } else { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1068 | /* Online tests */ |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1069 | netif_info(pf, drv, netdev, "online testing starting\n"); |
| 1070 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1071 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1072 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1073 | |
| 1074 | /* Offline only tests, not run in online; pass by default */ |
| 1075 | data[I40E_ETH_TEST_REG] = 0; |
| 1076 | data[I40E_ETH_TEST_EEPROM] = 0; |
| 1077 | data[I40E_ETH_TEST_INTR] = 0; |
| 1078 | data[I40E_ETH_TEST_LOOPBACK] = 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1079 | } |
Shannon Nelson | c140c17 | 2013-11-20 10:02:58 +0000 | [diff] [blame] | 1080 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1081 | netif_info(pf, drv, netdev, "testing finished\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | static void i40e_get_wol(struct net_device *netdev, |
| 1085 | struct ethtool_wolinfo *wol) |
| 1086 | { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1087 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1088 | struct i40e_pf *pf = np->vsi->back; |
| 1089 | struct i40e_hw *hw = &pf->hw; |
| 1090 | u16 wol_nvm_bits; |
| 1091 | |
| 1092 | /* NVM bit on means WoL disabled for the port */ |
| 1093 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); |
| 1094 | if ((1 << hw->port) & wol_nvm_bits) { |
| 1095 | wol->supported = 0; |
| 1096 | wol->wolopts = 0; |
| 1097 | } else { |
| 1098 | wol->supported = WAKE_MAGIC; |
| 1099 | wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 1104 | { |
| 1105 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1106 | struct i40e_pf *pf = np->vsi->back; |
| 1107 | struct i40e_hw *hw = &pf->hw; |
| 1108 | u16 wol_nvm_bits; |
| 1109 | |
| 1110 | /* NVM bit on means WoL disabled for the port */ |
| 1111 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); |
| 1112 | if (((1 << hw->port) & wol_nvm_bits)) |
| 1113 | return -EOPNOTSUPP; |
| 1114 | |
| 1115 | /* only magic packet is supported */ |
| 1116 | if (wol->wolopts && (wol->wolopts != WAKE_MAGIC)) |
| 1117 | return -EOPNOTSUPP; |
| 1118 | |
| 1119 | /* is this a new value? */ |
| 1120 | if (pf->wol_en != !!wol->wolopts) { |
| 1121 | pf->wol_en = !!wol->wolopts; |
| 1122 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 1123 | } |
| 1124 | |
| 1125 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | static int i40e_nway_reset(struct net_device *netdev) |
| 1129 | { |
| 1130 | /* restart autonegotiation */ |
| 1131 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1132 | struct i40e_pf *pf = np->vsi->back; |
| 1133 | struct i40e_hw *hw = &pf->hw; |
Catherine Sullivan | 1ac978a | 2014-06-04 01:23:20 +0000 | [diff] [blame] | 1134 | bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1135 | i40e_status ret = 0; |
| 1136 | |
Catherine Sullivan | 1ac978a | 2014-06-04 01:23:20 +0000 | [diff] [blame] | 1137 | ret = i40e_aq_set_link_restart_an(hw, link_up, NULL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1138 | if (ret) { |
| 1139 | netdev_info(netdev, "link restart failed, aq_err=%d\n", |
| 1140 | pf->hw.aq.asq_last_status); |
| 1141 | return -EIO; |
| 1142 | } |
| 1143 | |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
| 1147 | static int i40e_set_phys_id(struct net_device *netdev, |
| 1148 | enum ethtool_phys_id_state state) |
| 1149 | { |
| 1150 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1151 | struct i40e_pf *pf = np->vsi->back; |
| 1152 | struct i40e_hw *hw = &pf->hw; |
| 1153 | int blink_freq = 2; |
| 1154 | |
| 1155 | switch (state) { |
| 1156 | case ETHTOOL_ID_ACTIVE: |
| 1157 | pf->led_status = i40e_led_get(hw); |
| 1158 | return blink_freq; |
| 1159 | case ETHTOOL_ID_ON: |
Jesse Brandeburg | 0556a9e | 2013-11-28 06:39:33 +0000 | [diff] [blame] | 1160 | i40e_led_set(hw, 0xF, false); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1161 | break; |
| 1162 | case ETHTOOL_ID_OFF: |
Jesse Brandeburg | 0556a9e | 2013-11-28 06:39:33 +0000 | [diff] [blame] | 1163 | i40e_led_set(hw, 0x0, false); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1164 | break; |
| 1165 | case ETHTOOL_ID_INACTIVE: |
Jesse Brandeburg | 0556a9e | 2013-11-28 06:39:33 +0000 | [diff] [blame] | 1166 | i40e_led_set(hw, pf->led_status, false); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1167 | break; |
| 1168 | } |
| 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
| 1173 | /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt |
| 1174 | * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also |
| 1175 | * 125us (8000 interrupts per second) == ITR(62) |
| 1176 | */ |
| 1177 | |
| 1178 | static int i40e_get_coalesce(struct net_device *netdev, |
| 1179 | struct ethtool_coalesce *ec) |
| 1180 | { |
| 1181 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1182 | struct i40e_vsi *vsi = np->vsi; |
| 1183 | |
| 1184 | ec->tx_max_coalesced_frames_irq = vsi->work_limit; |
| 1185 | ec->rx_max_coalesced_frames_irq = vsi->work_limit; |
| 1186 | |
| 1187 | if (ITR_IS_DYNAMIC(vsi->rx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1188 | ec->use_adaptive_rx_coalesce = 1; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1189 | |
| 1190 | if (ITR_IS_DYNAMIC(vsi->tx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1191 | ec->use_adaptive_tx_coalesce = 1; |
| 1192 | |
| 1193 | ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC; |
| 1194 | ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | static int i40e_set_coalesce(struct net_device *netdev, |
| 1200 | struct ethtool_coalesce *ec) |
| 1201 | { |
| 1202 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1203 | struct i40e_q_vector *q_vector; |
| 1204 | struct i40e_vsi *vsi = np->vsi; |
| 1205 | struct i40e_pf *pf = vsi->back; |
| 1206 | struct i40e_hw *hw = &pf->hw; |
| 1207 | u16 vector; |
| 1208 | int i; |
| 1209 | |
| 1210 | if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq) |
| 1211 | vsi->work_limit = ec->tx_max_coalesced_frames_irq; |
| 1212 | |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1213 | vector = vsi->base_vector; |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1214 | if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) && |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1215 | (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1))) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1216 | vsi->rx_itr_setting = ec->rx_coalesce_usecs; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1217 | } else if (ec->rx_coalesce_usecs == 0) { |
| 1218 | vsi->rx_itr_setting = ec->rx_coalesce_usecs; |
| 1219 | i40e_irq_dynamic_disable(vsi, vector); |
| 1220 | if (ec->use_adaptive_rx_coalesce) |
| 1221 | netif_info(pf, drv, netdev, |
| 1222 | "Rx-secs=0, need to disable adaptive-Rx for a complete disable\n"); |
| 1223 | } else { |
| 1224 | netif_info(pf, drv, netdev, |
| 1225 | "Invalid value, Rx-usecs range is 0, 8-8160\n"); |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1226 | return -EINVAL; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1227 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1228 | |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1229 | if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) && |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1230 | (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1))) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1231 | vsi->tx_itr_setting = ec->tx_coalesce_usecs; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1232 | } else if (ec->tx_coalesce_usecs == 0) { |
| 1233 | vsi->tx_itr_setting = ec->tx_coalesce_usecs; |
| 1234 | i40e_irq_dynamic_disable(vsi, vector); |
| 1235 | if (ec->use_adaptive_tx_coalesce) |
| 1236 | netif_info(pf, drv, netdev, |
| 1237 | "Tx-secs=0, need to disable adaptive-Tx for a complete disable\n"); |
| 1238 | } else { |
| 1239 | netif_info(pf, drv, netdev, |
| 1240 | "Invalid value, Tx-usecs range is 0, 8-8160\n"); |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1241 | return -EINVAL; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 1242 | } |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 1243 | |
| 1244 | if (ec->use_adaptive_rx_coalesce) |
| 1245 | vsi->rx_itr_setting |= I40E_ITR_DYNAMIC; |
| 1246 | else |
| 1247 | vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC; |
| 1248 | |
| 1249 | if (ec->use_adaptive_tx_coalesce) |
| 1250 | vsi->tx_itr_setting |= I40E_ITR_DYNAMIC; |
| 1251 | else |
| 1252 | vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1253 | |
Alexander Duyck | 493fb30 | 2013-09-28 07:01:44 +0000 | [diff] [blame] | 1254 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
| 1255 | q_vector = vsi->q_vectors[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1256 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
| 1257 | wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr); |
| 1258 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); |
| 1259 | wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr); |
| 1260 | i40e_flush(hw); |
| 1261 | } |
| 1262 | |
| 1263 | return 0; |
| 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type |
| 1268 | * @pf: pointer to the physical function struct |
| 1269 | * @cmd: ethtool rxnfc command |
| 1270 | * |
| 1271 | * Returns Success if the flow is supported, else Invalid Input. |
| 1272 | **/ |
| 1273 | static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd) |
| 1274 | { |
| 1275 | cmd->data = 0; |
| 1276 | |
| 1277 | /* Report default options for RSS on i40e */ |
| 1278 | switch (cmd->flow_type) { |
| 1279 | case TCP_V4_FLOW: |
| 1280 | case UDP_V4_FLOW: |
| 1281 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 1282 | /* fall through to add IP fields */ |
| 1283 | case SCTP_V4_FLOW: |
| 1284 | case AH_ESP_V4_FLOW: |
| 1285 | case AH_V4_FLOW: |
| 1286 | case ESP_V4_FLOW: |
| 1287 | case IPV4_FLOW: |
| 1288 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; |
| 1289 | break; |
| 1290 | case TCP_V6_FLOW: |
| 1291 | case UDP_V6_FLOW: |
| 1292 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 1293 | /* fall through to add IP fields */ |
| 1294 | case SCTP_V6_FLOW: |
| 1295 | case AH_ESP_V6_FLOW: |
| 1296 | case AH_V6_FLOW: |
| 1297 | case ESP_V6_FLOW: |
| 1298 | case IPV6_FLOW: |
| 1299 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; |
| 1300 | break; |
| 1301 | default: |
| 1302 | return -EINVAL; |
| 1303 | } |
| 1304 | |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1309 | * i40e_get_ethtool_fdir_all - Populates the rule count of a command |
| 1310 | * @pf: Pointer to the physical function struct |
| 1311 | * @cmd: The command to get or set Rx flow classification rules |
| 1312 | * @rule_locs: Array of used rule locations |
| 1313 | * |
| 1314 | * This function populates both the total and actual rule count of |
| 1315 | * the ethtool flow classification command |
| 1316 | * |
| 1317 | * Returns 0 on success or -EMSGSIZE if entry not found |
| 1318 | **/ |
| 1319 | static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf, |
| 1320 | struct ethtool_rxnfc *cmd, |
| 1321 | u32 *rule_locs) |
| 1322 | { |
| 1323 | struct i40e_fdir_filter *rule; |
| 1324 | struct hlist_node *node2; |
| 1325 | int cnt = 0; |
| 1326 | |
| 1327 | /* report total rule count */ |
Anjali Singhai Jain | 082def1 | 2014-04-09 05:59:00 +0000 | [diff] [blame] | 1328 | cmd->data = i40e_get_fd_cnt_all(pf); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1329 | |
| 1330 | hlist_for_each_entry_safe(rule, node2, |
| 1331 | &pf->fdir_filter_list, fdir_node) { |
| 1332 | if (cnt == cmd->rule_cnt) |
| 1333 | return -EMSGSIZE; |
| 1334 | |
| 1335 | rule_locs[cnt] = rule->fd_id; |
| 1336 | cnt++; |
| 1337 | } |
| 1338 | |
| 1339 | cmd->rule_cnt = cnt; |
| 1340 | |
| 1341 | return 0; |
| 1342 | } |
| 1343 | |
| 1344 | /** |
| 1345 | * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow |
| 1346 | * @pf: Pointer to the physical function struct |
| 1347 | * @cmd: The command to get or set Rx flow classification rules |
| 1348 | * |
| 1349 | * This function looks up a filter based on the Rx flow classification |
| 1350 | * command and fills the flow spec info for it if found |
| 1351 | * |
| 1352 | * Returns 0 on success or -EINVAL if filter not found |
| 1353 | **/ |
| 1354 | static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf, |
| 1355 | struct ethtool_rxnfc *cmd) |
| 1356 | { |
| 1357 | struct ethtool_rx_flow_spec *fsp = |
| 1358 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 1359 | struct i40e_fdir_filter *rule = NULL; |
| 1360 | struct hlist_node *node2; |
| 1361 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1362 | hlist_for_each_entry_safe(rule, node2, |
| 1363 | &pf->fdir_filter_list, fdir_node) { |
| 1364 | if (fsp->location <= rule->fd_id) |
| 1365 | break; |
| 1366 | } |
| 1367 | |
| 1368 | if (!rule || fsp->location != rule->fd_id) |
| 1369 | return -EINVAL; |
| 1370 | |
| 1371 | fsp->flow_type = rule->flow_type; |
Anjali Singhai Jain | 7d54eb2 | 2014-03-14 07:32:21 +0000 | [diff] [blame] | 1372 | if (fsp->flow_type == IP_USER_FLOW) { |
| 1373 | fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; |
| 1374 | fsp->h_u.usr_ip4_spec.proto = 0; |
| 1375 | fsp->m_u.usr_ip4_spec.proto = 0; |
| 1376 | } |
| 1377 | |
Anjali Singhai Jain | 04b73bd | 2014-05-22 06:31:41 +0000 | [diff] [blame] | 1378 | /* Reverse the src and dest notion, since the HW views them from |
| 1379 | * Tx perspective where as the user expects it from Rx filter view. |
| 1380 | */ |
| 1381 | fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port; |
| 1382 | fsp->h_u.tcp_ip4_spec.pdst = rule->src_port; |
| 1383 | fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0]; |
| 1384 | fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0]; |
Anjali Singhai Jain | 387ce1a | 2014-05-22 06:32:23 +0000 | [diff] [blame] | 1385 | |
| 1386 | if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET) |
| 1387 | fsp->ring_cookie = RX_CLS_FLOW_DISC; |
| 1388 | else |
| 1389 | fsp->ring_cookie = rule->q_index; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
| 1394 | /** |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1395 | * i40e_get_rxnfc - command to get RX flow classification rules |
| 1396 | * @netdev: network interface device structure |
| 1397 | * @cmd: ethtool rxnfc command |
| 1398 | * |
| 1399 | * Returns Success if the command is supported. |
| 1400 | **/ |
| 1401 | static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, |
| 1402 | u32 *rule_locs) |
| 1403 | { |
| 1404 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1405 | struct i40e_vsi *vsi = np->vsi; |
| 1406 | struct i40e_pf *pf = vsi->back; |
| 1407 | int ret = -EOPNOTSUPP; |
| 1408 | |
| 1409 | switch (cmd->cmd) { |
| 1410 | case ETHTOOL_GRXRINGS: |
| 1411 | cmd->data = vsi->alloc_queue_pairs; |
| 1412 | ret = 0; |
| 1413 | break; |
| 1414 | case ETHTOOL_GRXFH: |
| 1415 | ret = i40e_get_rss_hash_opts(pf, cmd); |
| 1416 | break; |
| 1417 | case ETHTOOL_GRXCLSRLCNT: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1418 | cmd->rule_cnt = pf->fdir_pf_active_filters; |
Anjali Singhai Jain | 082def1 | 2014-04-09 05:59:00 +0000 | [diff] [blame] | 1419 | /* report total rule count */ |
| 1420 | cmd->data = i40e_get_fd_cnt_all(pf); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1421 | ret = 0; |
| 1422 | break; |
| 1423 | case ETHTOOL_GRXCLSRULE: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1424 | ret = i40e_get_ethtool_fdir_entry(pf, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1425 | break; |
| 1426 | case ETHTOOL_GRXCLSRLALL: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1427 | ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs); |
| 1428 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1429 | default: |
| 1430 | break; |
| 1431 | } |
| 1432 | |
| 1433 | return ret; |
| 1434 | } |
| 1435 | |
| 1436 | /** |
| 1437 | * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash |
| 1438 | * @pf: pointer to the physical function struct |
| 1439 | * @cmd: ethtool rxnfc command |
| 1440 | * |
| 1441 | * Returns Success if the flow input set is supported. |
| 1442 | **/ |
| 1443 | static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc) |
| 1444 | { |
| 1445 | struct i40e_hw *hw = &pf->hw; |
| 1446 | u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | |
| 1447 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); |
| 1448 | |
| 1449 | /* RSS does not support anything other than hashing |
| 1450 | * to queues on src and dst IPs and ports |
| 1451 | */ |
| 1452 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | |
| 1453 | RXH_L4_B_0_1 | RXH_L4_B_2_3)) |
| 1454 | return -EINVAL; |
| 1455 | |
| 1456 | /* We need at least the IP SRC and DEST fields for hashing */ |
| 1457 | if (!(nfc->data & RXH_IP_SRC) || |
| 1458 | !(nfc->data & RXH_IP_DST)) |
| 1459 | return -EINVAL; |
| 1460 | |
| 1461 | switch (nfc->flow_type) { |
| 1462 | case TCP_V4_FLOW: |
| 1463 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 1464 | case 0: |
| 1465 | hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP); |
| 1466 | break; |
| 1467 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 1468 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP); |
| 1469 | break; |
| 1470 | default: |
| 1471 | return -EINVAL; |
| 1472 | } |
| 1473 | break; |
| 1474 | case TCP_V6_FLOW: |
| 1475 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 1476 | case 0: |
| 1477 | hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP); |
| 1478 | break; |
| 1479 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
| 1480 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP); |
| 1481 | break; |
| 1482 | default: |
| 1483 | return -EINVAL; |
| 1484 | } |
| 1485 | break; |
| 1486 | case UDP_V4_FLOW: |
| 1487 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 1488 | case 0: |
Kevin Scott | b2d36c0 | 2014-04-09 05:58:59 +0000 | [diff] [blame] | 1489 | hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | |
| 1490 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1491 | break; |
| 1492 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
Kevin Scott | b2d36c0 | 2014-04-09 05:58:59 +0000 | [diff] [blame] | 1493 | hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | |
| 1494 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1495 | break; |
| 1496 | default: |
| 1497 | return -EINVAL; |
| 1498 | } |
| 1499 | break; |
| 1500 | case UDP_V6_FLOW: |
| 1501 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { |
| 1502 | case 0: |
Kevin Scott | b2d36c0 | 2014-04-09 05:58:59 +0000 | [diff] [blame] | 1503 | hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | |
| 1504 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1505 | break; |
| 1506 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): |
Kevin Scott | b2d36c0 | 2014-04-09 05:58:59 +0000 | [diff] [blame] | 1507 | hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | |
| 1508 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1509 | break; |
| 1510 | default: |
| 1511 | return -EINVAL; |
| 1512 | } |
| 1513 | break; |
| 1514 | case AH_ESP_V4_FLOW: |
| 1515 | case AH_V4_FLOW: |
| 1516 | case ESP_V4_FLOW: |
| 1517 | case SCTP_V4_FLOW: |
| 1518 | if ((nfc->data & RXH_L4_B_0_1) || |
| 1519 | (nfc->data & RXH_L4_B_2_3)) |
| 1520 | return -EINVAL; |
| 1521 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER); |
| 1522 | break; |
| 1523 | case AH_ESP_V6_FLOW: |
| 1524 | case AH_V6_FLOW: |
| 1525 | case ESP_V6_FLOW: |
| 1526 | case SCTP_V6_FLOW: |
| 1527 | if ((nfc->data & RXH_L4_B_0_1) || |
| 1528 | (nfc->data & RXH_L4_B_2_3)) |
| 1529 | return -EINVAL; |
| 1530 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER); |
| 1531 | break; |
| 1532 | case IPV4_FLOW: |
| 1533 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | |
| 1534 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4); |
| 1535 | break; |
| 1536 | case IPV6_FLOW: |
| 1537 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | |
| 1538 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6); |
| 1539 | break; |
| 1540 | default: |
| 1541 | return -EINVAL; |
| 1542 | } |
| 1543 | |
| 1544 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 1545 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
| 1546 | i40e_flush(hw); |
| 1547 | |
| 1548 | return 0; |
| 1549 | } |
| 1550 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1551 | /** |
Anjali Singhai Jain | 43fddb7 | 2014-02-11 08:24:09 +0000 | [diff] [blame] | 1552 | * i40e_match_fdir_input_set - Match a new filter against an existing one |
| 1553 | * @rule: The filter already added |
| 1554 | * @input: The new filter to comapre against |
| 1555 | * |
| 1556 | * Returns true if the two input set match |
| 1557 | **/ |
| 1558 | static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule, |
| 1559 | struct i40e_fdir_filter *input) |
| 1560 | { |
| 1561 | if ((rule->dst_ip[0] != input->dst_ip[0]) || |
| 1562 | (rule->src_ip[0] != input->src_ip[0]) || |
| 1563 | (rule->dst_port != input->dst_port) || |
| 1564 | (rule->src_port != input->src_port)) |
| 1565 | return false; |
| 1566 | return true; |
| 1567 | } |
| 1568 | |
| 1569 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1570 | * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry |
| 1571 | * @vsi: Pointer to the targeted VSI |
| 1572 | * @input: The filter to update or NULL to indicate deletion |
| 1573 | * @sw_idx: Software index to the filter |
| 1574 | * @cmd: The command to get or set Rx flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1575 | * |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1576 | * This function updates (or deletes) a Flow Director entry from |
| 1577 | * the hlist of the corresponding PF |
| 1578 | * |
| 1579 | * Returns 0 on success |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1580 | **/ |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1581 | static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi, |
| 1582 | struct i40e_fdir_filter *input, |
| 1583 | u16 sw_idx, |
| 1584 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1585 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1586 | struct i40e_fdir_filter *rule, *parent; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1587 | struct i40e_pf *pf = vsi->back; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1588 | struct hlist_node *node2; |
| 1589 | int err = -EINVAL; |
Jesse Brandeburg | c35a1d7 | 2013-12-18 13:46:02 +0000 | [diff] [blame] | 1590 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1591 | parent = NULL; |
| 1592 | rule = NULL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1593 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1594 | hlist_for_each_entry_safe(rule, node2, |
| 1595 | &pf->fdir_filter_list, fdir_node) { |
| 1596 | /* hash found, or no matching entry */ |
| 1597 | if (rule->fd_id >= sw_idx) |
| 1598 | break; |
| 1599 | parent = rule; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1602 | /* if there is an old rule occupying our place remove it */ |
| 1603 | if (rule && (rule->fd_id == sw_idx)) { |
Anjali Singhai Jain | 43fddb7 | 2014-02-11 08:24:09 +0000 | [diff] [blame] | 1604 | if (input && !i40e_match_fdir_input_set(rule, input)) |
| 1605 | err = i40e_add_del_fdir(vsi, rule, false); |
| 1606 | else if (!input) |
| 1607 | err = i40e_add_del_fdir(vsi, rule, false); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1608 | hlist_del(&rule->fdir_node); |
| 1609 | kfree(rule); |
| 1610 | pf->fdir_pf_active_filters--; |
| 1611 | } |
| 1612 | |
| 1613 | /* If no input this was a delete, err should be 0 if a rule was |
| 1614 | * successfully found and removed from the list else -EINVAL |
| 1615 | */ |
| 1616 | if (!input) |
| 1617 | return err; |
| 1618 | |
| 1619 | /* initialize node and set software index */ |
| 1620 | INIT_HLIST_NODE(&input->fdir_node); |
| 1621 | |
| 1622 | /* add filter to the list */ |
| 1623 | if (parent) |
| 1624 | hlist_add_after(&parent->fdir_node, &input->fdir_node); |
| 1625 | else |
| 1626 | hlist_add_head(&input->fdir_node, |
| 1627 | &pf->fdir_filter_list); |
| 1628 | |
| 1629 | /* update counts */ |
| 1630 | pf->fdir_pf_active_filters++; |
| 1631 | |
| 1632 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1636 | * i40e_del_fdir_entry - Deletes a Flow Director filter entry |
| 1637 | * @vsi: Pointer to the targeted VSI |
| 1638 | * @cmd: The command to get or set Rx flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1639 | * |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1640 | * The function removes a Flow Director filter entry from the |
| 1641 | * hlist of the corresponding PF |
| 1642 | * |
| 1643 | * Returns 0 on success |
| 1644 | */ |
| 1645 | static int i40e_del_fdir_entry(struct i40e_vsi *vsi, |
| 1646 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1647 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1648 | struct ethtool_rx_flow_spec *fsp = |
| 1649 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1650 | struct i40e_pf *pf = vsi->back; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1651 | int ret = 0; |
Jesse Brandeburg | c35a1d7 | 2013-12-18 13:46:02 +0000 | [diff] [blame] | 1652 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1653 | ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1654 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 1655 | i40e_fdir_check_and_reenable(pf); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1656 | return ret; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | /** |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1660 | * i40e_add_fdir_ethtool - Add/Remove Flow Director filters |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1661 | * @vsi: pointer to the targeted VSI |
| 1662 | * @cmd: command to get or set RX flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1663 | * |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1664 | * Add Flow Director filters for a specific flow spec based on their |
| 1665 | * protocol. Returns 0 if the filters were successfully added. |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1666 | **/ |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1667 | static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, |
| 1668 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1669 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1670 | struct ethtool_rx_flow_spec *fsp; |
| 1671 | struct i40e_fdir_filter *input; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1672 | struct i40e_pf *pf; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1673 | int ret = -EINVAL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1674 | |
| 1675 | if (!vsi) |
| 1676 | return -EINVAL; |
| 1677 | |
| 1678 | pf = vsi->back; |
| 1679 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 1680 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 1681 | return -EOPNOTSUPP; |
| 1682 | |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1683 | if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 1684 | return -ENOSPC; |
| 1685 | |
| 1686 | fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 1687 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1688 | if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort + |
| 1689 | pf->hw.func_caps.fd_filters_guaranteed)) { |
| 1690 | return -EINVAL; |
| 1691 | } |
| 1692 | |
Anjali Singhai Jain | 387ce1a | 2014-05-22 06:32:23 +0000 | [diff] [blame] | 1693 | if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) && |
| 1694 | (fsp->ring_cookie >= vsi->num_queue_pairs)) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1695 | return -EINVAL; |
| 1696 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1697 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1698 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1699 | if (!input) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1700 | return -ENOMEM; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1701 | |
| 1702 | input->fd_id = fsp->location; |
| 1703 | |
Anjali Singhai Jain | 35a91fd | 2014-03-06 09:00:00 +0000 | [diff] [blame] | 1704 | if (fsp->ring_cookie == RX_CLS_FLOW_DISC) |
| 1705 | input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET; |
| 1706 | else |
| 1707 | input->dest_ctl = |
| 1708 | I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX; |
| 1709 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1710 | input->q_index = fsp->ring_cookie; |
| 1711 | input->flex_off = 0; |
| 1712 | input->pctype = 0; |
| 1713 | input->dest_vsi = vsi->id; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1714 | input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID; |
Anjali Singhai Jain | 433c47d | 2014-05-22 06:32:17 +0000 | [diff] [blame] | 1715 | input->cnt_index = pf->fd_sb_cnt_idx; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1716 | input->flow_type = fsp->flow_type; |
| 1717 | input->ip4_proto = fsp->h_u.usr_ip4_spec.proto; |
Anjali Singhai Jain | 04b73bd | 2014-05-22 06:31:41 +0000 | [diff] [blame] | 1718 | |
| 1719 | /* Reverse the src and dest notion, since the HW expects them to be from |
| 1720 | * Tx perspective where as the input from user is from Rx filter view. |
| 1721 | */ |
| 1722 | input->dst_port = fsp->h_u.tcp_ip4_spec.psrc; |
| 1723 | input->src_port = fsp->h_u.tcp_ip4_spec.pdst; |
| 1724 | input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src; |
| 1725 | input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1726 | |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1727 | ret = i40e_add_del_fdir(vsi, input, true); |
| 1728 | if (ret) |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1729 | kfree(input); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1730 | else |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1731 | i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1732 | |
| 1733 | return ret; |
| 1734 | } |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 1735 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1736 | /** |
| 1737 | * i40e_set_rxnfc - command to set RX flow classification rules |
| 1738 | * @netdev: network interface device structure |
| 1739 | * @cmd: ethtool rxnfc command |
| 1740 | * |
| 1741 | * Returns Success if the command is supported. |
| 1742 | **/ |
| 1743 | static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) |
| 1744 | { |
| 1745 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1746 | struct i40e_vsi *vsi = np->vsi; |
| 1747 | struct i40e_pf *pf = vsi->back; |
| 1748 | int ret = -EOPNOTSUPP; |
| 1749 | |
| 1750 | switch (cmd->cmd) { |
| 1751 | case ETHTOOL_SRXFH: |
| 1752 | ret = i40e_set_rss_hash_opt(pf, cmd); |
| 1753 | break; |
| 1754 | case ETHTOOL_SRXCLSRLINS: |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 1755 | ret = i40e_add_fdir_ethtool(vsi, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1756 | break; |
| 1757 | case ETHTOOL_SRXCLSRLDEL: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 1758 | ret = i40e_del_fdir_entry(vsi, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1759 | break; |
| 1760 | default: |
| 1761 | break; |
| 1762 | } |
| 1763 | |
| 1764 | return ret; |
| 1765 | } |
| 1766 | |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 1767 | /** |
| 1768 | * i40e_max_channels - get Max number of combined channels supported |
| 1769 | * @vsi: vsi pointer |
| 1770 | **/ |
| 1771 | static unsigned int i40e_max_channels(struct i40e_vsi *vsi) |
| 1772 | { |
| 1773 | /* TODO: This code assumes DCB and FD is disabled for now. */ |
| 1774 | return vsi->alloc_queue_pairs; |
| 1775 | } |
| 1776 | |
| 1777 | /** |
| 1778 | * i40e_get_channels - Get the current channels enabled and max supported etc. |
| 1779 | * @netdev: network interface device structure |
| 1780 | * @ch: ethtool channels structure |
| 1781 | * |
| 1782 | * We don't support separate tx and rx queues as channels. The other count |
| 1783 | * represents how many queues are being used for control. max_combined counts |
| 1784 | * how many queue pairs we can support. They may not be mapped 1 to 1 with |
| 1785 | * q_vectors since we support a lot more queue pairs than q_vectors. |
| 1786 | **/ |
| 1787 | static void i40e_get_channels(struct net_device *dev, |
| 1788 | struct ethtool_channels *ch) |
| 1789 | { |
| 1790 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 1791 | struct i40e_vsi *vsi = np->vsi; |
| 1792 | struct i40e_pf *pf = vsi->back; |
| 1793 | |
| 1794 | /* report maximum channels */ |
| 1795 | ch->max_combined = i40e_max_channels(vsi); |
| 1796 | |
| 1797 | /* report info for other vector */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 1798 | 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] | 1799 | ch->max_other = ch->other_count; |
| 1800 | |
| 1801 | /* Note: This code assumes DCB is disabled for now. */ |
| 1802 | ch->combined_count = vsi->num_queue_pairs; |
| 1803 | } |
| 1804 | |
| 1805 | /** |
| 1806 | * i40e_set_channels - Set the new channels count. |
| 1807 | * @netdev: network interface device structure |
| 1808 | * @ch: ethtool channels structure |
| 1809 | * |
| 1810 | * The new channels count may not be the same as requested by the user |
| 1811 | * since it gets rounded down to a power of 2 value. |
| 1812 | **/ |
| 1813 | static int i40e_set_channels(struct net_device *dev, |
| 1814 | struct ethtool_channels *ch) |
| 1815 | { |
| 1816 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 1817 | unsigned int count = ch->combined_count; |
| 1818 | struct i40e_vsi *vsi = np->vsi; |
| 1819 | struct i40e_pf *pf = vsi->back; |
| 1820 | int new_count; |
| 1821 | |
| 1822 | /* We do not support setting channels for any other VSI at present */ |
| 1823 | if (vsi->type != I40E_VSI_MAIN) |
| 1824 | return -EINVAL; |
| 1825 | |
| 1826 | /* verify they are not requesting separate vectors */ |
| 1827 | if (!count || ch->rx_count || ch->tx_count) |
| 1828 | return -EINVAL; |
| 1829 | |
| 1830 | /* verify other_count has not changed */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 1831 | 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] | 1832 | return -EINVAL; |
| 1833 | |
| 1834 | /* verify the number of channels does not exceed hardware limits */ |
| 1835 | if (count > i40e_max_channels(vsi)) |
| 1836 | return -EINVAL; |
| 1837 | |
| 1838 | /* update feature limits from largest to smallest supported values */ |
| 1839 | /* TODO: Flow director limit, DCB etc */ |
| 1840 | |
| 1841 | /* cap RSS limit */ |
| 1842 | if (count > pf->rss_size_max) |
| 1843 | count = pf->rss_size_max; |
| 1844 | |
| 1845 | /* use rss_reconfig to rebuild with new queue count and update traffic |
| 1846 | * class queue mapping |
| 1847 | */ |
| 1848 | new_count = i40e_reconfig_rss_queues(pf, count); |
Anjali Singhai Jain | 5f90f42 | 2013-12-21 05:44:43 +0000 | [diff] [blame] | 1849 | if (new_count > 0) |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 1850 | return 0; |
| 1851 | else |
| 1852 | return -EINVAL; |
| 1853 | } |
| 1854 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1855 | static const struct ethtool_ops i40e_ethtool_ops = { |
| 1856 | .get_settings = i40e_get_settings, |
| 1857 | .get_drvinfo = i40e_get_drvinfo, |
| 1858 | .get_regs_len = i40e_get_regs_len, |
| 1859 | .get_regs = i40e_get_regs, |
| 1860 | .nway_reset = i40e_nway_reset, |
| 1861 | .get_link = ethtool_op_get_link, |
| 1862 | .get_wol = i40e_get_wol, |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1863 | .set_wol = i40e_set_wol, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1864 | .get_eeprom_len = i40e_get_eeprom_len, |
| 1865 | .get_eeprom = i40e_get_eeprom, |
| 1866 | .get_ringparam = i40e_get_ringparam, |
| 1867 | .set_ringparam = i40e_set_ringparam, |
| 1868 | .get_pauseparam = i40e_get_pauseparam, |
| 1869 | .get_msglevel = i40e_get_msglevel, |
| 1870 | .set_msglevel = i40e_set_msglevel, |
| 1871 | .get_rxnfc = i40e_get_rxnfc, |
| 1872 | .set_rxnfc = i40e_set_rxnfc, |
| 1873 | .self_test = i40e_diag_test, |
| 1874 | .get_strings = i40e_get_strings, |
| 1875 | .set_phys_id = i40e_set_phys_id, |
| 1876 | .get_sset_count = i40e_get_sset_count, |
| 1877 | .get_ethtool_stats = i40e_get_ethtool_stats, |
| 1878 | .get_coalesce = i40e_get_coalesce, |
| 1879 | .set_coalesce = i40e_set_coalesce, |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 1880 | .get_channels = i40e_get_channels, |
| 1881 | .set_channels = i40e_set_channels, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1882 | .get_ts_info = i40e_get_ts_info, |
| 1883 | }; |
| 1884 | |
| 1885 | void i40e_set_ethtool_ops(struct net_device *netdev) |
| 1886 | { |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 1887 | netdev->ethtool_ops = &i40e_ethtool_ops; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1888 | } |