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