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