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