1 /******************************************************************************* 2 * 3 * Intel Ethernet Controller XL710 Family Linux Driver 4 * Copyright(c) 2013 - 2016 Intel Corporation. 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 * 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/>. 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 44 #define I40E_NETDEV_STAT(_net_stat) \ 45 I40E_STAT(struct rtnl_link_stats64, #_net_stat, _net_stat) 46 #define I40E_PF_STAT(_name, _stat) \ 47 I40E_STAT(struct i40e_pf, _name, _stat) 48 #define I40E_VSI_STAT(_name, _stat) \ 49 I40E_STAT(struct i40e_vsi, _name, _stat) 50 #define I40E_VEB_STAT(_name, _stat) \ 51 I40E_STAT(struct i40e_veb, _name, _stat) 52 53 static const struct i40e_stats i40e_gstrings_net_stats[] = { 54 I40E_NETDEV_STAT(rx_packets), 55 I40E_NETDEV_STAT(tx_packets), 56 I40E_NETDEV_STAT(rx_bytes), 57 I40E_NETDEV_STAT(tx_bytes), 58 I40E_NETDEV_STAT(rx_errors), 59 I40E_NETDEV_STAT(tx_errors), 60 I40E_NETDEV_STAT(rx_dropped), 61 I40E_NETDEV_STAT(tx_dropped), 62 I40E_NETDEV_STAT(collisions), 63 I40E_NETDEV_STAT(rx_length_errors), 64 I40E_NETDEV_STAT(rx_crc_errors), 65 }; 66 67 static const struct i40e_stats i40e_gstrings_veb_stats[] = { 68 I40E_VEB_STAT("rx_bytes", stats.rx_bytes), 69 I40E_VEB_STAT("tx_bytes", stats.tx_bytes), 70 I40E_VEB_STAT("rx_unicast", stats.rx_unicast), 71 I40E_VEB_STAT("tx_unicast", stats.tx_unicast), 72 I40E_VEB_STAT("rx_multicast", stats.rx_multicast), 73 I40E_VEB_STAT("tx_multicast", stats.tx_multicast), 74 I40E_VEB_STAT("rx_broadcast", stats.rx_broadcast), 75 I40E_VEB_STAT("tx_broadcast", stats.tx_broadcast), 76 I40E_VEB_STAT("rx_discards", stats.rx_discards), 77 I40E_VEB_STAT("tx_discards", stats.tx_discards), 78 I40E_VEB_STAT("tx_errors", stats.tx_errors), 79 I40E_VEB_STAT("rx_unknown_protocol", stats.rx_unknown_protocol), 80 }; 81 82 static const struct i40e_stats i40e_gstrings_misc_stats[] = { 83 I40E_VSI_STAT("rx_unicast", eth_stats.rx_unicast), 84 I40E_VSI_STAT("tx_unicast", eth_stats.tx_unicast), 85 I40E_VSI_STAT("rx_multicast", eth_stats.rx_multicast), 86 I40E_VSI_STAT("tx_multicast", eth_stats.tx_multicast), 87 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast), 88 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast), 89 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol), 90 I40E_VSI_STAT("tx_linearize", tx_linearize), 91 I40E_VSI_STAT("tx_force_wb", tx_force_wb), 92 I40E_VSI_STAT("tx_lost_interrupt", tx_lost_interrupt), 93 I40E_VSI_STAT("rx_alloc_fail", rx_buf_failed), 94 I40E_VSI_STAT("rx_pg_alloc_fail", rx_page_failed), 95 }; 96 97 /* These PF_STATs might look like duplicates of some NETDEV_STATs, 98 * but they are separate. This device supports Virtualization, and 99 * as such might have several netdevs supporting VMDq and FCoE going 100 * through a single port. The NETDEV_STATs are for individual netdevs 101 * seen at the top of the stack, and the PF_STATs are for the physical 102 * function at the bottom of the stack hosting those netdevs. 103 * 104 * The PF_STATs are appended to the netdev stats only when ethtool -S 105 * is queried on the base PF netdev, not on the VMDq or FCoE netdev. 106 */ 107 static struct i40e_stats i40e_gstrings_stats[] = { 108 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes), 109 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes), 110 I40E_PF_STAT("rx_unicast", stats.eth.rx_unicast), 111 I40E_PF_STAT("tx_unicast", stats.eth.tx_unicast), 112 I40E_PF_STAT("rx_multicast", stats.eth.rx_multicast), 113 I40E_PF_STAT("tx_multicast", stats.eth.tx_multicast), 114 I40E_PF_STAT("rx_broadcast", stats.eth.rx_broadcast), 115 I40E_PF_STAT("tx_broadcast", stats.eth.tx_broadcast), 116 I40E_PF_STAT("tx_errors", stats.eth.tx_errors), 117 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards), 118 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down), 119 I40E_PF_STAT("rx_crc_errors", stats.crc_errors), 120 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes), 121 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults), 122 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults), 123 I40E_PF_STAT("tx_timeout", tx_timeout_count), 124 I40E_PF_STAT("rx_csum_bad", hw_csum_rx_error), 125 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors), 126 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx), 127 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx), 128 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx), 129 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx), 130 I40E_PF_STAT("rx_size_64", stats.rx_size_64), 131 I40E_PF_STAT("rx_size_127", stats.rx_size_127), 132 I40E_PF_STAT("rx_size_255", stats.rx_size_255), 133 I40E_PF_STAT("rx_size_511", stats.rx_size_511), 134 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023), 135 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522), 136 I40E_PF_STAT("rx_size_big", stats.rx_size_big), 137 I40E_PF_STAT("tx_size_64", stats.tx_size_64), 138 I40E_PF_STAT("tx_size_127", stats.tx_size_127), 139 I40E_PF_STAT("tx_size_255", stats.tx_size_255), 140 I40E_PF_STAT("tx_size_511", stats.tx_size_511), 141 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023), 142 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522), 143 I40E_PF_STAT("tx_size_big", stats.tx_size_big), 144 I40E_PF_STAT("rx_undersize", stats.rx_undersize), 145 I40E_PF_STAT("rx_fragments", stats.rx_fragments), 146 I40E_PF_STAT("rx_oversize", stats.rx_oversize), 147 I40E_PF_STAT("rx_jabber", stats.rx_jabber), 148 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests), 149 I40E_PF_STAT("arq_overflows", arq_overflows), 150 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared), 151 I40E_PF_STAT("fdir_flush_cnt", fd_flush_cnt), 152 I40E_PF_STAT("fdir_atr_match", stats.fd_atr_match), 153 I40E_PF_STAT("fdir_atr_tunnel_match", stats.fd_atr_tunnel_match), 154 I40E_PF_STAT("fdir_atr_status", stats.fd_atr_status), 155 I40E_PF_STAT("fdir_sb_match", stats.fd_sb_match), 156 I40E_PF_STAT("fdir_sb_status", stats.fd_sb_status), 157 158 /* LPI stats */ 159 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status), 160 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status), 161 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count), 162 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count), 163 }; 164 165 #ifdef I40E_FCOE 166 static const struct i40e_stats i40e_gstrings_fcoe_stats[] = { 167 I40E_VSI_STAT("fcoe_bad_fccrc", fcoe_stats.fcoe_bad_fccrc), 168 I40E_VSI_STAT("rx_fcoe_dropped", fcoe_stats.rx_fcoe_dropped), 169 I40E_VSI_STAT("rx_fcoe_packets", fcoe_stats.rx_fcoe_packets), 170 I40E_VSI_STAT("rx_fcoe_dwords", fcoe_stats.rx_fcoe_dwords), 171 I40E_VSI_STAT("fcoe_ddp_count", fcoe_stats.fcoe_ddp_count), 172 I40E_VSI_STAT("fcoe_last_error", fcoe_stats.fcoe_last_error), 173 I40E_VSI_STAT("tx_fcoe_packets", fcoe_stats.tx_fcoe_packets), 174 I40E_VSI_STAT("tx_fcoe_dwords", fcoe_stats.tx_fcoe_dwords), 175 }; 176 177 #endif /* I40E_FCOE */ 178 #define I40E_QUEUE_STATS_LEN(n) \ 179 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \ 180 * 2 /* Tx and Rx together */ \ 181 * (sizeof(struct i40e_queue_stats) / sizeof(u64))) 182 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats) 183 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats) 184 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats) 185 #ifdef I40E_FCOE 186 #define I40E_FCOE_STATS_LEN ARRAY_SIZE(i40e_gstrings_fcoe_stats) 187 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \ 188 I40E_FCOE_STATS_LEN + \ 189 I40E_MISC_STATS_LEN + \ 190 I40E_QUEUE_STATS_LEN((n))) 191 #else 192 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \ 193 I40E_MISC_STATS_LEN + \ 194 I40E_QUEUE_STATS_LEN((n))) 195 #endif /* I40E_FCOE */ 196 #define I40E_PFC_STATS_LEN ( \ 197 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \ 198 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \ 199 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \ 200 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \ 201 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \ 202 / sizeof(u64)) 203 #define I40E_VEB_TC_STATS_LEN ( \ 204 (FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_packets) + \ 205 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_rx_bytes) + \ 206 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_packets) + \ 207 FIELD_SIZEOF(struct i40e_veb, tc_stats.tc_tx_bytes)) \ 208 / sizeof(u64)) 209 #define I40E_VEB_STATS_LEN ARRAY_SIZE(i40e_gstrings_veb_stats) 210 #define I40E_VEB_STATS_TOTAL (I40E_VEB_STATS_LEN + I40E_VEB_TC_STATS_LEN) 211 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \ 212 I40E_PFC_STATS_LEN + \ 213 I40E_VSI_STATS_LEN((n))) 214 215 enum i40e_ethtool_test_id { 216 I40E_ETH_TEST_REG = 0, 217 I40E_ETH_TEST_EEPROM, 218 I40E_ETH_TEST_INTR, 219 I40E_ETH_TEST_LOOPBACK, 220 I40E_ETH_TEST_LINK, 221 }; 222 223 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = { 224 "Register test (offline)", 225 "Eeprom test (offline)", 226 "Interrupt test (offline)", 227 "Loopback test (offline)", 228 "Link test (on/offline)" 229 }; 230 231 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN) 232 233 static const char i40e_priv_flags_strings_gl[][ETH_GSTRING_LEN] = { 234 "MFP", 235 "LinkPolling", 236 "flow-director-atr", 237 "veb-stats", 238 "hw-atr-eviction", 239 "vf-true-promisc-support", 240 }; 241 242 #define I40E_PRIV_FLAGS_GL_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings_gl) 243 244 static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = { 245 "NPAR", 246 "LinkPolling", 247 "flow-director-atr", 248 "veb-stats", 249 "hw-atr-eviction", 250 }; 251 252 #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings) 253 254 /** 255 * i40e_partition_setting_complaint - generic complaint for MFP restriction 256 * @pf: the PF struct 257 **/ 258 static void i40e_partition_setting_complaint(struct i40e_pf *pf) 259 { 260 dev_info(&pf->pdev->dev, 261 "The link settings are allowed to be changed only from the first partition of a given port. Please switch to the first partition in order to change the setting.\n"); 262 } 263 264 /** 265 * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes 266 * @phy_types: PHY types to convert 267 * @supported: pointer to the ethtool supported variable to fill in 268 * @advertising: pointer to the ethtool advertising variable to fill in 269 * 270 **/ 271 static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported, 272 u32 *advertising) 273 { 274 enum i40e_aq_capabilities_phy_type phy_types = pf->hw.phy.phy_types; 275 276 *supported = 0x0; 277 *advertising = 0x0; 278 279 if (phy_types & I40E_CAP_PHY_TYPE_SGMII) { 280 *supported |= SUPPORTED_Autoneg | 281 SUPPORTED_1000baseT_Full; 282 *advertising |= ADVERTISED_Autoneg | 283 ADVERTISED_1000baseT_Full; 284 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) { 285 *supported |= SUPPORTED_100baseT_Full; 286 *advertising |= ADVERTISED_100baseT_Full; 287 } 288 } 289 if (phy_types & I40E_CAP_PHY_TYPE_XAUI || 290 phy_types & I40E_CAP_PHY_TYPE_XFI || 291 phy_types & I40E_CAP_PHY_TYPE_SFI || 292 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU || 293 phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) 294 *supported |= SUPPORTED_10000baseT_Full; 295 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU || 296 phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 || 297 phy_types & I40E_CAP_PHY_TYPE_10GBASE_T || 298 phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR || 299 phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) { 300 *supported |= SUPPORTED_Autoneg | 301 SUPPORTED_10000baseT_Full; 302 *advertising |= ADVERTISED_Autoneg | 303 ADVERTISED_10000baseT_Full; 304 } 305 if (phy_types & I40E_CAP_PHY_TYPE_XLAUI || 306 phy_types & I40E_CAP_PHY_TYPE_XLPPI || 307 phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC) 308 *supported |= SUPPORTED_40000baseCR4_Full; 309 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU || 310 phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) { 311 *supported |= SUPPORTED_Autoneg | 312 SUPPORTED_40000baseCR4_Full; 313 *advertising |= ADVERTISED_Autoneg | 314 ADVERTISED_40000baseCR4_Full; 315 } 316 if ((phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) && 317 !(phy_types & I40E_CAP_PHY_TYPE_1000BASE_T)) { 318 *supported |= SUPPORTED_Autoneg | 319 SUPPORTED_100baseT_Full; 320 *advertising |= ADVERTISED_Autoneg | 321 ADVERTISED_100baseT_Full; 322 } 323 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T || 324 phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX || 325 phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX || 326 phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) { 327 *supported |= SUPPORTED_Autoneg | 328 SUPPORTED_1000baseT_Full; 329 *advertising |= ADVERTISED_Autoneg | 330 ADVERTISED_1000baseT_Full; 331 } 332 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4) 333 *supported |= SUPPORTED_40000baseSR4_Full; 334 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4) 335 *supported |= SUPPORTED_40000baseLR4_Full; 336 if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) { 337 *supported |= SUPPORTED_40000baseKR4_Full | 338 SUPPORTED_Autoneg; 339 *advertising |= ADVERTISED_40000baseKR4_Full | 340 ADVERTISED_Autoneg; 341 } 342 if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) { 343 *supported |= SUPPORTED_20000baseKR2_Full | 344 SUPPORTED_Autoneg; 345 *advertising |= ADVERTISED_20000baseKR2_Full | 346 ADVERTISED_Autoneg; 347 } 348 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) { 349 *supported |= SUPPORTED_10000baseKR_Full | 350 SUPPORTED_Autoneg; 351 *advertising |= ADVERTISED_10000baseKR_Full | 352 ADVERTISED_Autoneg; 353 } 354 if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) { 355 *supported |= SUPPORTED_10000baseKX4_Full | 356 SUPPORTED_Autoneg; 357 *advertising |= ADVERTISED_10000baseKX4_Full | 358 ADVERTISED_Autoneg; 359 } 360 if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) { 361 *supported |= SUPPORTED_1000baseKX_Full | 362 SUPPORTED_Autoneg; 363 *advertising |= ADVERTISED_1000baseKX_Full | 364 ADVERTISED_Autoneg; 365 } 366 } 367 368 /** 369 * i40e_get_settings_link_up - Get the Link settings for when link is up 370 * @hw: hw structure 371 * @ecmd: ethtool command to fill in 372 * @netdev: network interface device structure 373 * 374 **/ 375 static void i40e_get_settings_link_up(struct i40e_hw *hw, 376 struct ethtool_cmd *ecmd, 377 struct net_device *netdev, 378 struct i40e_pf *pf) 379 { 380 struct i40e_link_status *hw_link_info = &hw->phy.link_info; 381 u32 link_speed = hw_link_info->link_speed; 382 u32 e_advertising = 0x0; 383 u32 e_supported = 0x0; 384 385 /* Initialize supported and advertised settings based on phy settings */ 386 switch (hw_link_info->phy_type) { 387 case I40E_PHY_TYPE_40GBASE_CR4: 388 case I40E_PHY_TYPE_40GBASE_CR4_CU: 389 ecmd->supported = SUPPORTED_Autoneg | 390 SUPPORTED_40000baseCR4_Full; 391 ecmd->advertising = ADVERTISED_Autoneg | 392 ADVERTISED_40000baseCR4_Full; 393 break; 394 case I40E_PHY_TYPE_XLAUI: 395 case I40E_PHY_TYPE_XLPPI: 396 case I40E_PHY_TYPE_40GBASE_AOC: 397 ecmd->supported = SUPPORTED_40000baseCR4_Full; 398 break; 399 case I40E_PHY_TYPE_40GBASE_SR4: 400 ecmd->supported = SUPPORTED_40000baseSR4_Full; 401 break; 402 case I40E_PHY_TYPE_40GBASE_LR4: 403 ecmd->supported = SUPPORTED_40000baseLR4_Full; 404 break; 405 case I40E_PHY_TYPE_10GBASE_SR: 406 case I40E_PHY_TYPE_10GBASE_LR: 407 case I40E_PHY_TYPE_1000BASE_SX: 408 case I40E_PHY_TYPE_1000BASE_LX: 409 ecmd->supported = SUPPORTED_10000baseT_Full; 410 if (hw_link_info->module_type[2] & 411 I40E_MODULE_TYPE_1000BASE_SX || 412 hw_link_info->module_type[2] & 413 I40E_MODULE_TYPE_1000BASE_LX) { 414 ecmd->supported |= SUPPORTED_1000baseT_Full; 415 if (hw_link_info->requested_speeds & 416 I40E_LINK_SPEED_1GB) 417 ecmd->advertising |= ADVERTISED_1000baseT_Full; 418 } 419 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 420 ecmd->advertising |= ADVERTISED_10000baseT_Full; 421 break; 422 case I40E_PHY_TYPE_10GBASE_T: 423 case I40E_PHY_TYPE_1000BASE_T: 424 case I40E_PHY_TYPE_100BASE_TX: 425 ecmd->supported = SUPPORTED_Autoneg | 426 SUPPORTED_10000baseT_Full | 427 SUPPORTED_1000baseT_Full | 428 SUPPORTED_100baseT_Full; 429 ecmd->advertising = ADVERTISED_Autoneg; 430 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) 431 ecmd->advertising |= ADVERTISED_10000baseT_Full; 432 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) 433 ecmd->advertising |= ADVERTISED_1000baseT_Full; 434 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB) 435 ecmd->advertising |= ADVERTISED_100baseT_Full; 436 break; 437 case I40E_PHY_TYPE_1000BASE_T_OPTICAL: 438 ecmd->supported = SUPPORTED_Autoneg | 439 SUPPORTED_1000baseT_Full; 440 ecmd->advertising = ADVERTISED_Autoneg | 441 ADVERTISED_1000baseT_Full; 442 break; 443 case I40E_PHY_TYPE_10GBASE_CR1_CU: 444 case I40E_PHY_TYPE_10GBASE_CR1: 445 ecmd->supported = SUPPORTED_Autoneg | 446 SUPPORTED_10000baseT_Full; 447 ecmd->advertising = ADVERTISED_Autoneg | 448 ADVERTISED_10000baseT_Full; 449 break; 450 case I40E_PHY_TYPE_XAUI: 451 case I40E_PHY_TYPE_XFI: 452 case I40E_PHY_TYPE_SFI: 453 case I40E_PHY_TYPE_10GBASE_SFPP_CU: 454 case I40E_PHY_TYPE_10GBASE_AOC: 455 ecmd->supported = SUPPORTED_10000baseT_Full; 456 break; 457 case I40E_PHY_TYPE_SGMII: 458 ecmd->supported = SUPPORTED_Autoneg | 459 SUPPORTED_1000baseT_Full; 460 if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) 461 ecmd->advertising |= ADVERTISED_1000baseT_Full; 462 if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) { 463 ecmd->supported |= SUPPORTED_100baseT_Full; 464 if (hw_link_info->requested_speeds & 465 I40E_LINK_SPEED_100MB) 466 ecmd->advertising |= ADVERTISED_100baseT_Full; 467 } 468 break; 469 case I40E_PHY_TYPE_40GBASE_KR4: 470 case I40E_PHY_TYPE_20GBASE_KR2: 471 case I40E_PHY_TYPE_10GBASE_KR: 472 case I40E_PHY_TYPE_10GBASE_KX4: 473 case I40E_PHY_TYPE_1000BASE_KX: 474 ecmd->supported |= SUPPORTED_40000baseKR4_Full | 475 SUPPORTED_20000baseKR2_Full | 476 SUPPORTED_10000baseKR_Full | 477 SUPPORTED_10000baseKX4_Full | 478 SUPPORTED_1000baseKX_Full | 479 SUPPORTED_Autoneg; 480 ecmd->advertising |= ADVERTISED_40000baseKR4_Full | 481 ADVERTISED_20000baseKR2_Full | 482 ADVERTISED_10000baseKR_Full | 483 ADVERTISED_10000baseKX4_Full | 484 ADVERTISED_1000baseKX_Full | 485 ADVERTISED_Autoneg; 486 break; 487 default: 488 /* if we got here and link is up something bad is afoot */ 489 netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n", 490 hw_link_info->phy_type); 491 } 492 493 /* Now that we've worked out everything that could be supported by the 494 * current PHY type, get what is supported by the NVM and them to 495 * get what is truly supported 496 */ 497 i40e_phy_type_to_ethtool(pf, &e_supported, 498 &e_advertising); 499 500 ecmd->supported = ecmd->supported & e_supported; 501 ecmd->advertising = ecmd->advertising & e_advertising; 502 503 /* Set speed and duplex */ 504 switch (link_speed) { 505 case I40E_LINK_SPEED_40GB: 506 ethtool_cmd_speed_set(ecmd, SPEED_40000); 507 break; 508 case I40E_LINK_SPEED_20GB: 509 ethtool_cmd_speed_set(ecmd, SPEED_20000); 510 break; 511 case I40E_LINK_SPEED_10GB: 512 ethtool_cmd_speed_set(ecmd, SPEED_10000); 513 break; 514 case I40E_LINK_SPEED_1GB: 515 ethtool_cmd_speed_set(ecmd, SPEED_1000); 516 break; 517 case I40E_LINK_SPEED_100MB: 518 ethtool_cmd_speed_set(ecmd, SPEED_100); 519 break; 520 default: 521 break; 522 } 523 ecmd->duplex = DUPLEX_FULL; 524 } 525 526 /** 527 * i40e_get_settings_link_down - Get the Link settings for when link is down 528 * @hw: hw structure 529 * @ecmd: ethtool command to fill in 530 * 531 * Reports link settings that can be determined when link is down 532 **/ 533 static void i40e_get_settings_link_down(struct i40e_hw *hw, 534 struct ethtool_cmd *ecmd, 535 struct i40e_pf *pf) 536 { 537 /* link is down and the driver needs to fall back on 538 * supported phy types to figure out what info to display 539 */ 540 i40e_phy_type_to_ethtool(pf, &ecmd->supported, 541 &ecmd->advertising); 542 543 /* With no link speed and duplex are unknown */ 544 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN); 545 ecmd->duplex = DUPLEX_UNKNOWN; 546 } 547 548 /** 549 * i40e_get_settings - Get Link Speed and Duplex settings 550 * @netdev: network interface device structure 551 * @ecmd: ethtool command 552 * 553 * Reports speed/duplex settings based on media_type 554 **/ 555 static int i40e_get_settings(struct net_device *netdev, 556 struct ethtool_cmd *ecmd) 557 { 558 struct i40e_netdev_priv *np = netdev_priv(netdev); 559 struct i40e_pf *pf = np->vsi->back; 560 struct i40e_hw *hw = &pf->hw; 561 struct i40e_link_status *hw_link_info = &hw->phy.link_info; 562 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; 563 564 if (link_up) 565 i40e_get_settings_link_up(hw, ecmd, netdev, pf); 566 else 567 i40e_get_settings_link_down(hw, ecmd, pf); 568 569 /* Now set the settings that don't rely on link being up/down */ 570 /* Set autoneg settings */ 571 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? 572 AUTONEG_ENABLE : AUTONEG_DISABLE); 573 574 switch (hw->phy.media_type) { 575 case I40E_MEDIA_TYPE_BACKPLANE: 576 ecmd->supported |= SUPPORTED_Autoneg | 577 SUPPORTED_Backplane; 578 ecmd->advertising |= ADVERTISED_Autoneg | 579 ADVERTISED_Backplane; 580 ecmd->port = PORT_NONE; 581 break; 582 case I40E_MEDIA_TYPE_BASET: 583 ecmd->supported |= SUPPORTED_TP; 584 ecmd->advertising |= ADVERTISED_TP; 585 ecmd->port = PORT_TP; 586 break; 587 case I40E_MEDIA_TYPE_DA: 588 case I40E_MEDIA_TYPE_CX4: 589 ecmd->supported |= SUPPORTED_FIBRE; 590 ecmd->advertising |= ADVERTISED_FIBRE; 591 ecmd->port = PORT_DA; 592 break; 593 case I40E_MEDIA_TYPE_FIBER: 594 ecmd->supported |= SUPPORTED_FIBRE; 595 ecmd->port = PORT_FIBRE; 596 break; 597 case I40E_MEDIA_TYPE_UNKNOWN: 598 default: 599 ecmd->port = PORT_OTHER; 600 break; 601 } 602 603 /* Set transceiver */ 604 ecmd->transceiver = XCVR_EXTERNAL; 605 606 /* Set flow control settings */ 607 ecmd->supported |= SUPPORTED_Pause; 608 609 switch (hw->fc.requested_mode) { 610 case I40E_FC_FULL: 611 ecmd->advertising |= ADVERTISED_Pause; 612 break; 613 case I40E_FC_TX_PAUSE: 614 ecmd->advertising |= ADVERTISED_Asym_Pause; 615 break; 616 case I40E_FC_RX_PAUSE: 617 ecmd->advertising |= (ADVERTISED_Pause | 618 ADVERTISED_Asym_Pause); 619 break; 620 default: 621 ecmd->advertising &= ~(ADVERTISED_Pause | 622 ADVERTISED_Asym_Pause); 623 break; 624 } 625 626 return 0; 627 } 628 629 /** 630 * i40e_set_settings - Set Speed and Duplex 631 * @netdev: network interface device structure 632 * @ecmd: ethtool command 633 * 634 * Set speed/duplex per media_types advertised/forced 635 **/ 636 static int i40e_set_settings(struct net_device *netdev, 637 struct ethtool_cmd *ecmd) 638 { 639 struct i40e_netdev_priv *np = netdev_priv(netdev); 640 struct i40e_aq_get_phy_abilities_resp abilities; 641 struct i40e_aq_set_phy_config config; 642 struct i40e_pf *pf = np->vsi->back; 643 struct i40e_vsi *vsi = np->vsi; 644 struct i40e_hw *hw = &pf->hw; 645 struct ethtool_cmd safe_ecmd; 646 i40e_status status = 0; 647 bool change = false; 648 int err = 0; 649 u8 autoneg; 650 u32 advertise; 651 652 /* Changing port settings is not supported if this isn't the 653 * port's controlling PF 654 */ 655 if (hw->partition_id != 1) { 656 i40e_partition_setting_complaint(pf); 657 return -EOPNOTSUPP; 658 } 659 660 if (vsi != pf->vsi[pf->lan_vsi]) 661 return -EOPNOTSUPP; 662 663 if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET && 664 hw->phy.media_type != I40E_MEDIA_TYPE_FIBER && 665 hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE && 666 hw->phy.link_info.link_info & I40E_AQ_LINK_UP) 667 return -EOPNOTSUPP; 668 669 if (hw->device_id == I40E_DEV_ID_KX_B || 670 hw->device_id == I40E_DEV_ID_KX_C || 671 hw->device_id == I40E_DEV_ID_20G_KR2 || 672 hw->device_id == I40E_DEV_ID_20G_KR2_A) { 673 netdev_info(netdev, "Changing settings is not supported on backplane.\n"); 674 return -EOPNOTSUPP; 675 } 676 677 /* get our own copy of the bits to check against */ 678 memset(&safe_ecmd, 0, sizeof(struct ethtool_cmd)); 679 i40e_get_settings(netdev, &safe_ecmd); 680 681 /* save autoneg and speed out of ecmd */ 682 autoneg = ecmd->autoneg; 683 advertise = ecmd->advertising; 684 685 /* set autoneg and speed back to what they currently are */ 686 ecmd->autoneg = safe_ecmd.autoneg; 687 ecmd->advertising = safe_ecmd.advertising; 688 689 ecmd->cmd = safe_ecmd.cmd; 690 /* If ecmd and safe_ecmd are not the same now, then they are 691 * trying to set something that we do not support 692 */ 693 if (memcmp(ecmd, &safe_ecmd, sizeof(struct ethtool_cmd))) 694 return -EOPNOTSUPP; 695 696 while (test_bit(__I40E_CONFIG_BUSY, &vsi->state)) 697 usleep_range(1000, 2000); 698 699 /* Get the current phy config */ 700 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, 701 NULL); 702 if (status) 703 return -EAGAIN; 704 705 /* Copy abilities to config in case autoneg is not 706 * set below 707 */ 708 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config)); 709 config.abilities = abilities.abilities; 710 711 /* Check autoneg */ 712 if (autoneg == AUTONEG_ENABLE) { 713 /* If autoneg was not already enabled */ 714 if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) { 715 /* If autoneg is not supported, return error */ 716 if (!(safe_ecmd.supported & SUPPORTED_Autoneg)) { 717 netdev_info(netdev, "Autoneg not supported on this phy\n"); 718 return -EINVAL; 719 } 720 /* Autoneg is allowed to change */ 721 config.abilities = abilities.abilities | 722 I40E_AQ_PHY_ENABLE_AN; 723 change = true; 724 } 725 } else { 726 /* If autoneg is currently enabled */ 727 if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) { 728 /* If autoneg is supported 10GBASE_T is the only PHY 729 * that can disable it, so otherwise return error 730 */ 731 if (safe_ecmd.supported & SUPPORTED_Autoneg && 732 hw->phy.link_info.phy_type != 733 I40E_PHY_TYPE_10GBASE_T) { 734 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n"); 735 return -EINVAL; 736 } 737 /* Autoneg is allowed to change */ 738 config.abilities = abilities.abilities & 739 ~I40E_AQ_PHY_ENABLE_AN; 740 change = true; 741 } 742 } 743 744 if (advertise & ~safe_ecmd.supported) 745 return -EINVAL; 746 747 if (advertise & ADVERTISED_100baseT_Full) 748 config.link_speed |= I40E_LINK_SPEED_100MB; 749 if (advertise & ADVERTISED_1000baseT_Full || 750 advertise & ADVERTISED_1000baseKX_Full) 751 config.link_speed |= I40E_LINK_SPEED_1GB; 752 if (advertise & ADVERTISED_10000baseT_Full || 753 advertise & ADVERTISED_10000baseKX4_Full || 754 advertise & ADVERTISED_10000baseKR_Full) 755 config.link_speed |= I40E_LINK_SPEED_10GB; 756 if (advertise & ADVERTISED_20000baseKR2_Full) 757 config.link_speed |= I40E_LINK_SPEED_20GB; 758 if (advertise & ADVERTISED_40000baseKR4_Full || 759 advertise & ADVERTISED_40000baseCR4_Full || 760 advertise & ADVERTISED_40000baseSR4_Full || 761 advertise & ADVERTISED_40000baseLR4_Full) 762 config.link_speed |= I40E_LINK_SPEED_40GB; 763 764 /* If speed didn't get set, set it to what it currently is. 765 * This is needed because if advertise is 0 (as it is when autoneg 766 * is disabled) then speed won't get set. 767 */ 768 if (!config.link_speed) 769 config.link_speed = abilities.link_speed; 770 771 if (change || (abilities.link_speed != config.link_speed)) { 772 /* copy over the rest of the abilities */ 773 config.phy_type = abilities.phy_type; 774 config.eee_capability = abilities.eee_capability; 775 config.eeer = abilities.eeer_val; 776 config.low_power_ctrl = abilities.d3_lpan; 777 778 /* save the requested speeds */ 779 hw->phy.link_info.requested_speeds = config.link_speed; 780 /* set link and auto negotiation so changes take effect */ 781 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK; 782 /* If link is up put link down */ 783 if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) { 784 /* Tell the OS link is going down, the link will go 785 * back up when fw says it is ready asynchronously 786 */ 787 i40e_print_link_message(vsi, false); 788 netif_carrier_off(netdev); 789 netif_tx_stop_all_queues(netdev); 790 } 791 792 /* make the aq call */ 793 status = i40e_aq_set_phy_config(hw, &config, NULL); 794 if (status) { 795 netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n", 796 i40e_stat_str(hw, status), 797 i40e_aq_str(hw, hw->aq.asq_last_status)); 798 return -EAGAIN; 799 } 800 801 status = i40e_update_link_info(hw); 802 if (status) 803 netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n", 804 i40e_stat_str(hw, status), 805 i40e_aq_str(hw, hw->aq.asq_last_status)); 806 807 } else { 808 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n"); 809 } 810 811 return err; 812 } 813 814 static int i40e_nway_reset(struct net_device *netdev) 815 { 816 /* restart autonegotiation */ 817 struct i40e_netdev_priv *np = netdev_priv(netdev); 818 struct i40e_pf *pf = np->vsi->back; 819 struct i40e_hw *hw = &pf->hw; 820 bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP; 821 i40e_status ret = 0; 822 823 ret = i40e_aq_set_link_restart_an(hw, link_up, NULL); 824 if (ret) { 825 netdev_info(netdev, "link restart failed, err %s aq_err %s\n", 826 i40e_stat_str(hw, ret), 827 i40e_aq_str(hw, hw->aq.asq_last_status)); 828 return -EIO; 829 } 830 831 return 0; 832 } 833 834 /** 835 * i40e_get_pauseparam - Get Flow Control status 836 * Return tx/rx-pause status 837 **/ 838 static void i40e_get_pauseparam(struct net_device *netdev, 839 struct ethtool_pauseparam *pause) 840 { 841 struct i40e_netdev_priv *np = netdev_priv(netdev); 842 struct i40e_pf *pf = np->vsi->back; 843 struct i40e_hw *hw = &pf->hw; 844 struct i40e_link_status *hw_link_info = &hw->phy.link_info; 845 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; 846 847 pause->autoneg = 848 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? 849 AUTONEG_ENABLE : AUTONEG_DISABLE); 850 851 /* PFC enabled so report LFC as off */ 852 if (dcbx_cfg->pfc.pfcenable) { 853 pause->rx_pause = 0; 854 pause->tx_pause = 0; 855 return; 856 } 857 858 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) { 859 pause->rx_pause = 1; 860 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) { 861 pause->tx_pause = 1; 862 } else if (hw->fc.current_mode == I40E_FC_FULL) { 863 pause->rx_pause = 1; 864 pause->tx_pause = 1; 865 } 866 } 867 868 /** 869 * i40e_set_pauseparam - Set Flow Control parameter 870 * @netdev: network interface device structure 871 * @pause: return tx/rx flow control status 872 **/ 873 static int i40e_set_pauseparam(struct net_device *netdev, 874 struct ethtool_pauseparam *pause) 875 { 876 struct i40e_netdev_priv *np = netdev_priv(netdev); 877 struct i40e_pf *pf = np->vsi->back; 878 struct i40e_vsi *vsi = np->vsi; 879 struct i40e_hw *hw = &pf->hw; 880 struct i40e_link_status *hw_link_info = &hw->phy.link_info; 881 struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; 882 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; 883 i40e_status status; 884 u8 aq_failures; 885 int err = 0; 886 887 /* Changing the port's flow control is not supported if this isn't the 888 * port's controlling PF 889 */ 890 if (hw->partition_id != 1) { 891 i40e_partition_setting_complaint(pf); 892 return -EOPNOTSUPP; 893 } 894 895 if (vsi != pf->vsi[pf->lan_vsi]) 896 return -EOPNOTSUPP; 897 898 if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? 899 AUTONEG_ENABLE : AUTONEG_DISABLE)) { 900 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n"); 901 return -EOPNOTSUPP; 902 } 903 904 /* If we have link and don't have autoneg */ 905 if (!test_bit(__I40E_DOWN, &pf->state) && 906 !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) { 907 /* Send message that it might not necessarily work*/ 908 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n"); 909 } 910 911 if (dcbx_cfg->pfc.pfcenable) { 912 netdev_info(netdev, 913 "Priority flow control enabled. Cannot set link flow control.\n"); 914 return -EOPNOTSUPP; 915 } 916 917 if (pause->rx_pause && pause->tx_pause) 918 hw->fc.requested_mode = I40E_FC_FULL; 919 else if (pause->rx_pause && !pause->tx_pause) 920 hw->fc.requested_mode = I40E_FC_RX_PAUSE; 921 else if (!pause->rx_pause && pause->tx_pause) 922 hw->fc.requested_mode = I40E_FC_TX_PAUSE; 923 else if (!pause->rx_pause && !pause->tx_pause) 924 hw->fc.requested_mode = I40E_FC_NONE; 925 else 926 return -EINVAL; 927 928 /* Tell the OS link is going down, the link will go back up when fw 929 * says it is ready asynchronously 930 */ 931 i40e_print_link_message(vsi, false); 932 netif_carrier_off(netdev); 933 netif_tx_stop_all_queues(netdev); 934 935 /* Set the fc mode and only restart an if link is up*/ 936 status = i40e_set_fc(hw, &aq_failures, link_up); 937 938 if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) { 939 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n", 940 i40e_stat_str(hw, status), 941 i40e_aq_str(hw, hw->aq.asq_last_status)); 942 err = -EAGAIN; 943 } 944 if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) { 945 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n", 946 i40e_stat_str(hw, status), 947 i40e_aq_str(hw, hw->aq.asq_last_status)); 948 err = -EAGAIN; 949 } 950 if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) { 951 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n", 952 i40e_stat_str(hw, status), 953 i40e_aq_str(hw, hw->aq.asq_last_status)); 954 err = -EAGAIN; 955 } 956 957 if (!test_bit(__I40E_DOWN, &pf->state)) { 958 /* Give it a little more time to try to come back */ 959 msleep(75); 960 if (!test_bit(__I40E_DOWN, &pf->state)) 961 return i40e_nway_reset(netdev); 962 } 963 964 return err; 965 } 966 967 static u32 i40e_get_msglevel(struct net_device *netdev) 968 { 969 struct i40e_netdev_priv *np = netdev_priv(netdev); 970 struct i40e_pf *pf = np->vsi->back; 971 972 return pf->msg_enable; 973 } 974 975 static void i40e_set_msglevel(struct net_device *netdev, u32 data) 976 { 977 struct i40e_netdev_priv *np = netdev_priv(netdev); 978 struct i40e_pf *pf = np->vsi->back; 979 980 if (I40E_DEBUG_USER & data) 981 pf->hw.debug_mask = data; 982 pf->msg_enable = data; 983 } 984 985 static int i40e_get_regs_len(struct net_device *netdev) 986 { 987 int reg_count = 0; 988 int i; 989 990 for (i = 0; i40e_reg_list[i].offset != 0; i++) 991 reg_count += i40e_reg_list[i].elements; 992 993 return reg_count * sizeof(u32); 994 } 995 996 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs, 997 void *p) 998 { 999 struct i40e_netdev_priv *np = netdev_priv(netdev); 1000 struct i40e_pf *pf = np->vsi->back; 1001 struct i40e_hw *hw = &pf->hw; 1002 u32 *reg_buf = p; 1003 int i, j, ri; 1004 u32 reg; 1005 1006 /* Tell ethtool which driver-version-specific regs output we have. 1007 * 1008 * At some point, if we have ethtool doing special formatting of 1009 * this data, it will rely on this version number to know how to 1010 * interpret things. Hence, this needs to be updated if/when the 1011 * diags register table is changed. 1012 */ 1013 regs->version = 1; 1014 1015 /* loop through the diags reg table for what to print */ 1016 ri = 0; 1017 for (i = 0; i40e_reg_list[i].offset != 0; i++) { 1018 for (j = 0; j < i40e_reg_list[i].elements; j++) { 1019 reg = i40e_reg_list[i].offset 1020 + (j * i40e_reg_list[i].stride); 1021 reg_buf[ri++] = rd32(hw, reg); 1022 } 1023 } 1024 1025 } 1026 1027 static int i40e_get_eeprom(struct net_device *netdev, 1028 struct ethtool_eeprom *eeprom, u8 *bytes) 1029 { 1030 struct i40e_netdev_priv *np = netdev_priv(netdev); 1031 struct i40e_hw *hw = &np->vsi->back->hw; 1032 struct i40e_pf *pf = np->vsi->back; 1033 int ret_val = 0, len, offset; 1034 u8 *eeprom_buff; 1035 u16 i, sectors; 1036 bool last; 1037 u32 magic; 1038 1039 #define I40E_NVM_SECTOR_SIZE 4096 1040 if (eeprom->len == 0) 1041 return -EINVAL; 1042 1043 /* check for NVMUpdate access method */ 1044 magic = hw->vendor_id | (hw->device_id << 16); 1045 if (eeprom->magic && eeprom->magic != magic) { 1046 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom; 1047 int errno = 0; 1048 1049 /* make sure it is the right magic for NVMUpdate */ 1050 if ((eeprom->magic >> 16) != hw->device_id) 1051 errno = -EINVAL; 1052 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || 1053 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) 1054 errno = -EBUSY; 1055 else 1056 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno); 1057 1058 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM)) 1059 dev_info(&pf->pdev->dev, 1060 "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n", 1061 ret_val, hw->aq.asq_last_status, errno, 1062 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK), 1063 cmd->offset, cmd->data_size); 1064 1065 return errno; 1066 } 1067 1068 /* normal ethtool get_eeprom support */ 1069 eeprom->magic = hw->vendor_id | (hw->device_id << 16); 1070 1071 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL); 1072 if (!eeprom_buff) 1073 return -ENOMEM; 1074 1075 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ); 1076 if (ret_val) { 1077 dev_info(&pf->pdev->dev, 1078 "Failed Acquiring NVM resource for read err=%d status=0x%x\n", 1079 ret_val, hw->aq.asq_last_status); 1080 goto free_buff; 1081 } 1082 1083 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE; 1084 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0; 1085 len = I40E_NVM_SECTOR_SIZE; 1086 last = false; 1087 for (i = 0; i < sectors; i++) { 1088 if (i == (sectors - 1)) { 1089 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i); 1090 last = true; 1091 } 1092 offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i), 1093 ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len, 1094 (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i), 1095 last, NULL); 1096 if (ret_val && hw->aq.asq_last_status == I40E_AQ_RC_EPERM) { 1097 dev_info(&pf->pdev->dev, 1098 "read NVM failed, invalid offset 0x%x\n", 1099 offset); 1100 break; 1101 } else if (ret_val && 1102 hw->aq.asq_last_status == I40E_AQ_RC_EACCES) { 1103 dev_info(&pf->pdev->dev, 1104 "read NVM failed, access, offset 0x%x\n", 1105 offset); 1106 break; 1107 } else if (ret_val) { 1108 dev_info(&pf->pdev->dev, 1109 "read NVM failed offset %d err=%d status=0x%x\n", 1110 offset, ret_val, hw->aq.asq_last_status); 1111 break; 1112 } 1113 } 1114 1115 i40e_release_nvm(hw); 1116 memcpy(bytes, (u8 *)eeprom_buff, eeprom->len); 1117 free_buff: 1118 kfree(eeprom_buff); 1119 return ret_val; 1120 } 1121 1122 static int i40e_get_eeprom_len(struct net_device *netdev) 1123 { 1124 struct i40e_netdev_priv *np = netdev_priv(netdev); 1125 struct i40e_hw *hw = &np->vsi->back->hw; 1126 u32 val; 1127 1128 val = (rd32(hw, I40E_GLPCI_LBARCTRL) 1129 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK) 1130 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT; 1131 /* register returns value in power of 2, 64Kbyte chunks. */ 1132 val = (64 * 1024) * BIT(val); 1133 return val; 1134 } 1135 1136 static int i40e_set_eeprom(struct net_device *netdev, 1137 struct ethtool_eeprom *eeprom, u8 *bytes) 1138 { 1139 struct i40e_netdev_priv *np = netdev_priv(netdev); 1140 struct i40e_hw *hw = &np->vsi->back->hw; 1141 struct i40e_pf *pf = np->vsi->back; 1142 struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom; 1143 int ret_val = 0; 1144 int errno = 0; 1145 u32 magic; 1146 1147 /* normal ethtool set_eeprom is not supported */ 1148 magic = hw->vendor_id | (hw->device_id << 16); 1149 if (eeprom->magic == magic) 1150 errno = -EOPNOTSUPP; 1151 /* check for NVMUpdate access method */ 1152 else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id) 1153 errno = -EINVAL; 1154 else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || 1155 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) 1156 errno = -EBUSY; 1157 else 1158 ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno); 1159 1160 if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM)) 1161 dev_info(&pf->pdev->dev, 1162 "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n", 1163 ret_val, hw->aq.asq_last_status, errno, 1164 (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK), 1165 cmd->offset, cmd->data_size); 1166 1167 return errno; 1168 } 1169 1170 static void i40e_get_drvinfo(struct net_device *netdev, 1171 struct ethtool_drvinfo *drvinfo) 1172 { 1173 struct i40e_netdev_priv *np = netdev_priv(netdev); 1174 struct i40e_vsi *vsi = np->vsi; 1175 struct i40e_pf *pf = vsi->back; 1176 1177 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver)); 1178 strlcpy(drvinfo->version, i40e_driver_version_str, 1179 sizeof(drvinfo->version)); 1180 strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw), 1181 sizeof(drvinfo->fw_version)); 1182 strlcpy(drvinfo->bus_info, pci_name(pf->pdev), 1183 sizeof(drvinfo->bus_info)); 1184 if (pf->hw.pf_id == 0) 1185 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_GL_STR_LEN; 1186 else 1187 drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN; 1188 } 1189 1190 static void i40e_get_ringparam(struct net_device *netdev, 1191 struct ethtool_ringparam *ring) 1192 { 1193 struct i40e_netdev_priv *np = netdev_priv(netdev); 1194 struct i40e_pf *pf = np->vsi->back; 1195 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; 1196 1197 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS; 1198 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS; 1199 ring->rx_mini_max_pending = 0; 1200 ring->rx_jumbo_max_pending = 0; 1201 ring->rx_pending = vsi->rx_rings[0]->count; 1202 ring->tx_pending = vsi->tx_rings[0]->count; 1203 ring->rx_mini_pending = 0; 1204 ring->rx_jumbo_pending = 0; 1205 } 1206 1207 static int i40e_set_ringparam(struct net_device *netdev, 1208 struct ethtool_ringparam *ring) 1209 { 1210 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL; 1211 struct i40e_netdev_priv *np = netdev_priv(netdev); 1212 struct i40e_vsi *vsi = np->vsi; 1213 struct i40e_pf *pf = vsi->back; 1214 u32 new_rx_count, new_tx_count; 1215 int i, err = 0; 1216 1217 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) 1218 return -EINVAL; 1219 1220 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS || 1221 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS || 1222 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS || 1223 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) { 1224 netdev_info(netdev, 1225 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n", 1226 ring->tx_pending, ring->rx_pending, 1227 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS); 1228 return -EINVAL; 1229 } 1230 1231 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); 1232 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); 1233 1234 /* if nothing to do return success */ 1235 if ((new_tx_count == vsi->tx_rings[0]->count) && 1236 (new_rx_count == vsi->rx_rings[0]->count)) 1237 return 0; 1238 1239 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) 1240 usleep_range(1000, 2000); 1241 1242 if (!netif_running(vsi->netdev)) { 1243 /* simple case - set for the next time the netdev is started */ 1244 for (i = 0; i < vsi->num_queue_pairs; i++) { 1245 vsi->tx_rings[i]->count = new_tx_count; 1246 vsi->rx_rings[i]->count = new_rx_count; 1247 } 1248 goto done; 1249 } 1250 1251 /* We can't just free everything and then setup again, 1252 * because the ISRs in MSI-X mode get passed pointers 1253 * to the Tx and Rx ring structs. 1254 */ 1255 1256 /* alloc updated Tx resources */ 1257 if (new_tx_count != vsi->tx_rings[0]->count) { 1258 netdev_info(netdev, 1259 "Changing Tx descriptor count from %d to %d.\n", 1260 vsi->tx_rings[0]->count, new_tx_count); 1261 tx_rings = kcalloc(vsi->alloc_queue_pairs, 1262 sizeof(struct i40e_ring), GFP_KERNEL); 1263 if (!tx_rings) { 1264 err = -ENOMEM; 1265 goto done; 1266 } 1267 1268 for (i = 0; i < vsi->num_queue_pairs; i++) { 1269 /* clone ring and setup updated count */ 1270 tx_rings[i] = *vsi->tx_rings[i]; 1271 tx_rings[i].count = new_tx_count; 1272 /* the desc and bi pointers will be reallocated in the 1273 * setup call 1274 */ 1275 tx_rings[i].desc = NULL; 1276 tx_rings[i].rx_bi = NULL; 1277 err = i40e_setup_tx_descriptors(&tx_rings[i]); 1278 if (err) { 1279 while (i) { 1280 i--; 1281 i40e_free_tx_resources(&tx_rings[i]); 1282 } 1283 kfree(tx_rings); 1284 tx_rings = NULL; 1285 1286 goto done; 1287 } 1288 } 1289 } 1290 1291 /* alloc updated Rx resources */ 1292 if (new_rx_count != vsi->rx_rings[0]->count) { 1293 netdev_info(netdev, 1294 "Changing Rx descriptor count from %d to %d\n", 1295 vsi->rx_rings[0]->count, new_rx_count); 1296 rx_rings = kcalloc(vsi->alloc_queue_pairs, 1297 sizeof(struct i40e_ring), GFP_KERNEL); 1298 if (!rx_rings) { 1299 err = -ENOMEM; 1300 goto free_tx; 1301 } 1302 1303 for (i = 0; i < vsi->num_queue_pairs; i++) { 1304 /* this is to allow wr32 to have something to write to 1305 * during early allocation of Rx buffers 1306 */ 1307 u32 __iomem faketail = 0; 1308 struct i40e_ring *ring; 1309 u16 unused; 1310 1311 /* clone ring and setup updated count */ 1312 rx_rings[i] = *vsi->rx_rings[i]; 1313 rx_rings[i].count = new_rx_count; 1314 /* the desc and bi pointers will be reallocated in the 1315 * setup call 1316 */ 1317 rx_rings[i].desc = NULL; 1318 rx_rings[i].rx_bi = NULL; 1319 rx_rings[i].tail = (u8 __iomem *)&faketail; 1320 err = i40e_setup_rx_descriptors(&rx_rings[i]); 1321 if (err) 1322 goto rx_unwind; 1323 1324 /* now allocate the Rx buffers to make sure the OS 1325 * has enough memory, any failure here means abort 1326 */ 1327 ring = &rx_rings[i]; 1328 unused = I40E_DESC_UNUSED(ring); 1329 err = i40e_alloc_rx_buffers(ring, unused); 1330 rx_unwind: 1331 if (err) { 1332 do { 1333 i40e_free_rx_resources(&rx_rings[i]); 1334 } while (i--); 1335 kfree(rx_rings); 1336 rx_rings = NULL; 1337 1338 goto free_tx; 1339 } 1340 } 1341 } 1342 1343 /* Bring interface down, copy in the new ring info, 1344 * then restore the interface 1345 */ 1346 i40e_down(vsi); 1347 1348 if (tx_rings) { 1349 for (i = 0; i < vsi->num_queue_pairs; i++) { 1350 i40e_free_tx_resources(vsi->tx_rings[i]); 1351 *vsi->tx_rings[i] = tx_rings[i]; 1352 } 1353 kfree(tx_rings); 1354 tx_rings = NULL; 1355 } 1356 1357 if (rx_rings) { 1358 for (i = 0; i < vsi->num_queue_pairs; i++) { 1359 i40e_free_rx_resources(vsi->rx_rings[i]); 1360 /* get the real tail offset */ 1361 rx_rings[i].tail = vsi->rx_rings[i]->tail; 1362 /* this is to fake out the allocation routine 1363 * into thinking it has to realloc everything 1364 * but the recycling logic will let us re-use 1365 * the buffers allocated above 1366 */ 1367 rx_rings[i].next_to_use = 0; 1368 rx_rings[i].next_to_clean = 0; 1369 rx_rings[i].next_to_alloc = 0; 1370 /* do a struct copy */ 1371 *vsi->rx_rings[i] = rx_rings[i]; 1372 } 1373 kfree(rx_rings); 1374 rx_rings = NULL; 1375 } 1376 1377 i40e_up(vsi); 1378 1379 free_tx: 1380 /* error cleanup if the Rx allocations failed after getting Tx */ 1381 if (tx_rings) { 1382 for (i = 0; i < vsi->num_queue_pairs; i++) 1383 i40e_free_tx_resources(&tx_rings[i]); 1384 kfree(tx_rings); 1385 tx_rings = NULL; 1386 } 1387 1388 done: 1389 clear_bit(__I40E_CONFIG_BUSY, &pf->state); 1390 1391 return err; 1392 } 1393 1394 static int i40e_get_sset_count(struct net_device *netdev, int sset) 1395 { 1396 struct i40e_netdev_priv *np = netdev_priv(netdev); 1397 struct i40e_vsi *vsi = np->vsi; 1398 struct i40e_pf *pf = vsi->back; 1399 1400 switch (sset) { 1401 case ETH_SS_TEST: 1402 return I40E_TEST_LEN; 1403 case ETH_SS_STATS: 1404 if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) { 1405 int len = I40E_PF_STATS_LEN(netdev); 1406 1407 if ((pf->lan_veb != I40E_NO_VEB) && 1408 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) 1409 len += I40E_VEB_STATS_TOTAL; 1410 return len; 1411 } else { 1412 return I40E_VSI_STATS_LEN(netdev); 1413 } 1414 case ETH_SS_PRIV_FLAGS: 1415 if (pf->hw.pf_id == 0) 1416 return I40E_PRIV_FLAGS_GL_STR_LEN; 1417 else 1418 return I40E_PRIV_FLAGS_STR_LEN; 1419 default: 1420 return -EOPNOTSUPP; 1421 } 1422 } 1423 1424 static void i40e_get_ethtool_stats(struct net_device *netdev, 1425 struct ethtool_stats *stats, u64 *data) 1426 { 1427 struct i40e_netdev_priv *np = netdev_priv(netdev); 1428 struct i40e_ring *tx_ring, *rx_ring; 1429 struct i40e_vsi *vsi = np->vsi; 1430 struct i40e_pf *pf = vsi->back; 1431 int i = 0; 1432 char *p; 1433 int j; 1434 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi); 1435 unsigned int start; 1436 1437 i40e_update_stats(vsi); 1438 1439 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) { 1440 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset; 1441 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat == 1442 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 1443 } 1444 for (j = 0; j < I40E_MISC_STATS_LEN; j++) { 1445 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset; 1446 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat == 1447 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 1448 } 1449 #ifdef I40E_FCOE 1450 for (j = 0; j < I40E_FCOE_STATS_LEN; j++) { 1451 p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset; 1452 data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat == 1453 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 1454 } 1455 #endif 1456 rcu_read_lock(); 1457 for (j = 0; j < vsi->num_queue_pairs; j++) { 1458 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]); 1459 1460 if (!tx_ring) 1461 continue; 1462 1463 /* process Tx ring statistics */ 1464 do { 1465 start = u64_stats_fetch_begin_irq(&tx_ring->syncp); 1466 data[i] = tx_ring->stats.packets; 1467 data[i + 1] = tx_ring->stats.bytes; 1468 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); 1469 i += 2; 1470 1471 /* Rx ring is the 2nd half of the queue pair */ 1472 rx_ring = &tx_ring[1]; 1473 do { 1474 start = u64_stats_fetch_begin_irq(&rx_ring->syncp); 1475 data[i] = rx_ring->stats.packets; 1476 data[i + 1] = rx_ring->stats.bytes; 1477 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); 1478 i += 2; 1479 } 1480 rcu_read_unlock(); 1481 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) 1482 return; 1483 1484 if ((pf->lan_veb != I40E_NO_VEB) && 1485 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { 1486 struct i40e_veb *veb = pf->veb[pf->lan_veb]; 1487 1488 for (j = 0; j < I40E_VEB_STATS_LEN; j++) { 1489 p = (char *)veb; 1490 p += i40e_gstrings_veb_stats[j].stat_offset; 1491 data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat == 1492 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 1493 } 1494 for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) { 1495 data[i++] = veb->tc_stats.tc_tx_packets[j]; 1496 data[i++] = veb->tc_stats.tc_tx_bytes[j]; 1497 data[i++] = veb->tc_stats.tc_rx_packets[j]; 1498 data[i++] = veb->tc_stats.tc_rx_bytes[j]; 1499 } 1500 } 1501 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) { 1502 p = (char *)pf + i40e_gstrings_stats[j].stat_offset; 1503 data[i++] = (i40e_gstrings_stats[j].sizeof_stat == 1504 sizeof(u64)) ? *(u64 *)p : *(u32 *)p; 1505 } 1506 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { 1507 data[i++] = pf->stats.priority_xon_tx[j]; 1508 data[i++] = pf->stats.priority_xoff_tx[j]; 1509 } 1510 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { 1511 data[i++] = pf->stats.priority_xon_rx[j]; 1512 data[i++] = pf->stats.priority_xoff_rx[j]; 1513 } 1514 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) 1515 data[i++] = pf->stats.priority_xon_2_xoff[j]; 1516 } 1517 1518 static void i40e_get_strings(struct net_device *netdev, u32 stringset, 1519 u8 *data) 1520 { 1521 struct i40e_netdev_priv *np = netdev_priv(netdev); 1522 struct i40e_vsi *vsi = np->vsi; 1523 struct i40e_pf *pf = vsi->back; 1524 char *p = (char *)data; 1525 int i; 1526 1527 switch (stringset) { 1528 case ETH_SS_TEST: 1529 for (i = 0; i < I40E_TEST_LEN; i++) { 1530 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN); 1531 data += ETH_GSTRING_LEN; 1532 } 1533 break; 1534 case ETH_SS_STATS: 1535 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) { 1536 snprintf(p, ETH_GSTRING_LEN, "%s", 1537 i40e_gstrings_net_stats[i].stat_string); 1538 p += ETH_GSTRING_LEN; 1539 } 1540 for (i = 0; i < I40E_MISC_STATS_LEN; i++) { 1541 snprintf(p, ETH_GSTRING_LEN, "%s", 1542 i40e_gstrings_misc_stats[i].stat_string); 1543 p += ETH_GSTRING_LEN; 1544 } 1545 #ifdef I40E_FCOE 1546 for (i = 0; i < I40E_FCOE_STATS_LEN; i++) { 1547 snprintf(p, ETH_GSTRING_LEN, "%s", 1548 i40e_gstrings_fcoe_stats[i].stat_string); 1549 p += ETH_GSTRING_LEN; 1550 } 1551 #endif 1552 for (i = 0; i < vsi->num_queue_pairs; i++) { 1553 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i); 1554 p += ETH_GSTRING_LEN; 1555 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i); 1556 p += ETH_GSTRING_LEN; 1557 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i); 1558 p += ETH_GSTRING_LEN; 1559 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i); 1560 p += ETH_GSTRING_LEN; 1561 } 1562 if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) 1563 return; 1564 1565 if ((pf->lan_veb != I40E_NO_VEB) && 1566 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { 1567 for (i = 0; i < I40E_VEB_STATS_LEN; i++) { 1568 snprintf(p, ETH_GSTRING_LEN, "veb.%s", 1569 i40e_gstrings_veb_stats[i].stat_string); 1570 p += ETH_GSTRING_LEN; 1571 } 1572 for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { 1573 snprintf(p, ETH_GSTRING_LEN, 1574 "veb.tc_%u_tx_packets", i); 1575 p += ETH_GSTRING_LEN; 1576 snprintf(p, ETH_GSTRING_LEN, 1577 "veb.tc_%u_tx_bytes", i); 1578 p += ETH_GSTRING_LEN; 1579 snprintf(p, ETH_GSTRING_LEN, 1580 "veb.tc_%u_rx_packets", i); 1581 p += ETH_GSTRING_LEN; 1582 snprintf(p, ETH_GSTRING_LEN, 1583 "veb.tc_%u_rx_bytes", i); 1584 p += ETH_GSTRING_LEN; 1585 } 1586 } 1587 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) { 1588 snprintf(p, ETH_GSTRING_LEN, "port.%s", 1589 i40e_gstrings_stats[i].stat_string); 1590 p += ETH_GSTRING_LEN; 1591 } 1592 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { 1593 snprintf(p, ETH_GSTRING_LEN, 1594 "port.tx_priority_%u_xon", i); 1595 p += ETH_GSTRING_LEN; 1596 snprintf(p, ETH_GSTRING_LEN, 1597 "port.tx_priority_%u_xoff", i); 1598 p += ETH_GSTRING_LEN; 1599 } 1600 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { 1601 snprintf(p, ETH_GSTRING_LEN, 1602 "port.rx_priority_%u_xon", i); 1603 p += ETH_GSTRING_LEN; 1604 snprintf(p, ETH_GSTRING_LEN, 1605 "port.rx_priority_%u_xoff", i); 1606 p += ETH_GSTRING_LEN; 1607 } 1608 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { 1609 snprintf(p, ETH_GSTRING_LEN, 1610 "port.rx_priority_%u_xon_2_xoff", i); 1611 p += ETH_GSTRING_LEN; 1612 } 1613 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */ 1614 break; 1615 case ETH_SS_PRIV_FLAGS: 1616 if (pf->hw.pf_id == 0) { 1617 for (i = 0; i < I40E_PRIV_FLAGS_GL_STR_LEN; i++) { 1618 memcpy(data, i40e_priv_flags_strings_gl[i], 1619 ETH_GSTRING_LEN); 1620 data += ETH_GSTRING_LEN; 1621 } 1622 } else { 1623 for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++) { 1624 memcpy(data, i40e_priv_flags_strings[i], 1625 ETH_GSTRING_LEN); 1626 data += ETH_GSTRING_LEN; 1627 } 1628 } 1629 break; 1630 default: 1631 break; 1632 } 1633 } 1634 1635 static int i40e_get_ts_info(struct net_device *dev, 1636 struct ethtool_ts_info *info) 1637 { 1638 struct i40e_pf *pf = i40e_netdev_to_pf(dev); 1639 1640 /* only report HW timestamping if PTP is enabled */ 1641 if (!(pf->flags & I40E_FLAG_PTP)) 1642 return ethtool_op_get_ts_info(dev, info); 1643 1644 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | 1645 SOF_TIMESTAMPING_RX_SOFTWARE | 1646 SOF_TIMESTAMPING_SOFTWARE | 1647 SOF_TIMESTAMPING_TX_HARDWARE | 1648 SOF_TIMESTAMPING_RX_HARDWARE | 1649 SOF_TIMESTAMPING_RAW_HARDWARE; 1650 1651 if (pf->ptp_clock) 1652 info->phc_index = ptp_clock_index(pf->ptp_clock); 1653 else 1654 info->phc_index = -1; 1655 1656 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON); 1657 1658 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | 1659 BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) | 1660 BIT(HWTSTAMP_FILTER_PTP_V2_EVENT); 1661 1662 return 0; 1663 } 1664 1665 static int i40e_link_test(struct net_device *netdev, u64 *data) 1666 { 1667 struct i40e_netdev_priv *np = netdev_priv(netdev); 1668 struct i40e_pf *pf = np->vsi->back; 1669 i40e_status status; 1670 bool link_up = false; 1671 1672 netif_info(pf, hw, netdev, "link test\n"); 1673 status = i40e_get_link_status(&pf->hw, &link_up); 1674 if (status) { 1675 netif_err(pf, drv, netdev, "link query timed out, please retry test\n"); 1676 *data = 1; 1677 return *data; 1678 } 1679 1680 if (link_up) 1681 *data = 0; 1682 else 1683 *data = 1; 1684 1685 return *data; 1686 } 1687 1688 static int i40e_reg_test(struct net_device *netdev, u64 *data) 1689 { 1690 struct i40e_netdev_priv *np = netdev_priv(netdev); 1691 struct i40e_pf *pf = np->vsi->back; 1692 1693 netif_info(pf, hw, netdev, "register test\n"); 1694 *data = i40e_diag_reg_test(&pf->hw); 1695 1696 return *data; 1697 } 1698 1699 static int i40e_eeprom_test(struct net_device *netdev, u64 *data) 1700 { 1701 struct i40e_netdev_priv *np = netdev_priv(netdev); 1702 struct i40e_pf *pf = np->vsi->back; 1703 1704 netif_info(pf, hw, netdev, "eeprom test\n"); 1705 *data = i40e_diag_eeprom_test(&pf->hw); 1706 1707 /* forcebly clear the NVM Update state machine */ 1708 pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT; 1709 1710 return *data; 1711 } 1712 1713 static int i40e_intr_test(struct net_device *netdev, u64 *data) 1714 { 1715 struct i40e_netdev_priv *np = netdev_priv(netdev); 1716 struct i40e_pf *pf = np->vsi->back; 1717 u16 swc_old = pf->sw_int_count; 1718 1719 netif_info(pf, hw, netdev, "interrupt test\n"); 1720 wr32(&pf->hw, I40E_PFINT_DYN_CTL0, 1721 (I40E_PFINT_DYN_CTL0_INTENA_MASK | 1722 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK | 1723 I40E_PFINT_DYN_CTL0_ITR_INDX_MASK | 1724 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK | 1725 I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK)); 1726 usleep_range(1000, 2000); 1727 *data = (swc_old == pf->sw_int_count); 1728 1729 return *data; 1730 } 1731 1732 static int i40e_loopback_test(struct net_device *netdev, u64 *data) 1733 { 1734 struct i40e_netdev_priv *np = netdev_priv(netdev); 1735 struct i40e_pf *pf = np->vsi->back; 1736 1737 netif_info(pf, hw, netdev, "loopback test not implemented\n"); 1738 *data = 0; 1739 1740 return *data; 1741 } 1742 1743 static inline bool i40e_active_vfs(struct i40e_pf *pf) 1744 { 1745 struct i40e_vf *vfs = pf->vf; 1746 int i; 1747 1748 for (i = 0; i < pf->num_alloc_vfs; i++) 1749 if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states)) 1750 return true; 1751 return false; 1752 } 1753 1754 static inline bool i40e_active_vmdqs(struct i40e_pf *pf) 1755 { 1756 struct i40e_vsi **vsi = pf->vsi; 1757 int i; 1758 1759 for (i = 0; i < pf->num_alloc_vsi; i++) { 1760 if (!vsi[i]) 1761 continue; 1762 if (vsi[i]->type == I40E_VSI_VMDQ2) 1763 return true; 1764 } 1765 1766 return false; 1767 } 1768 1769 static void i40e_diag_test(struct net_device *netdev, 1770 struct ethtool_test *eth_test, u64 *data) 1771 { 1772 struct i40e_netdev_priv *np = netdev_priv(netdev); 1773 bool if_running = netif_running(netdev); 1774 struct i40e_pf *pf = np->vsi->back; 1775 1776 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 1777 /* Offline tests */ 1778 netif_info(pf, drv, netdev, "offline testing starting\n"); 1779 1780 set_bit(__I40E_TESTING, &pf->state); 1781 1782 if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) { 1783 dev_warn(&pf->pdev->dev, 1784 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n"); 1785 data[I40E_ETH_TEST_REG] = 1; 1786 data[I40E_ETH_TEST_EEPROM] = 1; 1787 data[I40E_ETH_TEST_INTR] = 1; 1788 data[I40E_ETH_TEST_LOOPBACK] = 1; 1789 data[I40E_ETH_TEST_LINK] = 1; 1790 eth_test->flags |= ETH_TEST_FL_FAILED; 1791 clear_bit(__I40E_TESTING, &pf->state); 1792 goto skip_ol_tests; 1793 } 1794 1795 /* If the device is online then take it offline */ 1796 if (if_running) 1797 /* indicate we're in test mode */ 1798 i40e_close(netdev); 1799 else 1800 /* This reset does not affect link - if it is 1801 * changed to a type of reset that does affect 1802 * link then the following link test would have 1803 * to be moved to before the reset 1804 */ 1805 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED)); 1806 1807 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) 1808 eth_test->flags |= ETH_TEST_FL_FAILED; 1809 1810 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM])) 1811 eth_test->flags |= ETH_TEST_FL_FAILED; 1812 1813 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR])) 1814 eth_test->flags |= ETH_TEST_FL_FAILED; 1815 1816 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK])) 1817 eth_test->flags |= ETH_TEST_FL_FAILED; 1818 1819 /* run reg test last, a reset is required after it */ 1820 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG])) 1821 eth_test->flags |= ETH_TEST_FL_FAILED; 1822 1823 clear_bit(__I40E_TESTING, &pf->state); 1824 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED)); 1825 1826 if (if_running) 1827 i40e_open(netdev); 1828 } else { 1829 /* Online tests */ 1830 netif_info(pf, drv, netdev, "online testing starting\n"); 1831 1832 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) 1833 eth_test->flags |= ETH_TEST_FL_FAILED; 1834 1835 /* Offline only tests, not run in online; pass by default */ 1836 data[I40E_ETH_TEST_REG] = 0; 1837 data[I40E_ETH_TEST_EEPROM] = 0; 1838 data[I40E_ETH_TEST_INTR] = 0; 1839 data[I40E_ETH_TEST_LOOPBACK] = 0; 1840 } 1841 1842 skip_ol_tests: 1843 1844 netif_info(pf, drv, netdev, "testing finished\n"); 1845 } 1846 1847 static void i40e_get_wol(struct net_device *netdev, 1848 struct ethtool_wolinfo *wol) 1849 { 1850 struct i40e_netdev_priv *np = netdev_priv(netdev); 1851 struct i40e_pf *pf = np->vsi->back; 1852 struct i40e_hw *hw = &pf->hw; 1853 u16 wol_nvm_bits; 1854 1855 /* NVM bit on means WoL disabled for the port */ 1856 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); 1857 if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) { 1858 wol->supported = 0; 1859 wol->wolopts = 0; 1860 } else { 1861 wol->supported = WAKE_MAGIC; 1862 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0); 1863 } 1864 } 1865 1866 /** 1867 * i40e_set_wol - set the WakeOnLAN configuration 1868 * @netdev: the netdev in question 1869 * @wol: the ethtool WoL setting data 1870 **/ 1871 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) 1872 { 1873 struct i40e_netdev_priv *np = netdev_priv(netdev); 1874 struct i40e_pf *pf = np->vsi->back; 1875 struct i40e_vsi *vsi = np->vsi; 1876 struct i40e_hw *hw = &pf->hw; 1877 u16 wol_nvm_bits; 1878 1879 /* WoL not supported if this isn't the controlling PF on the port */ 1880 if (hw->partition_id != 1) { 1881 i40e_partition_setting_complaint(pf); 1882 return -EOPNOTSUPP; 1883 } 1884 1885 if (vsi != pf->vsi[pf->lan_vsi]) 1886 return -EOPNOTSUPP; 1887 1888 /* NVM bit on means WoL disabled for the port */ 1889 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); 1890 if (BIT(hw->port) & wol_nvm_bits) 1891 return -EOPNOTSUPP; 1892 1893 /* only magic packet is supported */ 1894 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC)) 1895 return -EOPNOTSUPP; 1896 1897 /* is this a new value? */ 1898 if (pf->wol_en != !!wol->wolopts) { 1899 pf->wol_en = !!wol->wolopts; 1900 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); 1901 } 1902 1903 return 0; 1904 } 1905 1906 static int i40e_set_phys_id(struct net_device *netdev, 1907 enum ethtool_phys_id_state state) 1908 { 1909 struct i40e_netdev_priv *np = netdev_priv(netdev); 1910 i40e_status ret = 0; 1911 struct i40e_pf *pf = np->vsi->back; 1912 struct i40e_hw *hw = &pf->hw; 1913 int blink_freq = 2; 1914 u16 temp_status; 1915 1916 switch (state) { 1917 case ETHTOOL_ID_ACTIVE: 1918 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) { 1919 pf->led_status = i40e_led_get(hw); 1920 } else { 1921 i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL); 1922 ret = i40e_led_get_phy(hw, &temp_status, 1923 &pf->phy_led_val); 1924 pf->led_status = temp_status; 1925 } 1926 return blink_freq; 1927 case ETHTOOL_ID_ON: 1928 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) 1929 i40e_led_set(hw, 0xf, false); 1930 else 1931 ret = i40e_led_set_phy(hw, true, pf->led_status, 0); 1932 break; 1933 case ETHTOOL_ID_OFF: 1934 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) 1935 i40e_led_set(hw, 0x0, false); 1936 else 1937 ret = i40e_led_set_phy(hw, false, pf->led_status, 0); 1938 break; 1939 case ETHTOOL_ID_INACTIVE: 1940 if (!(pf->flags & I40E_FLAG_HAVE_10GBASET_PHY)) { 1941 i40e_led_set(hw, false, pf->led_status); 1942 } else { 1943 ret = i40e_led_set_phy(hw, false, pf->led_status, 1944 (pf->phy_led_val | 1945 I40E_PHY_LED_MODE_ORIG)); 1946 i40e_aq_set_phy_debug(hw, 0, NULL); 1947 } 1948 break; 1949 default: 1950 break; 1951 } 1952 if (ret) 1953 return -ENOENT; 1954 else 1955 return 0; 1956 } 1957 1958 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt 1959 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also 1960 * 125us (8000 interrupts per second) == ITR(62) 1961 */ 1962 1963 static int __i40e_get_coalesce(struct net_device *netdev, 1964 struct ethtool_coalesce *ec, 1965 int queue) 1966 { 1967 struct i40e_netdev_priv *np = netdev_priv(netdev); 1968 struct i40e_vsi *vsi = np->vsi; 1969 1970 ec->tx_max_coalesced_frames_irq = vsi->work_limit; 1971 ec->rx_max_coalesced_frames_irq = vsi->work_limit; 1972 1973 /* rx and tx usecs has per queue value. If user doesn't specify the queue, 1974 * return queue 0's value to represent. 1975 */ 1976 if (queue < 0) { 1977 queue = 0; 1978 } else if (queue >= vsi->num_queue_pairs) { 1979 return -EINVAL; 1980 } 1981 1982 if (ITR_IS_DYNAMIC(vsi->rx_rings[queue]->rx_itr_setting)) 1983 ec->use_adaptive_rx_coalesce = 1; 1984 1985 if (ITR_IS_DYNAMIC(vsi->tx_rings[queue]->tx_itr_setting)) 1986 ec->use_adaptive_tx_coalesce = 1; 1987 1988 ec->rx_coalesce_usecs = vsi->rx_rings[queue]->rx_itr_setting & ~I40E_ITR_DYNAMIC; 1989 ec->tx_coalesce_usecs = vsi->tx_rings[queue]->tx_itr_setting & ~I40E_ITR_DYNAMIC; 1990 1991 /* we use the _usecs_high to store/set the interrupt rate limit 1992 * that the hardware supports, that almost but not quite 1993 * fits the original intent of the ethtool variable, 1994 * the rx_coalesce_usecs_high limits total interrupts 1995 * per second from both tx/rx sources. 1996 */ 1997 ec->rx_coalesce_usecs_high = vsi->int_rate_limit; 1998 ec->tx_coalesce_usecs_high = vsi->int_rate_limit; 1999 2000 return 0; 2001 } 2002 2003 static int i40e_get_coalesce(struct net_device *netdev, 2004 struct ethtool_coalesce *ec) 2005 { 2006 return __i40e_get_coalesce(netdev, ec, -1); 2007 } 2008 2009 static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue, 2010 struct ethtool_coalesce *ec) 2011 { 2012 return __i40e_get_coalesce(netdev, ec, queue); 2013 } 2014 2015 static void i40e_set_itr_per_queue(struct i40e_vsi *vsi, 2016 struct ethtool_coalesce *ec, 2017 int queue) 2018 { 2019 struct i40e_pf *pf = vsi->back; 2020 struct i40e_hw *hw = &pf->hw; 2021 struct i40e_q_vector *q_vector; 2022 u16 vector, intrl; 2023 2024 intrl = INTRL_USEC_TO_REG(vsi->int_rate_limit); 2025 2026 vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs; 2027 vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs; 2028 2029 if (ec->use_adaptive_rx_coalesce) 2030 vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC; 2031 else 2032 vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC; 2033 2034 if (ec->use_adaptive_tx_coalesce) 2035 vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC; 2036 else 2037 vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC; 2038 2039 q_vector = vsi->rx_rings[queue]->q_vector; 2040 q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting); 2041 vector = vsi->base_vector + q_vector->v_idx; 2042 wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr); 2043 2044 q_vector = vsi->tx_rings[queue]->q_vector; 2045 q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting); 2046 vector = vsi->base_vector + q_vector->v_idx; 2047 wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr); 2048 2049 wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl); 2050 i40e_flush(hw); 2051 } 2052 2053 static int __i40e_set_coalesce(struct net_device *netdev, 2054 struct ethtool_coalesce *ec, 2055 int queue) 2056 { 2057 struct i40e_netdev_priv *np = netdev_priv(netdev); 2058 struct i40e_vsi *vsi = np->vsi; 2059 struct i40e_pf *pf = vsi->back; 2060 int i; 2061 2062 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq) 2063 vsi->work_limit = ec->tx_max_coalesced_frames_irq; 2064 2065 /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */ 2066 if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) { 2067 netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n"); 2068 return -EINVAL; 2069 } 2070 2071 if (ec->rx_coalesce_usecs_high >= INTRL_REG_TO_USEC(I40E_MAX_INTRL)) { 2072 netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-235\n"); 2073 return -EINVAL; 2074 } 2075 2076 if (ec->rx_coalesce_usecs == 0) { 2077 if (ec->use_adaptive_rx_coalesce) 2078 netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n"); 2079 } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) || 2080 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) { 2081 netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n"); 2082 return -EINVAL; 2083 } 2084 2085 vsi->int_rate_limit = ec->rx_coalesce_usecs_high; 2086 2087 if (ec->tx_coalesce_usecs == 0) { 2088 if (ec->use_adaptive_tx_coalesce) 2089 netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n"); 2090 } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) || 2091 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) { 2092 netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n"); 2093 return -EINVAL; 2094 } 2095 2096 /* rx and tx usecs has per queue value. If user doesn't specify the queue, 2097 * apply to all queues. 2098 */ 2099 if (queue < 0) { 2100 for (i = 0; i < vsi->num_queue_pairs; i++) 2101 i40e_set_itr_per_queue(vsi, ec, i); 2102 } else if (queue < vsi->num_queue_pairs) { 2103 i40e_set_itr_per_queue(vsi, ec, queue); 2104 } else { 2105 netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n", 2106 vsi->num_queue_pairs - 1); 2107 return -EINVAL; 2108 } 2109 2110 return 0; 2111 } 2112 2113 static int i40e_set_coalesce(struct net_device *netdev, 2114 struct ethtool_coalesce *ec) 2115 { 2116 return __i40e_set_coalesce(netdev, ec, -1); 2117 } 2118 2119 static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue, 2120 struct ethtool_coalesce *ec) 2121 { 2122 return __i40e_set_coalesce(netdev, ec, queue); 2123 } 2124 2125 /** 2126 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type 2127 * @pf: pointer to the physical function struct 2128 * @cmd: ethtool rxnfc command 2129 * 2130 * Returns Success if the flow is supported, else Invalid Input. 2131 **/ 2132 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd) 2133 { 2134 cmd->data = 0; 2135 2136 if (pf->vsi[pf->lan_vsi]->rxnfc.data != 0) { 2137 cmd->data = pf->vsi[pf->lan_vsi]->rxnfc.data; 2138 cmd->flow_type = pf->vsi[pf->lan_vsi]->rxnfc.flow_type; 2139 return 0; 2140 } 2141 /* Report default options for RSS on i40e */ 2142 switch (cmd->flow_type) { 2143 case TCP_V4_FLOW: 2144 case UDP_V4_FLOW: 2145 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 2146 /* fall through to add IP fields */ 2147 case SCTP_V4_FLOW: 2148 case AH_ESP_V4_FLOW: 2149 case AH_V4_FLOW: 2150 case ESP_V4_FLOW: 2151 case IPV4_FLOW: 2152 cmd->data |= RXH_IP_SRC | RXH_IP_DST; 2153 break; 2154 case TCP_V6_FLOW: 2155 case UDP_V6_FLOW: 2156 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; 2157 /* fall through to add IP fields */ 2158 case SCTP_V6_FLOW: 2159 case AH_ESP_V6_FLOW: 2160 case AH_V6_FLOW: 2161 case ESP_V6_FLOW: 2162 case IPV6_FLOW: 2163 cmd->data |= RXH_IP_SRC | RXH_IP_DST; 2164 break; 2165 default: 2166 return -EINVAL; 2167 } 2168 2169 return 0; 2170 } 2171 2172 /** 2173 * i40e_get_ethtool_fdir_all - Populates the rule count of a command 2174 * @pf: Pointer to the physical function struct 2175 * @cmd: The command to get or set Rx flow classification rules 2176 * @rule_locs: Array of used rule locations 2177 * 2178 * This function populates both the total and actual rule count of 2179 * the ethtool flow classification command 2180 * 2181 * Returns 0 on success or -EMSGSIZE if entry not found 2182 **/ 2183 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf, 2184 struct ethtool_rxnfc *cmd, 2185 u32 *rule_locs) 2186 { 2187 struct i40e_fdir_filter *rule; 2188 struct hlist_node *node2; 2189 int cnt = 0; 2190 2191 /* report total rule count */ 2192 cmd->data = i40e_get_fd_cnt_all(pf); 2193 2194 hlist_for_each_entry_safe(rule, node2, 2195 &pf->fdir_filter_list, fdir_node) { 2196 if (cnt == cmd->rule_cnt) 2197 return -EMSGSIZE; 2198 2199 rule_locs[cnt] = rule->fd_id; 2200 cnt++; 2201 } 2202 2203 cmd->rule_cnt = cnt; 2204 2205 return 0; 2206 } 2207 2208 /** 2209 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow 2210 * @pf: Pointer to the physical function struct 2211 * @cmd: The command to get or set Rx flow classification rules 2212 * 2213 * This function looks up a filter based on the Rx flow classification 2214 * command and fills the flow spec info for it if found 2215 * 2216 * Returns 0 on success or -EINVAL if filter not found 2217 **/ 2218 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf, 2219 struct ethtool_rxnfc *cmd) 2220 { 2221 struct ethtool_rx_flow_spec *fsp = 2222 (struct ethtool_rx_flow_spec *)&cmd->fs; 2223 struct i40e_fdir_filter *rule = NULL; 2224 struct hlist_node *node2; 2225 2226 hlist_for_each_entry_safe(rule, node2, 2227 &pf->fdir_filter_list, fdir_node) { 2228 if (fsp->location <= rule->fd_id) 2229 break; 2230 } 2231 2232 if (!rule || fsp->location != rule->fd_id) 2233 return -EINVAL; 2234 2235 fsp->flow_type = rule->flow_type; 2236 if (fsp->flow_type == IP_USER_FLOW) { 2237 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; 2238 fsp->h_u.usr_ip4_spec.proto = 0; 2239 fsp->m_u.usr_ip4_spec.proto = 0; 2240 } 2241 2242 /* Reverse the src and dest notion, since the HW views them from 2243 * Tx perspective where as the user expects it from Rx filter view. 2244 */ 2245 fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port; 2246 fsp->h_u.tcp_ip4_spec.pdst = rule->src_port; 2247 fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip[0]; 2248 fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip[0]; 2249 2250 if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET) 2251 fsp->ring_cookie = RX_CLS_FLOW_DISC; 2252 else 2253 fsp->ring_cookie = rule->q_index; 2254 2255 if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) { 2256 struct i40e_vsi *vsi; 2257 2258 vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi); 2259 if (vsi && vsi->type == I40E_VSI_SRIOV) { 2260 fsp->h_ext.data[1] = htonl(vsi->vf_id); 2261 fsp->m_ext.data[1] = htonl(0x1); 2262 } 2263 } 2264 2265 return 0; 2266 } 2267 2268 /** 2269 * i40e_get_rxnfc - command to get RX flow classification rules 2270 * @netdev: network interface device structure 2271 * @cmd: ethtool rxnfc command 2272 * 2273 * Returns Success if the command is supported. 2274 **/ 2275 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, 2276 u32 *rule_locs) 2277 { 2278 struct i40e_netdev_priv *np = netdev_priv(netdev); 2279 struct i40e_vsi *vsi = np->vsi; 2280 struct i40e_pf *pf = vsi->back; 2281 int ret = -EOPNOTSUPP; 2282 2283 switch (cmd->cmd) { 2284 case ETHTOOL_GRXRINGS: 2285 cmd->data = vsi->num_queue_pairs; 2286 ret = 0; 2287 break; 2288 case ETHTOOL_GRXFH: 2289 ret = i40e_get_rss_hash_opts(pf, cmd); 2290 break; 2291 case ETHTOOL_GRXCLSRLCNT: 2292 cmd->rule_cnt = pf->fdir_pf_active_filters; 2293 /* report total rule count */ 2294 cmd->data = i40e_get_fd_cnt_all(pf); 2295 ret = 0; 2296 break; 2297 case ETHTOOL_GRXCLSRULE: 2298 ret = i40e_get_ethtool_fdir_entry(pf, cmd); 2299 break; 2300 case ETHTOOL_GRXCLSRLALL: 2301 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs); 2302 break; 2303 default: 2304 break; 2305 } 2306 2307 return ret; 2308 } 2309 2310 /** 2311 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash 2312 * @pf: pointer to the physical function struct 2313 * @cmd: ethtool rxnfc command 2314 * 2315 * Returns Success if the flow input set is supported. 2316 **/ 2317 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc) 2318 { 2319 struct i40e_hw *hw = &pf->hw; 2320 u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | 2321 ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); 2322 2323 /* RSS does not support anything other than hashing 2324 * to queues on src and dst IPs and ports 2325 */ 2326 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | 2327 RXH_L4_B_0_1 | RXH_L4_B_2_3)) 2328 return -EINVAL; 2329 2330 /* We need at least the IP SRC and DEST fields for hashing */ 2331 if (!(nfc->data & RXH_IP_SRC) || 2332 !(nfc->data & RXH_IP_DST)) 2333 return -EINVAL; 2334 2335 switch (nfc->flow_type) { 2336 case TCP_V4_FLOW: 2337 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 2338 case 0: 2339 return -EINVAL; 2340 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 2341 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) 2342 hena |= 2343 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK); 2344 2345 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP); 2346 break; 2347 default: 2348 return -EINVAL; 2349 } 2350 break; 2351 case TCP_V6_FLOW: 2352 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 2353 case 0: 2354 return -EINVAL; 2355 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 2356 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) 2357 hena |= 2358 BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK); 2359 2360 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP); 2361 break; 2362 default: 2363 return -EINVAL; 2364 } 2365 break; 2366 case UDP_V4_FLOW: 2367 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 2368 case 0: 2369 return -EINVAL; 2370 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 2371 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) 2372 hena |= 2373 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | 2374 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP); 2375 2376 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | 2377 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4)); 2378 break; 2379 default: 2380 return -EINVAL; 2381 } 2382 break; 2383 case UDP_V6_FLOW: 2384 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { 2385 case 0: 2386 return -EINVAL; 2387 case (RXH_L4_B_0_1 | RXH_L4_B_2_3): 2388 if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) 2389 hena |= 2390 BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | 2391 BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP); 2392 2393 hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | 2394 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6)); 2395 break; 2396 default: 2397 return -EINVAL; 2398 } 2399 break; 2400 case AH_ESP_V4_FLOW: 2401 case AH_V4_FLOW: 2402 case ESP_V4_FLOW: 2403 case SCTP_V4_FLOW: 2404 if ((nfc->data & RXH_L4_B_0_1) || 2405 (nfc->data & RXH_L4_B_2_3)) 2406 return -EINVAL; 2407 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER); 2408 break; 2409 case AH_ESP_V6_FLOW: 2410 case AH_V6_FLOW: 2411 case ESP_V6_FLOW: 2412 case SCTP_V6_FLOW: 2413 if ((nfc->data & RXH_L4_B_0_1) || 2414 (nfc->data & RXH_L4_B_2_3)) 2415 return -EINVAL; 2416 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER); 2417 break; 2418 case IPV4_FLOW: 2419 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | 2420 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4); 2421 break; 2422 case IPV6_FLOW: 2423 hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | 2424 BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6); 2425 break; 2426 default: 2427 return -EINVAL; 2428 } 2429 2430 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); 2431 i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); 2432 i40e_flush(hw); 2433 2434 /* Save setting for future output/update */ 2435 pf->vsi[pf->lan_vsi]->rxnfc = *nfc; 2436 2437 return 0; 2438 } 2439 2440 /** 2441 * i40e_match_fdir_input_set - Match a new filter against an existing one 2442 * @rule: The filter already added 2443 * @input: The new filter to comapre against 2444 * 2445 * Returns true if the two input set match 2446 **/ 2447 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule, 2448 struct i40e_fdir_filter *input) 2449 { 2450 if ((rule->dst_ip[0] != input->dst_ip[0]) || 2451 (rule->src_ip[0] != input->src_ip[0]) || 2452 (rule->dst_port != input->dst_port) || 2453 (rule->src_port != input->src_port)) 2454 return false; 2455 return true; 2456 } 2457 2458 /** 2459 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry 2460 * @vsi: Pointer to the targeted VSI 2461 * @input: The filter to update or NULL to indicate deletion 2462 * @sw_idx: Software index to the filter 2463 * @cmd: The command to get or set Rx flow classification rules 2464 * 2465 * This function updates (or deletes) a Flow Director entry from 2466 * the hlist of the corresponding PF 2467 * 2468 * Returns 0 on success 2469 **/ 2470 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi, 2471 struct i40e_fdir_filter *input, 2472 u16 sw_idx, 2473 struct ethtool_rxnfc *cmd) 2474 { 2475 struct i40e_fdir_filter *rule, *parent; 2476 struct i40e_pf *pf = vsi->back; 2477 struct hlist_node *node2; 2478 int err = -EINVAL; 2479 2480 parent = NULL; 2481 rule = NULL; 2482 2483 hlist_for_each_entry_safe(rule, node2, 2484 &pf->fdir_filter_list, fdir_node) { 2485 /* hash found, or no matching entry */ 2486 if (rule->fd_id >= sw_idx) 2487 break; 2488 parent = rule; 2489 } 2490 2491 /* if there is an old rule occupying our place remove it */ 2492 if (rule && (rule->fd_id == sw_idx)) { 2493 if (input && !i40e_match_fdir_input_set(rule, input)) 2494 err = i40e_add_del_fdir(vsi, rule, false); 2495 else if (!input) 2496 err = i40e_add_del_fdir(vsi, rule, false); 2497 hlist_del(&rule->fdir_node); 2498 kfree(rule); 2499 pf->fdir_pf_active_filters--; 2500 } 2501 2502 /* If no input this was a delete, err should be 0 if a rule was 2503 * successfully found and removed from the list else -EINVAL 2504 */ 2505 if (!input) 2506 return err; 2507 2508 /* initialize node and set software index */ 2509 INIT_HLIST_NODE(&input->fdir_node); 2510 2511 /* add filter to the list */ 2512 if (parent) 2513 hlist_add_behind(&input->fdir_node, &parent->fdir_node); 2514 else 2515 hlist_add_head(&input->fdir_node, 2516 &pf->fdir_filter_list); 2517 2518 /* update counts */ 2519 pf->fdir_pf_active_filters++; 2520 2521 return 0; 2522 } 2523 2524 /** 2525 * i40e_del_fdir_entry - Deletes a Flow Director filter entry 2526 * @vsi: Pointer to the targeted VSI 2527 * @cmd: The command to get or set Rx flow classification rules 2528 * 2529 * The function removes a Flow Director filter entry from the 2530 * hlist of the corresponding PF 2531 * 2532 * Returns 0 on success 2533 */ 2534 static int i40e_del_fdir_entry(struct i40e_vsi *vsi, 2535 struct ethtool_rxnfc *cmd) 2536 { 2537 struct ethtool_rx_flow_spec *fsp = 2538 (struct ethtool_rx_flow_spec *)&cmd->fs; 2539 struct i40e_pf *pf = vsi->back; 2540 int ret = 0; 2541 2542 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || 2543 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) 2544 return -EBUSY; 2545 2546 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) 2547 return -EBUSY; 2548 2549 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd); 2550 2551 i40e_fdir_check_and_reenable(pf); 2552 return ret; 2553 } 2554 2555 /** 2556 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters 2557 * @vsi: pointer to the targeted VSI 2558 * @cmd: command to get or set RX flow classification rules 2559 * 2560 * Add Flow Director filters for a specific flow spec based on their 2561 * protocol. Returns 0 if the filters were successfully added. 2562 **/ 2563 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, 2564 struct ethtool_rxnfc *cmd) 2565 { 2566 struct ethtool_rx_flow_spec *fsp; 2567 struct i40e_fdir_filter *input; 2568 struct i40e_pf *pf; 2569 int ret = -EINVAL; 2570 u16 vf_id; 2571 2572 if (!vsi) 2573 return -EINVAL; 2574 pf = vsi->back; 2575 2576 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) 2577 return -EOPNOTSUPP; 2578 2579 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED) 2580 return -ENOSPC; 2581 2582 if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || 2583 test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) 2584 return -EBUSY; 2585 2586 if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) 2587 return -EBUSY; 2588 2589 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; 2590 2591 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort + 2592 pf->hw.func_caps.fd_filters_guaranteed)) { 2593 return -EINVAL; 2594 } 2595 2596 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) && 2597 (fsp->ring_cookie >= vsi->num_queue_pairs)) 2598 return -EINVAL; 2599 2600 input = kzalloc(sizeof(*input), GFP_KERNEL); 2601 2602 if (!input) 2603 return -ENOMEM; 2604 2605 input->fd_id = fsp->location; 2606 2607 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) 2608 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET; 2609 else 2610 input->dest_ctl = 2611 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX; 2612 2613 input->q_index = fsp->ring_cookie; 2614 input->flex_off = 0; 2615 input->pctype = 0; 2616 input->dest_vsi = vsi->id; 2617 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID; 2618 input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id); 2619 input->flow_type = fsp->flow_type; 2620 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto; 2621 2622 /* Reverse the src and dest notion, since the HW expects them to be from 2623 * Tx perspective where as the input from user is from Rx filter view. 2624 */ 2625 input->dst_port = fsp->h_u.tcp_ip4_spec.psrc; 2626 input->src_port = fsp->h_u.tcp_ip4_spec.pdst; 2627 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src; 2628 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst; 2629 2630 if (ntohl(fsp->m_ext.data[1])) { 2631 vf_id = ntohl(fsp->h_ext.data[1]); 2632 if (vf_id >= pf->num_alloc_vfs) { 2633 netif_info(pf, drv, vsi->netdev, 2634 "Invalid VF id %d\n", vf_id); 2635 goto free_input; 2636 } 2637 /* Find vsi id from vf id and override dest vsi */ 2638 input->dest_vsi = pf->vf[vf_id].lan_vsi_id; 2639 if (input->q_index >= pf->vf[vf_id].num_queue_pairs) { 2640 netif_info(pf, drv, vsi->netdev, 2641 "Invalid queue id %d for VF %d\n", 2642 input->q_index, vf_id); 2643 goto free_input; 2644 } 2645 } 2646 2647 ret = i40e_add_del_fdir(vsi, input, true); 2648 free_input: 2649 if (ret) 2650 kfree(input); 2651 else 2652 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL); 2653 2654 return ret; 2655 } 2656 2657 /** 2658 * i40e_set_rxnfc - command to set RX flow classification rules 2659 * @netdev: network interface device structure 2660 * @cmd: ethtool rxnfc command 2661 * 2662 * Returns Success if the command is supported. 2663 **/ 2664 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) 2665 { 2666 struct i40e_netdev_priv *np = netdev_priv(netdev); 2667 struct i40e_vsi *vsi = np->vsi; 2668 struct i40e_pf *pf = vsi->back; 2669 int ret = -EOPNOTSUPP; 2670 2671 switch (cmd->cmd) { 2672 case ETHTOOL_SRXFH: 2673 ret = i40e_set_rss_hash_opt(pf, cmd); 2674 break; 2675 case ETHTOOL_SRXCLSRLINS: 2676 ret = i40e_add_fdir_ethtool(vsi, cmd); 2677 break; 2678 case ETHTOOL_SRXCLSRLDEL: 2679 ret = i40e_del_fdir_entry(vsi, cmd); 2680 break; 2681 default: 2682 break; 2683 } 2684 2685 return ret; 2686 } 2687 2688 /** 2689 * i40e_max_channels - get Max number of combined channels supported 2690 * @vsi: vsi pointer 2691 **/ 2692 static unsigned int i40e_max_channels(struct i40e_vsi *vsi) 2693 { 2694 /* TODO: This code assumes DCB and FD is disabled for now. */ 2695 return vsi->alloc_queue_pairs; 2696 } 2697 2698 /** 2699 * i40e_get_channels - Get the current channels enabled and max supported etc. 2700 * @netdev: network interface device structure 2701 * @ch: ethtool channels structure 2702 * 2703 * We don't support separate tx and rx queues as channels. The other count 2704 * represents how many queues are being used for control. max_combined counts 2705 * how many queue pairs we can support. They may not be mapped 1 to 1 with 2706 * q_vectors since we support a lot more queue pairs than q_vectors. 2707 **/ 2708 static void i40e_get_channels(struct net_device *dev, 2709 struct ethtool_channels *ch) 2710 { 2711 struct i40e_netdev_priv *np = netdev_priv(dev); 2712 struct i40e_vsi *vsi = np->vsi; 2713 struct i40e_pf *pf = vsi->back; 2714 2715 /* report maximum channels */ 2716 ch->max_combined = i40e_max_channels(vsi); 2717 2718 /* report info for other vector */ 2719 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0; 2720 ch->max_other = ch->other_count; 2721 2722 /* Note: This code assumes DCB is disabled for now. */ 2723 ch->combined_count = vsi->num_queue_pairs; 2724 } 2725 2726 /** 2727 * i40e_set_channels - Set the new channels count. 2728 * @netdev: network interface device structure 2729 * @ch: ethtool channels structure 2730 * 2731 * The new channels count may not be the same as requested by the user 2732 * since it gets rounded down to a power of 2 value. 2733 **/ 2734 static int i40e_set_channels(struct net_device *dev, 2735 struct ethtool_channels *ch) 2736 { 2737 struct i40e_netdev_priv *np = netdev_priv(dev); 2738 unsigned int count = ch->combined_count; 2739 struct i40e_vsi *vsi = np->vsi; 2740 struct i40e_pf *pf = vsi->back; 2741 int new_count; 2742 2743 /* We do not support setting channels for any other VSI at present */ 2744 if (vsi->type != I40E_VSI_MAIN) 2745 return -EINVAL; 2746 2747 /* verify they are not requesting separate vectors */ 2748 if (!count || ch->rx_count || ch->tx_count) 2749 return -EINVAL; 2750 2751 /* verify other_count has not changed */ 2752 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0)) 2753 return -EINVAL; 2754 2755 /* verify the number of channels does not exceed hardware limits */ 2756 if (count > i40e_max_channels(vsi)) 2757 return -EINVAL; 2758 2759 /* update feature limits from largest to smallest supported values */ 2760 /* TODO: Flow director limit, DCB etc */ 2761 2762 /* use rss_reconfig to rebuild with new queue count and update traffic 2763 * class queue mapping 2764 */ 2765 new_count = i40e_reconfig_rss_queues(pf, count); 2766 if (new_count > 0) 2767 return 0; 2768 else 2769 return -EINVAL; 2770 } 2771 2772 /** 2773 * i40e_get_rxfh_key_size - get the RSS hash key size 2774 * @netdev: network interface device structure 2775 * 2776 * Returns the table size. 2777 **/ 2778 static u32 i40e_get_rxfh_key_size(struct net_device *netdev) 2779 { 2780 return I40E_HKEY_ARRAY_SIZE; 2781 } 2782 2783 /** 2784 * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size 2785 * @netdev: network interface device structure 2786 * 2787 * Returns the table size. 2788 **/ 2789 static u32 i40e_get_rxfh_indir_size(struct net_device *netdev) 2790 { 2791 return I40E_HLUT_ARRAY_SIZE; 2792 } 2793 2794 static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, 2795 u8 *hfunc) 2796 { 2797 struct i40e_netdev_priv *np = netdev_priv(netdev); 2798 struct i40e_vsi *vsi = np->vsi; 2799 u8 *lut, *seed = NULL; 2800 int ret; 2801 u16 i; 2802 2803 if (hfunc) 2804 *hfunc = ETH_RSS_HASH_TOP; 2805 2806 if (!indir) 2807 return 0; 2808 2809 seed = key; 2810 lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL); 2811 if (!lut) 2812 return -ENOMEM; 2813 ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE); 2814 if (ret) 2815 goto out; 2816 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++) 2817 indir[i] = (u32)(lut[i]); 2818 2819 out: 2820 kfree(lut); 2821 2822 return ret; 2823 } 2824 2825 /** 2826 * i40e_set_rxfh - set the rx flow hash indirection table 2827 * @netdev: network interface device structure 2828 * @indir: indirection table 2829 * @key: hash key 2830 * 2831 * Returns -EINVAL if the table specifies an invalid queue id, otherwise 2832 * returns 0 after programming the table. 2833 **/ 2834 static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir, 2835 const u8 *key, const u8 hfunc) 2836 { 2837 struct i40e_netdev_priv *np = netdev_priv(netdev); 2838 struct i40e_vsi *vsi = np->vsi; 2839 u8 *seed = NULL; 2840 u16 i; 2841 2842 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) 2843 return -EOPNOTSUPP; 2844 2845 if (!indir) 2846 return 0; 2847 2848 if (key) { 2849 if (!vsi->rss_hkey_user) { 2850 vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE, 2851 GFP_KERNEL); 2852 if (!vsi->rss_hkey_user) 2853 return -ENOMEM; 2854 } 2855 memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE); 2856 seed = vsi->rss_hkey_user; 2857 } 2858 if (!vsi->rss_lut_user) { 2859 vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL); 2860 if (!vsi->rss_lut_user) 2861 return -ENOMEM; 2862 } 2863 2864 /* Each 32 bits pointed by 'indir' is stored with a lut entry */ 2865 for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++) 2866 vsi->rss_lut_user[i] = (u8)(indir[i]); 2867 2868 return i40e_config_rss(vsi, seed, vsi->rss_lut_user, 2869 I40E_HLUT_ARRAY_SIZE); 2870 } 2871 2872 /** 2873 * i40e_get_priv_flags - report device private flags 2874 * @dev: network interface device structure 2875 * 2876 * The get string set count and the string set should be matched for each 2877 * flag returned. Add new strings for each flag to the i40e_priv_flags_strings 2878 * array. 2879 * 2880 * Returns a u32 bitmap of flags. 2881 **/ 2882 static u32 i40e_get_priv_flags(struct net_device *dev) 2883 { 2884 struct i40e_netdev_priv *np = netdev_priv(dev); 2885 struct i40e_vsi *vsi = np->vsi; 2886 struct i40e_pf *pf = vsi->back; 2887 u32 ret_flags = 0; 2888 2889 ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ? 2890 I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0; 2891 ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ? 2892 I40E_PRIV_FLAGS_FD_ATR : 0; 2893 ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ? 2894 I40E_PRIV_FLAGS_VEB_STATS : 0; 2895 ret_flags |= pf->auto_disable_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ? 2896 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT; 2897 if (pf->hw.pf_id == 0) { 2898 ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ? 2899 I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0; 2900 } 2901 2902 return ret_flags; 2903 } 2904 2905 /** 2906 * i40e_set_priv_flags - set private flags 2907 * @dev: network interface device structure 2908 * @flags: bit flags to be set 2909 **/ 2910 static int i40e_set_priv_flags(struct net_device *dev, u32 flags) 2911 { 2912 struct i40e_netdev_priv *np = netdev_priv(dev); 2913 struct i40e_vsi *vsi = np->vsi; 2914 struct i40e_pf *pf = vsi->back; 2915 u16 sw_flags = 0, valid_flags = 0; 2916 bool reset_required = false; 2917 bool promisc_change = false; 2918 int ret; 2919 2920 /* NOTE: MFP is not settable */ 2921 2922 if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG) 2923 pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED; 2924 else 2925 pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED; 2926 2927 /* allow the user to control the state of the Flow 2928 * Director ATR (Application Targeted Routing) feature 2929 * of the driver 2930 */ 2931 if (flags & I40E_PRIV_FLAGS_FD_ATR) { 2932 pf->flags |= I40E_FLAG_FD_ATR_ENABLED; 2933 } else { 2934 pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; 2935 pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED; 2936 } 2937 2938 if ((flags & I40E_PRIV_FLAGS_VEB_STATS) && 2939 !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { 2940 pf->flags |= I40E_FLAG_VEB_STATS_ENABLED; 2941 reset_required = true; 2942 } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) && 2943 (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { 2944 pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; 2945 reset_required = true; 2946 } 2947 2948 if (pf->hw.pf_id == 0) { 2949 if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) && 2950 !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) { 2951 pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT; 2952 promisc_change = true; 2953 } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) && 2954 (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) { 2955 pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT; 2956 promisc_change = true; 2957 } 2958 } 2959 if (promisc_change) { 2960 if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) 2961 sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; 2962 valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; 2963 ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags, 2964 NULL); 2965 if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { 2966 dev_info(&pf->pdev->dev, 2967 "couldn't set switch config bits, err %s aq_err %s\n", 2968 i40e_stat_str(&pf->hw, ret), 2969 i40e_aq_str(&pf->hw, 2970 pf->hw.aq.asq_last_status)); 2971 /* not a fatal problem, just keep going */ 2972 } 2973 } 2974 2975 if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) && 2976 (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE)) 2977 pf->auto_disable_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE; 2978 else 2979 pf->auto_disable_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE; 2980 2981 /* if needed, issue reset to cause things to take effect */ 2982 if (reset_required) 2983 i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED)); 2984 2985 return 0; 2986 } 2987 2988 static const struct ethtool_ops i40e_ethtool_ops = { 2989 .get_settings = i40e_get_settings, 2990 .set_settings = i40e_set_settings, 2991 .get_drvinfo = i40e_get_drvinfo, 2992 .get_regs_len = i40e_get_regs_len, 2993 .get_regs = i40e_get_regs, 2994 .nway_reset = i40e_nway_reset, 2995 .get_link = ethtool_op_get_link, 2996 .get_wol = i40e_get_wol, 2997 .set_wol = i40e_set_wol, 2998 .set_eeprom = i40e_set_eeprom, 2999 .get_eeprom_len = i40e_get_eeprom_len, 3000 .get_eeprom = i40e_get_eeprom, 3001 .get_ringparam = i40e_get_ringparam, 3002 .set_ringparam = i40e_set_ringparam, 3003 .get_pauseparam = i40e_get_pauseparam, 3004 .set_pauseparam = i40e_set_pauseparam, 3005 .get_msglevel = i40e_get_msglevel, 3006 .set_msglevel = i40e_set_msglevel, 3007 .get_rxnfc = i40e_get_rxnfc, 3008 .set_rxnfc = i40e_set_rxnfc, 3009 .self_test = i40e_diag_test, 3010 .get_strings = i40e_get_strings, 3011 .set_phys_id = i40e_set_phys_id, 3012 .get_sset_count = i40e_get_sset_count, 3013 .get_ethtool_stats = i40e_get_ethtool_stats, 3014 .get_coalesce = i40e_get_coalesce, 3015 .set_coalesce = i40e_set_coalesce, 3016 .get_rxfh_key_size = i40e_get_rxfh_key_size, 3017 .get_rxfh_indir_size = i40e_get_rxfh_indir_size, 3018 .get_rxfh = i40e_get_rxfh, 3019 .set_rxfh = i40e_set_rxfh, 3020 .get_channels = i40e_get_channels, 3021 .set_channels = i40e_set_channels, 3022 .get_ts_info = i40e_get_ts_info, 3023 .get_priv_flags = i40e_get_priv_flags, 3024 .set_priv_flags = i40e_set_priv_flags, 3025 .get_per_queue_coalesce = i40e_get_per_queue_coalesce, 3026 .set_per_queue_coalesce = i40e_set_per_queue_coalesce, 3027 }; 3028 3029 void i40e_set_ethtool_ops(struct net_device *netdev) 3030 { 3031 netdev->ethtool_ops = &i40e_ethtool_ops; 3032 } 3033