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 | */ |
Joe Perches | fe180a5 | 2016-09-26 20:17:01 -0700 | [diff] [blame] | 107 | static const struct i40e_stats i40e_gstrings_stats[] = { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 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, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 219 | I40E_ETH_TEST_LINK, |
| 220 | }; |
| 221 | |
| 222 | static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = { |
| 223 | "Register test (offline)", |
| 224 | "Eeprom test (offline)", |
| 225 | "Interrupt test (offline)", |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 226 | "Link test (on/offline)" |
| 227 | }; |
| 228 | |
| 229 | #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN) |
| 230 | |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 231 | static const char i40e_priv_flags_strings[][ETH_GSTRING_LEN] = { |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 232 | "MFP", |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 233 | "LinkPolling", |
Jesse Brandeburg | ef17178 | 2015-09-03 17:18:49 -0400 | [diff] [blame] | 234 | "flow-director-atr", |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 235 | "veb-stats", |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 236 | "hw-atr-eviction", |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 239 | #define I40E_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_priv_flags_strings) |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 240 | |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 241 | /* Private flags with a global effect, restricted to PF 0 */ |
| 242 | static const char i40e_gl_priv_flags_strings[][ETH_GSTRING_LEN] = { |
| 243 | "vf-true-promisc-support", |
| 244 | }; |
| 245 | |
| 246 | #define I40E_GL_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40e_gl_priv_flags_strings) |
| 247 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 248 | /** |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 249 | * i40e_partition_setting_complaint - generic complaint for MFP restriction |
| 250 | * @pf: the PF struct |
| 251 | **/ |
| 252 | static void i40e_partition_setting_complaint(struct i40e_pf *pf) |
| 253 | { |
| 254 | dev_info(&pf->pdev->dev, |
| 255 | "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"); |
| 256 | } |
| 257 | |
| 258 | /** |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 259 | * i40e_phy_type_to_ethtool - convert the phy_types to ethtool link modes |
| 260 | * @phy_types: PHY types to convert |
| 261 | * @supported: pointer to the ethtool supported variable to fill in |
| 262 | * @advertising: pointer to the ethtool advertising variable to fill in |
| 263 | * |
| 264 | **/ |
| 265 | static void i40e_phy_type_to_ethtool(struct i40e_pf *pf, u32 *supported, |
| 266 | u32 *advertising) |
| 267 | { |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 268 | struct i40e_link_status *hw_link_info = &pf->hw.phy.link_info; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 269 | u64 phy_types = pf->hw.phy.phy_types; |
| 270 | |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 271 | *supported = 0x0; |
| 272 | *advertising = 0x0; |
| 273 | |
| 274 | if (phy_types & I40E_CAP_PHY_TYPE_SGMII) { |
| 275 | *supported |= SUPPORTED_Autoneg | |
| 276 | SUPPORTED_1000baseT_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 277 | *advertising |= ADVERTISED_Autoneg; |
| 278 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
| 279 | *advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 280 | if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) { |
| 281 | *supported |= SUPPORTED_100baseT_Full; |
| 282 | *advertising |= ADVERTISED_100baseT_Full; |
| 283 | } |
| 284 | } |
| 285 | if (phy_types & I40E_CAP_PHY_TYPE_XAUI || |
| 286 | phy_types & I40E_CAP_PHY_TYPE_XFI || |
| 287 | phy_types & I40E_CAP_PHY_TYPE_SFI || |
| 288 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_SFPP_CU || |
| 289 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_AOC) |
| 290 | *supported |= SUPPORTED_10000baseT_Full; |
| 291 | if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1_CU || |
| 292 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_CR1 || |
| 293 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_T || |
| 294 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_SR || |
| 295 | phy_types & I40E_CAP_PHY_TYPE_10GBASE_LR) { |
| 296 | *supported |= SUPPORTED_Autoneg | |
| 297 | SUPPORTED_10000baseT_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 298 | *advertising |= ADVERTISED_Autoneg; |
| 299 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
| 300 | *advertising |= ADVERTISED_10000baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 301 | } |
| 302 | if (phy_types & I40E_CAP_PHY_TYPE_XLAUI || |
| 303 | phy_types & I40E_CAP_PHY_TYPE_XLPPI || |
| 304 | phy_types & I40E_CAP_PHY_TYPE_40GBASE_AOC) |
| 305 | *supported |= SUPPORTED_40000baseCR4_Full; |
| 306 | if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU || |
| 307 | phy_types & I40E_CAP_PHY_TYPE_40GBASE_CR4) { |
| 308 | *supported |= SUPPORTED_Autoneg | |
| 309 | SUPPORTED_40000baseCR4_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 310 | *advertising |= ADVERTISED_Autoneg; |
| 311 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_40GB) |
| 312 | *advertising |= ADVERTISED_40000baseCR4_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 313 | } |
Avinash Dayanand | 01a7a9f | 2016-05-16 10:26:40 -0700 | [diff] [blame] | 314 | if (phy_types & I40E_CAP_PHY_TYPE_100BASE_TX) { |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 315 | *supported |= SUPPORTED_Autoneg | |
| 316 | SUPPORTED_100baseT_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 317 | *advertising |= ADVERTISED_Autoneg; |
| 318 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB) |
| 319 | *advertising |= ADVERTISED_100baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 320 | } |
| 321 | if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_T || |
| 322 | phy_types & I40E_CAP_PHY_TYPE_1000BASE_SX || |
| 323 | phy_types & I40E_CAP_PHY_TYPE_1000BASE_LX || |
| 324 | phy_types & I40E_CAP_PHY_TYPE_1000BASE_T_OPTICAL) { |
| 325 | *supported |= SUPPORTED_Autoneg | |
| 326 | SUPPORTED_1000baseT_Full; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 327 | *advertising |= ADVERTISED_Autoneg; |
| 328 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
| 329 | *advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 330 | } |
| 331 | if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_SR4) |
| 332 | *supported |= SUPPORTED_40000baseSR4_Full; |
| 333 | if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_LR4) |
| 334 | *supported |= SUPPORTED_40000baseLR4_Full; |
| 335 | if (phy_types & I40E_CAP_PHY_TYPE_40GBASE_KR4) { |
| 336 | *supported |= SUPPORTED_40000baseKR4_Full | |
| 337 | SUPPORTED_Autoneg; |
| 338 | *advertising |= ADVERTISED_40000baseKR4_Full | |
| 339 | ADVERTISED_Autoneg; |
| 340 | } |
| 341 | if (phy_types & I40E_CAP_PHY_TYPE_20GBASE_KR2) { |
| 342 | *supported |= SUPPORTED_20000baseKR2_Full | |
| 343 | SUPPORTED_Autoneg; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 344 | *advertising |= ADVERTISED_Autoneg; |
| 345 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_20GB) |
| 346 | *advertising |= ADVERTISED_20000baseKR2_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 347 | } |
| 348 | if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KR) { |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 349 | if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER)) |
| 350 | *supported |= SUPPORTED_10000baseKR_Full | |
| 351 | SUPPORTED_Autoneg; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 352 | *advertising |= ADVERTISED_Autoneg; |
| 353 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 354 | if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER)) |
| 355 | *advertising |= ADVERTISED_10000baseKR_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 356 | } |
| 357 | if (phy_types & I40E_CAP_PHY_TYPE_10GBASE_KX4) { |
| 358 | *supported |= SUPPORTED_10000baseKX4_Full | |
| 359 | SUPPORTED_Autoneg; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 360 | *advertising |= ADVERTISED_Autoneg; |
| 361 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
| 362 | *advertising |= ADVERTISED_10000baseKX4_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 363 | } |
| 364 | if (phy_types & I40E_CAP_PHY_TYPE_1000BASE_KX) { |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 365 | if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER)) |
| 366 | *supported |= SUPPORTED_1000baseKX_Full | |
| 367 | SUPPORTED_Autoneg; |
Avinash Dayanand | 2853704 | 2016-06-20 09:10:33 -0700 | [diff] [blame] | 368 | *advertising |= ADVERTISED_Autoneg; |
| 369 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
Harshitha Ramamurthy | 4ad9f4f | 2016-11-08 13:05:09 -0800 | [diff] [blame] | 370 | if (!(pf->flags & I40E_FLAG_HAVE_CRT_RETIMER)) |
| 371 | *advertising |= ADVERTISED_1000baseKX_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 372 | } |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 373 | if (phy_types & I40E_CAP_PHY_TYPE_25GBASE_KR || |
| 374 | phy_types & I40E_CAP_PHY_TYPE_25GBASE_CR || |
| 375 | phy_types & I40E_CAP_PHY_TYPE_25GBASE_SR || |
| 376 | phy_types & I40E_CAP_PHY_TYPE_25GBASE_LR) { |
| 377 | *supported |= SUPPORTED_Autoneg; |
| 378 | *advertising |= ADVERTISED_Autoneg; |
| 379 | } |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | /** |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 383 | * i40e_get_settings_link_up - Get the Link settings for when link is up |
| 384 | * @hw: hw structure |
| 385 | * @ecmd: ethtool command to fill in |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 386 | * @netdev: network interface device structure |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 387 | * |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 388 | **/ |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 389 | static void i40e_get_settings_link_up(struct i40e_hw *hw, |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 390 | struct ethtool_link_ksettings *cmd, |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 391 | struct net_device *netdev, |
| 392 | struct i40e_pf *pf) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 393 | { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 394 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 395 | u32 link_speed = hw_link_info->link_speed; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 396 | u32 e_advertising = 0x0; |
| 397 | u32 e_supported = 0x0; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 398 | u32 supported, advertising; |
| 399 | |
| 400 | ethtool_convert_link_mode_to_legacy_u32(&supported, |
| 401 | cmd->link_modes.supported); |
| 402 | ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 403 | cmd->link_modes.advertising); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 404 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 405 | /* Initialize supported and advertised settings based on phy settings */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 406 | switch (hw_link_info->phy_type) { |
| 407 | case I40E_PHY_TYPE_40GBASE_CR4: |
| 408 | case I40E_PHY_TYPE_40GBASE_CR4_CU: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 409 | supported = SUPPORTED_Autoneg | |
| 410 | SUPPORTED_40000baseCR4_Full; |
| 411 | advertising = ADVERTISED_Autoneg | |
| 412 | ADVERTISED_40000baseCR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 413 | break; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 414 | case I40E_PHY_TYPE_XLAUI: |
| 415 | case I40E_PHY_TYPE_XLPPI: |
Catherine Sullivan | 180204c | 2015-02-26 16:14:58 +0000 | [diff] [blame] | 416 | case I40E_PHY_TYPE_40GBASE_AOC: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 417 | supported = SUPPORTED_40000baseCR4_Full; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 418 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 419 | case I40E_PHY_TYPE_40GBASE_SR4: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 420 | supported = SUPPORTED_40000baseSR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 421 | break; |
| 422 | case I40E_PHY_TYPE_40GBASE_LR4: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 423 | supported = SUPPORTED_40000baseLR4_Full; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 424 | break; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 425 | case I40E_PHY_TYPE_10GBASE_SR: |
| 426 | case I40E_PHY_TYPE_10GBASE_LR: |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 427 | case I40E_PHY_TYPE_1000BASE_SX: |
| 428 | case I40E_PHY_TYPE_1000BASE_LX: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 429 | supported = SUPPORTED_10000baseT_Full; |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 430 | if (hw_link_info->module_type[2] & |
| 431 | I40E_MODULE_TYPE_1000BASE_SX || |
| 432 | hw_link_info->module_type[2] & |
| 433 | I40E_MODULE_TYPE_1000BASE_LX) { |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 434 | supported |= SUPPORTED_1000baseT_Full; |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 435 | if (hw_link_info->requested_speeds & |
| 436 | I40E_LINK_SPEED_1GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 437 | advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 438 | } |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 439 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 440 | advertising |= ADVERTISED_10000baseT_Full; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 441 | break; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 442 | case I40E_PHY_TYPE_10GBASE_T: |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 443 | case I40E_PHY_TYPE_1000BASE_T: |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 444 | case I40E_PHY_TYPE_100BASE_TX: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 445 | supported = SUPPORTED_Autoneg | |
| 446 | SUPPORTED_10000baseT_Full | |
| 447 | SUPPORTED_1000baseT_Full | |
| 448 | SUPPORTED_100baseT_Full; |
| 449 | advertising = ADVERTISED_Autoneg; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 450 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_10GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 451 | advertising |= ADVERTISED_10000baseT_Full; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 452 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 453 | advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 454 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_100MB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 455 | advertising |= ADVERTISED_100baseT_Full; |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 456 | break; |
Catherine Sullivan | 48becae | 2015-09-28 14:12:41 -0400 | [diff] [blame] | 457 | case I40E_PHY_TYPE_1000BASE_T_OPTICAL: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 458 | supported = SUPPORTED_Autoneg | |
| 459 | SUPPORTED_1000baseT_Full; |
| 460 | advertising = ADVERTISED_Autoneg | |
| 461 | ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 48becae | 2015-09-28 14:12:41 -0400 | [diff] [blame] | 462 | break; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 463 | case I40E_PHY_TYPE_10GBASE_CR1_CU: |
| 464 | case I40E_PHY_TYPE_10GBASE_CR1: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 465 | supported = SUPPORTED_Autoneg | |
| 466 | SUPPORTED_10000baseT_Full; |
| 467 | advertising = ADVERTISED_Autoneg | |
| 468 | ADVERTISED_10000baseT_Full; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 469 | break; |
| 470 | case I40E_PHY_TYPE_XAUI: |
| 471 | case I40E_PHY_TYPE_XFI: |
| 472 | case I40E_PHY_TYPE_SFI: |
| 473 | case I40E_PHY_TYPE_10GBASE_SFPP_CU: |
Catherine Sullivan | 180204c | 2015-02-26 16:14:58 +0000 | [diff] [blame] | 474 | case I40E_PHY_TYPE_10GBASE_AOC: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 475 | supported = SUPPORTED_10000baseT_Full; |
| 476 | advertising = SUPPORTED_10000baseT_Full; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 477 | break; |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 478 | case I40E_PHY_TYPE_SGMII: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 479 | supported = SUPPORTED_Autoneg | |
| 480 | SUPPORTED_1000baseT_Full; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 481 | if (hw_link_info->requested_speeds & I40E_LINK_SPEED_1GB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 482 | advertising |= ADVERTISED_1000baseT_Full; |
Catherine Sullivan | 48b1804 | 2015-12-09 15:50:25 -0800 | [diff] [blame] | 483 | if (pf->flags & I40E_FLAG_100M_SGMII_CAPABLE) { |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 484 | supported |= SUPPORTED_100baseT_Full; |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 485 | if (hw_link_info->requested_speeds & |
| 486 | I40E_LINK_SPEED_100MB) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 487 | advertising |= ADVERTISED_100baseT_Full; |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 488 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 489 | break; |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 490 | case I40E_PHY_TYPE_40GBASE_KR4: |
| 491 | case I40E_PHY_TYPE_20GBASE_KR2: |
| 492 | case I40E_PHY_TYPE_10GBASE_KR: |
| 493 | case I40E_PHY_TYPE_10GBASE_KX4: |
| 494 | case I40E_PHY_TYPE_1000BASE_KX: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 495 | supported |= SUPPORTED_40000baseKR4_Full | |
| 496 | SUPPORTED_20000baseKR2_Full | |
| 497 | SUPPORTED_10000baseKR_Full | |
| 498 | SUPPORTED_10000baseKX4_Full | |
| 499 | SUPPORTED_1000baseKX_Full | |
| 500 | SUPPORTED_Autoneg; |
| 501 | advertising |= ADVERTISED_40000baseKR4_Full | |
| 502 | ADVERTISED_20000baseKR2_Full | |
| 503 | ADVERTISED_10000baseKR_Full | |
| 504 | ADVERTISED_10000baseKX4_Full | |
| 505 | ADVERTISED_1000baseKX_Full | |
| 506 | ADVERTISED_Autoneg; |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 507 | break; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 508 | case I40E_PHY_TYPE_25GBASE_KR: |
| 509 | case I40E_PHY_TYPE_25GBASE_CR: |
| 510 | case I40E_PHY_TYPE_25GBASE_SR: |
| 511 | case I40E_PHY_TYPE_25GBASE_LR: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 512 | supported = SUPPORTED_Autoneg; |
| 513 | advertising = ADVERTISED_Autoneg; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 514 | /* TODO: add speeds when ethtool is ready to support*/ |
| 515 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 516 | default: |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 517 | /* if we got here and link is up something bad is afoot */ |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 518 | netdev_info(netdev, "WARNING: Link is up but PHY type 0x%x is not recognized.\n", |
| 519 | hw_link_info->phy_type); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 522 | /* Now that we've worked out everything that could be supported by the |
| 523 | * current PHY type, get what is supported by the NVM and them to |
| 524 | * get what is truly supported |
| 525 | */ |
| 526 | i40e_phy_type_to_ethtool(pf, &e_supported, |
| 527 | &e_advertising); |
| 528 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 529 | supported = supported & e_supported; |
| 530 | advertising = advertising & e_advertising; |
Catherine Sullivan | 06566e5 | 2016-05-03 15:13:14 -0700 | [diff] [blame] | 531 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 532 | /* Set speed and duplex */ |
| 533 | switch (link_speed) { |
| 534 | case I40E_LINK_SPEED_40GB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 535 | cmd->base.speed = SPEED_40000; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 536 | break; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 537 | case I40E_LINK_SPEED_25GB: |
| 538 | #ifdef SPEED_25000 |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 539 | cmd->base.speed = SPEED_25000; |
Carolyn Wyborny | 3123237 | 2016-11-21 13:03:48 -0800 | [diff] [blame] | 540 | #else |
| 541 | netdev_info(netdev, |
| 542 | "Speed is 25G, display not supported by this version of ethtool.\n"); |
| 543 | #endif |
| 544 | break; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 545 | case I40E_LINK_SPEED_20GB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 546 | cmd->base.speed = SPEED_20000; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 547 | break; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 548 | case I40E_LINK_SPEED_10GB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 549 | cmd->base.speed = SPEED_10000; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 550 | break; |
| 551 | case I40E_LINK_SPEED_1GB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 552 | cmd->base.speed = SPEED_1000; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 553 | break; |
| 554 | case I40E_LINK_SPEED_100MB: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 555 | cmd->base.speed = SPEED_100; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 556 | break; |
| 557 | default: |
| 558 | break; |
| 559 | } |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 560 | cmd->base.duplex = DUPLEX_FULL; |
| 561 | |
| 562 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 563 | supported); |
| 564 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 565 | advertising); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /** |
| 569 | * i40e_get_settings_link_down - Get the Link settings for when link is down |
| 570 | * @hw: hw structure |
| 571 | * @ecmd: ethtool command to fill in |
| 572 | * |
| 573 | * Reports link settings that can be determined when link is down |
| 574 | **/ |
| 575 | static void i40e_get_settings_link_down(struct i40e_hw *hw, |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 576 | struct ethtool_link_ksettings *cmd, |
Catherine Sullivan | 3b6c217 | 2015-09-03 17:18:52 -0400 | [diff] [blame] | 577 | struct i40e_pf *pf) |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 578 | { |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 579 | u32 supported, advertising; |
| 580 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 581 | /* link is down and the driver needs to fall back on |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 582 | * supported phy types to figure out what info to display |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 583 | */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 584 | i40e_phy_type_to_ethtool(pf, &supported, &advertising); |
| 585 | |
| 586 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 587 | supported); |
| 588 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 589 | advertising); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 590 | |
| 591 | /* With no link speed and duplex are unknown */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 592 | cmd->base.speed = SPEED_UNKNOWN; |
| 593 | cmd->base.duplex = DUPLEX_UNKNOWN; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /** |
| 597 | * i40e_get_settings - Get Link Speed and Duplex settings |
| 598 | * @netdev: network interface device structure |
| 599 | * @ecmd: ethtool command |
| 600 | * |
| 601 | * Reports speed/duplex settings based on media_type |
| 602 | **/ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 603 | static int i40e_get_link_ksettings(struct net_device *netdev, |
| 604 | struct ethtool_link_ksettings *cmd) |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 605 | { |
| 606 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 607 | struct i40e_pf *pf = np->vsi->back; |
| 608 | struct i40e_hw *hw = &pf->hw; |
| 609 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
| 610 | bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 611 | u32 advertising; |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 612 | |
| 613 | if (link_up) |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 614 | i40e_get_settings_link_up(hw, cmd, netdev, pf); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 615 | else |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 616 | i40e_get_settings_link_down(hw, cmd, pf); |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 617 | |
| 618 | /* Now set the settings that don't rely on link being up/down */ |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 619 | /* Set autoneg settings */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 620 | cmd->base.autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 621 | AUTONEG_ENABLE : AUTONEG_DISABLE); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 622 | |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 623 | switch (hw->phy.media_type) { |
| 624 | case I40E_MEDIA_TYPE_BACKPLANE: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 625 | ethtool_link_ksettings_add_link_mode(cmd, supported, |
| 626 | Autoneg); |
| 627 | ethtool_link_ksettings_add_link_mode(cmd, supported, |
| 628 | Backplane); |
| 629 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 630 | Autoneg); |
| 631 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 632 | Backplane); |
| 633 | cmd->base.port = PORT_NONE; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 634 | break; |
| 635 | case I40E_MEDIA_TYPE_BASET: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 636 | ethtool_link_ksettings_add_link_mode(cmd, supported, TP); |
| 637 | ethtool_link_ksettings_add_link_mode(cmd, advertising, TP); |
| 638 | cmd->base.port = PORT_TP; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 639 | break; |
| 640 | case I40E_MEDIA_TYPE_DA: |
| 641 | case I40E_MEDIA_TYPE_CX4: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 642 | ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE); |
| 643 | ethtool_link_ksettings_add_link_mode(cmd, advertising, FIBRE); |
| 644 | cmd->base.port = PORT_DA; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 645 | break; |
| 646 | case I40E_MEDIA_TYPE_FIBER: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 647 | ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE); |
| 648 | cmd->base.port = PORT_FIBRE; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 649 | break; |
| 650 | case I40E_MEDIA_TYPE_UNKNOWN: |
| 651 | default: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 652 | cmd->base.port = PORT_OTHER; |
Jesse Brandeburg | c9a3d47 | 2013-11-26 10:49:10 +0000 | [diff] [blame] | 653 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 656 | /* Set flow control settings */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 657 | ethtool_link_ksettings_add_link_mode(cmd, supported, Pause); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 658 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 659 | switch (hw->fc.requested_mode) { |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 660 | case I40E_FC_FULL: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 661 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 662 | Pause); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 663 | break; |
| 664 | case I40E_FC_TX_PAUSE: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 665 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 666 | Asym_Pause); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 667 | break; |
| 668 | case I40E_FC_RX_PAUSE: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 669 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 670 | Pause); |
| 671 | ethtool_link_ksettings_add_link_mode(cmd, advertising, |
| 672 | Asym_Pause); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 673 | break; |
| 674 | default: |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 675 | ethtool_convert_link_mode_to_legacy_u32( |
| 676 | &advertising, cmd->link_modes.advertising); |
| 677 | |
| 678 | advertising &= ~(ADVERTISED_Pause | ADVERTISED_Asym_Pause); |
| 679 | |
| 680 | ethtool_convert_legacy_u32_to_link_mode( |
| 681 | cmd->link_modes.advertising, advertising); |
Jesse Brandeburg | 4e91bcd | 2014-06-04 08:45:23 +0000 | [diff] [blame] | 682 | break; |
| 683 | } |
| 684 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 685 | return 0; |
| 686 | } |
| 687 | |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 688 | /** |
| 689 | * i40e_set_settings - Set Speed and Duplex |
| 690 | * @netdev: network interface device structure |
| 691 | * @ecmd: ethtool command |
| 692 | * |
| 693 | * Set speed/duplex per media_types advertised/forced |
| 694 | **/ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 695 | static int i40e_set_link_ksettings(struct net_device *netdev, |
| 696 | const struct ethtool_link_ksettings *cmd) |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 697 | { |
| 698 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 699 | struct i40e_aq_get_phy_abilities_resp abilities; |
| 700 | struct i40e_aq_set_phy_config config; |
| 701 | struct i40e_pf *pf = np->vsi->back; |
| 702 | struct i40e_vsi *vsi = np->vsi; |
| 703 | struct i40e_hw *hw = &pf->hw; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 704 | struct ethtool_link_ksettings safe_cmd; |
| 705 | struct ethtool_link_ksettings copy_cmd; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 706 | i40e_status status = 0; |
| 707 | bool change = false; |
| 708 | int err = 0; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 709 | u32 autoneg; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 710 | u32 advertise; |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 711 | u32 tmp; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 712 | |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 713 | /* Changing port settings is not supported if this isn't the |
| 714 | * port's controlling PF |
| 715 | */ |
| 716 | if (hw->partition_id != 1) { |
| 717 | i40e_partition_setting_complaint(pf); |
| 718 | return -EOPNOTSUPP; |
| 719 | } |
| 720 | |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 721 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 722 | return -EOPNOTSUPP; |
| 723 | |
| 724 | if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET && |
| 725 | hw->phy.media_type != I40E_MEDIA_TYPE_FIBER && |
Catherine Sullivan | c57e9f1 | 2014-07-12 07:28:13 +0000 | [diff] [blame] | 726 | hw->phy.media_type != I40E_MEDIA_TYPE_BACKPLANE && |
Serey Kong | 6536227 | 2016-05-16 10:26:39 -0700 | [diff] [blame] | 727 | hw->phy.media_type != I40E_MEDIA_TYPE_DA && |
Catherine Sullivan | c57e9f1 | 2014-07-12 07:28:13 +0000 | [diff] [blame] | 728 | hw->phy.link_info.link_info & I40E_AQ_LINK_UP) |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 729 | return -EOPNOTSUPP; |
| 730 | |
Catherine Sullivan | fc72dbc | 2015-09-01 11:36:30 -0400 | [diff] [blame] | 731 | if (hw->device_id == I40E_DEV_ID_KX_B || |
| 732 | hw->device_id == I40E_DEV_ID_KX_C || |
| 733 | hw->device_id == I40E_DEV_ID_20G_KR2 || |
| 734 | hw->device_id == I40E_DEV_ID_20G_KR2_A) { |
| 735 | netdev_info(netdev, "Changing settings is not supported on backplane.\n"); |
| 736 | return -EOPNOTSUPP; |
| 737 | } |
| 738 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 739 | /* copy the cmd to copy_cmd to avoid modifying the origin */ |
| 740 | memcpy(©_cmd, cmd, sizeof(struct ethtool_link_ksettings)); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 741 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 742 | /* get our own copy of the bits to check against */ |
| 743 | memset(&safe_cmd, 0, sizeof(struct ethtool_link_ksettings)); |
| 744 | i40e_get_link_ksettings(netdev, &safe_cmd); |
| 745 | |
| 746 | /* save autoneg and speed out of cmd */ |
| 747 | autoneg = cmd->base.autoneg; |
| 748 | ethtool_convert_link_mode_to_legacy_u32(&advertise, |
| 749 | cmd->link_modes.advertising); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 750 | |
| 751 | /* set autoneg and speed back to what they currently are */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 752 | copy_cmd.base.autoneg = safe_cmd.base.autoneg; |
| 753 | ethtool_convert_link_mode_to_legacy_u32( |
| 754 | &tmp, safe_cmd.link_modes.advertising); |
| 755 | ethtool_convert_legacy_u32_to_link_mode( |
| 756 | copy_cmd.link_modes.advertising, tmp); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 757 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 758 | copy_cmd.base.cmd = safe_cmd.base.cmd; |
| 759 | |
| 760 | /* If copy_cmd and safe_cmd are not the same now, then they are |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 761 | * trying to set something that we do not support |
| 762 | */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 763 | if (memcmp(©_cmd, &safe_cmd, sizeof(struct ethtool_link_ksettings))) |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 764 | return -EOPNOTSUPP; |
| 765 | |
| 766 | while (test_bit(__I40E_CONFIG_BUSY, &vsi->state)) |
| 767 | usleep_range(1000, 2000); |
| 768 | |
| 769 | /* Get the current phy config */ |
| 770 | status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, |
| 771 | NULL); |
| 772 | if (status) |
| 773 | return -EAGAIN; |
| 774 | |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 775 | /* Copy abilities to config in case autoneg is not |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 776 | * set below |
| 777 | */ |
| 778 | memset(&config, 0, sizeof(struct i40e_aq_set_phy_config)); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 779 | config.abilities = abilities.abilities; |
| 780 | |
| 781 | /* Check autoneg */ |
| 782 | if (autoneg == AUTONEG_ENABLE) { |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 783 | /* If autoneg was not already enabled */ |
| 784 | if (!(hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED)) { |
Catherine Sullivan | 3ce12ee | 2015-09-28 14:16:58 -0400 | [diff] [blame] | 785 | /* If autoneg is not supported, return error */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 786 | if (!ethtool_link_ksettings_test_link_mode( |
| 787 | &safe_cmd, supported, Autoneg)) { |
Catherine Sullivan | 3ce12ee | 2015-09-28 14:16:58 -0400 | [diff] [blame] | 788 | netdev_info(netdev, "Autoneg not supported on this phy\n"); |
| 789 | return -EINVAL; |
| 790 | } |
| 791 | /* Autoneg is allowed to change */ |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 792 | config.abilities = abilities.abilities | |
| 793 | I40E_AQ_PHY_ENABLE_AN; |
| 794 | change = true; |
| 795 | } |
| 796 | } else { |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 797 | /* If autoneg is currently enabled */ |
| 798 | if (hw->phy.link_info.an_info & I40E_AQ_AN_COMPLETED) { |
Catherine Sullivan | 3ce12ee | 2015-09-28 14:16:58 -0400 | [diff] [blame] | 799 | /* If autoneg is supported 10GBASE_T is the only PHY |
| 800 | * that can disable it, so otherwise return error |
| 801 | */ |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 802 | if (ethtool_link_ksettings_test_link_mode( |
| 803 | &safe_cmd, supported, Autoneg) && |
Catherine Sullivan | 3ce12ee | 2015-09-28 14:16:58 -0400 | [diff] [blame] | 804 | hw->phy.link_info.phy_type != |
| 805 | I40E_PHY_TYPE_10GBASE_T) { |
| 806 | netdev_info(netdev, "Autoneg cannot be disabled on this phy\n"); |
| 807 | return -EINVAL; |
| 808 | } |
| 809 | /* Autoneg is allowed to change */ |
Mitch Williams | 5960d33 | 2014-09-13 07:40:47 +0000 | [diff] [blame] | 810 | config.abilities = abilities.abilities & |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 811 | ~I40E_AQ_PHY_ENABLE_AN; |
| 812 | change = true; |
| 813 | } |
| 814 | } |
| 815 | |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 816 | ethtool_convert_link_mode_to_legacy_u32(&tmp, |
| 817 | safe_cmd.link_modes.supported); |
| 818 | if (advertise & ~tmp) |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 819 | return -EINVAL; |
| 820 | |
| 821 | if (advertise & ADVERTISED_100baseT_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 822 | config.link_speed |= I40E_LINK_SPEED_100MB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 823 | if (advertise & ADVERTISED_1000baseT_Full || |
| 824 | advertise & ADVERTISED_1000baseKX_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 825 | config.link_speed |= I40E_LINK_SPEED_1GB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 826 | if (advertise & ADVERTISED_10000baseT_Full || |
| 827 | advertise & ADVERTISED_10000baseKX4_Full || |
| 828 | advertise & ADVERTISED_10000baseKR_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 829 | config.link_speed |= I40E_LINK_SPEED_10GB; |
Jesse Brandeburg | ae24b40 | 2015-03-27 00:12:09 -0700 | [diff] [blame] | 830 | if (advertise & ADVERTISED_20000baseKR2_Full) |
| 831 | config.link_speed |= I40E_LINK_SPEED_20GB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 832 | if (advertise & ADVERTISED_40000baseKR4_Full || |
| 833 | advertise & ADVERTISED_40000baseCR4_Full || |
| 834 | advertise & ADVERTISED_40000baseSR4_Full || |
| 835 | advertise & ADVERTISED_40000baseLR4_Full) |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 836 | config.link_speed |= I40E_LINK_SPEED_40GB; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 837 | |
Catherine Sullivan | 0002e11 | 2015-08-26 15:14:16 -0400 | [diff] [blame] | 838 | /* If speed didn't get set, set it to what it currently is. |
| 839 | * This is needed because if advertise is 0 (as it is when autoneg |
| 840 | * is disabled) then speed won't get set. |
| 841 | */ |
| 842 | if (!config.link_speed) |
| 843 | config.link_speed = abilities.link_speed; |
| 844 | |
Catherine Sullivan | 124ed15 | 2014-07-12 07:28:12 +0000 | [diff] [blame] | 845 | if (change || (abilities.link_speed != config.link_speed)) { |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 846 | /* copy over the rest of the abilities */ |
| 847 | config.phy_type = abilities.phy_type; |
Henry Tieman | b7eaf8f | 2016-12-02 12:33:01 -0800 | [diff] [blame] | 848 | config.phy_type_ext = abilities.phy_type_ext; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 849 | config.eee_capability = abilities.eee_capability; |
| 850 | config.eeer = abilities.eeer_val; |
| 851 | config.low_power_ctrl = abilities.d3_lpan; |
Henry Tieman | b7eaf8f | 2016-12-02 12:33:01 -0800 | [diff] [blame] | 852 | config.fec_config = abilities.fec_cfg_curr_mod_ext_info & |
| 853 | I40E_AQ_PHY_FEC_CONFIG_MASK; |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 854 | |
Catherine Sullivan | e827845 | 2015-02-06 08:52:08 +0000 | [diff] [blame] | 855 | /* save the requested speeds */ |
| 856 | hw->phy.link_info.requested_speeds = config.link_speed; |
Catherine Sullivan | 9412851 | 2014-07-12 07:28:16 +0000 | [diff] [blame] | 857 | /* set link and auto negotiation so changes take effect */ |
| 858 | config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK; |
| 859 | /* If link is up put link down */ |
| 860 | if (hw->phy.link_info.link_info & I40E_AQ_LINK_UP) { |
| 861 | /* Tell the OS link is going down, the link will go |
| 862 | * back up when fw says it is ready asynchronously |
| 863 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 864 | i40e_print_link_message(vsi, false); |
Catherine Sullivan | 9412851 | 2014-07-12 07:28:16 +0000 | [diff] [blame] | 865 | netif_carrier_off(netdev); |
| 866 | netif_tx_stop_all_queues(netdev); |
| 867 | } |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 868 | |
| 869 | /* make the aq call */ |
| 870 | status = i40e_aq_set_phy_config(hw, &config, NULL); |
| 871 | if (status) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 872 | netdev_info(netdev, "Set phy config failed, err %s aq_err %s\n", |
| 873 | i40e_stat_str(hw, status), |
| 874 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 875 | return -EAGAIN; |
| 876 | } |
| 877 | |
Catherine Sullivan | 0a862b4 | 2015-08-31 19:54:53 -0400 | [diff] [blame] | 878 | status = i40e_update_link_info(hw); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 879 | if (status) |
Catherine Sullivan | 52e9689 | 2015-09-28 14:16:59 -0400 | [diff] [blame] | 880 | netdev_dbg(netdev, "Updating link info failed with err %s aq_err %s\n", |
| 881 | i40e_stat_str(hw, status), |
| 882 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | bf9c714 | 2014-06-04 08:45:28 +0000 | [diff] [blame] | 883 | |
| 884 | } else { |
| 885 | netdev_info(netdev, "Nothing changed, exiting without setting anything.\n"); |
| 886 | } |
| 887 | |
| 888 | return err; |
| 889 | } |
| 890 | |
Jesse Brandeburg | a659972 | 2014-06-04 08:45:25 +0000 | [diff] [blame] | 891 | static int i40e_nway_reset(struct net_device *netdev) |
| 892 | { |
| 893 | /* restart autonegotiation */ |
| 894 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 895 | struct i40e_pf *pf = np->vsi->back; |
| 896 | struct i40e_hw *hw = &pf->hw; |
| 897 | bool link_up = hw->phy.link_info.link_info & I40E_AQ_LINK_UP; |
| 898 | i40e_status ret = 0; |
| 899 | |
| 900 | ret = i40e_aq_set_link_restart_an(hw, link_up, NULL); |
| 901 | if (ret) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 902 | netdev_info(netdev, "link restart failed, err %s aq_err %s\n", |
| 903 | i40e_stat_str(hw, ret), |
| 904 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Jesse Brandeburg | a659972 | 2014-06-04 08:45:25 +0000 | [diff] [blame] | 905 | return -EIO; |
| 906 | } |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 911 | /** |
| 912 | * i40e_get_pauseparam - Get Flow Control status |
| 913 | * Return tx/rx-pause status |
| 914 | **/ |
| 915 | static void i40e_get_pauseparam(struct net_device *netdev, |
| 916 | struct ethtool_pauseparam *pause) |
| 917 | { |
| 918 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 919 | struct i40e_pf *pf = np->vsi->back; |
| 920 | struct i40e_hw *hw = &pf->hw; |
| 921 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
Neerav Parikh | 4b7698c | 2014-11-12 00:18:57 +0000 | [diff] [blame] | 922 | struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 923 | |
| 924 | pause->autoneg = |
| 925 | ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
| 926 | AUTONEG_ENABLE : AUTONEG_DISABLE); |
| 927 | |
Neerav Parikh | 4b7698c | 2014-11-12 00:18:57 +0000 | [diff] [blame] | 928 | /* PFC enabled so report LFC as off */ |
| 929 | if (dcbx_cfg->pfc.pfcenable) { |
| 930 | pause->rx_pause = 0; |
| 931 | pause->tx_pause = 0; |
| 932 | return; |
| 933 | } |
| 934 | |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 935 | if (hw->fc.current_mode == I40E_FC_RX_PAUSE) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 936 | pause->rx_pause = 1; |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 937 | } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 938 | pause->tx_pause = 1; |
Jesse Brandeburg | d52c20b | 2013-11-26 10:49:15 +0000 | [diff] [blame] | 939 | } else if (hw->fc.current_mode == I40E_FC_FULL) { |
| 940 | pause->rx_pause = 1; |
| 941 | pause->tx_pause = 1; |
| 942 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 943 | } |
| 944 | |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 945 | /** |
| 946 | * i40e_set_pauseparam - Set Flow Control parameter |
| 947 | * @netdev: network interface device structure |
| 948 | * @pause: return tx/rx flow control status |
| 949 | **/ |
| 950 | static int i40e_set_pauseparam(struct net_device *netdev, |
| 951 | struct ethtool_pauseparam *pause) |
| 952 | { |
| 953 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 954 | struct i40e_pf *pf = np->vsi->back; |
| 955 | struct i40e_vsi *vsi = np->vsi; |
| 956 | struct i40e_hw *hw = &pf->hw; |
| 957 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; |
Neerav Parikh | 4b7698c | 2014-11-12 00:18:57 +0000 | [diff] [blame] | 958 | struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config; |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 959 | bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; |
| 960 | i40e_status status; |
| 961 | u8 aq_failures; |
Catherine Sullivan | 7d62dac | 2014-07-09 07:46:18 +0000 | [diff] [blame] | 962 | int err = 0; |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 963 | |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 964 | /* Changing the port's flow control is not supported if this isn't the |
| 965 | * port's controlling PF |
| 966 | */ |
| 967 | if (hw->partition_id != 1) { |
| 968 | i40e_partition_setting_complaint(pf); |
| 969 | return -EOPNOTSUPP; |
| 970 | } |
| 971 | |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 972 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 973 | return -EOPNOTSUPP; |
| 974 | |
| 975 | if (pause->autoneg != ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? |
| 976 | AUTONEG_ENABLE : AUTONEG_DISABLE)) { |
| 977 | netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n"); |
| 978 | return -EOPNOTSUPP; |
| 979 | } |
| 980 | |
| 981 | /* If we have link and don't have autoneg */ |
| 982 | if (!test_bit(__I40E_DOWN, &pf->state) && |
| 983 | !(hw_link_info->an_info & I40E_AQ_AN_COMPLETED)) { |
| 984 | /* Send message that it might not necessarily work*/ |
| 985 | netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n"); |
| 986 | } |
| 987 | |
Neerav Parikh | 4b7698c | 2014-11-12 00:18:57 +0000 | [diff] [blame] | 988 | if (dcbx_cfg->pfc.pfcenable) { |
| 989 | netdev_info(netdev, |
| 990 | "Priority flow control enabled. Cannot set link flow control.\n"); |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 991 | return -EOPNOTSUPP; |
| 992 | } |
| 993 | |
| 994 | if (pause->rx_pause && pause->tx_pause) |
| 995 | hw->fc.requested_mode = I40E_FC_FULL; |
| 996 | else if (pause->rx_pause && !pause->tx_pause) |
| 997 | hw->fc.requested_mode = I40E_FC_RX_PAUSE; |
| 998 | else if (!pause->rx_pause && pause->tx_pause) |
| 999 | hw->fc.requested_mode = I40E_FC_TX_PAUSE; |
| 1000 | else if (!pause->rx_pause && !pause->tx_pause) |
| 1001 | hw->fc.requested_mode = I40E_FC_NONE; |
| 1002 | else |
| 1003 | return -EINVAL; |
| 1004 | |
Catherine Sullivan | 9412851 | 2014-07-12 07:28:16 +0000 | [diff] [blame] | 1005 | /* Tell the OS link is going down, the link will go back up when fw |
| 1006 | * says it is ready asynchronously |
| 1007 | */ |
Matt Jared | c156f85 | 2015-08-27 11:42:39 -0400 | [diff] [blame] | 1008 | i40e_print_link_message(vsi, false); |
Catherine Sullivan | 9412851 | 2014-07-12 07:28:16 +0000 | [diff] [blame] | 1009 | netif_carrier_off(netdev); |
| 1010 | netif_tx_stop_all_queues(netdev); |
| 1011 | |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1012 | /* Set the fc mode and only restart an if link is up*/ |
| 1013 | status = i40e_set_fc(hw, &aq_failures, link_up); |
| 1014 | |
| 1015 | if (aq_failures & I40E_SET_FC_AQ_FAIL_GET) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1016 | netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n", |
| 1017 | i40e_stat_str(hw, status), |
| 1018 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1019 | err = -EAGAIN; |
| 1020 | } |
| 1021 | if (aq_failures & I40E_SET_FC_AQ_FAIL_SET) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1022 | netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n", |
| 1023 | i40e_stat_str(hw, status), |
| 1024 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1025 | err = -EAGAIN; |
| 1026 | } |
| 1027 | if (aq_failures & I40E_SET_FC_AQ_FAIL_UPDATE) { |
Shannon Nelson | f1c7e72 | 2015-06-04 16:24:01 -0400 | [diff] [blame] | 1028 | netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n", |
| 1029 | i40e_stat_str(hw, status), |
| 1030 | i40e_aq_str(hw, hw->aq.asq_last_status)); |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1031 | err = -EAGAIN; |
| 1032 | } |
| 1033 | |
Catherine Sullivan | 7d62dac | 2014-07-09 07:46:18 +0000 | [diff] [blame] | 1034 | if (!test_bit(__I40E_DOWN, &pf->state)) { |
| 1035 | /* Give it a little more time to try to come back */ |
| 1036 | msleep(75); |
| 1037 | if (!test_bit(__I40E_DOWN, &pf->state)) |
| 1038 | return i40e_nway_reset(netdev); |
| 1039 | } |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 1040 | |
| 1041 | return err; |
| 1042 | } |
| 1043 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1044 | static u32 i40e_get_msglevel(struct net_device *netdev) |
| 1045 | { |
| 1046 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1047 | struct i40e_pf *pf = np->vsi->back; |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 1048 | u32 debug_mask = pf->hw.debug_mask; |
| 1049 | |
| 1050 | if (debug_mask) |
| 1051 | netdev_info(netdev, "i40e debug_mask: 0x%08X\n", debug_mask); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1052 | |
| 1053 | return pf->msg_enable; |
| 1054 | } |
| 1055 | |
| 1056 | static void i40e_set_msglevel(struct net_device *netdev, u32 data) |
| 1057 | { |
| 1058 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1059 | struct i40e_pf *pf = np->vsi->back; |
| 1060 | |
| 1061 | if (I40E_DEBUG_USER & data) |
| 1062 | pf->hw.debug_mask = data; |
Alexander Duyck | 5d4ca23 | 2016-09-30 08:21:46 -0400 | [diff] [blame] | 1063 | else |
| 1064 | pf->msg_enable = data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | static int i40e_get_regs_len(struct net_device *netdev) |
| 1068 | { |
| 1069 | int reg_count = 0; |
| 1070 | int i; |
| 1071 | |
| 1072 | for (i = 0; i40e_reg_list[i].offset != 0; i++) |
| 1073 | reg_count += i40e_reg_list[i].elements; |
| 1074 | |
| 1075 | return reg_count * sizeof(u32); |
| 1076 | } |
| 1077 | |
| 1078 | static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs, |
| 1079 | void *p) |
| 1080 | { |
| 1081 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1082 | struct i40e_pf *pf = np->vsi->back; |
| 1083 | struct i40e_hw *hw = &pf->hw; |
| 1084 | u32 *reg_buf = p; |
| 1085 | int i, j, ri; |
| 1086 | u32 reg; |
| 1087 | |
| 1088 | /* Tell ethtool which driver-version-specific regs output we have. |
| 1089 | * |
| 1090 | * At some point, if we have ethtool doing special formatting of |
| 1091 | * this data, it will rely on this version number to know how to |
| 1092 | * interpret things. Hence, this needs to be updated if/when the |
| 1093 | * diags register table is changed. |
| 1094 | */ |
| 1095 | regs->version = 1; |
| 1096 | |
| 1097 | /* loop through the diags reg table for what to print */ |
| 1098 | ri = 0; |
| 1099 | for (i = 0; i40e_reg_list[i].offset != 0; i++) { |
| 1100 | for (j = 0; j < i40e_reg_list[i].elements; j++) { |
| 1101 | reg = i40e_reg_list[i].offset |
| 1102 | + (j * i40e_reg_list[i].stride); |
| 1103 | reg_buf[ri++] = rd32(hw, reg); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | } |
| 1108 | |
| 1109 | static int i40e_get_eeprom(struct net_device *netdev, |
| 1110 | struct ethtool_eeprom *eeprom, u8 *bytes) |
| 1111 | { |
| 1112 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1113 | struct i40e_hw *hw = &np->vsi->back->hw; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1114 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1115 | int ret_val = 0, len, offset; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1116 | u8 *eeprom_buff; |
| 1117 | u16 i, sectors; |
| 1118 | bool last; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1119 | u32 magic; |
| 1120 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1121 | #define I40E_NVM_SECTOR_SIZE 4096 |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1122 | if (eeprom->len == 0) |
| 1123 | return -EINVAL; |
| 1124 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1125 | /* check for NVMUpdate access method */ |
| 1126 | magic = hw->vendor_id | (hw->device_id << 16); |
| 1127 | if (eeprom->magic && eeprom->magic != magic) { |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1128 | struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom; |
| 1129 | int errno = 0; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1130 | |
| 1131 | /* make sure it is the right magic for NVMUpdate */ |
| 1132 | if ((eeprom->magic >> 16) != hw->device_id) |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1133 | errno = -EINVAL; |
| 1134 | else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 1135 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 1136 | errno = -EBUSY; |
| 1137 | else |
| 1138 | ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1139 | |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1140 | if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM)) |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1141 | dev_info(&pf->pdev->dev, |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1142 | "NVMUpdate read failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n", |
| 1143 | ret_val, hw->aq.asq_last_status, errno, |
| 1144 | (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK), |
| 1145 | cmd->offset, cmd->data_size); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1146 | |
| 1147 | return errno; |
| 1148 | } |
| 1149 | |
| 1150 | /* normal ethtool get_eeprom support */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1151 | eeprom->magic = hw->vendor_id | (hw->device_id << 16); |
| 1152 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1153 | eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1154 | if (!eeprom_buff) |
| 1155 | return -ENOMEM; |
| 1156 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1157 | ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ); |
| 1158 | if (ret_val) { |
| 1159 | dev_info(&pf->pdev->dev, |
| 1160 | "Failed Acquiring NVM resource for read err=%d status=0x%x\n", |
| 1161 | ret_val, hw->aq.asq_last_status); |
| 1162 | goto free_buff; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1165 | sectors = eeprom->len / I40E_NVM_SECTOR_SIZE; |
| 1166 | sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0; |
| 1167 | len = I40E_NVM_SECTOR_SIZE; |
| 1168 | last = false; |
| 1169 | for (i = 0; i < sectors; i++) { |
| 1170 | if (i == (sectors - 1)) { |
| 1171 | len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i); |
| 1172 | last = true; |
| 1173 | } |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1174 | offset = eeprom->offset + (I40E_NVM_SECTOR_SIZE * i), |
| 1175 | ret_val = i40e_aq_read_nvm(hw, 0x0, offset, len, |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1176 | (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i), |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1177 | last, NULL); |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1178 | 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] | 1179 | dev_info(&pf->pdev->dev, |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1180 | "read NVM failed, invalid offset 0x%x\n", |
| 1181 | offset); |
| 1182 | break; |
| 1183 | } else if (ret_val && |
| 1184 | hw->aq.asq_last_status == I40E_AQ_RC_EACCES) { |
| 1185 | dev_info(&pf->pdev->dev, |
| 1186 | "read NVM failed, access, offset 0x%x\n", |
| 1187 | offset); |
| 1188 | break; |
| 1189 | } else if (ret_val) { |
| 1190 | dev_info(&pf->pdev->dev, |
| 1191 | "read NVM failed offset %d err=%d status=0x%x\n", |
| 1192 | offset, ret_val, hw->aq.asq_last_status); |
| 1193 | break; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1194 | } |
| 1195 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1196 | |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1197 | i40e_release_nvm(hw); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1198 | memcpy(bytes, (u8 *)eeprom_buff, eeprom->len); |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1199 | free_buff: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1200 | kfree(eeprom_buff); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1201 | return ret_val; |
| 1202 | } |
| 1203 | |
| 1204 | static int i40e_get_eeprom_len(struct net_device *netdev) |
| 1205 | { |
| 1206 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1207 | struct i40e_hw *hw = &np->vsi->back->hw; |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1208 | u32 val; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1209 | |
Lihong Yang | c271dd6 | 2017-01-30 12:29:32 -0800 | [diff] [blame] | 1210 | #define X722_EEPROM_SCOPE_LIMIT 0x5B9FFF |
| 1211 | if (hw->mac.type == I40E_MAC_X722) { |
| 1212 | val = X722_EEPROM_SCOPE_LIMIT + 1; |
| 1213 | return val; |
| 1214 | } |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1215 | val = (rd32(hw, I40E_GLPCI_LBARCTRL) |
| 1216 | & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK) |
| 1217 | >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT; |
| 1218 | /* register returns value in power of 2, 64Kbyte chunks. */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1219 | val = (64 * 1024) * BIT(val); |
Anjali Singhai Jain | e5e0a5d | 2013-11-28 06:39:28 +0000 | [diff] [blame] | 1220 | return val; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1223 | static int i40e_set_eeprom(struct net_device *netdev, |
| 1224 | struct ethtool_eeprom *eeprom, u8 *bytes) |
| 1225 | { |
| 1226 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1227 | struct i40e_hw *hw = &np->vsi->back->hw; |
| 1228 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1229 | struct i40e_nvm_access *cmd = (struct i40e_nvm_access *)eeprom; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1230 | int ret_val = 0; |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1231 | int errno = 0; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1232 | u32 magic; |
| 1233 | |
| 1234 | /* normal ethtool set_eeprom is not supported */ |
| 1235 | magic = hw->vendor_id | (hw->device_id << 16); |
| 1236 | if (eeprom->magic == magic) |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1237 | errno = -EOPNOTSUPP; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1238 | /* check for NVMUpdate access method */ |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1239 | else if (!eeprom->magic || (eeprom->magic >> 16) != hw->device_id) |
| 1240 | errno = -EINVAL; |
| 1241 | else if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 1242 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 1243 | errno = -EBUSY; |
| 1244 | else |
| 1245 | ret_val = i40e_nvmupd_command(hw, cmd, bytes, &errno); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1246 | |
Shannon Nelson | 6e93d0c | 2016-01-15 14:33:18 -0800 | [diff] [blame] | 1247 | if ((errno || ret_val) && (hw->debug_mask & I40E_DEBUG_NVM)) |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1248 | dev_info(&pf->pdev->dev, |
Shannon Nelson | c150a50 | 2014-11-13 08:23:13 +0000 | [diff] [blame] | 1249 | "NVMUpdate write failed err=%d status=0x%x errno=%d module=%d offset=0x%x size=%d\n", |
| 1250 | ret_val, hw->aq.asq_last_status, errno, |
| 1251 | (u8)(cmd->config & I40E_NVM_MOD_PNT_MASK), |
| 1252 | cmd->offset, cmd->data_size); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 1253 | |
| 1254 | return errno; |
| 1255 | } |
| 1256 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1257 | static void i40e_get_drvinfo(struct net_device *netdev, |
| 1258 | struct ethtool_drvinfo *drvinfo) |
| 1259 | { |
| 1260 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1261 | struct i40e_vsi *vsi = np->vsi; |
| 1262 | struct i40e_pf *pf = vsi->back; |
| 1263 | |
| 1264 | strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver)); |
| 1265 | strlcpy(drvinfo->version, i40e_driver_version_str, |
| 1266 | sizeof(drvinfo->version)); |
Shannon Nelson | 6dec101 | 2015-09-28 14:12:30 -0400 | [diff] [blame] | 1267 | strlcpy(drvinfo->fw_version, i40e_nvm_version_str(&pf->hw), |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1268 | sizeof(drvinfo->fw_version)); |
| 1269 | strlcpy(drvinfo->bus_info, pci_name(pf->pdev), |
| 1270 | sizeof(drvinfo->bus_info)); |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 1271 | drvinfo->n_priv_flags = I40E_PRIV_FLAGS_STR_LEN; |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 1272 | if (pf->hw.pf_id == 0) |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 1273 | drvinfo->n_priv_flags += I40E_GL_PRIV_FLAGS_STR_LEN; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | static void i40e_get_ringparam(struct net_device *netdev, |
| 1277 | struct ethtool_ringparam *ring) |
| 1278 | { |
| 1279 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1280 | struct i40e_pf *pf = np->vsi->back; |
| 1281 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; |
| 1282 | |
| 1283 | ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS; |
| 1284 | ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS; |
| 1285 | ring->rx_mini_max_pending = 0; |
| 1286 | ring->rx_jumbo_max_pending = 0; |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1287 | ring->rx_pending = vsi->rx_rings[0]->count; |
| 1288 | ring->tx_pending = vsi->tx_rings[0]->count; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1289 | ring->rx_mini_pending = 0; |
| 1290 | ring->rx_jumbo_pending = 0; |
| 1291 | } |
| 1292 | |
| 1293 | static int i40e_set_ringparam(struct net_device *netdev, |
| 1294 | struct ethtool_ringparam *ring) |
| 1295 | { |
| 1296 | struct i40e_ring *tx_rings = NULL, *rx_rings = NULL; |
| 1297 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Tushar Dave | 2f7679e | 2016-10-26 10:49:27 -0700 | [diff] [blame] | 1298 | struct i40e_hw *hw = &np->vsi->back->hw; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1299 | struct i40e_vsi *vsi = np->vsi; |
| 1300 | struct i40e_pf *pf = vsi->back; |
| 1301 | u32 new_rx_count, new_tx_count; |
| 1302 | int i, err = 0; |
| 1303 | |
| 1304 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) |
| 1305 | return -EINVAL; |
| 1306 | |
Shannon Nelson | 1fa1837 | 2013-11-20 10:03:08 +0000 | [diff] [blame] | 1307 | if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS || |
| 1308 | ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS || |
| 1309 | ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS || |
| 1310 | ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) { |
| 1311 | netdev_info(netdev, |
| 1312 | "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n", |
| 1313 | ring->tx_pending, ring->rx_pending, |
| 1314 | I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS); |
| 1315 | return -EINVAL; |
| 1316 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1317 | |
Shannon Nelson | 1fa1837 | 2013-11-20 10:03:08 +0000 | [diff] [blame] | 1318 | new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); |
| 1319 | new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1320 | |
| 1321 | /* if nothing to do return success */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1322 | if ((new_tx_count == vsi->tx_rings[0]->count) && |
| 1323 | (new_rx_count == vsi->rx_rings[0]->count)) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1324 | return 0; |
| 1325 | |
| 1326 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) |
| 1327 | usleep_range(1000, 2000); |
| 1328 | |
| 1329 | if (!netif_running(vsi->netdev)) { |
| 1330 | /* simple case - set for the next time the netdev is started */ |
| 1331 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1332 | vsi->tx_rings[i]->count = new_tx_count; |
| 1333 | vsi->rx_rings[i]->count = new_rx_count; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1334 | } |
| 1335 | goto done; |
| 1336 | } |
| 1337 | |
| 1338 | /* We can't just free everything and then setup again, |
| 1339 | * because the ISRs in MSI-X mode get passed pointers |
| 1340 | * to the Tx and Rx ring structs. |
| 1341 | */ |
| 1342 | |
| 1343 | /* alloc updated Tx resources */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1344 | if (new_tx_count != vsi->tx_rings[0]->count) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1345 | netdev_info(netdev, |
| 1346 | "Changing Tx descriptor count from %d to %d.\n", |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1347 | vsi->tx_rings[0]->count, new_tx_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1348 | tx_rings = kcalloc(vsi->alloc_queue_pairs, |
| 1349 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 1350 | if (!tx_rings) { |
| 1351 | err = -ENOMEM; |
| 1352 | goto done; |
| 1353 | } |
| 1354 | |
| 1355 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
| 1356 | /* clone ring and setup updated count */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1357 | tx_rings[i] = *vsi->tx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1358 | tx_rings[i].count = new_tx_count; |
Jesse Brandeburg | 1e8efb4 | 2015-08-27 11:42:33 -0400 | [diff] [blame] | 1359 | /* the desc and bi pointers will be reallocated in the |
| 1360 | * setup call |
| 1361 | */ |
| 1362 | tx_rings[i].desc = NULL; |
| 1363 | tx_rings[i].rx_bi = NULL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1364 | err = i40e_setup_tx_descriptors(&tx_rings[i]); |
| 1365 | if (err) { |
| 1366 | while (i) { |
| 1367 | i--; |
| 1368 | i40e_free_tx_resources(&tx_rings[i]); |
| 1369 | } |
| 1370 | kfree(tx_rings); |
| 1371 | tx_rings = NULL; |
| 1372 | |
| 1373 | goto done; |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | |
| 1378 | /* alloc updated Rx resources */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1379 | if (new_rx_count != vsi->rx_rings[0]->count) { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1380 | netdev_info(netdev, |
| 1381 | "Changing Rx descriptor count from %d to %d\n", |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1382 | vsi->rx_rings[0]->count, new_rx_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1383 | rx_rings = kcalloc(vsi->alloc_queue_pairs, |
| 1384 | sizeof(struct i40e_ring), GFP_KERNEL); |
| 1385 | if (!rx_rings) { |
| 1386 | err = -ENOMEM; |
| 1387 | goto free_tx; |
| 1388 | } |
| 1389 | |
| 1390 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1391 | struct i40e_ring *ring; |
| 1392 | u16 unused; |
| 1393 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1394 | /* clone ring and setup updated count */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1395 | rx_rings[i] = *vsi->rx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1396 | rx_rings[i].count = new_rx_count; |
Jesse Brandeburg | 1e8efb4 | 2015-08-27 11:42:33 -0400 | [diff] [blame] | 1397 | /* the desc and bi pointers will be reallocated in the |
| 1398 | * setup call |
| 1399 | */ |
| 1400 | rx_rings[i].desc = NULL; |
| 1401 | rx_rings[i].rx_bi = NULL; |
Tushar Dave | 2f7679e | 2016-10-26 10:49:27 -0700 | [diff] [blame] | 1402 | /* this is to allow wr32 to have something to write to |
| 1403 | * during early allocation of Rx buffers |
| 1404 | */ |
| 1405 | rx_rings[i].tail = hw->hw_addr + I40E_PRTGEN_STATUS; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1406 | err = i40e_setup_rx_descriptors(&rx_rings[i]); |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1407 | if (err) |
| 1408 | goto rx_unwind; |
| 1409 | |
| 1410 | /* now allocate the Rx buffers to make sure the OS |
| 1411 | * has enough memory, any failure here means abort |
| 1412 | */ |
| 1413 | ring = &rx_rings[i]; |
| 1414 | unused = I40E_DESC_UNUSED(ring); |
| 1415 | err = i40e_alloc_rx_buffers(ring, unused); |
| 1416 | rx_unwind: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1417 | if (err) { |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1418 | do { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1419 | i40e_free_rx_resources(&rx_rings[i]); |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1420 | } while (i--); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1421 | kfree(rx_rings); |
| 1422 | rx_rings = NULL; |
| 1423 | |
| 1424 | goto free_tx; |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | /* Bring interface down, copy in the new ring info, |
| 1430 | * then restore the interface |
| 1431 | */ |
| 1432 | i40e_down(vsi); |
| 1433 | |
| 1434 | if (tx_rings) { |
| 1435 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1436 | i40e_free_tx_resources(vsi->tx_rings[i]); |
| 1437 | *vsi->tx_rings[i] = tx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1438 | } |
| 1439 | kfree(tx_rings); |
| 1440 | tx_rings = NULL; |
| 1441 | } |
| 1442 | |
| 1443 | if (rx_rings) { |
| 1444 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1445 | i40e_free_rx_resources(vsi->rx_rings[i]); |
Jesse Brandeburg | 147e81e | 2016-04-18 11:33:49 -0700 | [diff] [blame] | 1446 | /* get the real tail offset */ |
| 1447 | rx_rings[i].tail = vsi->rx_rings[i]->tail; |
| 1448 | /* this is to fake out the allocation routine |
| 1449 | * into thinking it has to realloc everything |
| 1450 | * but the recycling logic will let us re-use |
| 1451 | * the buffers allocated above |
| 1452 | */ |
| 1453 | rx_rings[i].next_to_use = 0; |
| 1454 | rx_rings[i].next_to_clean = 0; |
| 1455 | rx_rings[i].next_to_alloc = 0; |
| 1456 | /* do a struct copy */ |
Alexander Duyck | 9f65e15 | 2013-09-28 06:00:58 +0000 | [diff] [blame] | 1457 | *vsi->rx_rings[i] = rx_rings[i]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1458 | } |
| 1459 | kfree(rx_rings); |
| 1460 | rx_rings = NULL; |
| 1461 | } |
| 1462 | |
| 1463 | i40e_up(vsi); |
| 1464 | |
| 1465 | free_tx: |
| 1466 | /* error cleanup if the Rx allocations failed after getting Tx */ |
| 1467 | if (tx_rings) { |
| 1468 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 1469 | i40e_free_tx_resources(&tx_rings[i]); |
| 1470 | kfree(tx_rings); |
| 1471 | tx_rings = NULL; |
| 1472 | } |
| 1473 | |
| 1474 | done: |
| 1475 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); |
| 1476 | |
| 1477 | return err; |
| 1478 | } |
| 1479 | |
| 1480 | static int i40e_get_sset_count(struct net_device *netdev, int sset) |
| 1481 | { |
| 1482 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1483 | struct i40e_vsi *vsi = np->vsi; |
| 1484 | struct i40e_pf *pf = vsi->back; |
| 1485 | |
| 1486 | switch (sset) { |
| 1487 | case ETH_SS_TEST: |
| 1488 | return I40E_TEST_LEN; |
| 1489 | case ETH_SS_STATS: |
Shannon Nelson | 58ce517 | 2015-02-27 09:15:26 +0000 | [diff] [blame] | 1490 | if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1) { |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1491 | int len = I40E_PF_STATS_LEN(netdev); |
| 1492 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 1493 | if ((pf->lan_veb != I40E_NO_VEB) && |
| 1494 | (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1495 | len += I40E_VEB_STATS_TOTAL; |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1496 | return len; |
| 1497 | } else { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1498 | return I40E_VSI_STATS_LEN(netdev); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1499 | } |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 1500 | case ETH_SS_PRIV_FLAGS: |
Jacob Keller | d182a5c | 2016-10-25 16:08:50 -0700 | [diff] [blame] | 1501 | return I40E_PRIV_FLAGS_STR_LEN + |
| 1502 | (pf->hw.pf_id == 0 ? I40E_GL_PRIV_FLAGS_STR_LEN : 0); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1503 | default: |
| 1504 | return -EOPNOTSUPP; |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | static void i40e_get_ethtool_stats(struct net_device *netdev, |
| 1509 | struct ethtool_stats *stats, u64 *data) |
| 1510 | { |
| 1511 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 1512 | struct i40e_ring *tx_ring, *rx_ring; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1513 | struct i40e_vsi *vsi = np->vsi; |
| 1514 | struct i40e_pf *pf = vsi->back; |
| 1515 | int i = 0; |
| 1516 | char *p; |
| 1517 | int j; |
| 1518 | struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1519 | unsigned int start; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1520 | |
| 1521 | i40e_update_stats(vsi); |
| 1522 | |
| 1523 | for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) { |
| 1524 | p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset; |
| 1525 | data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat == |
| 1526 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1527 | } |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 1528 | for (j = 0; j < I40E_MISC_STATS_LEN; j++) { |
| 1529 | p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset; |
| 1530 | data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat == |
| 1531 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1532 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1533 | #ifdef I40E_FCOE |
| 1534 | for (j = 0; j < I40E_FCOE_STATS_LEN; j++) { |
| 1535 | p = (char *)vsi + i40e_gstrings_fcoe_stats[j].stat_offset; |
| 1536 | data[i++] = (i40e_gstrings_fcoe_stats[j].sizeof_stat == |
| 1537 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1538 | } |
| 1539 | #endif |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1540 | rcu_read_lock(); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1541 | for (j = 0; j < vsi->num_queue_pairs; j++) { |
Akeem G Abodunrin | e7046ee | 2014-04-09 05:58:58 +0000 | [diff] [blame] | 1542 | tx_ring = ACCESS_ONCE(vsi->tx_rings[j]); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1543 | |
| 1544 | if (!tx_ring) |
| 1545 | continue; |
| 1546 | |
| 1547 | /* process Tx ring statistics */ |
| 1548 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1549 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1550 | data[i] = tx_ring->stats.packets; |
| 1551 | data[i + 1] = tx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1552 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1553 | i += 2; |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1554 | |
| 1555 | /* Rx ring is the 2nd half of the queue pair */ |
| 1556 | rx_ring = &tx_ring[1]; |
| 1557 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1558 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1559 | data[i] = rx_ring->stats.packets; |
| 1560 | data[i + 1] = rx_ring->stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 1561 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
Catherine Sullivan | 99c472a | 2014-03-14 07:32:30 +0000 | [diff] [blame] | 1562 | i += 2; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1563 | } |
Alexander Duyck | 980e9b1 | 2013-09-28 06:01:03 +0000 | [diff] [blame] | 1564 | rcu_read_unlock(); |
Shannon Nelson | 58ce517 | 2015-02-27 09:15:26 +0000 | [diff] [blame] | 1565 | if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1566 | return; |
| 1567 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 1568 | if ((pf->lan_veb != I40E_NO_VEB) && |
| 1569 | (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1570 | struct i40e_veb *veb = pf->veb[pf->lan_veb]; |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1571 | |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1572 | for (j = 0; j < I40E_VEB_STATS_LEN; j++) { |
| 1573 | p = (char *)veb; |
| 1574 | p += i40e_gstrings_veb_stats[j].stat_offset; |
| 1575 | data[i++] = (i40e_gstrings_veb_stats[j].sizeof_stat == |
| 1576 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1577 | } |
Jesse Brandeburg | 74a6c66 | 2015-10-02 19:09:34 -0700 | [diff] [blame] | 1578 | for (j = 0; j < I40E_MAX_TRAFFIC_CLASS; j++) { |
| 1579 | data[i++] = veb->tc_stats.tc_tx_packets[j]; |
| 1580 | data[i++] = veb->tc_stats.tc_tx_bytes[j]; |
| 1581 | data[i++] = veb->tc_stats.tc_rx_packets[j]; |
| 1582 | data[i++] = veb->tc_stats.tc_rx_bytes[j]; |
| 1583 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1584 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1585 | for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) { |
| 1586 | p = (char *)pf + i40e_gstrings_stats[j].stat_offset; |
| 1587 | data[i++] = (i40e_gstrings_stats[j].sizeof_stat == |
| 1588 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; |
| 1589 | } |
| 1590 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { |
| 1591 | data[i++] = pf->stats.priority_xon_tx[j]; |
| 1592 | data[i++] = pf->stats.priority_xoff_tx[j]; |
| 1593 | } |
| 1594 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { |
| 1595 | data[i++] = pf->stats.priority_xon_rx[j]; |
| 1596 | data[i++] = pf->stats.priority_xoff_rx[j]; |
| 1597 | } |
| 1598 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) |
| 1599 | data[i++] = pf->stats.priority_xon_2_xoff[j]; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | static void i40e_get_strings(struct net_device *netdev, u32 stringset, |
| 1603 | u8 *data) |
| 1604 | { |
| 1605 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1606 | struct i40e_vsi *vsi = np->vsi; |
| 1607 | struct i40e_pf *pf = vsi->back; |
| 1608 | char *p = (char *)data; |
| 1609 | int i; |
| 1610 | |
| 1611 | switch (stringset) { |
| 1612 | case ETH_SS_TEST: |
Jacob Keller | e5d3220 | 2016-11-08 13:05:11 -0800 | [diff] [blame] | 1613 | memcpy(data, i40e_gstrings_test, |
| 1614 | I40E_TEST_LEN * ETH_GSTRING_LEN); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1615 | break; |
| 1616 | case ETH_SS_STATS: |
| 1617 | for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) { |
| 1618 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 1619 | i40e_gstrings_net_stats[i].stat_string); |
| 1620 | p += ETH_GSTRING_LEN; |
| 1621 | } |
Shannon Nelson | 41a9e55 | 2014-04-23 04:50:20 +0000 | [diff] [blame] | 1622 | for (i = 0; i < I40E_MISC_STATS_LEN; i++) { |
| 1623 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 1624 | i40e_gstrings_misc_stats[i].stat_string); |
| 1625 | p += ETH_GSTRING_LEN; |
| 1626 | } |
Vasu Dev | 38e0043 | 2014-08-01 13:27:03 -0700 | [diff] [blame] | 1627 | #ifdef I40E_FCOE |
| 1628 | for (i = 0; i < I40E_FCOE_STATS_LEN; i++) { |
| 1629 | snprintf(p, ETH_GSTRING_LEN, "%s", |
| 1630 | i40e_gstrings_fcoe_stats[i].stat_string); |
| 1631 | p += ETH_GSTRING_LEN; |
| 1632 | } |
| 1633 | #endif |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1634 | for (i = 0; i < vsi->num_queue_pairs; i++) { |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1635 | snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_packets", i); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1636 | p += ETH_GSTRING_LEN; |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1637 | snprintf(p, ETH_GSTRING_LEN, "tx-%d.tx_bytes", i); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1638 | p += ETH_GSTRING_LEN; |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1639 | snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_packets", i); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1640 | p += ETH_GSTRING_LEN; |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1641 | snprintf(p, ETH_GSTRING_LEN, "rx-%d.rx_bytes", i); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1642 | p += ETH_GSTRING_LEN; |
| 1643 | } |
Shannon Nelson | 58ce517 | 2015-02-27 09:15:26 +0000 | [diff] [blame] | 1644 | if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1) |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1645 | return; |
| 1646 | |
Anjali Singhai Jain | d1a8d27 | 2015-07-23 16:54:40 -0400 | [diff] [blame] | 1647 | if ((pf->lan_veb != I40E_NO_VEB) && |
| 1648 | (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1649 | for (i = 0; i < I40E_VEB_STATS_LEN; i++) { |
| 1650 | snprintf(p, ETH_GSTRING_LEN, "veb.%s", |
| 1651 | i40e_gstrings_veb_stats[i].stat_string); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1652 | p += ETH_GSTRING_LEN; |
| 1653 | } |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1654 | for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) { |
| 1655 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1656 | "veb.tc_%d_tx_packets", i); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1657 | p += ETH_GSTRING_LEN; |
| 1658 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1659 | "veb.tc_%d_tx_bytes", i); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1660 | p += ETH_GSTRING_LEN; |
| 1661 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1662 | "veb.tc_%d_rx_packets", i); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1663 | p += ETH_GSTRING_LEN; |
| 1664 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1665 | "veb.tc_%d_rx_bytes", i); |
Neerav Parikh | fe860af | 2015-07-10 19:36:02 -0400 | [diff] [blame] | 1666 | p += ETH_GSTRING_LEN; |
| 1667 | } |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1668 | } |
| 1669 | for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) { |
| 1670 | snprintf(p, ETH_GSTRING_LEN, "port.%s", |
| 1671 | i40e_gstrings_stats[i].stat_string); |
| 1672 | p += ETH_GSTRING_LEN; |
| 1673 | } |
| 1674 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 1675 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1676 | "port.tx_priority_%d_xon", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1677 | p += ETH_GSTRING_LEN; |
| 1678 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1679 | "port.tx_priority_%d_xoff", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1680 | p += ETH_GSTRING_LEN; |
| 1681 | } |
| 1682 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 1683 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1684 | "port.rx_priority_%d_xon", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1685 | p += ETH_GSTRING_LEN; |
| 1686 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1687 | "port.rx_priority_%d_xoff", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1688 | p += ETH_GSTRING_LEN; |
| 1689 | } |
| 1690 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { |
| 1691 | snprintf(p, ETH_GSTRING_LEN, |
Heinrich Schuchardt | fbcfac3 | 2016-08-11 01:07:22 +0200 | [diff] [blame] | 1692 | "port.rx_priority_%d_xon_2_xoff", i); |
Shannon Nelson | 8eab9cf | 2014-04-23 04:49:55 +0000 | [diff] [blame] | 1693 | p += ETH_GSTRING_LEN; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1694 | } |
| 1695 | /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */ |
| 1696 | break; |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 1697 | case ETH_SS_PRIV_FLAGS: |
Jacob Keller | e5d3220 | 2016-11-08 13:05:11 -0800 | [diff] [blame] | 1698 | memcpy(data, i40e_priv_flags_strings, |
| 1699 | I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN); |
| 1700 | data += I40E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN; |
| 1701 | if (pf->hw.pf_id == 0) |
| 1702 | memcpy(data, i40e_gl_priv_flags_strings, |
| 1703 | I40E_GL_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN); |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 1704 | break; |
Akeem G Abodunrin | 579b23d | 2015-02-24 06:58:42 +0000 | [diff] [blame] | 1705 | default: |
| 1706 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | static int i40e_get_ts_info(struct net_device *dev, |
| 1711 | struct ethtool_ts_info *info) |
| 1712 | { |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1713 | struct i40e_pf *pf = i40e_netdev_to_pf(dev); |
| 1714 | |
Jacob Keller | fe88bda | 2014-11-11 20:05:58 +0000 | [diff] [blame] | 1715 | /* only report HW timestamping if PTP is enabled */ |
| 1716 | if (!(pf->flags & I40E_FLAG_PTP)) |
| 1717 | return ethtool_op_get_ts_info(dev, info); |
| 1718 | |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1719 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | |
| 1720 | SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1721 | SOF_TIMESTAMPING_SOFTWARE | |
| 1722 | SOF_TIMESTAMPING_TX_HARDWARE | |
| 1723 | SOF_TIMESTAMPING_RX_HARDWARE | |
| 1724 | SOF_TIMESTAMPING_RAW_HARDWARE; |
| 1725 | |
| 1726 | if (pf->ptp_clock) |
| 1727 | info->phc_index = ptp_clock_index(pf->ptp_clock); |
| 1728 | else |
| 1729 | info->phc_index = -1; |
| 1730 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1731 | info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1732 | |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1733 | info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | |
Jacob Keller | 1e28e86 | 2016-11-11 12:39:25 -0800 | [diff] [blame] | 1734 | BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | |
| 1735 | BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) | |
| 1736 | BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ); |
| 1737 | |
| 1738 | if (pf->flags & I40E_FLAG_PTP_L4_CAPABLE) |
| 1739 | info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | |
| 1740 | BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | |
| 1741 | BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) | |
| 1742 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | |
| 1743 | BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) | |
| 1744 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | |
| 1745 | BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | |
| 1746 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ); |
Jacob Keller | beb0dff | 2014-01-11 05:43:19 +0000 | [diff] [blame] | 1747 | |
| 1748 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1749 | } |
| 1750 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1751 | static int i40e_link_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1752 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1753 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1754 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 1755 | i40e_status status; |
| 1756 | bool link_up = false; |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1757 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1758 | netif_info(pf, hw, netdev, "link test\n"); |
Jesse Brandeburg | a72a5abc | 2015-08-26 15:14:19 -0400 | [diff] [blame] | 1759 | status = i40e_get_link_status(&pf->hw, &link_up); |
| 1760 | if (status) { |
| 1761 | netif_err(pf, drv, netdev, "link query timed out, please retry test\n"); |
| 1762 | *data = 1; |
| 1763 | return *data; |
| 1764 | } |
| 1765 | |
| 1766 | if (link_up) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1767 | *data = 0; |
| 1768 | else |
| 1769 | *data = 1; |
| 1770 | |
| 1771 | return *data; |
| 1772 | } |
| 1773 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1774 | static int i40e_reg_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1775 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1776 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1777 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1778 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1779 | netif_info(pf, hw, netdev, "register test\n"); |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1780 | *data = i40e_diag_reg_test(&pf->hw); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1781 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1782 | return *data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1785 | static int i40e_eeprom_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1786 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1787 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1788 | struct i40e_pf *pf = np->vsi->back; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1789 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1790 | netif_info(pf, hw, netdev, "eeprom test\n"); |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1791 | *data = i40e_diag_eeprom_test(&pf->hw); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1792 | |
Shannon Nelson | 4443ec9 | 2014-11-13 08:23:12 +0000 | [diff] [blame] | 1793 | /* forcebly clear the NVM Update state machine */ |
| 1794 | pf->hw.nvmupd_state = I40E_NVMUPD_STATE_INIT; |
| 1795 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1796 | return *data; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1797 | } |
| 1798 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1799 | static int i40e_intr_test(struct net_device *netdev, u64 *data) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1800 | { |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1801 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1802 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1803 | u16 swc_old = pf->sw_int_count; |
| 1804 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1805 | netif_info(pf, hw, netdev, "interrupt test\n"); |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1806 | wr32(&pf->hw, I40E_PFINT_DYN_CTL0, |
| 1807 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | |
Shannon Nelson | 5d1ff106 | 2014-11-11 20:04:35 +0000 | [diff] [blame] | 1808 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK | |
| 1809 | I40E_PFINT_DYN_CTL0_ITR_INDX_MASK | |
| 1810 | I40E_PFINT_DYN_CTL0_SW_ITR_INDX_ENA_MASK | |
| 1811 | I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK)); |
Shannon Nelson | cd92e72 | 2013-11-16 10:00:44 +0000 | [diff] [blame] | 1812 | usleep_range(1000, 2000); |
| 1813 | *data = (swc_old == pf->sw_int_count); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1814 | |
| 1815 | return *data; |
| 1816 | } |
| 1817 | |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1818 | static inline bool i40e_active_vfs(struct i40e_pf *pf) |
| 1819 | { |
| 1820 | struct i40e_vf *vfs = pf->vf; |
| 1821 | int i; |
| 1822 | |
| 1823 | for (i = 0; i < pf->num_alloc_vfs; i++) |
Jesse Brandeburg | 6995b36 | 2015-08-28 17:55:54 -0400 | [diff] [blame] | 1824 | if (test_bit(I40E_VF_STAT_ACTIVE, &vfs[i].vf_states)) |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1825 | return true; |
| 1826 | return false; |
| 1827 | } |
| 1828 | |
Greg Rose | 510efb2 | 2015-07-10 19:36:01 -0400 | [diff] [blame] | 1829 | static inline bool i40e_active_vmdqs(struct i40e_pf *pf) |
| 1830 | { |
Alexander Duyck | 4b81644 | 2016-10-11 15:26:53 -0700 | [diff] [blame] | 1831 | return !!i40e_find_vsi_by_type(pf, I40E_VSI_VMDQ2); |
Greg Rose | 510efb2 | 2015-07-10 19:36:01 -0400 | [diff] [blame] | 1832 | } |
| 1833 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1834 | static void i40e_diag_test(struct net_device *netdev, |
| 1835 | struct ethtool_test *eth_test, u64 *data) |
| 1836 | { |
| 1837 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Greg Rose | 5b86c5c | 2015-02-26 16:14:35 +0000 | [diff] [blame] | 1838 | bool if_running = netif_running(netdev); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1839 | struct i40e_pf *pf = np->vsi->back; |
| 1840 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1841 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
| 1842 | /* Offline tests */ |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1843 | netif_info(pf, drv, netdev, "offline testing starting\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1844 | |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1845 | set_bit(__I40E_TESTING, &pf->state); |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1846 | |
Greg Rose | 510efb2 | 2015-07-10 19:36:01 -0400 | [diff] [blame] | 1847 | if (i40e_active_vfs(pf) || i40e_active_vmdqs(pf)) { |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1848 | dev_warn(&pf->pdev->dev, |
Greg Rose | 510efb2 | 2015-07-10 19:36:01 -0400 | [diff] [blame] | 1849 | "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] | 1850 | data[I40E_ETH_TEST_REG] = 1; |
| 1851 | data[I40E_ETH_TEST_EEPROM] = 1; |
| 1852 | data[I40E_ETH_TEST_INTR] = 1; |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1853 | data[I40E_ETH_TEST_LINK] = 1; |
| 1854 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1855 | clear_bit(__I40E_TESTING, &pf->state); |
| 1856 | goto skip_ol_tests; |
| 1857 | } |
| 1858 | |
Greg Rose | 5b86c5c | 2015-02-26 16:14:35 +0000 | [diff] [blame] | 1859 | /* If the device is online then take it offline */ |
| 1860 | if (if_running) |
| 1861 | /* indicate we're in test mode */ |
Stefan Assmann | 08ca387 | 2016-02-03 09:20:47 +0100 | [diff] [blame] | 1862 | i40e_close(netdev); |
Greg Rose | 5b86c5c | 2015-02-26 16:14:35 +0000 | [diff] [blame] | 1863 | else |
Greg Rose | b4e53f0 | 2015-07-10 19:36:03 -0400 | [diff] [blame] | 1864 | /* This reset does not affect link - if it is |
| 1865 | * changed to a type of reset that does affect |
| 1866 | * link then the following link test would have |
| 1867 | * to be moved to before the reset |
| 1868 | */ |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1869 | i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED)); |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1870 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1871 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1872 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1873 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1874 | if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1875 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1876 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1877 | if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1878 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1879 | |
Shannon Nelson | f551b43 | 2013-11-26 10:49:12 +0000 | [diff] [blame] | 1880 | /* run reg test last, a reset is required after it */ |
| 1881 | if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG])) |
| 1882 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1883 | |
| 1884 | clear_bit(__I40E_TESTING, &pf->state); |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 1885 | i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED)); |
Greg Rose | 5b86c5c | 2015-02-26 16:14:35 +0000 | [diff] [blame] | 1886 | |
| 1887 | if (if_running) |
Stefan Assmann | 08ca387 | 2016-02-03 09:20:47 +0100 | [diff] [blame] | 1888 | i40e_open(netdev); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1889 | } else { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1890 | /* Online tests */ |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1891 | netif_info(pf, drv, netdev, "online testing starting\n"); |
| 1892 | |
Shannon Nelson | 7b08639 | 2013-11-20 10:02:59 +0000 | [diff] [blame] | 1893 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1894 | eth_test->flags |= ETH_TEST_FL_FAILED; |
| 1895 | |
| 1896 | /* Offline only tests, not run in online; pass by default */ |
| 1897 | data[I40E_ETH_TEST_REG] = 0; |
| 1898 | data[I40E_ETH_TEST_EEPROM] = 0; |
| 1899 | data[I40E_ETH_TEST_INTR] = 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1900 | } |
Shannon Nelson | c140c17 | 2013-11-20 10:02:58 +0000 | [diff] [blame] | 1901 | |
Greg Rose | e17bc41 | 2015-04-16 20:05:59 -0400 | [diff] [blame] | 1902 | skip_ol_tests: |
| 1903 | |
Shannon Nelson | b03aaa9 | 2013-11-20 10:03:06 +0000 | [diff] [blame] | 1904 | netif_info(pf, drv, netdev, "testing finished\n"); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | static void i40e_get_wol(struct net_device *netdev, |
| 1908 | struct ethtool_wolinfo *wol) |
| 1909 | { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1910 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1911 | struct i40e_pf *pf = np->vsi->back; |
| 1912 | struct i40e_hw *hw = &pf->hw; |
| 1913 | u16 wol_nvm_bits; |
| 1914 | |
| 1915 | /* NVM bit on means WoL disabled for the port */ |
| 1916 | 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] | 1917 | if ((BIT(hw->port) & wol_nvm_bits) || (hw->partition_id != 1)) { |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1918 | wol->supported = 0; |
| 1919 | wol->wolopts = 0; |
| 1920 | } else { |
| 1921 | wol->supported = WAKE_MAGIC; |
| 1922 | wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0); |
| 1923 | } |
| 1924 | } |
| 1925 | |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 1926 | /** |
| 1927 | * i40e_set_wol - set the WakeOnLAN configuration |
| 1928 | * @netdev: the netdev in question |
| 1929 | * @wol: the ethtool WoL setting data |
| 1930 | **/ |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1931 | static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 1932 | { |
| 1933 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 1934 | struct i40e_pf *pf = np->vsi->back; |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 1935 | struct i40e_vsi *vsi = np->vsi; |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1936 | struct i40e_hw *hw = &pf->hw; |
| 1937 | u16 wol_nvm_bits; |
| 1938 | |
Shannon Nelson | f0d8c73 | 2014-12-11 07:06:32 +0000 | [diff] [blame] | 1939 | /* WoL not supported if this isn't the controlling PF on the port */ |
| 1940 | if (hw->partition_id != 1) { |
| 1941 | i40e_partition_setting_complaint(pf); |
| 1942 | return -EOPNOTSUPP; |
| 1943 | } |
| 1944 | |
| 1945 | if (vsi != pf->vsi[pf->lan_vsi]) |
| 1946 | return -EOPNOTSUPP; |
| 1947 | |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1948 | /* NVM bit on means WoL disabled for the port */ |
| 1949 | 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] | 1950 | if (BIT(hw->port) & wol_nvm_bits) |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 1951 | return -EOPNOTSUPP; |
| 1952 | |
| 1953 | /* only magic packet is supported */ |
| 1954 | if (wol->wolopts && (wol->wolopts != WAKE_MAGIC)) |
| 1955 | return -EOPNOTSUPP; |
| 1956 | |
| 1957 | /* is this a new value? */ |
| 1958 | if (pf->wol_en != !!wol->wolopts) { |
| 1959 | pf->wol_en = !!wol->wolopts; |
| 1960 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); |
| 1961 | } |
| 1962 | |
| 1963 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1966 | static int i40e_set_phys_id(struct net_device *netdev, |
| 1967 | enum ethtool_phys_id_state state) |
| 1968 | { |
| 1969 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1970 | i40e_status ret = 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1971 | struct i40e_pf *pf = np->vsi->back; |
| 1972 | struct i40e_hw *hw = &pf->hw; |
| 1973 | int blink_freq = 2; |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1974 | u16 temp_status; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1975 | |
| 1976 | switch (state) { |
| 1977 | case ETHTOOL_ID_ACTIVE: |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 1978 | if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) { |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1979 | pf->led_status = i40e_led_get(hw); |
| 1980 | } else { |
Kevin Scott | 06c0e39 | 2016-05-03 15:13:09 -0700 | [diff] [blame] | 1981 | i40e_aq_set_phy_debug(hw, I40E_PHY_DEBUG_ALL, NULL); |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1982 | ret = i40e_led_get_phy(hw, &temp_status, |
| 1983 | &pf->phy_led_val); |
| 1984 | pf->led_status = temp_status; |
| 1985 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1986 | return blink_freq; |
| 1987 | case ETHTOOL_ID_ON: |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 1988 | if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1989 | i40e_led_set(hw, 0xf, false); |
| 1990 | else |
| 1991 | ret = i40e_led_set_phy(hw, true, pf->led_status, 0); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1992 | break; |
| 1993 | case ETHTOOL_ID_OFF: |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 1994 | if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 1995 | i40e_led_set(hw, 0x0, false); |
| 1996 | else |
| 1997 | ret = i40e_led_set_phy(hw, false, pf->led_status, 0); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 1998 | break; |
| 1999 | case ETHTOOL_ID_INACTIVE: |
Henry Tieman | 4f9b430 | 2016-11-08 13:05:18 -0800 | [diff] [blame] | 2000 | if (!(pf->flags & I40E_FLAG_PHY_CONTROLS_LEDS)) { |
| 2001 | i40e_led_set(hw, pf->led_status, false); |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 2002 | } else { |
| 2003 | ret = i40e_led_set_phy(hw, false, pf->led_status, |
| 2004 | (pf->phy_led_val | |
| 2005 | I40E_PHY_LED_MODE_ORIG)); |
| 2006 | i40e_aq_set_phy_debug(hw, 0, NULL); |
| 2007 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2008 | break; |
Akeem G Abodunrin | 579b23d | 2015-02-24 06:58:42 +0000 | [diff] [blame] | 2009 | default: |
| 2010 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2011 | } |
Carolyn Wyborny | 31b606d | 2016-02-17 16:12:12 -0800 | [diff] [blame] | 2012 | if (ret) |
| 2013 | return -ENOENT; |
| 2014 | else |
| 2015 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt |
| 2019 | * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also |
| 2020 | * 125us (8000 interrupts per second) == ITR(62) |
| 2021 | */ |
| 2022 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2023 | /** |
| 2024 | * __i40e_get_coalesce - get per-queue coalesce settings |
| 2025 | * @netdev: the netdev to check |
| 2026 | * @ec: ethtool coalesce data structure |
| 2027 | * @queue: which queue to pick |
| 2028 | * |
| 2029 | * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs |
| 2030 | * are per queue. If queue is <0 then we default to queue 0 as the |
| 2031 | * representative value. |
| 2032 | **/ |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2033 | static int __i40e_get_coalesce(struct net_device *netdev, |
| 2034 | struct ethtool_coalesce *ec, |
| 2035 | int queue) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2036 | { |
| 2037 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2038 | struct i40e_ring *rx_ring, *tx_ring; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2039 | struct i40e_vsi *vsi = np->vsi; |
| 2040 | |
| 2041 | ec->tx_max_coalesced_frames_irq = vsi->work_limit; |
| 2042 | ec->rx_max_coalesced_frames_irq = vsi->work_limit; |
| 2043 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2044 | /* rx and tx usecs has per queue value. If user doesn't specify the queue, |
| 2045 | * return queue 0's value to represent. |
| 2046 | */ |
| 2047 | if (queue < 0) { |
| 2048 | queue = 0; |
| 2049 | } else if (queue >= vsi->num_queue_pairs) { |
| 2050 | return -EINVAL; |
| 2051 | } |
| 2052 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2053 | rx_ring = vsi->rx_rings[queue]; |
| 2054 | tx_ring = vsi->tx_rings[queue]; |
| 2055 | |
| 2056 | if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 2057 | ec->use_adaptive_rx_coalesce = 1; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2058 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2059 | if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting)) |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 2060 | ec->use_adaptive_tx_coalesce = 1; |
| 2061 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2062 | ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC; |
| 2063 | ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC; |
| 2064 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2065 | |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 2066 | /* we use the _usecs_high to store/set the interrupt rate limit |
| 2067 | * that the hardware supports, that almost but not quite |
| 2068 | * fits the original intent of the ethtool variable, |
| 2069 | * the rx_coalesce_usecs_high limits total interrupts |
| 2070 | * per second from both tx/rx sources. |
| 2071 | */ |
| 2072 | ec->rx_coalesce_usecs_high = vsi->int_rate_limit; |
| 2073 | ec->tx_coalesce_usecs_high = vsi->int_rate_limit; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2074 | |
| 2075 | return 0; |
| 2076 | } |
| 2077 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2078 | /** |
| 2079 | * i40e_get_coalesce - get a netdev's coalesce settings |
| 2080 | * @netdev: the netdev to check |
| 2081 | * @ec: ethtool coalesce data structure |
| 2082 | * |
| 2083 | * Gets the coalesce settings for a particular netdev. Note that if user has |
| 2084 | * modified per-queue settings, this only guarantees to represent queue 0. See |
| 2085 | * __i40e_get_coalesce for more details. |
| 2086 | **/ |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2087 | static int i40e_get_coalesce(struct net_device *netdev, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2088 | struct ethtool_coalesce *ec) |
| 2089 | { |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2090 | return __i40e_get_coalesce(netdev, ec, -1); |
| 2091 | } |
| 2092 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2093 | /** |
| 2094 | * i40e_get_per_queue_coalesce - gets coalesce settings for particular queue |
| 2095 | * @netdev: netdev structure |
| 2096 | * @ec: ethtool's coalesce settings |
| 2097 | * @queue: the particular queue to read |
| 2098 | * |
| 2099 | * Will read a specific queue's coalesce settings |
| 2100 | **/ |
Kan Liang | be280ba | 2016-02-19 09:24:05 -0500 | [diff] [blame] | 2101 | static int i40e_get_per_queue_coalesce(struct net_device *netdev, u32 queue, |
| 2102 | struct ethtool_coalesce *ec) |
| 2103 | { |
| 2104 | return __i40e_get_coalesce(netdev, ec, queue); |
| 2105 | } |
| 2106 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2107 | /** |
| 2108 | * i40e_set_itr_per_queue - set ITR values for specific queue |
| 2109 | * @vsi: the VSI to set values for |
| 2110 | * @ec: coalesce settings from ethtool |
| 2111 | * @queue: the queue to modify |
| 2112 | * |
| 2113 | * Change the ITR settings for a specific queue. |
| 2114 | **/ |
| 2115 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2116 | static void i40e_set_itr_per_queue(struct i40e_vsi *vsi, |
| 2117 | struct ethtool_coalesce *ec, |
| 2118 | int queue) |
| 2119 | { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2120 | struct i40e_pf *pf = vsi->back; |
| 2121 | struct i40e_hw *hw = &pf->hw; |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2122 | struct i40e_q_vector *q_vector; |
| 2123 | u16 vector, intrl; |
| 2124 | |
Alan Brady | 1c0e6a3 | 2016-11-28 16:06:02 -0800 | [diff] [blame] | 2125 | intrl = i40e_intrl_usec_to_reg(vsi->int_rate_limit); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2126 | |
| 2127 | vsi->rx_rings[queue]->rx_itr_setting = ec->rx_coalesce_usecs; |
| 2128 | vsi->tx_rings[queue]->tx_itr_setting = ec->tx_coalesce_usecs; |
| 2129 | |
| 2130 | if (ec->use_adaptive_rx_coalesce) |
| 2131 | vsi->rx_rings[queue]->rx_itr_setting |= I40E_ITR_DYNAMIC; |
| 2132 | else |
| 2133 | vsi->rx_rings[queue]->rx_itr_setting &= ~I40E_ITR_DYNAMIC; |
| 2134 | |
| 2135 | if (ec->use_adaptive_tx_coalesce) |
| 2136 | vsi->tx_rings[queue]->tx_itr_setting |= I40E_ITR_DYNAMIC; |
| 2137 | else |
| 2138 | vsi->tx_rings[queue]->tx_itr_setting &= ~I40E_ITR_DYNAMIC; |
| 2139 | |
| 2140 | q_vector = vsi->rx_rings[queue]->q_vector; |
| 2141 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[queue]->rx_itr_setting); |
| 2142 | vector = vsi->base_vector + q_vector->v_idx; |
| 2143 | wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1), q_vector->rx.itr); |
| 2144 | |
| 2145 | q_vector = vsi->tx_rings[queue]->q_vector; |
| 2146 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[queue]->tx_itr_setting); |
| 2147 | vector = vsi->base_vector + q_vector->v_idx; |
| 2148 | wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1), q_vector->tx.itr); |
| 2149 | |
| 2150 | wr32(hw, I40E_PFINT_RATEN(vector - 1), intrl); |
| 2151 | i40e_flush(hw); |
| 2152 | } |
| 2153 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2154 | /** |
| 2155 | * __i40e_set_coalesce - set coalesce settings for particular queue |
| 2156 | * @netdev: the netdev to change |
| 2157 | * @ec: ethtool coalesce settings |
| 2158 | * @queue: the queue to change |
| 2159 | * |
| 2160 | * Sets the coalesce settings for a particular queue. |
| 2161 | **/ |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2162 | static int __i40e_set_coalesce(struct net_device *netdev, |
| 2163 | struct ethtool_coalesce *ec, |
| 2164 | int queue) |
| 2165 | { |
| 2166 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2167 | struct i40e_vsi *vsi = np->vsi; |
| 2168 | struct i40e_pf *pf = vsi->back; |
Alan Brady | 3308406 | 2016-11-28 16:06:03 -0800 | [diff] [blame] | 2169 | u16 intrl_reg; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2170 | int i; |
| 2171 | |
| 2172 | if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq) |
| 2173 | vsi->work_limit = ec->tx_max_coalesced_frames_irq; |
| 2174 | |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 2175 | /* tx_coalesce_usecs_high is ignored, use rx-usecs-high instead */ |
| 2176 | if (ec->tx_coalesce_usecs_high != vsi->int_rate_limit) { |
| 2177 | netif_info(pf, drv, netdev, "tx-usecs-high is not used, please program rx-usecs-high\n"); |
| 2178 | return -EINVAL; |
| 2179 | } |
| 2180 | |
Alan Brady | 3308406 | 2016-11-28 16:06:03 -0800 | [diff] [blame] | 2181 | if (ec->rx_coalesce_usecs_high > INTRL_REG_TO_USEC(I40E_MAX_INTRL)) { |
| 2182 | netif_info(pf, drv, netdev, "Invalid value, rx-usecs-high range is 0-%lu\n", |
| 2183 | INTRL_REG_TO_USEC(I40E_MAX_INTRL)); |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 2184 | return -EINVAL; |
| 2185 | } |
| 2186 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2187 | if (ec->rx_coalesce_usecs == 0) { |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2188 | if (ec->use_adaptive_rx_coalesce) |
Jesse Brandeburg | 79442d3 | 2014-10-25 03:24:32 +0000 | [diff] [blame] | 2189 | netif_info(pf, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n"); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2190 | } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) || |
| 2191 | (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) { |
| 2192 | netif_info(pf, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n"); |
| 2193 | return -EINVAL; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2194 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2195 | |
Alan Brady | 3308406 | 2016-11-28 16:06:03 -0800 | [diff] [blame] | 2196 | intrl_reg = i40e_intrl_usec_to_reg(ec->rx_coalesce_usecs_high); |
| 2197 | vsi->int_rate_limit = INTRL_REG_TO_USEC(intrl_reg); |
| 2198 | if (vsi->int_rate_limit != ec->rx_coalesce_usecs_high) { |
| 2199 | netif_info(pf, drv, netdev, "Interrupt rate limit rounded down to %d\n", |
| 2200 | vsi->int_rate_limit); |
| 2201 | } |
Jesse Brandeburg | ac26fc1 | 2015-09-28 14:12:37 -0400 | [diff] [blame] | 2202 | |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2203 | if (ec->tx_coalesce_usecs == 0) { |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2204 | if (ec->use_adaptive_tx_coalesce) |
Jesse Brandeburg | 79442d3 | 2014-10-25 03:24:32 +0000 | [diff] [blame] | 2205 | netif_info(pf, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n"); |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2206 | } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) || |
| 2207 | (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) { |
| 2208 | netif_info(pf, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n"); |
| 2209 | return -EINVAL; |
| 2210 | } |
| 2211 | |
| 2212 | /* rx and tx usecs has per queue value. If user doesn't specify the queue, |
| 2213 | * apply to all queues. |
| 2214 | */ |
| 2215 | if (queue < 0) { |
| 2216 | for (i = 0; i < vsi->num_queue_pairs; i++) |
| 2217 | i40e_set_itr_per_queue(vsi, ec, i); |
| 2218 | } else if (queue < vsi->num_queue_pairs) { |
| 2219 | i40e_set_itr_per_queue(vsi, ec, queue); |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2220 | } else { |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2221 | netif_info(pf, drv, netdev, "Invalid queue value, queue range is 0 - %d\n", |
| 2222 | vsi->num_queue_pairs - 1); |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 2223 | return -EINVAL; |
Carolyn Wyborny | 5c2cebd | 2014-06-04 01:23:18 +0000 | [diff] [blame] | 2224 | } |
Mitch Williams | 32f5f54 | 2014-04-04 04:43:10 +0000 | [diff] [blame] | 2225 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2226 | return 0; |
| 2227 | } |
| 2228 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2229 | /** |
| 2230 | * i40e_set_coalesce - set coalesce settings for every queue on the netdev |
| 2231 | * @netdev: the netdev to change |
| 2232 | * @ec: ethtool coalesce settings |
| 2233 | * |
| 2234 | * This will set each queue to the same coalesce settings. |
| 2235 | **/ |
Kan Liang | a75e800 | 2016-02-19 09:24:04 -0500 | [diff] [blame] | 2236 | static int i40e_set_coalesce(struct net_device *netdev, |
| 2237 | struct ethtool_coalesce *ec) |
| 2238 | { |
| 2239 | return __i40e_set_coalesce(netdev, ec, -1); |
| 2240 | } |
| 2241 | |
Jacob Keller | 65e87c0 | 2016-09-12 14:18:44 -0700 | [diff] [blame] | 2242 | /** |
| 2243 | * i40e_set_per_queue_coalesce - set specific queue's coalesce settings |
| 2244 | * @netdev: the netdev to change |
| 2245 | * @ec: ethtool's coalesce settings |
| 2246 | * @queue: the queue to change |
| 2247 | * |
| 2248 | * Sets the specified queue's coalesce settings. |
| 2249 | **/ |
Kan Liang | f3757a4 | 2016-02-19 09:24:06 -0500 | [diff] [blame] | 2250 | static int i40e_set_per_queue_coalesce(struct net_device *netdev, u32 queue, |
| 2251 | struct ethtool_coalesce *ec) |
| 2252 | { |
| 2253 | return __i40e_set_coalesce(netdev, ec, queue); |
| 2254 | } |
| 2255 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2256 | /** |
| 2257 | * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type |
| 2258 | * @pf: pointer to the physical function struct |
| 2259 | * @cmd: ethtool rxnfc command |
| 2260 | * |
| 2261 | * Returns Success if the flow is supported, else Invalid Input. |
| 2262 | **/ |
| 2263 | static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd) |
| 2264 | { |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2265 | struct i40e_hw *hw = &pf->hw; |
| 2266 | u8 flow_pctype = 0; |
| 2267 | u64 i_set = 0; |
| 2268 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2269 | cmd->data = 0; |
| 2270 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2271 | switch (cmd->flow_type) { |
| 2272 | case TCP_V4_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2273 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; |
| 2274 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2275 | case UDP_V4_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2276 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP; |
| 2277 | break; |
| 2278 | case TCP_V6_FLOW: |
| 2279 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP; |
| 2280 | break; |
| 2281 | case UDP_V6_FLOW: |
| 2282 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP; |
| 2283 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2284 | case SCTP_V4_FLOW: |
| 2285 | case AH_ESP_V4_FLOW: |
| 2286 | case AH_V4_FLOW: |
| 2287 | case ESP_V4_FLOW: |
| 2288 | case IPV4_FLOW: |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2289 | case SCTP_V6_FLOW: |
| 2290 | case AH_ESP_V6_FLOW: |
| 2291 | case AH_V6_FLOW: |
| 2292 | case ESP_V6_FLOW: |
| 2293 | case IPV6_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2294 | /* Default is src/dest for IP, no matter the L4 hashing */ |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2295 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; |
| 2296 | break; |
| 2297 | default: |
| 2298 | return -EINVAL; |
| 2299 | } |
| 2300 | |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2301 | /* Read flow based hash input set register */ |
| 2302 | if (flow_pctype) { |
| 2303 | i_set = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, |
| 2304 | flow_pctype)) | |
| 2305 | ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, |
| 2306 | flow_pctype)) << 32); |
| 2307 | } |
| 2308 | |
| 2309 | /* Process bits of hash input set */ |
| 2310 | if (i_set) { |
| 2311 | if (i_set & I40E_L4_SRC_MASK) |
| 2312 | cmd->data |= RXH_L4_B_0_1; |
| 2313 | if (i_set & I40E_L4_DST_MASK) |
| 2314 | cmd->data |= RXH_L4_B_2_3; |
| 2315 | |
| 2316 | if (cmd->flow_type == TCP_V4_FLOW || |
| 2317 | cmd->flow_type == UDP_V4_FLOW) { |
| 2318 | if (i_set & I40E_L3_SRC_MASK) |
| 2319 | cmd->data |= RXH_IP_SRC; |
| 2320 | if (i_set & I40E_L3_DST_MASK) |
| 2321 | cmd->data |= RXH_IP_DST; |
| 2322 | } else if (cmd->flow_type == TCP_V6_FLOW || |
| 2323 | cmd->flow_type == UDP_V6_FLOW) { |
| 2324 | if (i_set & I40E_L3_V6_SRC_MASK) |
| 2325 | cmd->data |= RXH_IP_SRC; |
| 2326 | if (i_set & I40E_L3_V6_DST_MASK) |
| 2327 | cmd->data |= RXH_IP_DST; |
| 2328 | } |
| 2329 | } |
| 2330 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2331 | return 0; |
| 2332 | } |
| 2333 | |
| 2334 | /** |
Jacob Keller | e793095 | 2017-02-06 14:38:49 -0800 | [diff] [blame] | 2335 | * i40e_check_mask - Check whether a mask field is set |
| 2336 | * @mask: the full mask value |
| 2337 | * @field; mask of the field to check |
| 2338 | * |
| 2339 | * If the given mask is fully set, return positive value. If the mask for the |
| 2340 | * field is fully unset, return zero. Otherwise return a negative error code. |
| 2341 | **/ |
| 2342 | static int i40e_check_mask(u64 mask, u64 field) |
| 2343 | { |
| 2344 | u64 value = mask & field; |
| 2345 | |
| 2346 | if (value == field) |
| 2347 | return 1; |
| 2348 | else if (!value) |
| 2349 | return 0; |
| 2350 | else |
| 2351 | return -1; |
| 2352 | } |
| 2353 | |
| 2354 | /** |
| 2355 | * i40e_parse_rx_flow_user_data - Deconstruct user-defined data |
| 2356 | * @fsp: pointer to rx flow specification |
| 2357 | * @data: pointer to userdef data structure for storage |
| 2358 | * |
| 2359 | * Read the user-defined data and deconstruct the value into a structure. No |
| 2360 | * other code should read the user-defined data, so as to ensure that every |
| 2361 | * place consistently reads the value correctly. |
| 2362 | * |
| 2363 | * The user-defined field is a 64bit Big Endian format value, which we |
| 2364 | * deconstruct by reading bits or bit fields from it. Single bit flags shall |
| 2365 | * be defined starting from the highest bits, while small bit field values |
| 2366 | * shall be defined starting from the lowest bits. |
| 2367 | * |
| 2368 | * Returns 0 if the data is valid, and non-zero if the userdef data is invalid |
| 2369 | * and the filter should be rejected. The data structure will always be |
| 2370 | * modified even if FLOW_EXT is not set. |
| 2371 | * |
| 2372 | **/ |
| 2373 | static int i40e_parse_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp, |
| 2374 | struct i40e_rx_flow_userdef *data) |
| 2375 | { |
| 2376 | u64 value, mask; |
| 2377 | int valid; |
| 2378 | |
| 2379 | /* Zero memory first so it's always consistent. */ |
| 2380 | memset(data, 0, sizeof(*data)); |
| 2381 | |
| 2382 | if (!(fsp->flow_type & FLOW_EXT)) |
| 2383 | return 0; |
| 2384 | |
| 2385 | value = be64_to_cpu(*((__be64 *)fsp->h_ext.data)); |
| 2386 | mask = be64_to_cpu(*((__be64 *)fsp->m_ext.data)); |
| 2387 | |
| 2388 | #define I40E_USERDEF_FLEX_WORD GENMASK_ULL(15, 0) |
| 2389 | #define I40E_USERDEF_FLEX_OFFSET GENMASK_ULL(31, 16) |
| 2390 | #define I40E_USERDEF_FLEX_FILTER GENMASK_ULL(31, 0) |
| 2391 | |
| 2392 | valid = i40e_check_mask(mask, I40E_USERDEF_FLEX_FILTER); |
| 2393 | if (valid < 0) { |
| 2394 | return -EINVAL; |
| 2395 | } else if (valid) { |
| 2396 | data->flex_word = value & I40E_USERDEF_FLEX_WORD; |
| 2397 | data->flex_offset = |
| 2398 | (value & I40E_USERDEF_FLEX_OFFSET) >> 16; |
| 2399 | data->flex_filter = true; |
| 2400 | } |
| 2401 | |
| 2402 | return 0; |
| 2403 | } |
| 2404 | |
| 2405 | /** |
| 2406 | * i40e_fill_rx_flow_user_data - Fill in user-defined data field |
| 2407 | * @fsp: pointer to rx_flow specification |
| 2408 | * |
| 2409 | * Reads the userdef data structure and properly fills in the user defined |
| 2410 | * fields of the rx_flow_spec. |
| 2411 | **/ |
| 2412 | static void i40e_fill_rx_flow_user_data(struct ethtool_rx_flow_spec *fsp, |
| 2413 | struct i40e_rx_flow_userdef *data) |
| 2414 | { |
| 2415 | u64 value = 0, mask = 0; |
| 2416 | |
| 2417 | if (data->flex_filter) { |
| 2418 | value |= data->flex_word; |
| 2419 | value |= (u64)data->flex_offset << 16; |
| 2420 | mask |= I40E_USERDEF_FLEX_FILTER; |
| 2421 | } |
| 2422 | |
| 2423 | if (value || mask) |
| 2424 | fsp->flow_type |= FLOW_EXT; |
| 2425 | |
| 2426 | *((__be64 *)fsp->h_ext.data) = cpu_to_be64(value); |
| 2427 | *((__be64 *)fsp->m_ext.data) = cpu_to_be64(mask); |
| 2428 | } |
| 2429 | |
| 2430 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2431 | * i40e_get_ethtool_fdir_all - Populates the rule count of a command |
| 2432 | * @pf: Pointer to the physical function struct |
| 2433 | * @cmd: The command to get or set Rx flow classification rules |
| 2434 | * @rule_locs: Array of used rule locations |
| 2435 | * |
| 2436 | * This function populates both the total and actual rule count of |
| 2437 | * the ethtool flow classification command |
| 2438 | * |
| 2439 | * Returns 0 on success or -EMSGSIZE if entry not found |
| 2440 | **/ |
| 2441 | static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf, |
| 2442 | struct ethtool_rxnfc *cmd, |
| 2443 | u32 *rule_locs) |
| 2444 | { |
| 2445 | struct i40e_fdir_filter *rule; |
| 2446 | struct hlist_node *node2; |
| 2447 | int cnt = 0; |
| 2448 | |
| 2449 | /* report total rule count */ |
Anjali Singhai Jain | 082def1 | 2014-04-09 05:59:00 +0000 | [diff] [blame] | 2450 | cmd->data = i40e_get_fd_cnt_all(pf); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2451 | |
| 2452 | hlist_for_each_entry_safe(rule, node2, |
| 2453 | &pf->fdir_filter_list, fdir_node) { |
| 2454 | if (cnt == cmd->rule_cnt) |
| 2455 | return -EMSGSIZE; |
| 2456 | |
| 2457 | rule_locs[cnt] = rule->fd_id; |
| 2458 | cnt++; |
| 2459 | } |
| 2460 | |
| 2461 | cmd->rule_cnt = cnt; |
| 2462 | |
| 2463 | return 0; |
| 2464 | } |
| 2465 | |
| 2466 | /** |
| 2467 | * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow |
| 2468 | * @pf: Pointer to the physical function struct |
| 2469 | * @cmd: The command to get or set Rx flow classification rules |
| 2470 | * |
| 2471 | * This function looks up a filter based on the Rx flow classification |
| 2472 | * command and fills the flow spec info for it if found |
| 2473 | * |
| 2474 | * Returns 0 on success or -EINVAL if filter not found |
| 2475 | **/ |
| 2476 | static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf, |
| 2477 | struct ethtool_rxnfc *cmd) |
| 2478 | { |
| 2479 | struct ethtool_rx_flow_spec *fsp = |
| 2480 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
Jacob Keller | e793095 | 2017-02-06 14:38:49 -0800 | [diff] [blame] | 2481 | struct i40e_rx_flow_userdef userdef = {0}; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2482 | struct i40e_fdir_filter *rule = NULL; |
| 2483 | struct hlist_node *node2; |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 2484 | u64 input_set; |
| 2485 | u16 index; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2486 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2487 | hlist_for_each_entry_safe(rule, node2, |
| 2488 | &pf->fdir_filter_list, fdir_node) { |
| 2489 | if (fsp->location <= rule->fd_id) |
| 2490 | break; |
| 2491 | } |
| 2492 | |
| 2493 | if (!rule || fsp->location != rule->fd_id) |
| 2494 | return -EINVAL; |
| 2495 | |
| 2496 | fsp->flow_type = rule->flow_type; |
Anjali Singhai Jain | 7d54eb2 | 2014-03-14 07:32:21 +0000 | [diff] [blame] | 2497 | if (fsp->flow_type == IP_USER_FLOW) { |
| 2498 | fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; |
| 2499 | fsp->h_u.usr_ip4_spec.proto = 0; |
| 2500 | fsp->m_u.usr_ip4_spec.proto = 0; |
| 2501 | } |
| 2502 | |
Anjali Singhai Jain | 04b73bd | 2014-05-22 06:31:41 +0000 | [diff] [blame] | 2503 | /* Reverse the src and dest notion, since the HW views them from |
| 2504 | * Tx perspective where as the user expects it from Rx filter view. |
| 2505 | */ |
| 2506 | fsp->h_u.tcp_ip4_spec.psrc = rule->dst_port; |
| 2507 | fsp->h_u.tcp_ip4_spec.pdst = rule->src_port; |
Jacob Keller | 8ce43dc | 2017-02-06 14:38:39 -0800 | [diff] [blame] | 2508 | fsp->h_u.tcp_ip4_spec.ip4src = rule->dst_ip; |
| 2509 | fsp->h_u.tcp_ip4_spec.ip4dst = rule->src_ip; |
Anjali Singhai Jain | 387ce1a | 2014-05-22 06:32:23 +0000 | [diff] [blame] | 2510 | |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 2511 | switch (rule->flow_type) { |
| 2512 | case TCP_V4_FLOW: |
| 2513 | index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; |
| 2514 | break; |
| 2515 | case UDP_V4_FLOW: |
| 2516 | index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP; |
| 2517 | break; |
| 2518 | case IP_USER_FLOW: |
| 2519 | index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER; |
| 2520 | break; |
| 2521 | default: |
| 2522 | /* If we have stored a filter with a flow type not listed here |
| 2523 | * it is almost certainly a driver bug. WARN(), and then |
| 2524 | * assign the input_set as if all fields are enabled to avoid |
| 2525 | * reading unassigned memory. |
| 2526 | */ |
| 2527 | WARN(1, "Missing input set index for flow_type %d\n", |
| 2528 | rule->flow_type); |
| 2529 | input_set = 0xFFFFFFFFFFFFFFFFULL; |
| 2530 | goto no_input_set; |
| 2531 | } |
| 2532 | |
| 2533 | input_set = i40e_read_fd_input_set(pf, index); |
| 2534 | |
| 2535 | no_input_set: |
| 2536 | if (input_set & I40E_L3_SRC_MASK) |
| 2537 | fsp->m_u.tcp_ip4_spec.ip4src = htonl(0xFFFF); |
| 2538 | |
| 2539 | if (input_set & I40E_L3_DST_MASK) |
| 2540 | fsp->m_u.tcp_ip4_spec.ip4dst = htonl(0xFFFF); |
| 2541 | |
| 2542 | if (input_set & I40E_L4_SRC_MASK) |
| 2543 | fsp->m_u.tcp_ip4_spec.psrc = htons(0xFFFFFFFF); |
| 2544 | |
| 2545 | if (input_set & I40E_L4_DST_MASK) |
| 2546 | fsp->m_u.tcp_ip4_spec.pdst = htons(0xFFFFFFFF); |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 2547 | |
Anjali Singhai Jain | 387ce1a | 2014-05-22 06:32:23 +0000 | [diff] [blame] | 2548 | if (rule->dest_ctl == I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET) |
| 2549 | fsp->ring_cookie = RX_CLS_FLOW_DISC; |
| 2550 | else |
| 2551 | fsp->ring_cookie = rule->q_index; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2552 | |
Anjali Singhai Jain | e7c8c60 | 2015-04-07 19:45:31 -0400 | [diff] [blame] | 2553 | if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) { |
| 2554 | struct i40e_vsi *vsi; |
| 2555 | |
| 2556 | vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi); |
| 2557 | if (vsi && vsi->type == I40E_VSI_SRIOV) { |
Jacob Keller | 43b1569 | 2017-02-06 14:38:48 -0800 | [diff] [blame] | 2558 | /* VFs are zero-indexed by the driver, but ethtool |
| 2559 | * expects them to be one-indexed, so add one here |
| 2560 | */ |
| 2561 | u64 ring_vf = vsi->vf_id + 1; |
| 2562 | |
| 2563 | ring_vf <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF; |
| 2564 | fsp->ring_cookie |= ring_vf; |
Anjali Singhai Jain | e7c8c60 | 2015-04-07 19:45:31 -0400 | [diff] [blame] | 2565 | } |
| 2566 | } |
| 2567 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 2568 | if (rule->flex_filter) { |
| 2569 | userdef.flex_filter = true; |
| 2570 | userdef.flex_word = be16_to_cpu(rule->flex_word); |
| 2571 | userdef.flex_offset = rule->flex_offset; |
| 2572 | } |
| 2573 | |
Jacob Keller | e793095 | 2017-02-06 14:38:49 -0800 | [diff] [blame] | 2574 | i40e_fill_rx_flow_user_data(fsp, &userdef); |
| 2575 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2576 | return 0; |
| 2577 | } |
| 2578 | |
| 2579 | /** |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2580 | * i40e_get_rxnfc - command to get RX flow classification rules |
| 2581 | * @netdev: network interface device structure |
| 2582 | * @cmd: ethtool rxnfc command |
| 2583 | * |
| 2584 | * Returns Success if the command is supported. |
| 2585 | **/ |
| 2586 | static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, |
| 2587 | u32 *rule_locs) |
| 2588 | { |
| 2589 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 2590 | struct i40e_vsi *vsi = np->vsi; |
| 2591 | struct i40e_pf *pf = vsi->back; |
| 2592 | int ret = -EOPNOTSUPP; |
| 2593 | |
| 2594 | switch (cmd->cmd) { |
| 2595 | case ETHTOOL_GRXRINGS: |
Helin Zhang | 3e3aa21 | 2015-10-21 19:47:13 -0400 | [diff] [blame] | 2596 | cmd->data = vsi->num_queue_pairs; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2597 | ret = 0; |
| 2598 | break; |
| 2599 | case ETHTOOL_GRXFH: |
| 2600 | ret = i40e_get_rss_hash_opts(pf, cmd); |
| 2601 | break; |
| 2602 | case ETHTOOL_GRXCLSRLCNT: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2603 | cmd->rule_cnt = pf->fdir_pf_active_filters; |
Anjali Singhai Jain | 082def1 | 2014-04-09 05:59:00 +0000 | [diff] [blame] | 2604 | /* report total rule count */ |
| 2605 | cmd->data = i40e_get_fd_cnt_all(pf); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2606 | ret = 0; |
| 2607 | break; |
| 2608 | case ETHTOOL_GRXCLSRULE: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2609 | ret = i40e_get_ethtool_fdir_entry(pf, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2610 | break; |
| 2611 | case ETHTOOL_GRXCLSRLALL: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2612 | ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs); |
| 2613 | break; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2614 | default: |
| 2615 | break; |
| 2616 | } |
| 2617 | |
| 2618 | return ret; |
| 2619 | } |
| 2620 | |
| 2621 | /** |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2622 | * i40e_get_rss_hash_bits - Read RSS Hash bits from register |
| 2623 | * @nfc: pointer to user request |
| 2624 | * @i_setc bits currently set |
| 2625 | * |
| 2626 | * Returns value of bits to be set per user request |
| 2627 | **/ |
| 2628 | static u64 i40e_get_rss_hash_bits(struct ethtool_rxnfc *nfc, u64 i_setc) |
| 2629 | { |
| 2630 | u64 i_set = i_setc; |
| 2631 | u64 src_l3 = 0, dst_l3 = 0; |
| 2632 | |
| 2633 | if (nfc->data & RXH_L4_B_0_1) |
| 2634 | i_set |= I40E_L4_SRC_MASK; |
| 2635 | else |
| 2636 | i_set &= ~I40E_L4_SRC_MASK; |
| 2637 | if (nfc->data & RXH_L4_B_2_3) |
| 2638 | i_set |= I40E_L4_DST_MASK; |
| 2639 | else |
| 2640 | i_set &= ~I40E_L4_DST_MASK; |
| 2641 | |
| 2642 | if (nfc->flow_type == TCP_V6_FLOW || nfc->flow_type == UDP_V6_FLOW) { |
| 2643 | src_l3 = I40E_L3_V6_SRC_MASK; |
| 2644 | dst_l3 = I40E_L3_V6_DST_MASK; |
| 2645 | } else if (nfc->flow_type == TCP_V4_FLOW || |
| 2646 | nfc->flow_type == UDP_V4_FLOW) { |
| 2647 | src_l3 = I40E_L3_SRC_MASK; |
| 2648 | dst_l3 = I40E_L3_DST_MASK; |
| 2649 | } else { |
| 2650 | /* Any other flow type are not supported here */ |
| 2651 | return i_set; |
| 2652 | } |
| 2653 | |
| 2654 | if (nfc->data & RXH_IP_SRC) |
| 2655 | i_set |= src_l3; |
| 2656 | else |
| 2657 | i_set &= ~src_l3; |
| 2658 | if (nfc->data & RXH_IP_DST) |
| 2659 | i_set |= dst_l3; |
| 2660 | else |
| 2661 | i_set &= ~dst_l3; |
| 2662 | |
| 2663 | return i_set; |
| 2664 | } |
| 2665 | |
| 2666 | /** |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2667 | * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash |
| 2668 | * @pf: pointer to the physical function struct |
| 2669 | * @cmd: ethtool rxnfc command |
| 2670 | * |
| 2671 | * Returns Success if the flow input set is supported. |
| 2672 | **/ |
| 2673 | static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc) |
| 2674 | { |
| 2675 | struct i40e_hw *hw = &pf->hw; |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 2676 | u64 hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) | |
| 2677 | ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32); |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2678 | u8 flow_pctype = 0; |
| 2679 | u64 i_set, i_setc; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2680 | |
| 2681 | /* RSS does not support anything other than hashing |
| 2682 | * to queues on src and dst IPs and ports |
| 2683 | */ |
| 2684 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | |
| 2685 | RXH_L4_B_0_1 | RXH_L4_B_2_3)) |
| 2686 | return -EINVAL; |
| 2687 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2688 | switch (nfc->flow_type) { |
| 2689 | case TCP_V4_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2690 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; |
| 2691 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2692 | hena |= |
| 2693 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2694 | break; |
| 2695 | case TCP_V6_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2696 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_TCP; |
| 2697 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2698 | hena |= |
| 2699 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK); |
| 2700 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2701 | hena |= |
| 2702 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2703 | break; |
| 2704 | case UDP_V4_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2705 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV4_UDP; |
| 2706 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2707 | hena |= |
| 2708 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | |
| 2709 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP); |
Anjali Singhai Jain | 3d0da5b | 2015-12-22 14:25:05 -0800 | [diff] [blame] | 2710 | |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2711 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2712 | break; |
| 2713 | case UDP_V6_FLOW: |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2714 | flow_pctype = I40E_FILTER_PCTYPE_NONF_IPV6_UDP; |
| 2715 | if (pf->flags & I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE) |
| 2716 | hena |= |
| 2717 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | |
| 2718 | BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP); |
Anjali Singhai Jain | 3d0da5b | 2015-12-22 14:25:05 -0800 | [diff] [blame] | 2719 | |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2720 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2721 | break; |
| 2722 | case AH_ESP_V4_FLOW: |
| 2723 | case AH_V4_FLOW: |
| 2724 | case ESP_V4_FLOW: |
| 2725 | case SCTP_V4_FLOW: |
| 2726 | if ((nfc->data & RXH_L4_B_0_1) || |
| 2727 | (nfc->data & RXH_L4_B_2_3)) |
| 2728 | return -EINVAL; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2729 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2730 | break; |
| 2731 | case AH_ESP_V6_FLOW: |
| 2732 | case AH_V6_FLOW: |
| 2733 | case ESP_V6_FLOW: |
| 2734 | case SCTP_V6_FLOW: |
| 2735 | if ((nfc->data & RXH_L4_B_0_1) || |
| 2736 | (nfc->data & RXH_L4_B_2_3)) |
| 2737 | return -EINVAL; |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2738 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2739 | break; |
| 2740 | case IPV4_FLOW: |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2741 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | |
| 2742 | BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2743 | break; |
| 2744 | case IPV6_FLOW: |
Jesse Brandeburg | 41a1d04 | 2015-06-04 16:24:02 -0400 | [diff] [blame] | 2745 | hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | |
| 2746 | BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2747 | break; |
| 2748 | default: |
| 2749 | return -EINVAL; |
| 2750 | } |
| 2751 | |
Carolyn Wyborny | eb0dd6e | 2016-07-27 12:02:40 -0700 | [diff] [blame] | 2752 | if (flow_pctype) { |
| 2753 | i_setc = (u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, |
| 2754 | flow_pctype)) | |
| 2755 | ((u64)i40e_read_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, |
| 2756 | flow_pctype)) << 32); |
| 2757 | i_set = i40e_get_rss_hash_bits(nfc, i_setc); |
| 2758 | i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(0, flow_pctype), |
| 2759 | (u32)i_set); |
| 2760 | i40e_write_rx_ctl(hw, I40E_GLQF_HASH_INSET(1, flow_pctype), |
| 2761 | (u32)(i_set >> 32)); |
| 2762 | hena |= BIT_ULL(flow_pctype); |
| 2763 | } |
| 2764 | |
Shannon Nelson | 272cdaf2 | 2016-02-17 16:12:21 -0800 | [diff] [blame] | 2765 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena); |
| 2766 | i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2767 | i40e_flush(hw); |
| 2768 | |
| 2769 | return 0; |
| 2770 | } |
| 2771 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2772 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2773 | * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry |
| 2774 | * @vsi: Pointer to the targeted VSI |
| 2775 | * @input: The filter to update or NULL to indicate deletion |
| 2776 | * @sw_idx: Software index to the filter |
| 2777 | * @cmd: The command to get or set Rx flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2778 | * |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2779 | * This function updates (or deletes) a Flow Director entry from |
| 2780 | * the hlist of the corresponding PF |
| 2781 | * |
| 2782 | * Returns 0 on success |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2783 | **/ |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2784 | static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi, |
| 2785 | struct i40e_fdir_filter *input, |
| 2786 | u16 sw_idx, |
| 2787 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2788 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2789 | struct i40e_fdir_filter *rule, *parent; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2790 | struct i40e_pf *pf = vsi->back; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2791 | struct hlist_node *node2; |
| 2792 | int err = -EINVAL; |
Jesse Brandeburg | c35a1d7 | 2013-12-18 13:46:02 +0000 | [diff] [blame] | 2793 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2794 | parent = NULL; |
| 2795 | rule = NULL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2796 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2797 | hlist_for_each_entry_safe(rule, node2, |
| 2798 | &pf->fdir_filter_list, fdir_node) { |
| 2799 | /* hash found, or no matching entry */ |
| 2800 | if (rule->fd_id >= sw_idx) |
| 2801 | break; |
| 2802 | parent = rule; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2803 | } |
| 2804 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2805 | /* if there is an old rule occupying our place remove it */ |
| 2806 | if (rule && (rule->fd_id == sw_idx)) { |
Jacob Keller | c6da525 | 2017-02-06 14:39:13 -0800 | [diff] [blame] | 2807 | /* Remove this rule, since we're either deleting it, or |
| 2808 | * replacing it. |
| 2809 | */ |
| 2810 | err = i40e_add_del_fdir(vsi, rule, false); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2811 | hlist_del(&rule->fdir_node); |
| 2812 | kfree(rule); |
| 2813 | pf->fdir_pf_active_filters--; |
| 2814 | } |
| 2815 | |
Jacob Keller | c6da525 | 2017-02-06 14:39:13 -0800 | [diff] [blame] | 2816 | /* If we weren't given an input, this is a delete, so just return the |
| 2817 | * error code indicating if there was an entry at the requested slot |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2818 | */ |
| 2819 | if (!input) |
| 2820 | return err; |
| 2821 | |
Jacob Keller | c6da525 | 2017-02-06 14:39:13 -0800 | [diff] [blame] | 2822 | /* Otherwise, install the new rule as requested */ |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2823 | INIT_HLIST_NODE(&input->fdir_node); |
| 2824 | |
| 2825 | /* add filter to the list */ |
| 2826 | if (parent) |
Ken Helias | 1d02328 | 2014-08-06 16:09:16 -0700 | [diff] [blame] | 2827 | hlist_add_behind(&input->fdir_node, &parent->fdir_node); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2828 | else |
| 2829 | hlist_add_head(&input->fdir_node, |
| 2830 | &pf->fdir_filter_list); |
| 2831 | |
| 2832 | /* update counts */ |
| 2833 | pf->fdir_pf_active_filters++; |
| 2834 | |
| 2835 | return 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | /** |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 2839 | * i40e_prune_flex_pit_list - Cleanup unused entries in FLX_PIT table |
| 2840 | * @pf: pointer to PF structure |
| 2841 | * |
| 2842 | * This function searches the list of filters and determines which FLX_PIT |
| 2843 | * entries are still required. It will prune any entries which are no longer |
| 2844 | * in use after the deletion. |
| 2845 | **/ |
| 2846 | static void i40e_prune_flex_pit_list(struct i40e_pf *pf) |
| 2847 | { |
| 2848 | struct i40e_flex_pit *entry, *tmp; |
| 2849 | struct i40e_fdir_filter *rule; |
| 2850 | |
| 2851 | /* First, we'll check the l3 table */ |
| 2852 | list_for_each_entry_safe(entry, tmp, &pf->l3_flex_pit_list, list) { |
| 2853 | bool found = false; |
| 2854 | |
| 2855 | hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) { |
| 2856 | if (rule->flow_type != IP_USER_FLOW) |
| 2857 | continue; |
| 2858 | if (rule->flex_filter && |
| 2859 | rule->flex_offset == entry->src_offset) { |
| 2860 | found = true; |
| 2861 | break; |
| 2862 | } |
| 2863 | } |
| 2864 | |
| 2865 | /* If we didn't find the filter, then we can prune this entry |
| 2866 | * from the list. |
| 2867 | */ |
| 2868 | if (!found) { |
| 2869 | list_del(&entry->list); |
| 2870 | kfree(entry); |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | /* Followed by the L4 table */ |
| 2875 | list_for_each_entry_safe(entry, tmp, &pf->l4_flex_pit_list, list) { |
| 2876 | bool found = false; |
| 2877 | |
| 2878 | hlist_for_each_entry(rule, &pf->fdir_filter_list, fdir_node) { |
| 2879 | /* Skip this filter if it's L3, since we already |
| 2880 | * checked those in the above loop |
| 2881 | */ |
| 2882 | if (rule->flow_type == IP_USER_FLOW) |
| 2883 | continue; |
| 2884 | if (rule->flex_filter && |
| 2885 | rule->flex_offset == entry->src_offset) { |
| 2886 | found = true; |
| 2887 | break; |
| 2888 | } |
| 2889 | } |
| 2890 | |
| 2891 | /* If we didn't find the filter, then we can prune this entry |
| 2892 | * from the list. |
| 2893 | */ |
| 2894 | if (!found) { |
| 2895 | list_del(&entry->list); |
| 2896 | kfree(entry); |
| 2897 | } |
| 2898 | } |
| 2899 | } |
| 2900 | |
| 2901 | /** |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2902 | * i40e_del_fdir_entry - Deletes a Flow Director filter entry |
| 2903 | * @vsi: Pointer to the targeted VSI |
| 2904 | * @cmd: The command to get or set Rx flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2905 | * |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2906 | * The function removes a Flow Director filter entry from the |
| 2907 | * hlist of the corresponding PF |
| 2908 | * |
| 2909 | * Returns 0 on success |
| 2910 | */ |
| 2911 | static int i40e_del_fdir_entry(struct i40e_vsi *vsi, |
| 2912 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2913 | { |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2914 | struct ethtool_rx_flow_spec *fsp = |
| 2915 | (struct ethtool_rx_flow_spec *)&cmd->fs; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2916 | struct i40e_pf *pf = vsi->back; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2917 | int ret = 0; |
Jesse Brandeburg | c35a1d7 | 2013-12-18 13:46:02 +0000 | [diff] [blame] | 2918 | |
Anjali Singhai Jain | 60793f4a | 2014-07-09 07:46:23 +0000 | [diff] [blame] | 2919 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 2920 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 2921 | return -EBUSY; |
| 2922 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 2923 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 2924 | return -EBUSY; |
| 2925 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2926 | ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2927 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 2928 | i40e_prune_flex_pit_list(pf); |
| 2929 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 2930 | i40e_fdir_check_and_reenable(pf); |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 2931 | return ret; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | /** |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 2935 | * i40e_unused_pit_index - Find an unused PIT index for given list |
| 2936 | * @pf: the PF data structure |
| 2937 | * |
| 2938 | * Find the first unused flexible PIT index entry. We search both the L3 and |
| 2939 | * L4 flexible PIT lists so that the returned index is unique and unused by |
| 2940 | * either currently programmed L3 or L4 filters. We use a bit field as storage |
| 2941 | * to track which indexes are already used. |
| 2942 | **/ |
| 2943 | static u8 i40e_unused_pit_index(struct i40e_pf *pf) |
| 2944 | { |
| 2945 | unsigned long available_index = 0xFF; |
| 2946 | struct i40e_flex_pit *entry; |
| 2947 | |
| 2948 | /* We need to make sure that the new index isn't in use by either L3 |
| 2949 | * or L4 filters so that IP_USER_FLOW filters can program both L3 and |
| 2950 | * L4 to use the same index. |
| 2951 | */ |
| 2952 | |
| 2953 | list_for_each_entry(entry, &pf->l4_flex_pit_list, list) |
| 2954 | clear_bit(entry->pit_index, &available_index); |
| 2955 | |
| 2956 | list_for_each_entry(entry, &pf->l3_flex_pit_list, list) |
| 2957 | clear_bit(entry->pit_index, &available_index); |
| 2958 | |
| 2959 | return find_first_bit(&available_index, 8); |
| 2960 | } |
| 2961 | |
| 2962 | /** |
| 2963 | * i40e_find_flex_offset - Find an existing flex src_offset |
| 2964 | * @flex_pit_list: L3 or L4 flex PIT list |
| 2965 | * @src_offset: new src_offset to find |
| 2966 | * |
| 2967 | * Searches the flex_pit_list for an existing offset. If no offset is |
| 2968 | * currently programmed, then this will return an ERR_PTR if there is no space |
| 2969 | * to add a new offset, otherwise it returns NULL. |
| 2970 | **/ |
| 2971 | static |
| 2972 | struct i40e_flex_pit *i40e_find_flex_offset(struct list_head *flex_pit_list, |
| 2973 | u16 src_offset) |
| 2974 | { |
| 2975 | struct i40e_flex_pit *entry; |
| 2976 | int size = 0; |
| 2977 | |
| 2978 | /* Search for the src_offset first. If we find a matching entry |
| 2979 | * already programmed, we can simply re-use it. |
| 2980 | */ |
| 2981 | list_for_each_entry(entry, flex_pit_list, list) { |
| 2982 | size++; |
| 2983 | if (entry->src_offset == src_offset) |
| 2984 | return entry; |
| 2985 | } |
| 2986 | |
| 2987 | /* If we haven't found an entry yet, then the provided src offset has |
| 2988 | * not yet been programmed. We will program the src offset later on, |
| 2989 | * but we need to indicate whether there is enough space to do so |
| 2990 | * here. We'll make use of ERR_PTR for this purpose. |
| 2991 | */ |
| 2992 | if (size >= I40E_FLEX_PIT_TABLE_SIZE) |
| 2993 | return ERR_PTR(-ENOSPC); |
| 2994 | |
| 2995 | return NULL; |
| 2996 | } |
| 2997 | |
| 2998 | /** |
| 2999 | * i40e_add_flex_offset - Add src_offset to flex PIT table list |
| 3000 | * @flex_pit_list: L3 or L4 flex PIT list |
| 3001 | * @src_offset: new src_offset to add |
| 3002 | * @pit_index: the PIT index to program |
| 3003 | * |
| 3004 | * This function programs the new src_offset to the list. It is expected that |
| 3005 | * i40e_find_flex_offset has already been tried and returned NULL, indicating |
| 3006 | * that this offset is not programmed, and that the list has enough space to |
| 3007 | * store another offset. |
| 3008 | * |
| 3009 | * Returns 0 on success, and negative value on error. |
| 3010 | **/ |
| 3011 | static int i40e_add_flex_offset(struct list_head *flex_pit_list, |
| 3012 | u16 src_offset, |
| 3013 | u8 pit_index) |
| 3014 | { |
| 3015 | struct i40e_flex_pit *new_pit, *entry; |
| 3016 | |
| 3017 | new_pit = kzalloc(sizeof(*entry), GFP_KERNEL); |
| 3018 | if (!new_pit) |
| 3019 | return -ENOMEM; |
| 3020 | |
| 3021 | new_pit->src_offset = src_offset; |
| 3022 | new_pit->pit_index = pit_index; |
| 3023 | |
| 3024 | /* We need to insert this item such that the list is sorted by |
| 3025 | * src_offset in ascending order. |
| 3026 | */ |
| 3027 | list_for_each_entry(entry, flex_pit_list, list) { |
| 3028 | if (new_pit->src_offset < entry->src_offset) { |
| 3029 | list_add_tail(&new_pit->list, &entry->list); |
| 3030 | return 0; |
| 3031 | } |
| 3032 | |
| 3033 | /* If we found an entry with our offset already programmed we |
| 3034 | * can simply return here, after freeing the memory. However, |
| 3035 | * if the pit_index does not match we need to report an error. |
| 3036 | */ |
| 3037 | if (new_pit->src_offset == entry->src_offset) { |
| 3038 | int err = 0; |
| 3039 | |
| 3040 | /* If the PIT index is not the same we can't re-use |
| 3041 | * the entry, so we must report an error. |
| 3042 | */ |
| 3043 | if (new_pit->pit_index != entry->pit_index) |
| 3044 | err = -EINVAL; |
| 3045 | |
| 3046 | kfree(new_pit); |
| 3047 | return err; |
| 3048 | } |
| 3049 | } |
| 3050 | |
| 3051 | /* If we reached here, then we haven't yet added the item. This means |
| 3052 | * that we should add the item at the end of the list. |
| 3053 | */ |
| 3054 | list_add_tail(&new_pit->list, flex_pit_list); |
| 3055 | return 0; |
| 3056 | } |
| 3057 | |
| 3058 | /** |
| 3059 | * __i40e_reprogram_flex_pit - Re-program specific FLX_PIT table |
| 3060 | * @pf: Pointer to the PF structure |
| 3061 | * @flex_pit_list: list of flexible src offsets in use |
| 3062 | * #flex_pit_start: index to first entry for this section of the table |
| 3063 | * |
| 3064 | * In order to handle flexible data, the hardware uses a table of values |
| 3065 | * called the FLX_PIT table. This table is used to indicate which sections of |
| 3066 | * the input correspond to what PIT index values. Unfortunately, hardware is |
| 3067 | * very restrictive about programming this table. Entries must be ordered by |
| 3068 | * src_offset in ascending order, without duplicates. Additionally, unused |
| 3069 | * entries must be set to the unused index value, and must have valid size and |
| 3070 | * length according to the src_offset ordering. |
| 3071 | * |
| 3072 | * This function will reprogram the FLX_PIT register from a book-keeping |
| 3073 | * structure that we guarantee is already ordered correctly, and has no more |
| 3074 | * than 3 entries. |
| 3075 | * |
| 3076 | * To make things easier, we only support flexible values of one word length, |
| 3077 | * rather than allowing variable length flexible values. |
| 3078 | **/ |
| 3079 | static void __i40e_reprogram_flex_pit(struct i40e_pf *pf, |
| 3080 | struct list_head *flex_pit_list, |
| 3081 | int flex_pit_start) |
| 3082 | { |
| 3083 | struct i40e_flex_pit *entry = NULL; |
| 3084 | u16 last_offset = 0; |
| 3085 | int i = 0, j = 0; |
| 3086 | |
| 3087 | /* First, loop over the list of flex PIT entries, and reprogram the |
| 3088 | * registers. |
| 3089 | */ |
| 3090 | list_for_each_entry(entry, flex_pit_list, list) { |
| 3091 | /* We have to be careful when programming values for the |
| 3092 | * largest SRC_OFFSET value. It is possible that adding |
| 3093 | * additional empty values at the end would overflow the space |
| 3094 | * for the SRC_OFFSET in the FLX_PIT register. To avoid this, |
| 3095 | * we check here and add the empty values prior to adding the |
| 3096 | * largest value. |
| 3097 | * |
| 3098 | * To determine this, we will use a loop from i+1 to 3, which |
| 3099 | * will determine whether the unused entries would have valid |
| 3100 | * SRC_OFFSET. Note that there cannot be extra entries past |
| 3101 | * this value, because the only valid values would have been |
| 3102 | * larger than I40E_MAX_FLEX_SRC_OFFSET, and thus would not |
| 3103 | * have been added to the list in the first place. |
| 3104 | */ |
| 3105 | for (j = i + 1; j < 3; j++) { |
| 3106 | u16 offset = entry->src_offset + j; |
| 3107 | int index = flex_pit_start + i; |
| 3108 | u32 value = I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED, |
| 3109 | 1, |
| 3110 | offset - 3); |
| 3111 | |
| 3112 | if (offset > I40E_MAX_FLEX_SRC_OFFSET) { |
| 3113 | i40e_write_rx_ctl(&pf->hw, |
| 3114 | I40E_PRTQF_FLX_PIT(index), |
| 3115 | value); |
| 3116 | i++; |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | /* Now, we can program the actual value into the table */ |
| 3121 | i40e_write_rx_ctl(&pf->hw, |
| 3122 | I40E_PRTQF_FLX_PIT(flex_pit_start + i), |
| 3123 | I40E_FLEX_PREP_VAL(entry->pit_index + 50, |
| 3124 | 1, |
| 3125 | entry->src_offset)); |
| 3126 | i++; |
| 3127 | } |
| 3128 | |
| 3129 | /* In order to program the last entries in the table, we need to |
| 3130 | * determine the valid offset. If the list is empty, we'll just start |
| 3131 | * with 0. Otherwise, we'll start with the last item offset and add 1. |
| 3132 | * This ensures that all entries have valid sizes. If we don't do this |
| 3133 | * correctly, the hardware will disable flexible field parsing. |
| 3134 | */ |
| 3135 | if (!list_empty(flex_pit_list)) |
| 3136 | last_offset = list_prev_entry(entry, list)->src_offset + 1; |
| 3137 | |
| 3138 | for (; i < 3; i++, last_offset++) { |
| 3139 | i40e_write_rx_ctl(&pf->hw, |
| 3140 | I40E_PRTQF_FLX_PIT(flex_pit_start + i), |
| 3141 | I40E_FLEX_PREP_VAL(I40E_FLEX_DEST_UNUSED, |
| 3142 | 1, |
| 3143 | last_offset)); |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | /** |
| 3148 | * i40e_reprogram_flex_pit - Reprogram all FLX_PIT tables after input set change |
| 3149 | * @pf: pointer to the PF structure |
| 3150 | * |
| 3151 | * This function reprograms both the L3 and L4 FLX_PIT tables. See the |
| 3152 | * internal helper function for implementation details. |
| 3153 | **/ |
| 3154 | static void i40e_reprogram_flex_pit(struct i40e_pf *pf) |
| 3155 | { |
| 3156 | __i40e_reprogram_flex_pit(pf, &pf->l3_flex_pit_list, |
| 3157 | I40E_FLEX_PIT_IDX_START_L3); |
| 3158 | |
| 3159 | __i40e_reprogram_flex_pit(pf, &pf->l4_flex_pit_list, |
| 3160 | I40E_FLEX_PIT_IDX_START_L4); |
| 3161 | |
| 3162 | /* We also need to program the L3 and L4 GLQF ORT register */ |
| 3163 | i40e_write_rx_ctl(&pf->hw, |
| 3164 | I40E_GLQF_ORT(I40E_L3_GLQF_ORT_IDX), |
| 3165 | I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L3, |
| 3166 | 3, 1)); |
| 3167 | |
| 3168 | i40e_write_rx_ctl(&pf->hw, |
| 3169 | I40E_GLQF_ORT(I40E_L4_GLQF_ORT_IDX), |
| 3170 | I40E_ORT_PREP_VAL(I40E_FLEX_PIT_IDX_START_L4, |
| 3171 | 3, 1)); |
| 3172 | } |
| 3173 | |
| 3174 | /** |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3175 | * i40e_flow_str - Converts a flow_type into a human readable string |
| 3176 | * @flow_type: the flow type from a flow specification |
| 3177 | * |
| 3178 | * Currently only flow types we support are included here, and the string |
| 3179 | * value attempts to match what ethtool would use to configure this flow type. |
| 3180 | **/ |
| 3181 | static const char *i40e_flow_str(struct ethtool_rx_flow_spec *fsp) |
| 3182 | { |
| 3183 | switch (fsp->flow_type & ~FLOW_EXT) { |
| 3184 | case TCP_V4_FLOW: |
| 3185 | return "tcp4"; |
| 3186 | case UDP_V4_FLOW: |
| 3187 | return "udp4"; |
| 3188 | case SCTP_V4_FLOW: |
| 3189 | return "sctp4"; |
| 3190 | case IP_USER_FLOW: |
| 3191 | return "ip4"; |
| 3192 | default: |
| 3193 | return "unknown"; |
| 3194 | } |
| 3195 | } |
| 3196 | |
| 3197 | /** |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3198 | * i40e_pit_index_to_mask - Return the FLEX mask for a given PIT index |
| 3199 | * @pit_index: PIT index to convert |
| 3200 | * |
| 3201 | * Returns the mask for a given PIT index. Will return 0 if the pit_index is |
| 3202 | * of range. |
| 3203 | **/ |
| 3204 | static u64 i40e_pit_index_to_mask(int pit_index) |
| 3205 | { |
| 3206 | switch (pit_index) { |
| 3207 | case 0: |
| 3208 | return I40E_FLEX_50_MASK; |
| 3209 | case 1: |
| 3210 | return I40E_FLEX_51_MASK; |
| 3211 | case 2: |
| 3212 | return I40E_FLEX_52_MASK; |
| 3213 | case 3: |
| 3214 | return I40E_FLEX_53_MASK; |
| 3215 | case 4: |
| 3216 | return I40E_FLEX_54_MASK; |
| 3217 | case 5: |
| 3218 | return I40E_FLEX_55_MASK; |
| 3219 | case 6: |
| 3220 | return I40E_FLEX_56_MASK; |
| 3221 | case 7: |
| 3222 | return I40E_FLEX_57_MASK; |
| 3223 | default: |
| 3224 | return 0; |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | /** |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3229 | * i40e_print_input_set - Show changes between two input sets |
| 3230 | * @vsi: the vsi being configured |
| 3231 | * @old: the old input set |
| 3232 | * @new: the new input set |
| 3233 | * |
| 3234 | * Print the difference between old and new input sets by showing which series |
| 3235 | * of words are toggled on or off. Only displays the bits we actually support |
| 3236 | * changing. |
| 3237 | **/ |
| 3238 | static void i40e_print_input_set(struct i40e_vsi *vsi, u64 old, u64 new) |
| 3239 | { |
| 3240 | struct i40e_pf *pf = vsi->back; |
| 3241 | bool old_value, new_value; |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3242 | int i; |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3243 | |
| 3244 | old_value = !!(old & I40E_L3_SRC_MASK); |
| 3245 | new_value = !!(new & I40E_L3_SRC_MASK); |
| 3246 | if (old_value != new_value) |
| 3247 | netif_info(pf, drv, vsi->netdev, "L3 source address: %s -> %s\n", |
| 3248 | old_value ? "ON" : "OFF", |
| 3249 | new_value ? "ON" : "OFF"); |
| 3250 | |
| 3251 | old_value = !!(old & I40E_L3_DST_MASK); |
| 3252 | new_value = !!(new & I40E_L3_DST_MASK); |
| 3253 | if (old_value != new_value) |
| 3254 | netif_info(pf, drv, vsi->netdev, "L3 destination address: %s -> %s\n", |
| 3255 | old_value ? "ON" : "OFF", |
| 3256 | new_value ? "ON" : "OFF"); |
| 3257 | |
| 3258 | old_value = !!(old & I40E_L4_SRC_MASK); |
| 3259 | new_value = !!(new & I40E_L4_SRC_MASK); |
| 3260 | if (old_value != new_value) |
| 3261 | netif_info(pf, drv, vsi->netdev, "L4 source port: %s -> %s\n", |
| 3262 | old_value ? "ON" : "OFF", |
| 3263 | new_value ? "ON" : "OFF"); |
| 3264 | |
| 3265 | old_value = !!(old & I40E_L4_DST_MASK); |
| 3266 | new_value = !!(new & I40E_L4_DST_MASK); |
| 3267 | if (old_value != new_value) |
| 3268 | netif_info(pf, drv, vsi->netdev, "L4 destination port: %s -> %s\n", |
| 3269 | old_value ? "ON" : "OFF", |
| 3270 | new_value ? "ON" : "OFF"); |
| 3271 | |
| 3272 | old_value = !!(old & I40E_VERIFY_TAG_MASK); |
| 3273 | new_value = !!(new & I40E_VERIFY_TAG_MASK); |
| 3274 | if (old_value != new_value) |
| 3275 | netif_info(pf, drv, vsi->netdev, "SCTP verification tag: %s -> %s\n", |
| 3276 | old_value ? "ON" : "OFF", |
| 3277 | new_value ? "ON" : "OFF"); |
| 3278 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3279 | /* Show change of flexible filter entries */ |
| 3280 | for (i = 0; i < I40E_FLEX_INDEX_ENTRIES; i++) { |
| 3281 | u64 flex_mask = i40e_pit_index_to_mask(i); |
| 3282 | |
| 3283 | old_value = !!(old & flex_mask); |
| 3284 | new_value = !!(new & flex_mask); |
| 3285 | if (old_value != new_value) |
| 3286 | netif_info(pf, drv, vsi->netdev, "FLEX index %d: %s -> %s\n", |
| 3287 | i, |
| 3288 | old_value ? "ON" : "OFF", |
| 3289 | new_value ? "ON" : "OFF"); |
| 3290 | } |
| 3291 | |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3292 | netif_info(pf, drv, vsi->netdev, " Current input set: %0llx\n", |
| 3293 | old); |
| 3294 | netif_info(pf, drv, vsi->netdev, "Requested input set: %0llx\n", |
| 3295 | new); |
| 3296 | } |
| 3297 | |
| 3298 | /** |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3299 | * i40e_check_fdir_input_set - Check that a given rx_flow_spec mask is valid |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3300 | * @vsi: pointer to the targeted VSI |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3301 | * @fsp: pointer to Rx flow specification |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3302 | * @userdef: userdefined data from flow specification |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3303 | * |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3304 | * Ensures that a given ethtool_rx_flow_spec has a valid mask. Some support |
| 3305 | * for partial matches exists with a few limitations. First, hardware only |
| 3306 | * supports masking by word boundary (2 bytes) and not per individual bit. |
| 3307 | * Second, hardware is limited to using one mask for a flow type and cannot |
| 3308 | * use a separate mask for each filter. |
| 3309 | * |
| 3310 | * To support these limitations, if we already have a configured filter for |
| 3311 | * the specified type, this function enforces that new filters of the type |
| 3312 | * match the configured input set. Otherwise, if we do not have a filter of |
| 3313 | * the specified type, we allow the input set to be updated to match the |
| 3314 | * desired filter. |
| 3315 | * |
| 3316 | * To help ensure that administrators understand why filters weren't displayed |
| 3317 | * as supported, we print a diagnostic message displaying how the input set |
| 3318 | * would change and warning to delete the preexisting filters if required. |
| 3319 | * |
| 3320 | * Returns 0 on successful input set match, and a negative return code on |
| 3321 | * failure. |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3322 | **/ |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3323 | static int i40e_check_fdir_input_set(struct i40e_vsi *vsi, |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3324 | struct ethtool_rx_flow_spec *fsp, |
| 3325 | struct i40e_rx_flow_userdef *userdef) |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3326 | { |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3327 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3328 | struct ethtool_tcpip4_spec *tcp_ip4_spec; |
| 3329 | struct ethtool_usrip4_spec *usr_ip4_spec; |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3330 | u64 current_mask, new_mask; |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3331 | bool new_flex_offset = false; |
| 3332 | bool flex_l3 = false; |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3333 | u16 *fdir_filter_count; |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3334 | u16 index, src_offset = 0; |
| 3335 | u8 pit_index = 0; |
| 3336 | int err; |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3337 | |
| 3338 | switch (fsp->flow_type & ~FLOW_EXT) { |
| 3339 | case TCP_V4_FLOW: |
| 3340 | index = I40E_FILTER_PCTYPE_NONF_IPV4_TCP; |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3341 | fdir_filter_count = &pf->fd_tcp4_filter_cnt; |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3342 | break; |
| 3343 | case UDP_V4_FLOW: |
| 3344 | index = I40E_FILTER_PCTYPE_NONF_IPV4_UDP; |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3345 | fdir_filter_count = &pf->fd_udp4_filter_cnt; |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3346 | break; |
| 3347 | case IP_USER_FLOW: |
| 3348 | index = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER; |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3349 | fdir_filter_count = &pf->fd_ip4_filter_cnt; |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3350 | flex_l3 = true; |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3351 | break; |
| 3352 | default: |
| 3353 | return -EOPNOTSUPP; |
| 3354 | } |
| 3355 | |
| 3356 | /* Read the current input set from register memory. */ |
| 3357 | current_mask = i40e_read_fd_input_set(pf, index); |
| 3358 | new_mask = current_mask; |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3359 | |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3360 | /* Determine, if any, the required changes to the input set in order |
| 3361 | * to support the provided mask. |
| 3362 | * |
| 3363 | * Hardware only supports masking at word (2 byte) granularity and does |
| 3364 | * not support full bitwise masking. This implementation simplifies |
| 3365 | * even further and only supports fully enabled or fully disabled |
| 3366 | * masks for each field, even though we could split the ip4src and |
| 3367 | * ip4dst fields. |
| 3368 | */ |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3369 | switch (fsp->flow_type & ~FLOW_EXT) { |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3370 | case TCP_V4_FLOW: |
| 3371 | case UDP_V4_FLOW: |
| 3372 | tcp_ip4_spec = &fsp->m_u.tcp_ip4_spec; |
| 3373 | |
| 3374 | /* IPv4 source address */ |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3375 | if (tcp_ip4_spec->ip4src == htonl(0xFFFFFFFF)) |
| 3376 | new_mask |= I40E_L3_SRC_MASK; |
| 3377 | else if (!tcp_ip4_spec->ip4src) |
| 3378 | new_mask &= ~I40E_L3_SRC_MASK; |
| 3379 | else |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3380 | return -EOPNOTSUPP; |
| 3381 | |
| 3382 | /* IPv4 destination address */ |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3383 | if (tcp_ip4_spec->ip4dst == htonl(0xFFFFFFFF)) |
| 3384 | new_mask |= I40E_L3_DST_MASK; |
| 3385 | else if (!tcp_ip4_spec->ip4dst) |
| 3386 | new_mask &= ~I40E_L3_DST_MASK; |
| 3387 | else |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3388 | return -EOPNOTSUPP; |
| 3389 | |
| 3390 | /* L4 source port */ |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3391 | if (tcp_ip4_spec->psrc == htons(0xFFFF)) |
| 3392 | new_mask |= I40E_L4_SRC_MASK; |
| 3393 | else if (!tcp_ip4_spec->psrc) |
| 3394 | new_mask &= ~I40E_L4_SRC_MASK; |
| 3395 | else |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3396 | return -EOPNOTSUPP; |
| 3397 | |
| 3398 | /* L4 destination port */ |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3399 | if (tcp_ip4_spec->pdst == htons(0xFFFF)) |
| 3400 | new_mask |= I40E_L4_DST_MASK; |
| 3401 | else if (!tcp_ip4_spec->pdst) |
| 3402 | new_mask &= ~I40E_L4_DST_MASK; |
| 3403 | else |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3404 | return -EOPNOTSUPP; |
| 3405 | |
| 3406 | /* Filtering on Type of Service is not supported. */ |
| 3407 | if (tcp_ip4_spec->tos) |
| 3408 | return -EOPNOTSUPP; |
| 3409 | |
| 3410 | break; |
| 3411 | case IP_USER_FLOW: |
| 3412 | usr_ip4_spec = &fsp->m_u.usr_ip4_spec; |
| 3413 | |
| 3414 | /* IPv4 source address */ |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3415 | if (usr_ip4_spec->ip4src == htonl(0xFFFFFFFF)) |
| 3416 | new_mask |= I40E_L3_SRC_MASK; |
| 3417 | else if (!usr_ip4_spec->ip4src) |
| 3418 | new_mask &= ~I40E_L3_SRC_MASK; |
| 3419 | else |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3420 | return -EOPNOTSUPP; |
| 3421 | |
| 3422 | /* IPv4 destination address */ |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3423 | if (usr_ip4_spec->ip4dst == htonl(0xFFFFFFFF)) |
| 3424 | new_mask |= I40E_L3_DST_MASK; |
| 3425 | else if (!usr_ip4_spec->ip4dst) |
| 3426 | new_mask &= ~I40E_L3_DST_MASK; |
| 3427 | else |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3428 | return -EOPNOTSUPP; |
| 3429 | |
| 3430 | /* First 4 bytes of L4 header */ |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3431 | if (usr_ip4_spec->l4_4_bytes == htonl(0xFFFFFFFF)) |
| 3432 | new_mask |= I40E_L4_SRC_MASK | I40E_L4_DST_MASK; |
| 3433 | else if (!usr_ip4_spec->l4_4_bytes) |
| 3434 | new_mask &= ~(I40E_L4_SRC_MASK | I40E_L4_DST_MASK); |
| 3435 | else |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3436 | return -EOPNOTSUPP; |
| 3437 | |
| 3438 | /* Filtering on Type of Service is not supported. */ |
| 3439 | if (usr_ip4_spec->tos) |
| 3440 | return -EOPNOTSUPP; |
| 3441 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3442 | /* Filtering on IP version is not supported */ |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3443 | if (usr_ip4_spec->ip_ver) |
| 3444 | return -EINVAL; |
| 3445 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3446 | /* Filtering on L4 protocol is not supported */ |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3447 | if (usr_ip4_spec->proto) |
| 3448 | return -EINVAL; |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3449 | |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3450 | break; |
| 3451 | default: |
| 3452 | return -EOPNOTSUPP; |
| 3453 | } |
| 3454 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3455 | /* First, clear all flexible filter entries */ |
| 3456 | new_mask &= ~I40E_FLEX_INPUT_MASK; |
| 3457 | |
| 3458 | /* If we have a flexible filter, try to add this offset to the correct |
| 3459 | * flexible filter PIT list. Once finished, we can update the mask. |
| 3460 | * If the src_offset changed, we will get a new mask value which will |
| 3461 | * trigger an input set change. |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3462 | */ |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3463 | if (userdef->flex_filter) { |
| 3464 | struct i40e_flex_pit *l3_flex_pit = NULL, *flex_pit = NULL; |
| 3465 | |
| 3466 | /* Flexible offset must be even, since the flexible payload |
| 3467 | * must be aligned on 2-byte boundary. |
| 3468 | */ |
| 3469 | if (userdef->flex_offset & 0x1) { |
| 3470 | dev_warn(&pf->pdev->dev, |
| 3471 | "Flexible data offset must be 2-byte aligned\n"); |
| 3472 | return -EINVAL; |
| 3473 | } |
| 3474 | |
| 3475 | src_offset = userdef->flex_offset >> 1; |
| 3476 | |
| 3477 | /* FLX_PIT source offset value is only so large */ |
| 3478 | if (src_offset > I40E_MAX_FLEX_SRC_OFFSET) { |
| 3479 | dev_warn(&pf->pdev->dev, |
| 3480 | "Flexible data must reside within first 64 bytes of the packet payload\n"); |
| 3481 | return -EINVAL; |
| 3482 | } |
| 3483 | |
| 3484 | /* See if this offset has already been programmed. If we get |
| 3485 | * an ERR_PTR, then the filter is not safe to add. Otherwise, |
| 3486 | * if we get a NULL pointer, this means we will need to add |
| 3487 | * the offset. |
| 3488 | */ |
| 3489 | flex_pit = i40e_find_flex_offset(&pf->l4_flex_pit_list, |
| 3490 | src_offset); |
| 3491 | if (IS_ERR(flex_pit)) |
| 3492 | return PTR_ERR(flex_pit); |
| 3493 | |
| 3494 | /* IP_USER_FLOW filters match both L4 (ICMP) and L3 (unknown) |
| 3495 | * packet types, and thus we need to program both L3 and L4 |
| 3496 | * flexible values. These must have identical flexible index, |
| 3497 | * as otherwise we can't correctly program the input set. So |
| 3498 | * we'll find both an L3 and L4 index and make sure they are |
| 3499 | * the same. |
| 3500 | */ |
| 3501 | if (flex_l3) { |
| 3502 | l3_flex_pit = |
| 3503 | i40e_find_flex_offset(&pf->l3_flex_pit_list, |
| 3504 | src_offset); |
| 3505 | if (IS_ERR(l3_flex_pit)) |
| 3506 | return PTR_ERR(l3_flex_pit); |
| 3507 | |
| 3508 | if (flex_pit) { |
| 3509 | /* If we already had a matching L4 entry, we |
| 3510 | * need to make sure that the L3 entry we |
| 3511 | * obtained uses the same index. |
| 3512 | */ |
| 3513 | if (l3_flex_pit) { |
| 3514 | if (l3_flex_pit->pit_index != |
| 3515 | flex_pit->pit_index) { |
| 3516 | return -EINVAL; |
| 3517 | } |
| 3518 | } else { |
| 3519 | new_flex_offset = true; |
| 3520 | } |
| 3521 | } else { |
| 3522 | flex_pit = l3_flex_pit; |
| 3523 | } |
| 3524 | } |
| 3525 | |
| 3526 | /* If we didn't find an existing flex offset, we need to |
| 3527 | * program a new one. However, we don't immediately program it |
| 3528 | * here because we will wait to program until after we check |
| 3529 | * that it is safe to change the input set. |
| 3530 | */ |
| 3531 | if (!flex_pit) { |
| 3532 | new_flex_offset = true; |
| 3533 | pit_index = i40e_unused_pit_index(pf); |
| 3534 | } else { |
| 3535 | pit_index = flex_pit->pit_index; |
| 3536 | } |
| 3537 | |
| 3538 | /* Update the mask with the new offset */ |
| 3539 | new_mask |= i40e_pit_index_to_mask(pit_index); |
| 3540 | } |
| 3541 | |
| 3542 | /* If the mask and flexible filter offsets for this filter match the |
| 3543 | * currently programmed values we don't need any input set change, so |
| 3544 | * this filter is safe to install. |
| 3545 | */ |
| 3546 | if (new_mask == current_mask && !new_flex_offset) |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3547 | return 0; |
| 3548 | |
| 3549 | netif_info(pf, drv, vsi->netdev, "Input set change requested for %s flows:\n", |
| 3550 | i40e_flow_str(fsp)); |
| 3551 | i40e_print_input_set(vsi, current_mask, new_mask); |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3552 | if (new_flex_offset) { |
| 3553 | netif_info(pf, drv, vsi->netdev, "FLEX index %d: Offset -> %d", |
| 3554 | pit_index, src_offset); |
| 3555 | } |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3556 | |
| 3557 | /* Hardware input sets are global across multiple ports, so even the |
| 3558 | * main port cannot change them when in MFP mode as this would impact |
| 3559 | * any filters on the other ports. |
| 3560 | */ |
| 3561 | if (pf->flags & I40E_FLAG_MFP_ENABLED) { |
| 3562 | netif_err(pf, drv, vsi->netdev, "Cannot change Flow Director input sets while MFP is enabled\n"); |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3563 | return -EOPNOTSUPP; |
Jacob Keller | 9229e99 | 2017-02-06 14:38:47 -0800 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | /* This filter requires us to update the input set. However, hardware |
| 3567 | * only supports one input set per flow type, and does not support |
| 3568 | * separate masks for each filter. This means that we can only support |
| 3569 | * a single mask for all filters of a specific type. |
| 3570 | * |
| 3571 | * If we have preexisting filters, they obviously depend on the |
| 3572 | * current programmed input set. Display a diagnostic message in this |
| 3573 | * case explaining why the filter could not be accepted. |
| 3574 | */ |
| 3575 | if (*fdir_filter_count) { |
| 3576 | netif_err(pf, drv, vsi->netdev, "Cannot change input set for %s flows until %d preexisting filters are removed\n", |
| 3577 | i40e_flow_str(fsp), |
| 3578 | *fdir_filter_count); |
| 3579 | return -EOPNOTSUPP; |
| 3580 | } |
| 3581 | |
| 3582 | i40e_write_fd_input_set(pf, index, new_mask); |
Jacob Keller | 36777d9 | 2017-03-07 15:05:23 -0800 | [diff] [blame] | 3583 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3584 | /* Add the new offset and update table, if necessary */ |
| 3585 | if (new_flex_offset) { |
| 3586 | err = i40e_add_flex_offset(&pf->l4_flex_pit_list, src_offset, |
| 3587 | pit_index); |
| 3588 | if (err) |
| 3589 | return err; |
| 3590 | |
| 3591 | if (flex_l3) { |
| 3592 | err = i40e_add_flex_offset(&pf->l3_flex_pit_list, |
| 3593 | src_offset, |
| 3594 | pit_index); |
| 3595 | if (err) |
| 3596 | return err; |
| 3597 | } |
| 3598 | |
| 3599 | i40e_reprogram_flex_pit(pf); |
| 3600 | } |
| 3601 | |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3602 | return 0; |
| 3603 | } |
| 3604 | |
| 3605 | /** |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 3606 | * i40e_add_fdir_ethtool - Add/Remove Flow Director filters |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3607 | * @vsi: pointer to the targeted VSI |
| 3608 | * @cmd: command to get or set RX flow classification rules |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3609 | * |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 3610 | * Add Flow Director filters for a specific flow spec based on their |
| 3611 | * protocol. Returns 0 if the filters were successfully added. |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3612 | **/ |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 3613 | static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, |
| 3614 | struct ethtool_rxnfc *cmd) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3615 | { |
Jacob Keller | e793095 | 2017-02-06 14:38:49 -0800 | [diff] [blame] | 3616 | struct i40e_rx_flow_userdef userdef; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3617 | struct ethtool_rx_flow_spec *fsp; |
| 3618 | struct i40e_fdir_filter *input; |
Jacob Keller | 43b1569 | 2017-02-06 14:38:48 -0800 | [diff] [blame] | 3619 | u16 dest_vsi = 0, q_index = 0; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3620 | struct i40e_pf *pf; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3621 | int ret = -EINVAL; |
Jacob Keller | 43b1569 | 2017-02-06 14:38:48 -0800 | [diff] [blame] | 3622 | u8 dest_ctl; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3623 | |
| 3624 | if (!vsi) |
| 3625 | return -EINVAL; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3626 | pf = vsi->back; |
| 3627 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3628 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
| 3629 | return -EOPNOTSUPP; |
| 3630 | |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 3631 | if (pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED) |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3632 | return -ENOSPC; |
| 3633 | |
Anjali Singhai Jain | 60793f4a | 2014-07-09 07:46:23 +0000 | [diff] [blame] | 3634 | if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) || |
| 3635 | test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) |
| 3636 | return -EBUSY; |
| 3637 | |
Anjali Singhai Jain | 1e1be8f | 2014-07-10 08:03:26 +0000 | [diff] [blame] | 3638 | if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state)) |
| 3639 | return -EBUSY; |
| 3640 | |
Anjali Singhai Jain | 55a5e60 | 2014-02-12 06:33:25 +0000 | [diff] [blame] | 3641 | fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 3642 | |
Jacob Keller | e793095 | 2017-02-06 14:38:49 -0800 | [diff] [blame] | 3643 | /* Parse the user-defined field */ |
| 3644 | if (i40e_parse_rx_flow_user_data(fsp, &userdef)) |
| 3645 | return -EINVAL; |
| 3646 | |
Jacob Keller | 1ec8dea | 2017-02-06 14:39:12 -0800 | [diff] [blame] | 3647 | /* Extended MAC field is not supported */ |
| 3648 | if (fsp->flow_type & FLOW_MAC_EXT) |
| 3649 | return -EINVAL; |
| 3650 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3651 | ret = i40e_check_fdir_input_set(vsi, fsp, &userdef); |
Jacob Keller | faa16e0 | 2017-03-07 15:05:22 -0800 | [diff] [blame] | 3652 | if (ret) |
| 3653 | return ret; |
| 3654 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3655 | if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort + |
| 3656 | pf->hw.func_caps.fd_filters_guaranteed)) { |
| 3657 | return -EINVAL; |
| 3658 | } |
| 3659 | |
Jacob Keller | 43b1569 | 2017-02-06 14:38:48 -0800 | [diff] [blame] | 3660 | /* ring_cookie is either the drop index, or is a mask of the queue |
| 3661 | * index and VF id we wish to target. |
| 3662 | */ |
| 3663 | if (fsp->ring_cookie == RX_CLS_FLOW_DISC) { |
| 3664 | dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET; |
| 3665 | } else { |
| 3666 | u32 ring = ethtool_get_flow_spec_ring(fsp->ring_cookie); |
| 3667 | u8 vf = ethtool_get_flow_spec_ring_vf(fsp->ring_cookie); |
| 3668 | |
| 3669 | if (!vf) { |
| 3670 | if (ring >= vsi->num_queue_pairs) |
| 3671 | return -EINVAL; |
| 3672 | dest_vsi = vsi->id; |
| 3673 | } else { |
| 3674 | /* VFs are zero-indexed, so we subtract one here */ |
| 3675 | vf--; |
| 3676 | |
| 3677 | if (vf >= pf->num_alloc_vfs) |
| 3678 | return -EINVAL; |
| 3679 | if (ring >= pf->vf[vf].num_queue_pairs) |
| 3680 | return -EINVAL; |
| 3681 | dest_vsi = pf->vf[vf].lan_vsi_id; |
| 3682 | } |
| 3683 | dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX; |
| 3684 | q_index = ring; |
| 3685 | } |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3686 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3687 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3688 | |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3689 | if (!input) |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3690 | return -ENOMEM; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3691 | |
| 3692 | input->fd_id = fsp->location; |
Jacob Keller | 43b1569 | 2017-02-06 14:38:48 -0800 | [diff] [blame] | 3693 | input->q_index = q_index; |
| 3694 | input->dest_vsi = dest_vsi; |
| 3695 | input->dest_ctl = dest_ctl; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3696 | input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID; |
Anjali Singhai Jain | 0bf4b1b | 2015-04-16 20:06:02 -0400 | [diff] [blame] | 3697 | input->cnt_index = I40E_FD_SB_STAT_IDX(pf->hw.pf_id); |
Jacob Keller | 43b1569 | 2017-02-06 14:38:48 -0800 | [diff] [blame] | 3698 | input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src; |
| 3699 | input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst; |
Jacob Keller | e793095 | 2017-02-06 14:38:49 -0800 | [diff] [blame] | 3700 | input->flow_type = fsp->flow_type & ~FLOW_EXT; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3701 | input->ip4_proto = fsp->h_u.usr_ip4_spec.proto; |
Anjali Singhai Jain | 04b73bd | 2014-05-22 06:31:41 +0000 | [diff] [blame] | 3702 | |
| 3703 | /* Reverse the src and dest notion, since the HW expects them to be from |
| 3704 | * Tx perspective where as the input from user is from Rx filter view. |
| 3705 | */ |
| 3706 | input->dst_port = fsp->h_u.tcp_ip4_spec.psrc; |
| 3707 | input->src_port = fsp->h_u.tcp_ip4_spec.pdst; |
Jacob Keller | 8ce43dc | 2017-02-06 14:38:39 -0800 | [diff] [blame] | 3708 | input->dst_ip = fsp->h_u.tcp_ip4_spec.ip4src; |
| 3709 | input->src_ip = fsp->h_u.tcp_ip4_spec.ip4dst; |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3710 | |
Jacob Keller | 0e588de | 2017-02-06 14:38:50 -0800 | [diff] [blame^] | 3711 | if (userdef.flex_filter) { |
| 3712 | input->flex_filter = true; |
| 3713 | input->flex_word = cpu_to_be16(userdef.flex_word); |
| 3714 | input->flex_offset = userdef.flex_offset; |
| 3715 | } |
| 3716 | |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 3717 | ret = i40e_add_del_fdir(vsi, input, true); |
| 3718 | if (ret) |
Jacob Keller | 01016da | 2017-02-06 14:38:40 -0800 | [diff] [blame] | 3719 | goto free_input; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3720 | |
Jacob Keller | 01016da | 2017-02-06 14:38:40 -0800 | [diff] [blame] | 3721 | /* Add the input filter to the fdir_input_list, possibly replacing |
| 3722 | * a previous filter. Do not free the input structure after adding it |
| 3723 | * to the list as this would cause a use-after-free bug. |
| 3724 | */ |
| 3725 | i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL); |
| 3726 | |
| 3727 | return 0; |
| 3728 | |
| 3729 | free_input: |
| 3730 | kfree(input); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3731 | return ret; |
| 3732 | } |
Jesse Brandeburg | 8fb905b | 2014-01-17 15:36:33 -0800 | [diff] [blame] | 3733 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3734 | /** |
| 3735 | * i40e_set_rxnfc - command to set RX flow classification rules |
| 3736 | * @netdev: network interface device structure |
| 3737 | * @cmd: ethtool rxnfc command |
| 3738 | * |
| 3739 | * Returns Success if the command is supported. |
| 3740 | **/ |
| 3741 | static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) |
| 3742 | { |
| 3743 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3744 | struct i40e_vsi *vsi = np->vsi; |
| 3745 | struct i40e_pf *pf = vsi->back; |
| 3746 | int ret = -EOPNOTSUPP; |
| 3747 | |
| 3748 | switch (cmd->cmd) { |
| 3749 | case ETHTOOL_SRXFH: |
| 3750 | ret = i40e_set_rss_hash_opt(pf, cmd); |
| 3751 | break; |
| 3752 | case ETHTOOL_SRXCLSRLINS: |
Anjali Singhai Jain | 1eaa384 | 2014-03-06 08:59:59 +0000 | [diff] [blame] | 3753 | ret = i40e_add_fdir_ethtool(vsi, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3754 | break; |
| 3755 | case ETHTOOL_SRXCLSRLDEL: |
Joseph Gasparakis | 17a73f6 | 2014-02-12 01:45:30 +0000 | [diff] [blame] | 3756 | ret = i40e_del_fdir_entry(vsi, cmd); |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 3757 | break; |
| 3758 | default: |
| 3759 | break; |
| 3760 | } |
| 3761 | |
| 3762 | return ret; |
| 3763 | } |
| 3764 | |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 3765 | /** |
| 3766 | * i40e_max_channels - get Max number of combined channels supported |
| 3767 | * @vsi: vsi pointer |
| 3768 | **/ |
| 3769 | static unsigned int i40e_max_channels(struct i40e_vsi *vsi) |
| 3770 | { |
| 3771 | /* TODO: This code assumes DCB and FD is disabled for now. */ |
| 3772 | return vsi->alloc_queue_pairs; |
| 3773 | } |
| 3774 | |
| 3775 | /** |
| 3776 | * i40e_get_channels - Get the current channels enabled and max supported etc. |
| 3777 | * @netdev: network interface device structure |
| 3778 | * @ch: ethtool channels structure |
| 3779 | * |
| 3780 | * We don't support separate tx and rx queues as channels. The other count |
| 3781 | * represents how many queues are being used for control. max_combined counts |
| 3782 | * how many queue pairs we can support. They may not be mapped 1 to 1 with |
| 3783 | * q_vectors since we support a lot more queue pairs than q_vectors. |
| 3784 | **/ |
| 3785 | static void i40e_get_channels(struct net_device *dev, |
| 3786 | struct ethtool_channels *ch) |
| 3787 | { |
| 3788 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 3789 | struct i40e_vsi *vsi = np->vsi; |
| 3790 | struct i40e_pf *pf = vsi->back; |
| 3791 | |
| 3792 | /* report maximum channels */ |
| 3793 | ch->max_combined = i40e_max_channels(vsi); |
| 3794 | |
| 3795 | /* report info for other vector */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 3796 | 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] | 3797 | ch->max_other = ch->other_count; |
| 3798 | |
| 3799 | /* Note: This code assumes DCB is disabled for now. */ |
| 3800 | ch->combined_count = vsi->num_queue_pairs; |
| 3801 | } |
| 3802 | |
| 3803 | /** |
| 3804 | * i40e_set_channels - Set the new channels count. |
| 3805 | * @netdev: network interface device structure |
| 3806 | * @ch: ethtool channels structure |
| 3807 | * |
| 3808 | * The new channels count may not be the same as requested by the user |
| 3809 | * since it gets rounded down to a power of 2 value. |
| 3810 | **/ |
| 3811 | static int i40e_set_channels(struct net_device *dev, |
| 3812 | struct ethtool_channels *ch) |
| 3813 | { |
Jacob Keller | 59826d9 | 2016-07-27 12:02:35 -0700 | [diff] [blame] | 3814 | const u8 drop = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET; |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 3815 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 3816 | unsigned int count = ch->combined_count; |
| 3817 | struct i40e_vsi *vsi = np->vsi; |
| 3818 | struct i40e_pf *pf = vsi->back; |
Jacob Keller | 59826d9 | 2016-07-27 12:02:35 -0700 | [diff] [blame] | 3819 | struct i40e_fdir_filter *rule; |
| 3820 | struct hlist_node *node2; |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 3821 | int new_count; |
Jacob Keller | 59826d9 | 2016-07-27 12:02:35 -0700 | [diff] [blame] | 3822 | int err = 0; |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 3823 | |
| 3824 | /* We do not support setting channels for any other VSI at present */ |
| 3825 | if (vsi->type != I40E_VSI_MAIN) |
| 3826 | return -EINVAL; |
| 3827 | |
| 3828 | /* verify they are not requesting separate vectors */ |
| 3829 | if (!count || ch->rx_count || ch->tx_count) |
| 3830 | return -EINVAL; |
| 3831 | |
| 3832 | /* verify other_count has not changed */ |
Jesse Brandeburg | 60ea5f8 | 2014-01-17 15:36:34 -0800 | [diff] [blame] | 3833 | 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] | 3834 | return -EINVAL; |
| 3835 | |
| 3836 | /* verify the number of channels does not exceed hardware limits */ |
| 3837 | if (count > i40e_max_channels(vsi)) |
| 3838 | return -EINVAL; |
| 3839 | |
Jacob Keller | 59826d9 | 2016-07-27 12:02:35 -0700 | [diff] [blame] | 3840 | /* verify that the number of channels does not invalidate any current |
| 3841 | * flow director rules |
| 3842 | */ |
| 3843 | hlist_for_each_entry_safe(rule, node2, |
| 3844 | &pf->fdir_filter_list, fdir_node) { |
| 3845 | if (rule->dest_ctl != drop && count <= rule->q_index) { |
| 3846 | dev_warn(&pf->pdev->dev, |
| 3847 | "Existing user defined filter %d assigns flow to queue %d\n", |
| 3848 | rule->fd_id, rule->q_index); |
| 3849 | err = -EINVAL; |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | if (err) { |
| 3854 | dev_err(&pf->pdev->dev, |
| 3855 | "Existing filter rules must be deleted to reduce combined channel count to %d\n", |
| 3856 | count); |
| 3857 | return err; |
| 3858 | } |
| 3859 | |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 3860 | /* update feature limits from largest to smallest supported values */ |
| 3861 | /* TODO: Flow director limit, DCB etc */ |
| 3862 | |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 3863 | /* use rss_reconfig to rebuild with new queue count and update traffic |
| 3864 | * class queue mapping |
| 3865 | */ |
| 3866 | new_count = i40e_reconfig_rss_queues(pf, count); |
Anjali Singhai Jain | 5f90f42 | 2013-12-21 05:44:43 +0000 | [diff] [blame] | 3867 | if (new_count > 0) |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 3868 | return 0; |
| 3869 | else |
| 3870 | return -EINVAL; |
| 3871 | } |
| 3872 | |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3873 | /** |
| 3874 | * i40e_get_rxfh_key_size - get the RSS hash key size |
| 3875 | * @netdev: network interface device structure |
| 3876 | * |
| 3877 | * Returns the table size. |
| 3878 | **/ |
| 3879 | static u32 i40e_get_rxfh_key_size(struct net_device *netdev) |
| 3880 | { |
| 3881 | return I40E_HKEY_ARRAY_SIZE; |
| 3882 | } |
| 3883 | |
| 3884 | /** |
| 3885 | * i40e_get_rxfh_indir_size - get the rx flow hash indirection table size |
| 3886 | * @netdev: network interface device structure |
| 3887 | * |
| 3888 | * Returns the table size. |
| 3889 | **/ |
| 3890 | static u32 i40e_get_rxfh_indir_size(struct net_device *netdev) |
| 3891 | { |
| 3892 | return I40E_HLUT_ARRAY_SIZE; |
| 3893 | } |
| 3894 | |
| 3895 | static int i40e_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, |
| 3896 | u8 *hfunc) |
| 3897 | { |
| 3898 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3899 | struct i40e_vsi *vsi = np->vsi; |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3900 | u8 *lut, *seed = NULL; |
| 3901 | int ret; |
| 3902 | u16 i; |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3903 | |
| 3904 | if (hfunc) |
| 3905 | *hfunc = ETH_RSS_HASH_TOP; |
| 3906 | |
| 3907 | if (!indir) |
| 3908 | return 0; |
| 3909 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3910 | seed = key; |
| 3911 | lut = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL); |
| 3912 | if (!lut) |
| 3913 | return -ENOMEM; |
| 3914 | ret = i40e_get_rss(vsi, seed, lut, I40E_HLUT_ARRAY_SIZE); |
| 3915 | if (ret) |
| 3916 | goto out; |
| 3917 | for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++) |
| 3918 | indir[i] = (u32)(lut[i]); |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3919 | |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3920 | out: |
| 3921 | kfree(lut); |
| 3922 | |
| 3923 | return ret; |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3924 | } |
| 3925 | |
| 3926 | /** |
| 3927 | * i40e_set_rxfh - set the rx flow hash indirection table |
| 3928 | * @netdev: network interface device structure |
| 3929 | * @indir: indirection table |
| 3930 | * @key: hash key |
| 3931 | * |
Mitch Williams | cd494fb | 2015-07-10 19:36:04 -0400 | [diff] [blame] | 3932 | * Returns -EINVAL if the table specifies an invalid queue id, otherwise |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3933 | * returns 0 after programming the table. |
| 3934 | **/ |
| 3935 | static int i40e_set_rxfh(struct net_device *netdev, const u32 *indir, |
| 3936 | const u8 *key, const u8 hfunc) |
| 3937 | { |
| 3938 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
| 3939 | struct i40e_vsi *vsi = np->vsi; |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 3940 | struct i40e_pf *pf = vsi->back; |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3941 | u8 *seed = NULL; |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3942 | u16 i; |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3943 | |
| 3944 | if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) |
| 3945 | return -EOPNOTSUPP; |
| 3946 | |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3947 | if (key) { |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3948 | if (!vsi->rss_hkey_user) { |
| 3949 | vsi->rss_hkey_user = kzalloc(I40E_HKEY_ARRAY_SIZE, |
| 3950 | GFP_KERNEL); |
| 3951 | if (!vsi->rss_hkey_user) |
| 3952 | return -ENOMEM; |
| 3953 | } |
| 3954 | memcpy(vsi->rss_hkey_user, key, I40E_HKEY_ARRAY_SIZE); |
| 3955 | seed = vsi->rss_hkey_user; |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3956 | } |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3957 | if (!vsi->rss_lut_user) { |
| 3958 | vsi->rss_lut_user = kzalloc(I40E_HLUT_ARRAY_SIZE, GFP_KERNEL); |
| 3959 | if (!vsi->rss_lut_user) |
| 3960 | return -ENOMEM; |
| 3961 | } |
Helin Zhang | 043dd65 | 2015-10-21 19:56:23 -0400 | [diff] [blame] | 3962 | |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3963 | /* Each 32 bits pointed by 'indir' is stored with a lut entry */ |
Alan Brady | f158235 | 2016-08-24 11:33:46 -0700 | [diff] [blame] | 3964 | if (indir) |
| 3965 | for (i = 0; i < I40E_HLUT_ARRAY_SIZE; i++) |
| 3966 | vsi->rss_lut_user[i] = (u8)(indir[i]); |
| 3967 | else |
| 3968 | i40e_fill_rss_lut(pf, vsi->rss_lut_user, I40E_HLUT_ARRAY_SIZE, |
| 3969 | vsi->rss_size); |
Helin Zhang | 28c5869 | 2015-10-26 19:44:27 -0400 | [diff] [blame] | 3970 | |
| 3971 | return i40e_config_rss(vsi, seed, vsi->rss_lut_user, |
| 3972 | I40E_HLUT_ARRAY_SIZE); |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 3973 | } |
| 3974 | |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 3975 | /** |
| 3976 | * i40e_get_priv_flags - report device private flags |
| 3977 | * @dev: network interface device structure |
| 3978 | * |
| 3979 | * The get string set count and the string set should be matched for each |
| 3980 | * flag returned. Add new strings for each flag to the i40e_priv_flags_strings |
| 3981 | * array. |
| 3982 | * |
| 3983 | * Returns a u32 bitmap of flags. |
| 3984 | **/ |
Jesse Brandeburg | 5bbc330 | 2015-02-26 16:15:20 +0000 | [diff] [blame] | 3985 | static u32 i40e_get_priv_flags(struct net_device *dev) |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 3986 | { |
| 3987 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 3988 | struct i40e_vsi *vsi = np->vsi; |
| 3989 | struct i40e_pf *pf = vsi->back; |
| 3990 | u32 ret_flags = 0; |
| 3991 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 3992 | ret_flags |= pf->flags & I40E_FLAG_LINK_POLLING_ENABLED ? |
| 3993 | I40E_PRIV_FLAGS_LINKPOLL_FLAG : 0; |
Jesse Brandeburg | ef17178 | 2015-09-03 17:18:49 -0400 | [diff] [blame] | 3994 | ret_flags |= pf->flags & I40E_FLAG_FD_ATR_ENABLED ? |
| 3995 | I40E_PRIV_FLAGS_FD_ATR : 0; |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 3996 | ret_flags |= pf->flags & I40E_FLAG_VEB_STATS_ENABLED ? |
| 3997 | I40E_PRIV_FLAGS_VEB_STATS : 0; |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 3998 | ret_flags |= pf->hw_disabled_flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE ? |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 3999 | 0 : I40E_PRIV_FLAGS_HW_ATR_EVICT; |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 4000 | if (pf->hw.pf_id == 0) { |
| 4001 | ret_flags |= pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT ? |
| 4002 | I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT : 0; |
| 4003 | } |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 4004 | |
| 4005 | return ret_flags; |
| 4006 | } |
| 4007 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 4008 | /** |
| 4009 | * i40e_set_priv_flags - set private flags |
| 4010 | * @dev: network interface device structure |
| 4011 | * @flags: bit flags to be set |
| 4012 | **/ |
| 4013 | static int i40e_set_priv_flags(struct net_device *dev, u32 flags) |
| 4014 | { |
| 4015 | struct i40e_netdev_priv *np = netdev_priv(dev); |
| 4016 | struct i40e_vsi *vsi = np->vsi; |
| 4017 | struct i40e_pf *pf = vsi->back; |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 4018 | u16 sw_flags = 0, valid_flags = 0; |
Jesse Brandeburg | 827de39 | 2015-11-06 15:26:07 -0800 | [diff] [blame] | 4019 | bool reset_required = false; |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 4020 | bool promisc_change = false; |
| 4021 | int ret; |
Jesse Brandeburg | 827de39 | 2015-11-06 15:26:07 -0800 | [diff] [blame] | 4022 | |
| 4023 | /* NOTE: MFP is not settable */ |
| 4024 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 4025 | if (flags & I40E_PRIV_FLAGS_LINKPOLL_FLAG) |
| 4026 | pf->flags |= I40E_FLAG_LINK_POLLING_ENABLED; |
| 4027 | else |
| 4028 | pf->flags &= ~I40E_FLAG_LINK_POLLING_ENABLED; |
| 4029 | |
Jesse Brandeburg | ef17178 | 2015-09-03 17:18:49 -0400 | [diff] [blame] | 4030 | /* allow the user to control the state of the Flow |
| 4031 | * Director ATR (Application Targeted Routing) feature |
| 4032 | * of the driver |
| 4033 | */ |
| 4034 | if (flags & I40E_PRIV_FLAGS_FD_ATR) { |
| 4035 | pf->flags |= I40E_FLAG_FD_ATR_ENABLED; |
| 4036 | } else { |
| 4037 | pf->flags &= ~I40E_FLAG_FD_ATR_ENABLED; |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 4038 | pf->hw_disabled_flags |= I40E_FLAG_FD_ATR_ENABLED; |
Jacob Keller | 234dc4e | 2016-09-06 18:05:09 -0700 | [diff] [blame] | 4039 | |
| 4040 | /* flush current ATR settings */ |
| 4041 | set_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state); |
Jesse Brandeburg | ef17178 | 2015-09-03 17:18:49 -0400 | [diff] [blame] | 4042 | } |
| 4043 | |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 4044 | if ((flags & I40E_PRIV_FLAGS_VEB_STATS) && |
| 4045 | !(pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 4046 | pf->flags |= I40E_FLAG_VEB_STATS_ENABLED; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 4047 | reset_required = true; |
| 4048 | } else if (!(flags & I40E_PRIV_FLAGS_VEB_STATS) && |
| 4049 | (pf->flags & I40E_FLAG_VEB_STATS_ENABLED)) { |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 4050 | pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED; |
Shannon Nelson | 66fc360 | 2016-01-13 16:51:42 -0800 | [diff] [blame] | 4051 | reset_required = true; |
| 4052 | } |
Shannon Nelson | 1cdfd88 | 2015-09-28 14:12:34 -0400 | [diff] [blame] | 4053 | |
Anjali Singhai Jain | b556989 | 2016-05-03 15:13:12 -0700 | [diff] [blame] | 4054 | if (pf->hw.pf_id == 0) { |
| 4055 | if ((flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) && |
| 4056 | !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) { |
| 4057 | pf->flags |= I40E_FLAG_TRUE_PROMISC_SUPPORT; |
| 4058 | promisc_change = true; |
| 4059 | } else if (!(flags & I40E_PRIV_FLAGS_TRUE_PROMISC_SUPPORT) && |
| 4060 | (pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) { |
| 4061 | pf->flags &= ~I40E_FLAG_TRUE_PROMISC_SUPPORT; |
| 4062 | promisc_change = true; |
| 4063 | } |
| 4064 | } |
| 4065 | if (promisc_change) { |
| 4066 | if (!(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT)) |
| 4067 | sw_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 4068 | valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC; |
| 4069 | ret = i40e_aq_set_switch_config(&pf->hw, sw_flags, valid_flags, |
| 4070 | NULL); |
| 4071 | if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) { |
| 4072 | dev_info(&pf->pdev->dev, |
| 4073 | "couldn't set switch config bits, err %s aq_err %s\n", |
| 4074 | i40e_stat_str(&pf->hw, ret), |
| 4075 | i40e_aq_str(&pf->hw, |
| 4076 | pf->hw.aq.asq_last_status)); |
| 4077 | /* not a fatal problem, just keep going */ |
| 4078 | } |
| 4079 | } |
| 4080 | |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 4081 | if ((flags & I40E_PRIV_FLAGS_HW_ATR_EVICT) && |
| 4082 | (pf->flags & I40E_FLAG_HW_ATR_EVICT_CAPABLE)) |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 4083 | pf->hw_disabled_flags &= ~I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 4084 | else |
Harshitha Ramamurthy | b77ac97 | 2017-02-03 10:57:42 -0800 | [diff] [blame] | 4085 | pf->hw_disabled_flags |= I40E_FLAG_HW_ATR_EVICT_CAPABLE; |
Anjali Singhai Jain | 72b7486 | 2016-01-08 17:50:21 -0800 | [diff] [blame] | 4086 | |
Jesse Brandeburg | 827de39 | 2015-11-06 15:26:07 -0800 | [diff] [blame] | 4087 | /* if needed, issue reset to cause things to take effect */ |
| 4088 | if (reset_required) |
| 4089 | i40e_do_reset(pf, BIT(__I40E_PF_RESET_REQUESTED)); |
| 4090 | |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 4091 | return 0; |
| 4092 | } |
| 4093 | |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 4094 | static const struct ethtool_ops i40e_ethtool_ops = { |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 4095 | .get_drvinfo = i40e_get_drvinfo, |
| 4096 | .get_regs_len = i40e_get_regs_len, |
| 4097 | .get_regs = i40e_get_regs, |
| 4098 | .nway_reset = i40e_nway_reset, |
| 4099 | .get_link = ethtool_op_get_link, |
| 4100 | .get_wol = i40e_get_wol, |
Shannon Nelson | 8e2773a | 2013-11-28 06:39:22 +0000 | [diff] [blame] | 4101 | .set_wol = i40e_set_wol, |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 4102 | .set_eeprom = i40e_set_eeprom, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 4103 | .get_eeprom_len = i40e_get_eeprom_len, |
| 4104 | .get_eeprom = i40e_get_eeprom, |
| 4105 | .get_ringparam = i40e_get_ringparam, |
| 4106 | .set_ringparam = i40e_set_ringparam, |
| 4107 | .get_pauseparam = i40e_get_pauseparam, |
Catherine Sullivan | 2becc35 | 2014-06-04 08:45:27 +0000 | [diff] [blame] | 4108 | .set_pauseparam = i40e_set_pauseparam, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 4109 | .get_msglevel = i40e_get_msglevel, |
| 4110 | .set_msglevel = i40e_set_msglevel, |
| 4111 | .get_rxnfc = i40e_get_rxnfc, |
| 4112 | .set_rxnfc = i40e_set_rxnfc, |
| 4113 | .self_test = i40e_diag_test, |
| 4114 | .get_strings = i40e_get_strings, |
| 4115 | .set_phys_id = i40e_set_phys_id, |
| 4116 | .get_sset_count = i40e_get_sset_count, |
| 4117 | .get_ethtool_stats = i40e_get_ethtool_stats, |
| 4118 | .get_coalesce = i40e_get_coalesce, |
| 4119 | .set_coalesce = i40e_set_coalesce, |
Mitch A Williams | b29e13b | 2015-03-05 04:14:40 +0000 | [diff] [blame] | 4120 | .get_rxfh_key_size = i40e_get_rxfh_key_size, |
| 4121 | .get_rxfh_indir_size = i40e_get_rxfh_indir_size, |
| 4122 | .get_rxfh = i40e_get_rxfh, |
| 4123 | .set_rxfh = i40e_set_rxfh, |
Anjali Singhai Jain | 4b7820c | 2013-11-26 11:59:30 +0000 | [diff] [blame] | 4124 | .get_channels = i40e_get_channels, |
| 4125 | .set_channels = i40e_set_channels, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 4126 | .get_ts_info = i40e_get_ts_info, |
Greg Rose | 7e45ab4 | 2015-02-06 08:52:19 +0000 | [diff] [blame] | 4127 | .get_priv_flags = i40e_get_priv_flags, |
Shannon Nelson | 9ac7726 | 2015-08-27 11:42:40 -0400 | [diff] [blame] | 4128 | .set_priv_flags = i40e_set_priv_flags, |
Kan Liang | be280ba | 2016-02-19 09:24:05 -0500 | [diff] [blame] | 4129 | .get_per_queue_coalesce = i40e_get_per_queue_coalesce, |
Kan Liang | f3757a4 | 2016-02-19 09:24:06 -0500 | [diff] [blame] | 4130 | .set_per_queue_coalesce = i40e_set_per_queue_coalesce, |
Philippe Reynes | a7f9094 | 2017-02-04 22:05:06 +0100 | [diff] [blame] | 4131 | .get_link_ksettings = i40e_get_link_ksettings, |
| 4132 | .set_link_ksettings = i40e_set_link_ksettings, |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 4133 | }; |
| 4134 | |
| 4135 | void i40e_set_ethtool_ops(struct net_device *netdev) |
| 4136 | { |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 4137 | netdev->ethtool_ops = &i40e_ethtool_ops; |
Jesse Brandeburg | c7d05ca | 2013-09-11 08:39:56 +0000 | [diff] [blame] | 4138 | } |