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