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