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