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