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