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