Commit | Line | Data |
---|---|---|
c7d05ca8 JB |
1 | /******************************************************************************* |
2 | * | |
3 | * Intel Ethernet Controller XL710 Family Linux Driver | |
dc641b73 | 4 | * Copyright(c) 2013 - 2014 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 | } | |
43 | #define I40E_NETDEV_STAT(_net_stat) \ | |
44 | I40E_STAT(struct net_device_stats, #_net_stat, _net_stat) | |
45 | #define I40E_PF_STAT(_name, _stat) \ | |
46 | I40E_STAT(struct i40e_pf, _name, _stat) | |
47 | #define I40E_VSI_STAT(_name, _stat) \ | |
48 | I40E_STAT(struct i40e_vsi, _name, _stat) | |
49 | ||
50 | static const struct i40e_stats i40e_gstrings_net_stats[] = { | |
51 | I40E_NETDEV_STAT(rx_packets), | |
52 | I40E_NETDEV_STAT(tx_packets), | |
53 | I40E_NETDEV_STAT(rx_bytes), | |
54 | I40E_NETDEV_STAT(tx_bytes), | |
55 | I40E_NETDEV_STAT(rx_errors), | |
56 | I40E_NETDEV_STAT(tx_errors), | |
57 | I40E_NETDEV_STAT(rx_dropped), | |
58 | I40E_NETDEV_STAT(tx_dropped), | |
59 | I40E_NETDEV_STAT(multicast), | |
60 | I40E_NETDEV_STAT(collisions), | |
61 | I40E_NETDEV_STAT(rx_length_errors), | |
62 | I40E_NETDEV_STAT(rx_crc_errors), | |
63 | }; | |
64 | ||
1eaa3840 ASJ |
65 | static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, |
66 | struct ethtool_rxnfc *cmd); | |
17a73f6b | 67 | |
c7d05ca8 JB |
68 | /* These PF_STATs might look like duplicates of some NETDEV_STATs, |
69 | * but they are separate. This device supports Virtualization, and | |
70 | * as such might have several netdevs supporting VMDq and FCoE going | |
71 | * through a single port. The NETDEV_STATs are for individual netdevs | |
72 | * seen at the top of the stack, and the PF_STATs are for the physical | |
73 | * function at the bottom of the stack hosting those netdevs. | |
74 | * | |
75 | * The PF_STATs are appended to the netdev stats only when ethtool -S | |
76 | * is queried on the base PF netdev, not on the VMDq or FCoE netdev. | |
77 | */ | |
78 | static struct i40e_stats i40e_gstrings_stats[] = { | |
79 | I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes), | |
80 | I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes), | |
81 | I40E_PF_STAT("rx_errors", stats.eth.rx_errors), | |
82 | I40E_PF_STAT("tx_errors", stats.eth.tx_errors), | |
83 | I40E_PF_STAT("rx_dropped", stats.eth.rx_discards), | |
84 | I40E_PF_STAT("tx_dropped", stats.eth.tx_discards), | |
85 | I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down), | |
86 | I40E_PF_STAT("crc_errors", stats.crc_errors), | |
87 | I40E_PF_STAT("illegal_bytes", stats.illegal_bytes), | |
88 | I40E_PF_STAT("mac_local_faults", stats.mac_local_faults), | |
89 | I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults), | |
a47a15f4 | 90 | I40E_PF_STAT("tx_timeout", tx_timeout_count), |
c7d05ca8 JB |
91 | I40E_PF_STAT("rx_length_errors", stats.rx_length_errors), |
92 | I40E_PF_STAT("link_xon_rx", stats.link_xon_rx), | |
93 | I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx), | |
94 | I40E_PF_STAT("link_xon_tx", stats.link_xon_tx), | |
95 | I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx), | |
96 | I40E_PF_STAT("rx_size_64", stats.rx_size_64), | |
97 | I40E_PF_STAT("rx_size_127", stats.rx_size_127), | |
98 | I40E_PF_STAT("rx_size_255", stats.rx_size_255), | |
99 | I40E_PF_STAT("rx_size_511", stats.rx_size_511), | |
100 | I40E_PF_STAT("rx_size_1023", stats.rx_size_1023), | |
101 | I40E_PF_STAT("rx_size_1522", stats.rx_size_1522), | |
102 | I40E_PF_STAT("rx_size_big", stats.rx_size_big), | |
103 | I40E_PF_STAT("tx_size_64", stats.tx_size_64), | |
104 | I40E_PF_STAT("tx_size_127", stats.tx_size_127), | |
105 | I40E_PF_STAT("tx_size_255", stats.tx_size_255), | |
106 | I40E_PF_STAT("tx_size_511", stats.tx_size_511), | |
107 | I40E_PF_STAT("tx_size_1023", stats.tx_size_1023), | |
108 | I40E_PF_STAT("tx_size_1522", stats.tx_size_1522), | |
109 | I40E_PF_STAT("tx_size_big", stats.tx_size_big), | |
110 | I40E_PF_STAT("rx_undersize", stats.rx_undersize), | |
111 | I40E_PF_STAT("rx_fragments", stats.rx_fragments), | |
112 | I40E_PF_STAT("rx_oversize", stats.rx_oversize), | |
113 | I40E_PF_STAT("rx_jabber", stats.rx_jabber), | |
114 | I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests), | |
beb0dff1 JK |
115 | I40E_PF_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts), |
116 | I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared), | |
bee5af7e ASJ |
117 | /* LPI stats */ |
118 | I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status), | |
119 | I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status), | |
120 | I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count), | |
121 | I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count), | |
c7d05ca8 JB |
122 | }; |
123 | ||
124 | #define I40E_QUEUE_STATS_LEN(n) \ | |
125 | ((((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs + \ | |
126 | ((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs) * 2) | |
127 | #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats) | |
128 | #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats) | |
129 | #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \ | |
130 | I40E_QUEUE_STATS_LEN((n))) | |
131 | #define I40E_PFC_STATS_LEN ( \ | |
132 | (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \ | |
133 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \ | |
134 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \ | |
135 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \ | |
136 | FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \ | |
137 | / sizeof(u64)) | |
138 | #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \ | |
139 | I40E_PFC_STATS_LEN + \ | |
140 | I40E_VSI_STATS_LEN((n))) | |
141 | ||
142 | enum i40e_ethtool_test_id { | |
143 | I40E_ETH_TEST_REG = 0, | |
144 | I40E_ETH_TEST_EEPROM, | |
145 | I40E_ETH_TEST_INTR, | |
146 | I40E_ETH_TEST_LOOPBACK, | |
147 | I40E_ETH_TEST_LINK, | |
148 | }; | |
149 | ||
150 | static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = { | |
151 | "Register test (offline)", | |
152 | "Eeprom test (offline)", | |
153 | "Interrupt test (offline)", | |
154 | "Loopback test (offline)", | |
155 | "Link test (on/offline)" | |
156 | }; | |
157 | ||
158 | #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN) | |
159 | ||
160 | /** | |
161 | * i40e_get_settings - Get Link Speed and Duplex settings | |
162 | * @netdev: network interface device structure | |
163 | * @ecmd: ethtool command | |
164 | * | |
165 | * Reports speed/duplex settings based on media_type | |
166 | **/ | |
167 | static int i40e_get_settings(struct net_device *netdev, | |
168 | struct ethtool_cmd *ecmd) | |
169 | { | |
170 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
171 | struct i40e_pf *pf = np->vsi->back; | |
172 | struct i40e_hw *hw = &pf->hw; | |
173 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; | |
174 | bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP; | |
175 | u32 link_speed = hw_link_info->link_speed; | |
176 | ||
177 | /* hardware is either in 40G mode or 10G mode | |
178 | * NOTE: this section initializes supported and advertising | |
179 | */ | |
180 | switch (hw_link_info->phy_type) { | |
181 | case I40E_PHY_TYPE_40GBASE_CR4: | |
182 | case I40E_PHY_TYPE_40GBASE_CR4_CU: | |
183 | ecmd->supported = SUPPORTED_40000baseCR4_Full; | |
184 | ecmd->advertising = ADVERTISED_40000baseCR4_Full; | |
185 | break; | |
186 | case I40E_PHY_TYPE_40GBASE_KR4: | |
187 | ecmd->supported = SUPPORTED_40000baseKR4_Full; | |
188 | ecmd->advertising = ADVERTISED_40000baseKR4_Full; | |
189 | break; | |
190 | case I40E_PHY_TYPE_40GBASE_SR4: | |
191 | ecmd->supported = SUPPORTED_40000baseSR4_Full; | |
192 | ecmd->advertising = ADVERTISED_40000baseSR4_Full; | |
193 | break; | |
194 | case I40E_PHY_TYPE_40GBASE_LR4: | |
195 | ecmd->supported = SUPPORTED_40000baseLR4_Full; | |
196 | ecmd->advertising = ADVERTISED_40000baseLR4_Full; | |
197 | break; | |
198 | case I40E_PHY_TYPE_10GBASE_KX4: | |
199 | ecmd->supported = SUPPORTED_10000baseKX4_Full; | |
200 | ecmd->advertising = ADVERTISED_10000baseKX4_Full; | |
201 | break; | |
202 | case I40E_PHY_TYPE_10GBASE_KR: | |
203 | ecmd->supported = SUPPORTED_10000baseKR_Full; | |
204 | ecmd->advertising = ADVERTISED_10000baseKR_Full; | |
205 | break; | |
c7d05ca8 | 206 | default: |
c9a3d471 JB |
207 | if (i40e_is_40G_device(hw->device_id)) { |
208 | ecmd->supported = SUPPORTED_40000baseSR4_Full; | |
209 | ecmd->advertising = ADVERTISED_40000baseSR4_Full; | |
210 | } else { | |
211 | ecmd->supported = SUPPORTED_10000baseT_Full; | |
212 | ecmd->advertising = ADVERTISED_10000baseT_Full; | |
213 | } | |
c7d05ca8 JB |
214 | break; |
215 | } | |
216 | ||
c7d05ca8 | 217 | ecmd->supported |= SUPPORTED_Autoneg; |
c9a3d471 JB |
218 | ecmd->advertising |= ADVERTISED_Autoneg; |
219 | ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? | |
220 | AUTONEG_ENABLE : AUTONEG_DISABLE); | |
c7d05ca8 | 221 | |
c9a3d471 JB |
222 | switch (hw->phy.media_type) { |
223 | case I40E_MEDIA_TYPE_BACKPLANE: | |
c7d05ca8 JB |
224 | ecmd->supported |= SUPPORTED_Backplane; |
225 | ecmd->advertising |= ADVERTISED_Backplane; | |
226 | ecmd->port = PORT_NONE; | |
c9a3d471 JB |
227 | break; |
228 | case I40E_MEDIA_TYPE_BASET: | |
c7d05ca8 JB |
229 | ecmd->supported |= SUPPORTED_TP; |
230 | ecmd->advertising |= ADVERTISED_TP; | |
231 | ecmd->port = PORT_TP; | |
c9a3d471 JB |
232 | break; |
233 | case I40E_MEDIA_TYPE_DA: | |
234 | case I40E_MEDIA_TYPE_CX4: | |
be405eb0 JB |
235 | ecmd->supported |= SUPPORTED_FIBRE; |
236 | ecmd->advertising |= ADVERTISED_FIBRE; | |
237 | ecmd->port = PORT_DA; | |
c9a3d471 JB |
238 | break; |
239 | case I40E_MEDIA_TYPE_FIBER: | |
c7d05ca8 JB |
240 | ecmd->supported |= SUPPORTED_FIBRE; |
241 | ecmd->advertising |= ADVERTISED_FIBRE; | |
242 | ecmd->port = PORT_FIBRE; | |
c9a3d471 JB |
243 | break; |
244 | case I40E_MEDIA_TYPE_UNKNOWN: | |
245 | default: | |
246 | ecmd->port = PORT_OTHER; | |
247 | break; | |
c7d05ca8 JB |
248 | } |
249 | ||
250 | ecmd->transceiver = XCVR_EXTERNAL; | |
251 | ||
252 | if (link_up) { | |
253 | switch (link_speed) { | |
254 | case I40E_LINK_SPEED_40GB: | |
255 | /* need a SPEED_40000 in ethtool.h */ | |
256 | ethtool_cmd_speed_set(ecmd, 40000); | |
257 | break; | |
258 | case I40E_LINK_SPEED_10GB: | |
259 | ethtool_cmd_speed_set(ecmd, SPEED_10000); | |
260 | break; | |
261 | default: | |
262 | break; | |
263 | } | |
264 | ecmd->duplex = DUPLEX_FULL; | |
265 | } else { | |
266 | ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN); | |
267 | ecmd->duplex = DUPLEX_UNKNOWN; | |
268 | } | |
269 | ||
270 | return 0; | |
271 | } | |
272 | ||
273 | /** | |
274 | * i40e_get_pauseparam - Get Flow Control status | |
275 | * Return tx/rx-pause status | |
276 | **/ | |
277 | static void i40e_get_pauseparam(struct net_device *netdev, | |
278 | struct ethtool_pauseparam *pause) | |
279 | { | |
280 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
281 | struct i40e_pf *pf = np->vsi->back; | |
282 | struct i40e_hw *hw = &pf->hw; | |
283 | struct i40e_link_status *hw_link_info = &hw->phy.link_info; | |
284 | ||
285 | pause->autoneg = | |
286 | ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ? | |
287 | AUTONEG_ENABLE : AUTONEG_DISABLE); | |
288 | ||
d52c20b7 | 289 | if (hw->fc.current_mode == I40E_FC_RX_PAUSE) { |
c7d05ca8 | 290 | pause->rx_pause = 1; |
d52c20b7 | 291 | } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) { |
c7d05ca8 | 292 | pause->tx_pause = 1; |
d52c20b7 JB |
293 | } else if (hw->fc.current_mode == I40E_FC_FULL) { |
294 | pause->rx_pause = 1; | |
295 | pause->tx_pause = 1; | |
296 | } | |
c7d05ca8 JB |
297 | } |
298 | ||
299 | static u32 i40e_get_msglevel(struct net_device *netdev) | |
300 | { | |
301 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
302 | struct i40e_pf *pf = np->vsi->back; | |
303 | ||
304 | return pf->msg_enable; | |
305 | } | |
306 | ||
307 | static void i40e_set_msglevel(struct net_device *netdev, u32 data) | |
308 | { | |
309 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
310 | struct i40e_pf *pf = np->vsi->back; | |
311 | ||
312 | if (I40E_DEBUG_USER & data) | |
313 | pf->hw.debug_mask = data; | |
314 | pf->msg_enable = data; | |
315 | } | |
316 | ||
317 | static int i40e_get_regs_len(struct net_device *netdev) | |
318 | { | |
319 | int reg_count = 0; | |
320 | int i; | |
321 | ||
322 | for (i = 0; i40e_reg_list[i].offset != 0; i++) | |
323 | reg_count += i40e_reg_list[i].elements; | |
324 | ||
325 | return reg_count * sizeof(u32); | |
326 | } | |
327 | ||
328 | static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs, | |
329 | void *p) | |
330 | { | |
331 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
332 | struct i40e_pf *pf = np->vsi->back; | |
333 | struct i40e_hw *hw = &pf->hw; | |
334 | u32 *reg_buf = p; | |
335 | int i, j, ri; | |
336 | u32 reg; | |
337 | ||
338 | /* Tell ethtool which driver-version-specific regs output we have. | |
339 | * | |
340 | * At some point, if we have ethtool doing special formatting of | |
341 | * this data, it will rely on this version number to know how to | |
342 | * interpret things. Hence, this needs to be updated if/when the | |
343 | * diags register table is changed. | |
344 | */ | |
345 | regs->version = 1; | |
346 | ||
347 | /* loop through the diags reg table for what to print */ | |
348 | ri = 0; | |
349 | for (i = 0; i40e_reg_list[i].offset != 0; i++) { | |
350 | for (j = 0; j < i40e_reg_list[i].elements; j++) { | |
351 | reg = i40e_reg_list[i].offset | |
352 | + (j * i40e_reg_list[i].stride); | |
353 | reg_buf[ri++] = rd32(hw, reg); | |
354 | } | |
355 | } | |
356 | ||
357 | } | |
358 | ||
359 | static int i40e_get_eeprom(struct net_device *netdev, | |
360 | struct ethtool_eeprom *eeprom, u8 *bytes) | |
361 | { | |
362 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
363 | struct i40e_hw *hw = &np->vsi->back->hw; | |
e5e0a5db ASJ |
364 | struct i40e_pf *pf = np->vsi->back; |
365 | int ret_val = 0, len; | |
366 | u8 *eeprom_buff; | |
367 | u16 i, sectors; | |
368 | bool last; | |
369 | #define I40E_NVM_SECTOR_SIZE 4096 | |
c7d05ca8 JB |
370 | if (eeprom->len == 0) |
371 | return -EINVAL; | |
372 | ||
373 | eeprom->magic = hw->vendor_id | (hw->device_id << 16); | |
374 | ||
e5e0a5db | 375 | eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL); |
c7d05ca8 JB |
376 | if (!eeprom_buff) |
377 | return -ENOMEM; | |
378 | ||
e5e0a5db ASJ |
379 | ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ); |
380 | if (ret_val) { | |
381 | dev_info(&pf->pdev->dev, | |
382 | "Failed Acquiring NVM resource for read err=%d status=0x%x\n", | |
383 | ret_val, hw->aq.asq_last_status); | |
384 | goto free_buff; | |
c7d05ca8 JB |
385 | } |
386 | ||
e5e0a5db ASJ |
387 | sectors = eeprom->len / I40E_NVM_SECTOR_SIZE; |
388 | sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0; | |
389 | len = I40E_NVM_SECTOR_SIZE; | |
390 | last = false; | |
391 | for (i = 0; i < sectors; i++) { | |
392 | if (i == (sectors - 1)) { | |
393 | len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i); | |
394 | last = true; | |
395 | } | |
396 | ret_val = i40e_aq_read_nvm(hw, 0x0, | |
397 | eeprom->offset + (I40E_NVM_SECTOR_SIZE * i), | |
398 | len, | |
399 | (u8 *)eeprom_buff + (I40E_NVM_SECTOR_SIZE * i), | |
400 | last, NULL); | |
401 | if (ret_val) { | |
402 | dev_info(&pf->pdev->dev, | |
403 | "read NVM failed err=%d status=0x%x\n", | |
404 | ret_val, hw->aq.asq_last_status); | |
405 | goto release_nvm; | |
406 | } | |
407 | } | |
c7d05ca8 | 408 | |
e5e0a5db ASJ |
409 | release_nvm: |
410 | i40e_release_nvm(hw); | |
411 | memcpy(bytes, (u8 *)eeprom_buff, eeprom->len); | |
412 | free_buff: | |
c7d05ca8 | 413 | kfree(eeprom_buff); |
c7d05ca8 JB |
414 | return ret_val; |
415 | } | |
416 | ||
417 | static int i40e_get_eeprom_len(struct net_device *netdev) | |
418 | { | |
419 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
420 | struct i40e_hw *hw = &np->vsi->back->hw; | |
e5e0a5db ASJ |
421 | u32 val; |
422 | ||
423 | val = (rd32(hw, I40E_GLPCI_LBARCTRL) | |
424 | & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK) | |
425 | >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT; | |
426 | /* register returns value in power of 2, 64Kbyte chunks. */ | |
427 | val = (64 * 1024) * (1 << val); | |
428 | return val; | |
c7d05ca8 JB |
429 | } |
430 | ||
431 | static void i40e_get_drvinfo(struct net_device *netdev, | |
432 | struct ethtool_drvinfo *drvinfo) | |
433 | { | |
434 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
435 | struct i40e_vsi *vsi = np->vsi; | |
436 | struct i40e_pf *pf = vsi->back; | |
437 | ||
438 | strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver)); | |
439 | strlcpy(drvinfo->version, i40e_driver_version_str, | |
440 | sizeof(drvinfo->version)); | |
441 | strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw), | |
442 | sizeof(drvinfo->fw_version)); | |
443 | strlcpy(drvinfo->bus_info, pci_name(pf->pdev), | |
444 | sizeof(drvinfo->bus_info)); | |
445 | } | |
446 | ||
447 | static void i40e_get_ringparam(struct net_device *netdev, | |
448 | struct ethtool_ringparam *ring) | |
449 | { | |
450 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
451 | struct i40e_pf *pf = np->vsi->back; | |
452 | struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi]; | |
453 | ||
454 | ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS; | |
455 | ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS; | |
456 | ring->rx_mini_max_pending = 0; | |
457 | ring->rx_jumbo_max_pending = 0; | |
9f65e15b AD |
458 | ring->rx_pending = vsi->rx_rings[0]->count; |
459 | ring->tx_pending = vsi->tx_rings[0]->count; | |
c7d05ca8 JB |
460 | ring->rx_mini_pending = 0; |
461 | ring->rx_jumbo_pending = 0; | |
462 | } | |
463 | ||
464 | static int i40e_set_ringparam(struct net_device *netdev, | |
465 | struct ethtool_ringparam *ring) | |
466 | { | |
467 | struct i40e_ring *tx_rings = NULL, *rx_rings = NULL; | |
468 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
469 | struct i40e_vsi *vsi = np->vsi; | |
470 | struct i40e_pf *pf = vsi->back; | |
471 | u32 new_rx_count, new_tx_count; | |
472 | int i, err = 0; | |
473 | ||
474 | if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) | |
475 | return -EINVAL; | |
476 | ||
1fa18370 SN |
477 | if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS || |
478 | ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS || | |
479 | ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS || | |
480 | ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) { | |
481 | netdev_info(netdev, | |
482 | "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n", | |
483 | ring->tx_pending, ring->rx_pending, | |
484 | I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS); | |
485 | return -EINVAL; | |
486 | } | |
487 | ||
488 | new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); | |
489 | new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE); | |
c7d05ca8 JB |
490 | |
491 | /* if nothing to do return success */ | |
9f65e15b AD |
492 | if ((new_tx_count == vsi->tx_rings[0]->count) && |
493 | (new_rx_count == vsi->rx_rings[0]->count)) | |
c7d05ca8 JB |
494 | return 0; |
495 | ||
496 | while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state)) | |
497 | usleep_range(1000, 2000); | |
498 | ||
499 | if (!netif_running(vsi->netdev)) { | |
500 | /* simple case - set for the next time the netdev is started */ | |
501 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b AD |
502 | vsi->tx_rings[i]->count = new_tx_count; |
503 | vsi->rx_rings[i]->count = new_rx_count; | |
c7d05ca8 JB |
504 | } |
505 | goto done; | |
506 | } | |
507 | ||
508 | /* We can't just free everything and then setup again, | |
509 | * because the ISRs in MSI-X mode get passed pointers | |
510 | * to the Tx and Rx ring structs. | |
511 | */ | |
512 | ||
513 | /* alloc updated Tx resources */ | |
9f65e15b | 514 | if (new_tx_count != vsi->tx_rings[0]->count) { |
c7d05ca8 JB |
515 | netdev_info(netdev, |
516 | "Changing Tx descriptor count from %d to %d.\n", | |
9f65e15b | 517 | vsi->tx_rings[0]->count, new_tx_count); |
c7d05ca8 JB |
518 | tx_rings = kcalloc(vsi->alloc_queue_pairs, |
519 | sizeof(struct i40e_ring), GFP_KERNEL); | |
520 | if (!tx_rings) { | |
521 | err = -ENOMEM; | |
522 | goto done; | |
523 | } | |
524 | ||
525 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
526 | /* clone ring and setup updated count */ | |
9f65e15b | 527 | tx_rings[i] = *vsi->tx_rings[i]; |
c7d05ca8 JB |
528 | tx_rings[i].count = new_tx_count; |
529 | err = i40e_setup_tx_descriptors(&tx_rings[i]); | |
530 | if (err) { | |
531 | while (i) { | |
532 | i--; | |
533 | i40e_free_tx_resources(&tx_rings[i]); | |
534 | } | |
535 | kfree(tx_rings); | |
536 | tx_rings = NULL; | |
537 | ||
538 | goto done; | |
539 | } | |
540 | } | |
541 | } | |
542 | ||
543 | /* alloc updated Rx resources */ | |
9f65e15b | 544 | if (new_rx_count != vsi->rx_rings[0]->count) { |
c7d05ca8 JB |
545 | netdev_info(netdev, |
546 | "Changing Rx descriptor count from %d to %d\n", | |
9f65e15b | 547 | vsi->rx_rings[0]->count, new_rx_count); |
c7d05ca8 JB |
548 | rx_rings = kcalloc(vsi->alloc_queue_pairs, |
549 | sizeof(struct i40e_ring), GFP_KERNEL); | |
550 | if (!rx_rings) { | |
551 | err = -ENOMEM; | |
552 | goto free_tx; | |
553 | } | |
554 | ||
555 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
556 | /* clone ring and setup updated count */ | |
9f65e15b | 557 | rx_rings[i] = *vsi->rx_rings[i]; |
c7d05ca8 JB |
558 | rx_rings[i].count = new_rx_count; |
559 | err = i40e_setup_rx_descriptors(&rx_rings[i]); | |
560 | if (err) { | |
561 | while (i) { | |
562 | i--; | |
563 | i40e_free_rx_resources(&rx_rings[i]); | |
564 | } | |
565 | kfree(rx_rings); | |
566 | rx_rings = NULL; | |
567 | ||
568 | goto free_tx; | |
569 | } | |
570 | } | |
571 | } | |
572 | ||
573 | /* Bring interface down, copy in the new ring info, | |
574 | * then restore the interface | |
575 | */ | |
576 | i40e_down(vsi); | |
577 | ||
578 | if (tx_rings) { | |
579 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b AD |
580 | i40e_free_tx_resources(vsi->tx_rings[i]); |
581 | *vsi->tx_rings[i] = tx_rings[i]; | |
c7d05ca8 JB |
582 | } |
583 | kfree(tx_rings); | |
584 | tx_rings = NULL; | |
585 | } | |
586 | ||
587 | if (rx_rings) { | |
588 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
9f65e15b AD |
589 | i40e_free_rx_resources(vsi->rx_rings[i]); |
590 | *vsi->rx_rings[i] = rx_rings[i]; | |
c7d05ca8 JB |
591 | } |
592 | kfree(rx_rings); | |
593 | rx_rings = NULL; | |
594 | } | |
595 | ||
596 | i40e_up(vsi); | |
597 | ||
598 | free_tx: | |
599 | /* error cleanup if the Rx allocations failed after getting Tx */ | |
600 | if (tx_rings) { | |
601 | for (i = 0; i < vsi->num_queue_pairs; i++) | |
602 | i40e_free_tx_resources(&tx_rings[i]); | |
603 | kfree(tx_rings); | |
604 | tx_rings = NULL; | |
605 | } | |
606 | ||
607 | done: | |
608 | clear_bit(__I40E_CONFIG_BUSY, &pf->state); | |
609 | ||
610 | return err; | |
611 | } | |
612 | ||
613 | static int i40e_get_sset_count(struct net_device *netdev, int sset) | |
614 | { | |
615 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
616 | struct i40e_vsi *vsi = np->vsi; | |
617 | struct i40e_pf *pf = vsi->back; | |
618 | ||
619 | switch (sset) { | |
620 | case ETH_SS_TEST: | |
621 | return I40E_TEST_LEN; | |
622 | case ETH_SS_STATS: | |
623 | if (vsi == pf->vsi[pf->lan_vsi]) | |
624 | return I40E_PF_STATS_LEN(netdev); | |
625 | else | |
626 | return I40E_VSI_STATS_LEN(netdev); | |
627 | default: | |
628 | return -EOPNOTSUPP; | |
629 | } | |
630 | } | |
631 | ||
632 | static void i40e_get_ethtool_stats(struct net_device *netdev, | |
633 | struct ethtool_stats *stats, u64 *data) | |
634 | { | |
635 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
636 | struct i40e_vsi *vsi = np->vsi; | |
637 | struct i40e_pf *pf = vsi->back; | |
638 | int i = 0; | |
639 | char *p; | |
640 | int j; | |
641 | struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi); | |
980e9b11 | 642 | unsigned int start; |
c7d05ca8 JB |
643 | |
644 | i40e_update_stats(vsi); | |
645 | ||
646 | for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) { | |
647 | p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset; | |
648 | data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat == | |
649 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; | |
650 | } | |
980e9b11 | 651 | rcu_read_lock(); |
a114d0a6 | 652 | for (j = 0; j < vsi->num_queue_pairs; j++, i += 4) { |
980e9b11 AD |
653 | struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[j]); |
654 | struct i40e_ring *rx_ring; | |
655 | ||
656 | if (!tx_ring) | |
657 | continue; | |
658 | ||
659 | /* process Tx ring statistics */ | |
660 | do { | |
57a7744e | 661 | start = u64_stats_fetch_begin_irq(&tx_ring->syncp); |
980e9b11 AD |
662 | data[i] = tx_ring->stats.packets; |
663 | data[i + 1] = tx_ring->stats.bytes; | |
57a7744e | 664 | } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start)); |
980e9b11 AD |
665 | |
666 | /* Rx ring is the 2nd half of the queue pair */ | |
667 | rx_ring = &tx_ring[1]; | |
668 | do { | |
57a7744e | 669 | start = u64_stats_fetch_begin_irq(&rx_ring->syncp); |
980e9b11 AD |
670 | data[i + 2] = rx_ring->stats.packets; |
671 | data[i + 3] = rx_ring->stats.bytes; | |
57a7744e | 672 | } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start)); |
c7d05ca8 | 673 | } |
980e9b11 | 674 | rcu_read_unlock(); |
c7d05ca8 JB |
675 | if (vsi == pf->vsi[pf->lan_vsi]) { |
676 | for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) { | |
677 | p = (char *)pf + i40e_gstrings_stats[j].stat_offset; | |
678 | data[i++] = (i40e_gstrings_stats[j].sizeof_stat == | |
679 | sizeof(u64)) ? *(u64 *)p : *(u32 *)p; | |
680 | } | |
681 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { | |
682 | data[i++] = pf->stats.priority_xon_tx[j]; | |
683 | data[i++] = pf->stats.priority_xoff_tx[j]; | |
684 | } | |
685 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) { | |
686 | data[i++] = pf->stats.priority_xon_rx[j]; | |
687 | data[i++] = pf->stats.priority_xoff_rx[j]; | |
688 | } | |
689 | for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) | |
690 | data[i++] = pf->stats.priority_xon_2_xoff[j]; | |
691 | } | |
692 | } | |
693 | ||
694 | static void i40e_get_strings(struct net_device *netdev, u32 stringset, | |
695 | u8 *data) | |
696 | { | |
697 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
698 | struct i40e_vsi *vsi = np->vsi; | |
699 | struct i40e_pf *pf = vsi->back; | |
700 | char *p = (char *)data; | |
701 | int i; | |
702 | ||
703 | switch (stringset) { | |
704 | case ETH_SS_TEST: | |
705 | for (i = 0; i < I40E_TEST_LEN; i++) { | |
706 | memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN); | |
707 | data += ETH_GSTRING_LEN; | |
708 | } | |
709 | break; | |
710 | case ETH_SS_STATS: | |
711 | for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) { | |
712 | snprintf(p, ETH_GSTRING_LEN, "%s", | |
713 | i40e_gstrings_net_stats[i].stat_string); | |
714 | p += ETH_GSTRING_LEN; | |
715 | } | |
716 | for (i = 0; i < vsi->num_queue_pairs; i++) { | |
717 | snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i); | |
718 | p += ETH_GSTRING_LEN; | |
719 | snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i); | |
720 | p += ETH_GSTRING_LEN; | |
c7d05ca8 JB |
721 | snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i); |
722 | p += ETH_GSTRING_LEN; | |
723 | snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i); | |
724 | p += ETH_GSTRING_LEN; | |
725 | } | |
726 | if (vsi == pf->vsi[pf->lan_vsi]) { | |
727 | for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) { | |
728 | snprintf(p, ETH_GSTRING_LEN, "port.%s", | |
729 | i40e_gstrings_stats[i].stat_string); | |
730 | p += ETH_GSTRING_LEN; | |
731 | } | |
732 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | |
733 | snprintf(p, ETH_GSTRING_LEN, | |
734 | "port.tx_priority_%u_xon", i); | |
735 | p += ETH_GSTRING_LEN; | |
736 | snprintf(p, ETH_GSTRING_LEN, | |
737 | "port.tx_priority_%u_xoff", i); | |
738 | p += ETH_GSTRING_LEN; | |
739 | } | |
740 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | |
741 | snprintf(p, ETH_GSTRING_LEN, | |
742 | "port.rx_priority_%u_xon", i); | |
743 | p += ETH_GSTRING_LEN; | |
744 | snprintf(p, ETH_GSTRING_LEN, | |
745 | "port.rx_priority_%u_xoff", i); | |
746 | p += ETH_GSTRING_LEN; | |
747 | } | |
748 | for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) { | |
749 | snprintf(p, ETH_GSTRING_LEN, | |
750 | "port.rx_priority_%u_xon_2_xoff", i); | |
751 | p += ETH_GSTRING_LEN; | |
752 | } | |
753 | } | |
754 | /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */ | |
755 | break; | |
756 | } | |
757 | } | |
758 | ||
759 | static int i40e_get_ts_info(struct net_device *dev, | |
760 | struct ethtool_ts_info *info) | |
761 | { | |
beb0dff1 JK |
762 | struct i40e_pf *pf = i40e_netdev_to_pf(dev); |
763 | ||
764 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE | | |
765 | SOF_TIMESTAMPING_RX_SOFTWARE | | |
766 | SOF_TIMESTAMPING_SOFTWARE | | |
767 | SOF_TIMESTAMPING_TX_HARDWARE | | |
768 | SOF_TIMESTAMPING_RX_HARDWARE | | |
769 | SOF_TIMESTAMPING_RAW_HARDWARE; | |
770 | ||
771 | if (pf->ptp_clock) | |
772 | info->phc_index = ptp_clock_index(pf->ptp_clock); | |
773 | else | |
774 | info->phc_index = -1; | |
775 | ||
776 | info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON); | |
777 | ||
778 | info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) | | |
779 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) | | |
780 | (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) | | |
781 | (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) | | |
782 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) | | |
783 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) | | |
784 | (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) | | |
785 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) | | |
786 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) | | |
787 | (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) | | |
788 | (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) | | |
789 | (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ); | |
790 | ||
791 | return 0; | |
c7d05ca8 JB |
792 | } |
793 | ||
7b086397 | 794 | static int i40e_link_test(struct net_device *netdev, u64 *data) |
c7d05ca8 | 795 | { |
7b086397 SN |
796 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
797 | struct i40e_pf *pf = np->vsi->back; | |
798 | ||
b03aaa9c | 799 | netif_info(pf, hw, netdev, "link test\n"); |
c7d05ca8 JB |
800 | if (i40e_get_link_status(&pf->hw)) |
801 | *data = 0; | |
802 | else | |
803 | *data = 1; | |
804 | ||
805 | return *data; | |
806 | } | |
807 | ||
7b086397 | 808 | static int i40e_reg_test(struct net_device *netdev, u64 *data) |
c7d05ca8 | 809 | { |
7b086397 SN |
810 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
811 | struct i40e_pf *pf = np->vsi->back; | |
c7d05ca8 | 812 | |
b03aaa9c | 813 | netif_info(pf, hw, netdev, "register test\n"); |
7b086397 | 814 | *data = i40e_diag_reg_test(&pf->hw); |
c7d05ca8 | 815 | |
7b086397 | 816 | return *data; |
c7d05ca8 JB |
817 | } |
818 | ||
7b086397 | 819 | static int i40e_eeprom_test(struct net_device *netdev, u64 *data) |
c7d05ca8 | 820 | { |
7b086397 SN |
821 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
822 | struct i40e_pf *pf = np->vsi->back; | |
c7d05ca8 | 823 | |
b03aaa9c | 824 | netif_info(pf, hw, netdev, "eeprom test\n"); |
7b086397 | 825 | *data = i40e_diag_eeprom_test(&pf->hw); |
c7d05ca8 | 826 | |
7b086397 | 827 | return *data; |
c7d05ca8 JB |
828 | } |
829 | ||
7b086397 | 830 | static int i40e_intr_test(struct net_device *netdev, u64 *data) |
c7d05ca8 | 831 | { |
7b086397 SN |
832 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
833 | struct i40e_pf *pf = np->vsi->back; | |
cd92e72f SN |
834 | u16 swc_old = pf->sw_int_count; |
835 | ||
b03aaa9c | 836 | netif_info(pf, hw, netdev, "interrupt test\n"); |
cd92e72f SN |
837 | wr32(&pf->hw, I40E_PFINT_DYN_CTL0, |
838 | (I40E_PFINT_DYN_CTL0_INTENA_MASK | | |
839 | I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK)); | |
840 | usleep_range(1000, 2000); | |
841 | *data = (swc_old == pf->sw_int_count); | |
c7d05ca8 JB |
842 | |
843 | return *data; | |
844 | } | |
845 | ||
7b086397 | 846 | static int i40e_loopback_test(struct net_device *netdev, u64 *data) |
c7d05ca8 | 847 | { |
b03aaa9c SN |
848 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
849 | struct i40e_pf *pf = np->vsi->back; | |
850 | ||
851 | netif_info(pf, hw, netdev, "loopback test not implemented\n"); | |
cd92e72f | 852 | *data = 0; |
c7d05ca8 JB |
853 | |
854 | return *data; | |
855 | } | |
856 | ||
857 | static void i40e_diag_test(struct net_device *netdev, | |
858 | struct ethtool_test *eth_test, u64 *data) | |
859 | { | |
860 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
861 | struct i40e_pf *pf = np->vsi->back; | |
862 | ||
c7d05ca8 JB |
863 | if (eth_test->flags == ETH_TEST_FL_OFFLINE) { |
864 | /* Offline tests */ | |
b03aaa9c | 865 | netif_info(pf, drv, netdev, "offline testing starting\n"); |
c7d05ca8 | 866 | |
f551b438 SN |
867 | set_bit(__I40E_TESTING, &pf->state); |
868 | ||
c7d05ca8 JB |
869 | /* Link test performed before hardware reset |
870 | * so autoneg doesn't interfere with test result | |
871 | */ | |
7b086397 | 872 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
c7d05ca8 JB |
873 | eth_test->flags |= ETH_TEST_FL_FAILED; |
874 | ||
7b086397 | 875 | if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM])) |
c7d05ca8 JB |
876 | eth_test->flags |= ETH_TEST_FL_FAILED; |
877 | ||
7b086397 | 878 | if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR])) |
c7d05ca8 JB |
879 | eth_test->flags |= ETH_TEST_FL_FAILED; |
880 | ||
7b086397 | 881 | if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK])) |
c7d05ca8 JB |
882 | eth_test->flags |= ETH_TEST_FL_FAILED; |
883 | ||
f551b438 SN |
884 | /* run reg test last, a reset is required after it */ |
885 | if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG])) | |
886 | eth_test->flags |= ETH_TEST_FL_FAILED; | |
887 | ||
888 | clear_bit(__I40E_TESTING, &pf->state); | |
889 | i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED)); | |
c7d05ca8 | 890 | } else { |
c7d05ca8 | 891 | /* Online tests */ |
b03aaa9c SN |
892 | netif_info(pf, drv, netdev, "online testing starting\n"); |
893 | ||
7b086397 | 894 | if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK])) |
c7d05ca8 JB |
895 | eth_test->flags |= ETH_TEST_FL_FAILED; |
896 | ||
897 | /* Offline only tests, not run in online; pass by default */ | |
898 | data[I40E_ETH_TEST_REG] = 0; | |
899 | data[I40E_ETH_TEST_EEPROM] = 0; | |
900 | data[I40E_ETH_TEST_INTR] = 0; | |
901 | data[I40E_ETH_TEST_LOOPBACK] = 0; | |
c7d05ca8 | 902 | } |
c140c17b | 903 | |
b03aaa9c | 904 | netif_info(pf, drv, netdev, "testing finished\n"); |
c7d05ca8 JB |
905 | } |
906 | ||
907 | static void i40e_get_wol(struct net_device *netdev, | |
908 | struct ethtool_wolinfo *wol) | |
909 | { | |
8e2773ae SN |
910 | struct i40e_netdev_priv *np = netdev_priv(netdev); |
911 | struct i40e_pf *pf = np->vsi->back; | |
912 | struct i40e_hw *hw = &pf->hw; | |
913 | u16 wol_nvm_bits; | |
914 | ||
915 | /* NVM bit on means WoL disabled for the port */ | |
916 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); | |
917 | if ((1 << hw->port) & wol_nvm_bits) { | |
918 | wol->supported = 0; | |
919 | wol->wolopts = 0; | |
920 | } else { | |
921 | wol->supported = WAKE_MAGIC; | |
922 | wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0); | |
923 | } | |
924 | } | |
925 | ||
926 | static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) | |
927 | { | |
928 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
929 | struct i40e_pf *pf = np->vsi->back; | |
930 | struct i40e_hw *hw = &pf->hw; | |
931 | u16 wol_nvm_bits; | |
932 | ||
933 | /* NVM bit on means WoL disabled for the port */ | |
934 | i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits); | |
935 | if (((1 << hw->port) & wol_nvm_bits)) | |
936 | return -EOPNOTSUPP; | |
937 | ||
938 | /* only magic packet is supported */ | |
939 | if (wol->wolopts && (wol->wolopts != WAKE_MAGIC)) | |
940 | return -EOPNOTSUPP; | |
941 | ||
942 | /* is this a new value? */ | |
943 | if (pf->wol_en != !!wol->wolopts) { | |
944 | pf->wol_en = !!wol->wolopts; | |
945 | device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en); | |
946 | } | |
947 | ||
948 | return 0; | |
c7d05ca8 JB |
949 | } |
950 | ||
951 | static int i40e_nway_reset(struct net_device *netdev) | |
952 | { | |
953 | /* restart autonegotiation */ | |
954 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
955 | struct i40e_pf *pf = np->vsi->back; | |
956 | struct i40e_hw *hw = &pf->hw; | |
957 | i40e_status ret = 0; | |
958 | ||
959 | ret = i40e_aq_set_link_restart_an(hw, NULL); | |
960 | if (ret) { | |
961 | netdev_info(netdev, "link restart failed, aq_err=%d\n", | |
962 | pf->hw.aq.asq_last_status); | |
963 | return -EIO; | |
964 | } | |
965 | ||
966 | return 0; | |
967 | } | |
968 | ||
969 | static int i40e_set_phys_id(struct net_device *netdev, | |
970 | enum ethtool_phys_id_state state) | |
971 | { | |
972 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
973 | struct i40e_pf *pf = np->vsi->back; | |
974 | struct i40e_hw *hw = &pf->hw; | |
975 | int blink_freq = 2; | |
976 | ||
977 | switch (state) { | |
978 | case ETHTOOL_ID_ACTIVE: | |
979 | pf->led_status = i40e_led_get(hw); | |
980 | return blink_freq; | |
981 | case ETHTOOL_ID_ON: | |
0556a9e3 | 982 | i40e_led_set(hw, 0xF, false); |
c7d05ca8 JB |
983 | break; |
984 | case ETHTOOL_ID_OFF: | |
0556a9e3 | 985 | i40e_led_set(hw, 0x0, false); |
c7d05ca8 JB |
986 | break; |
987 | case ETHTOOL_ID_INACTIVE: | |
0556a9e3 | 988 | i40e_led_set(hw, pf->led_status, false); |
c7d05ca8 JB |
989 | break; |
990 | } | |
991 | ||
992 | return 0; | |
993 | } | |
994 | ||
995 | /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt | |
996 | * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also | |
997 | * 125us (8000 interrupts per second) == ITR(62) | |
998 | */ | |
999 | ||
1000 | static int i40e_get_coalesce(struct net_device *netdev, | |
1001 | struct ethtool_coalesce *ec) | |
1002 | { | |
1003 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1004 | struct i40e_vsi *vsi = np->vsi; | |
1005 | ||
1006 | ec->tx_max_coalesced_frames_irq = vsi->work_limit; | |
1007 | ec->rx_max_coalesced_frames_irq = vsi->work_limit; | |
1008 | ||
1009 | if (ITR_IS_DYNAMIC(vsi->rx_itr_setting)) | |
1010 | ec->rx_coalesce_usecs = 1; | |
1011 | else | |
1012 | ec->rx_coalesce_usecs = vsi->rx_itr_setting; | |
1013 | ||
1014 | if (ITR_IS_DYNAMIC(vsi->tx_itr_setting)) | |
1015 | ec->tx_coalesce_usecs = 1; | |
1016 | else | |
1017 | ec->tx_coalesce_usecs = vsi->tx_itr_setting; | |
1018 | ||
1019 | return 0; | |
1020 | } | |
1021 | ||
1022 | static int i40e_set_coalesce(struct net_device *netdev, | |
1023 | struct ethtool_coalesce *ec) | |
1024 | { | |
1025 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1026 | struct i40e_q_vector *q_vector; | |
1027 | struct i40e_vsi *vsi = np->vsi; | |
1028 | struct i40e_pf *pf = vsi->back; | |
1029 | struct i40e_hw *hw = &pf->hw; | |
1030 | u16 vector; | |
1031 | int i; | |
1032 | ||
1033 | if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq) | |
1034 | vsi->work_limit = ec->tx_max_coalesced_frames_irq; | |
1035 | ||
1036 | switch (ec->rx_coalesce_usecs) { | |
1037 | case 0: | |
1038 | vsi->rx_itr_setting = 0; | |
1039 | break; | |
1040 | case 1: | |
1041 | vsi->rx_itr_setting = (I40E_ITR_DYNAMIC | | |
1042 | ITR_REG_TO_USEC(I40E_ITR_RX_DEF)); | |
1043 | break; | |
1044 | default: | |
1045 | if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) || | |
1046 | (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) | |
1047 | return -EINVAL; | |
1048 | vsi->rx_itr_setting = ec->rx_coalesce_usecs; | |
1049 | break; | |
1050 | } | |
1051 | ||
1052 | switch (ec->tx_coalesce_usecs) { | |
1053 | case 0: | |
1054 | vsi->tx_itr_setting = 0; | |
1055 | break; | |
1056 | case 1: | |
1057 | vsi->tx_itr_setting = (I40E_ITR_DYNAMIC | | |
1058 | ITR_REG_TO_USEC(I40E_ITR_TX_DEF)); | |
1059 | break; | |
1060 | default: | |
1061 | if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) || | |
1062 | (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) | |
1063 | return -EINVAL; | |
1064 | vsi->tx_itr_setting = ec->tx_coalesce_usecs; | |
1065 | break; | |
1066 | } | |
1067 | ||
1068 | vector = vsi->base_vector; | |
493fb300 AD |
1069 | for (i = 0; i < vsi->num_q_vectors; i++, vector++) { |
1070 | q_vector = vsi->q_vectors[i]; | |
c7d05ca8 JB |
1071 | q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting); |
1072 | wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr); | |
1073 | q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting); | |
1074 | wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr); | |
1075 | i40e_flush(hw); | |
1076 | } | |
1077 | ||
1078 | return 0; | |
1079 | } | |
1080 | ||
1081 | /** | |
1082 | * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type | |
1083 | * @pf: pointer to the physical function struct | |
1084 | * @cmd: ethtool rxnfc command | |
1085 | * | |
1086 | * Returns Success if the flow is supported, else Invalid Input. | |
1087 | **/ | |
1088 | static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd) | |
1089 | { | |
1090 | cmd->data = 0; | |
1091 | ||
1092 | /* Report default options for RSS on i40e */ | |
1093 | switch (cmd->flow_type) { | |
1094 | case TCP_V4_FLOW: | |
1095 | case UDP_V4_FLOW: | |
1096 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
1097 | /* fall through to add IP fields */ | |
1098 | case SCTP_V4_FLOW: | |
1099 | case AH_ESP_V4_FLOW: | |
1100 | case AH_V4_FLOW: | |
1101 | case ESP_V4_FLOW: | |
1102 | case IPV4_FLOW: | |
1103 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; | |
1104 | break; | |
1105 | case TCP_V6_FLOW: | |
1106 | case UDP_V6_FLOW: | |
1107 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
1108 | /* fall through to add IP fields */ | |
1109 | case SCTP_V6_FLOW: | |
1110 | case AH_ESP_V6_FLOW: | |
1111 | case AH_V6_FLOW: | |
1112 | case ESP_V6_FLOW: | |
1113 | case IPV6_FLOW: | |
1114 | cmd->data |= RXH_IP_SRC | RXH_IP_DST; | |
1115 | break; | |
1116 | default: | |
1117 | return -EINVAL; | |
1118 | } | |
1119 | ||
1120 | return 0; | |
1121 | } | |
1122 | ||
17a73f6b JG |
1123 | /** |
1124 | * i40e_get_ethtool_fdir_all - Populates the rule count of a command | |
1125 | * @pf: Pointer to the physical function struct | |
1126 | * @cmd: The command to get or set Rx flow classification rules | |
1127 | * @rule_locs: Array of used rule locations | |
1128 | * | |
1129 | * This function populates both the total and actual rule count of | |
1130 | * the ethtool flow classification command | |
1131 | * | |
1132 | * Returns 0 on success or -EMSGSIZE if entry not found | |
1133 | **/ | |
1134 | static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf, | |
1135 | struct ethtool_rxnfc *cmd, | |
1136 | u32 *rule_locs) | |
1137 | { | |
1138 | struct i40e_fdir_filter *rule; | |
1139 | struct hlist_node *node2; | |
1140 | int cnt = 0; | |
1141 | ||
1142 | /* report total rule count */ | |
1143 | cmd->data = pf->hw.fdir_shared_filter_count + | |
1144 | pf->fdir_pf_filter_count; | |
1145 | ||
1146 | hlist_for_each_entry_safe(rule, node2, | |
1147 | &pf->fdir_filter_list, fdir_node) { | |
1148 | if (cnt == cmd->rule_cnt) | |
1149 | return -EMSGSIZE; | |
1150 | ||
1151 | rule_locs[cnt] = rule->fd_id; | |
1152 | cnt++; | |
1153 | } | |
1154 | ||
1155 | cmd->rule_cnt = cnt; | |
1156 | ||
1157 | return 0; | |
1158 | } | |
1159 | ||
1160 | /** | |
1161 | * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow | |
1162 | * @pf: Pointer to the physical function struct | |
1163 | * @cmd: The command to get or set Rx flow classification rules | |
1164 | * | |
1165 | * This function looks up a filter based on the Rx flow classification | |
1166 | * command and fills the flow spec info for it if found | |
1167 | * | |
1168 | * Returns 0 on success or -EINVAL if filter not found | |
1169 | **/ | |
1170 | static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf, | |
1171 | struct ethtool_rxnfc *cmd) | |
1172 | { | |
1173 | struct ethtool_rx_flow_spec *fsp = | |
1174 | (struct ethtool_rx_flow_spec *)&cmd->fs; | |
1175 | struct i40e_fdir_filter *rule = NULL; | |
1176 | struct hlist_node *node2; | |
1177 | ||
1178 | /* report total rule count */ | |
1179 | cmd->data = pf->hw.fdir_shared_filter_count + | |
1180 | pf->fdir_pf_filter_count; | |
1181 | ||
1182 | hlist_for_each_entry_safe(rule, node2, | |
1183 | &pf->fdir_filter_list, fdir_node) { | |
1184 | if (fsp->location <= rule->fd_id) | |
1185 | break; | |
1186 | } | |
1187 | ||
1188 | if (!rule || fsp->location != rule->fd_id) | |
1189 | return -EINVAL; | |
1190 | ||
1191 | fsp->flow_type = rule->flow_type; | |
1192 | fsp->h_u.tcp_ip4_spec.psrc = rule->src_port; | |
1193 | fsp->h_u.tcp_ip4_spec.pdst = rule->dst_port; | |
1194 | fsp->h_u.tcp_ip4_spec.ip4src = rule->src_ip[0]; | |
1195 | fsp->h_u.tcp_ip4_spec.ip4dst = rule->dst_ip[0]; | |
1196 | fsp->ring_cookie = rule->q_index; | |
1197 | ||
1198 | return 0; | |
1199 | } | |
1200 | ||
c7d05ca8 JB |
1201 | /** |
1202 | * i40e_get_rxnfc - command to get RX flow classification rules | |
1203 | * @netdev: network interface device structure | |
1204 | * @cmd: ethtool rxnfc command | |
1205 | * | |
1206 | * Returns Success if the command is supported. | |
1207 | **/ | |
1208 | static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, | |
1209 | u32 *rule_locs) | |
1210 | { | |
1211 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1212 | struct i40e_vsi *vsi = np->vsi; | |
1213 | struct i40e_pf *pf = vsi->back; | |
1214 | int ret = -EOPNOTSUPP; | |
1215 | ||
1216 | switch (cmd->cmd) { | |
1217 | case ETHTOOL_GRXRINGS: | |
1218 | cmd->data = vsi->alloc_queue_pairs; | |
1219 | ret = 0; | |
1220 | break; | |
1221 | case ETHTOOL_GRXFH: | |
1222 | ret = i40e_get_rss_hash_opts(pf, cmd); | |
1223 | break; | |
1224 | case ETHTOOL_GRXCLSRLCNT: | |
17a73f6b | 1225 | cmd->rule_cnt = pf->fdir_pf_active_filters; |
c7d05ca8 JB |
1226 | ret = 0; |
1227 | break; | |
1228 | case ETHTOOL_GRXCLSRULE: | |
17a73f6b | 1229 | ret = i40e_get_ethtool_fdir_entry(pf, cmd); |
c7d05ca8 JB |
1230 | break; |
1231 | case ETHTOOL_GRXCLSRLALL: | |
17a73f6b JG |
1232 | ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs); |
1233 | break; | |
c7d05ca8 JB |
1234 | default: |
1235 | break; | |
1236 | } | |
1237 | ||
1238 | return ret; | |
1239 | } | |
1240 | ||
1241 | /** | |
1242 | * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash | |
1243 | * @pf: pointer to the physical function struct | |
1244 | * @cmd: ethtool rxnfc command | |
1245 | * | |
1246 | * Returns Success if the flow input set is supported. | |
1247 | **/ | |
1248 | static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc) | |
1249 | { | |
1250 | struct i40e_hw *hw = &pf->hw; | |
1251 | u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) | | |
1252 | ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32); | |
1253 | ||
1254 | /* RSS does not support anything other than hashing | |
1255 | * to queues on src and dst IPs and ports | |
1256 | */ | |
1257 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST | | |
1258 | RXH_L4_B_0_1 | RXH_L4_B_2_3)) | |
1259 | return -EINVAL; | |
1260 | ||
1261 | /* We need at least the IP SRC and DEST fields for hashing */ | |
1262 | if (!(nfc->data & RXH_IP_SRC) || | |
1263 | !(nfc->data & RXH_IP_DST)) | |
1264 | return -EINVAL; | |
1265 | ||
1266 | switch (nfc->flow_type) { | |
1267 | case TCP_V4_FLOW: | |
1268 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { | |
1269 | case 0: | |
1270 | hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP); | |
1271 | break; | |
1272 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): | |
1273 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP); | |
1274 | break; | |
1275 | default: | |
1276 | return -EINVAL; | |
1277 | } | |
1278 | break; | |
1279 | case TCP_V6_FLOW: | |
1280 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { | |
1281 | case 0: | |
1282 | hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP); | |
1283 | break; | |
1284 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): | |
1285 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP); | |
1286 | break; | |
1287 | default: | |
1288 | return -EINVAL; | |
1289 | } | |
1290 | break; | |
1291 | case UDP_V4_FLOW: | |
1292 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { | |
1293 | case 0: | |
1294 | hena &= | |
1295 | ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | | |
1296 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | | |
1297 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4)); | |
1298 | break; | |
1299 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): | |
1300 | hena |= | |
1301 | (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | | |
1302 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | | |
1303 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4)); | |
1304 | break; | |
1305 | default: | |
1306 | return -EINVAL; | |
1307 | } | |
1308 | break; | |
1309 | case UDP_V6_FLOW: | |
1310 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) { | |
1311 | case 0: | |
1312 | hena &= | |
1313 | ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | | |
1314 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) | | |
1315 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6)); | |
1316 | break; | |
1317 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3): | |
1318 | hena |= | |
1319 | (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | | |
1320 | ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) | | |
1321 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6)); | |
1322 | break; | |
1323 | default: | |
1324 | return -EINVAL; | |
1325 | } | |
1326 | break; | |
1327 | case AH_ESP_V4_FLOW: | |
1328 | case AH_V4_FLOW: | |
1329 | case ESP_V4_FLOW: | |
1330 | case SCTP_V4_FLOW: | |
1331 | if ((nfc->data & RXH_L4_B_0_1) || | |
1332 | (nfc->data & RXH_L4_B_2_3)) | |
1333 | return -EINVAL; | |
1334 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER); | |
1335 | break; | |
1336 | case AH_ESP_V6_FLOW: | |
1337 | case AH_V6_FLOW: | |
1338 | case ESP_V6_FLOW: | |
1339 | case SCTP_V6_FLOW: | |
1340 | if ((nfc->data & RXH_L4_B_0_1) || | |
1341 | (nfc->data & RXH_L4_B_2_3)) | |
1342 | return -EINVAL; | |
1343 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER); | |
1344 | break; | |
1345 | case IPV4_FLOW: | |
1346 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | | |
1347 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4); | |
1348 | break; | |
1349 | case IPV6_FLOW: | |
1350 | hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | | |
1351 | ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6); | |
1352 | break; | |
1353 | default: | |
1354 | return -EINVAL; | |
1355 | } | |
1356 | ||
1357 | wr32(hw, I40E_PFQF_HENA(0), (u32)hena); | |
1358 | wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32)); | |
1359 | i40e_flush(hw); | |
1360 | ||
1361 | return 0; | |
1362 | } | |
1363 | ||
43fddb75 ASJ |
1364 | /** |
1365 | * i40e_match_fdir_input_set - Match a new filter against an existing one | |
1366 | * @rule: The filter already added | |
1367 | * @input: The new filter to comapre against | |
1368 | * | |
1369 | * Returns true if the two input set match | |
1370 | **/ | |
1371 | static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule, | |
1372 | struct i40e_fdir_filter *input) | |
1373 | { | |
1374 | if ((rule->dst_ip[0] != input->dst_ip[0]) || | |
1375 | (rule->src_ip[0] != input->src_ip[0]) || | |
1376 | (rule->dst_port != input->dst_port) || | |
1377 | (rule->src_port != input->src_port)) | |
1378 | return false; | |
1379 | return true; | |
1380 | } | |
1381 | ||
c7d05ca8 | 1382 | /** |
17a73f6b JG |
1383 | * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry |
1384 | * @vsi: Pointer to the targeted VSI | |
1385 | * @input: The filter to update or NULL to indicate deletion | |
1386 | * @sw_idx: Software index to the filter | |
1387 | * @cmd: The command to get or set Rx flow classification rules | |
c7d05ca8 | 1388 | * |
17a73f6b JG |
1389 | * This function updates (or deletes) a Flow Director entry from |
1390 | * the hlist of the corresponding PF | |
1391 | * | |
1392 | * Returns 0 on success | |
c7d05ca8 | 1393 | **/ |
17a73f6b JG |
1394 | static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi, |
1395 | struct i40e_fdir_filter *input, | |
1396 | u16 sw_idx, | |
1397 | struct ethtool_rxnfc *cmd) | |
c7d05ca8 | 1398 | { |
17a73f6b | 1399 | struct i40e_fdir_filter *rule, *parent; |
c7d05ca8 | 1400 | struct i40e_pf *pf = vsi->back; |
17a73f6b JG |
1401 | struct hlist_node *node2; |
1402 | int err = -EINVAL; | |
c7d05ca8 | 1403 | |
17a73f6b JG |
1404 | parent = NULL; |
1405 | rule = NULL; | |
c7d05ca8 | 1406 | |
17a73f6b JG |
1407 | hlist_for_each_entry_safe(rule, node2, |
1408 | &pf->fdir_filter_list, fdir_node) { | |
1409 | /* hash found, or no matching entry */ | |
1410 | if (rule->fd_id >= sw_idx) | |
1411 | break; | |
1412 | parent = rule; | |
c7d05ca8 JB |
1413 | } |
1414 | ||
17a73f6b JG |
1415 | /* if there is an old rule occupying our place remove it */ |
1416 | if (rule && (rule->fd_id == sw_idx)) { | |
43fddb75 ASJ |
1417 | if (input && !i40e_match_fdir_input_set(rule, input)) |
1418 | err = i40e_add_del_fdir(vsi, rule, false); | |
1419 | else if (!input) | |
1420 | err = i40e_add_del_fdir(vsi, rule, false); | |
17a73f6b JG |
1421 | hlist_del(&rule->fdir_node); |
1422 | kfree(rule); | |
1423 | pf->fdir_pf_active_filters--; | |
cbf61325 ASJ |
1424 | } |
1425 | ||
17a73f6b JG |
1426 | /* If no input this was a delete, err should be 0 if a rule was |
1427 | * successfully found and removed from the list else -EINVAL | |
1428 | */ | |
1429 | if (!input) | |
1430 | return err; | |
c7d05ca8 | 1431 | |
17a73f6b JG |
1432 | /* initialize node and set software index */ |
1433 | INIT_HLIST_NODE(&input->fdir_node); | |
c7d05ca8 | 1434 | |
17a73f6b JG |
1435 | /* add filter to the list */ |
1436 | if (parent) | |
1437 | hlist_add_after(&parent->fdir_node, &input->fdir_node); | |
1438 | else | |
1439 | hlist_add_head(&input->fdir_node, | |
1440 | &pf->fdir_filter_list); | |
c7d05ca8 | 1441 | |
17a73f6b JG |
1442 | /* update counts */ |
1443 | pf->fdir_pf_active_filters++; | |
c7d05ca8 | 1444 | |
17a73f6b | 1445 | return 0; |
c7d05ca8 JB |
1446 | } |
1447 | ||
1448 | /** | |
17a73f6b JG |
1449 | * i40e_del_fdir_entry - Deletes a Flow Director filter entry |
1450 | * @vsi: Pointer to the targeted VSI | |
1451 | * @cmd: The command to get or set Rx flow classification rules | |
c7d05ca8 | 1452 | * |
17a73f6b JG |
1453 | * The function removes a Flow Director filter entry from the |
1454 | * hlist of the corresponding PF | |
c7d05ca8 | 1455 | * |
17a73f6b JG |
1456 | * Returns 0 on success |
1457 | */ | |
1458 | static int i40e_del_fdir_entry(struct i40e_vsi *vsi, | |
1459 | struct ethtool_rxnfc *cmd) | |
c7d05ca8 | 1460 | { |
17a73f6b JG |
1461 | struct ethtool_rx_flow_spec *fsp = |
1462 | (struct ethtool_rx_flow_spec *)&cmd->fs; | |
c7d05ca8 | 1463 | struct i40e_pf *pf = vsi->back; |
17a73f6b | 1464 | int ret = 0; |
c7d05ca8 | 1465 | |
17a73f6b | 1466 | ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd); |
c7d05ca8 | 1467 | |
55a5e60b | 1468 | i40e_fdir_check_and_reenable(pf); |
17a73f6b | 1469 | return ret; |
c7d05ca8 JB |
1470 | } |
1471 | ||
1472 | /** | |
1eaa3840 | 1473 | * i40e_add_fdir_ethtool - Add/Remove Flow Director filters |
c7d05ca8 JB |
1474 | * @vsi: pointer to the targeted VSI |
1475 | * @cmd: command to get or set RX flow classification rules | |
c7d05ca8 | 1476 | * |
1eaa3840 ASJ |
1477 | * Add Flow Director filters for a specific flow spec based on their |
1478 | * protocol. Returns 0 if the filters were successfully added. | |
c7d05ca8 | 1479 | **/ |
1eaa3840 ASJ |
1480 | static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi, |
1481 | struct ethtool_rxnfc *cmd) | |
c7d05ca8 | 1482 | { |
17a73f6b JG |
1483 | struct ethtool_rx_flow_spec *fsp; |
1484 | struct i40e_fdir_filter *input; | |
c7d05ca8 | 1485 | struct i40e_pf *pf; |
17a73f6b | 1486 | int ret = -EINVAL; |
c7d05ca8 JB |
1487 | |
1488 | if (!vsi) | |
1489 | return -EINVAL; | |
1490 | ||
1491 | pf = vsi->back; | |
1492 | ||
55a5e60b ASJ |
1493 | if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED)) |
1494 | return -EOPNOTSUPP; | |
1495 | ||
1eaa3840 | 1496 | if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED) |
55a5e60b ASJ |
1497 | return -ENOSPC; |
1498 | ||
1499 | fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; | |
1500 | ||
17a73f6b JG |
1501 | if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort + |
1502 | pf->hw.func_caps.fd_filters_guaranteed)) { | |
c7d05ca8 | 1503 | return -EINVAL; |
17a73f6b | 1504 | } |
c7d05ca8 | 1505 | |
1eaa3840 | 1506 | if (fsp->ring_cookie >= vsi->num_queue_pairs) |
17a73f6b | 1507 | return -EINVAL; |
c7d05ca8 | 1508 | |
17a73f6b | 1509 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
c7d05ca8 | 1510 | |
17a73f6b JG |
1511 | if (!input) |
1512 | return -ENOMEM; | |
c7d05ca8 | 1513 | |
17a73f6b JG |
1514 | input->fd_id = fsp->location; |
1515 | ||
1516 | input->q_index = fsp->ring_cookie; | |
1517 | input->flex_off = 0; | |
1518 | input->pctype = 0; | |
1519 | input->dest_vsi = vsi->id; | |
1520 | input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX; | |
1521 | input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID; | |
1522 | input->cnt_index = 0; | |
1523 | input->flow_type = fsp->flow_type; | |
1524 | input->ip4_proto = fsp->h_u.usr_ip4_spec.proto; | |
1525 | input->src_port = fsp->h_u.tcp_ip4_spec.psrc; | |
1526 | input->dst_port = fsp->h_u.tcp_ip4_spec.pdst; | |
1527 | input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src; | |
1528 | input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst; | |
1529 | ||
1eaa3840 ASJ |
1530 | ret = i40e_add_del_fdir(vsi, input, true); |
1531 | if (ret) | |
17a73f6b | 1532 | kfree(input); |
17a73f6b | 1533 | else |
1eaa3840 | 1534 | i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL); |
c7d05ca8 JB |
1535 | |
1536 | return ret; | |
1537 | } | |
8fb905b3 | 1538 | |
c7d05ca8 JB |
1539 | /** |
1540 | * i40e_set_rxnfc - command to set RX flow classification rules | |
1541 | * @netdev: network interface device structure | |
1542 | * @cmd: ethtool rxnfc command | |
1543 | * | |
1544 | * Returns Success if the command is supported. | |
1545 | **/ | |
1546 | static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd) | |
1547 | { | |
1548 | struct i40e_netdev_priv *np = netdev_priv(netdev); | |
1549 | struct i40e_vsi *vsi = np->vsi; | |
1550 | struct i40e_pf *pf = vsi->back; | |
1551 | int ret = -EOPNOTSUPP; | |
1552 | ||
1553 | switch (cmd->cmd) { | |
1554 | case ETHTOOL_SRXFH: | |
1555 | ret = i40e_set_rss_hash_opt(pf, cmd); | |
1556 | break; | |
1557 | case ETHTOOL_SRXCLSRLINS: | |
1eaa3840 | 1558 | ret = i40e_add_fdir_ethtool(vsi, cmd); |
c7d05ca8 JB |
1559 | break; |
1560 | case ETHTOOL_SRXCLSRLDEL: | |
17a73f6b | 1561 | ret = i40e_del_fdir_entry(vsi, cmd); |
c7d05ca8 JB |
1562 | break; |
1563 | default: | |
1564 | break; | |
1565 | } | |
1566 | ||
1567 | return ret; | |
1568 | } | |
1569 | ||
4b7820ca ASJ |
1570 | /** |
1571 | * i40e_max_channels - get Max number of combined channels supported | |
1572 | * @vsi: vsi pointer | |
1573 | **/ | |
1574 | static unsigned int i40e_max_channels(struct i40e_vsi *vsi) | |
1575 | { | |
1576 | /* TODO: This code assumes DCB and FD is disabled for now. */ | |
1577 | return vsi->alloc_queue_pairs; | |
1578 | } | |
1579 | ||
1580 | /** | |
1581 | * i40e_get_channels - Get the current channels enabled and max supported etc. | |
1582 | * @netdev: network interface device structure | |
1583 | * @ch: ethtool channels structure | |
1584 | * | |
1585 | * We don't support separate tx and rx queues as channels. The other count | |
1586 | * represents how many queues are being used for control. max_combined counts | |
1587 | * how many queue pairs we can support. They may not be mapped 1 to 1 with | |
1588 | * q_vectors since we support a lot more queue pairs than q_vectors. | |
1589 | **/ | |
1590 | static void i40e_get_channels(struct net_device *dev, | |
1591 | struct ethtool_channels *ch) | |
1592 | { | |
1593 | struct i40e_netdev_priv *np = netdev_priv(dev); | |
1594 | struct i40e_vsi *vsi = np->vsi; | |
1595 | struct i40e_pf *pf = vsi->back; | |
1596 | ||
1597 | /* report maximum channels */ | |
1598 | ch->max_combined = i40e_max_channels(vsi); | |
1599 | ||
1600 | /* report info for other vector */ | |
60ea5f83 | 1601 | ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0; |
4b7820ca ASJ |
1602 | ch->max_other = ch->other_count; |
1603 | ||
1604 | /* Note: This code assumes DCB is disabled for now. */ | |
1605 | ch->combined_count = vsi->num_queue_pairs; | |
1606 | } | |
1607 | ||
1608 | /** | |
1609 | * i40e_set_channels - Set the new channels count. | |
1610 | * @netdev: network interface device structure | |
1611 | * @ch: ethtool channels structure | |
1612 | * | |
1613 | * The new channels count may not be the same as requested by the user | |
1614 | * since it gets rounded down to a power of 2 value. | |
1615 | **/ | |
1616 | static int i40e_set_channels(struct net_device *dev, | |
1617 | struct ethtool_channels *ch) | |
1618 | { | |
1619 | struct i40e_netdev_priv *np = netdev_priv(dev); | |
1620 | unsigned int count = ch->combined_count; | |
1621 | struct i40e_vsi *vsi = np->vsi; | |
1622 | struct i40e_pf *pf = vsi->back; | |
1623 | int new_count; | |
1624 | ||
1625 | /* We do not support setting channels for any other VSI at present */ | |
1626 | if (vsi->type != I40E_VSI_MAIN) | |
1627 | return -EINVAL; | |
1628 | ||
1629 | /* verify they are not requesting separate vectors */ | |
1630 | if (!count || ch->rx_count || ch->tx_count) | |
1631 | return -EINVAL; | |
1632 | ||
1633 | /* verify other_count has not changed */ | |
60ea5f83 | 1634 | if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0)) |
4b7820ca ASJ |
1635 | return -EINVAL; |
1636 | ||
1637 | /* verify the number of channels does not exceed hardware limits */ | |
1638 | if (count > i40e_max_channels(vsi)) | |
1639 | return -EINVAL; | |
1640 | ||
1641 | /* update feature limits from largest to smallest supported values */ | |
1642 | /* TODO: Flow director limit, DCB etc */ | |
1643 | ||
1644 | /* cap RSS limit */ | |
1645 | if (count > pf->rss_size_max) | |
1646 | count = pf->rss_size_max; | |
1647 | ||
1648 | /* use rss_reconfig to rebuild with new queue count and update traffic | |
1649 | * class queue mapping | |
1650 | */ | |
1651 | new_count = i40e_reconfig_rss_queues(pf, count); | |
5f90f422 | 1652 | if (new_count > 0) |
4b7820ca ASJ |
1653 | return 0; |
1654 | else | |
1655 | return -EINVAL; | |
1656 | } | |
1657 | ||
c7d05ca8 JB |
1658 | static const struct ethtool_ops i40e_ethtool_ops = { |
1659 | .get_settings = i40e_get_settings, | |
1660 | .get_drvinfo = i40e_get_drvinfo, | |
1661 | .get_regs_len = i40e_get_regs_len, | |
1662 | .get_regs = i40e_get_regs, | |
1663 | .nway_reset = i40e_nway_reset, | |
1664 | .get_link = ethtool_op_get_link, | |
1665 | .get_wol = i40e_get_wol, | |
8e2773ae | 1666 | .set_wol = i40e_set_wol, |
c7d05ca8 JB |
1667 | .get_eeprom_len = i40e_get_eeprom_len, |
1668 | .get_eeprom = i40e_get_eeprom, | |
1669 | .get_ringparam = i40e_get_ringparam, | |
1670 | .set_ringparam = i40e_set_ringparam, | |
1671 | .get_pauseparam = i40e_get_pauseparam, | |
1672 | .get_msglevel = i40e_get_msglevel, | |
1673 | .set_msglevel = i40e_set_msglevel, | |
1674 | .get_rxnfc = i40e_get_rxnfc, | |
1675 | .set_rxnfc = i40e_set_rxnfc, | |
1676 | .self_test = i40e_diag_test, | |
1677 | .get_strings = i40e_get_strings, | |
1678 | .set_phys_id = i40e_set_phys_id, | |
1679 | .get_sset_count = i40e_get_sset_count, | |
1680 | .get_ethtool_stats = i40e_get_ethtool_stats, | |
1681 | .get_coalesce = i40e_get_coalesce, | |
1682 | .set_coalesce = i40e_set_coalesce, | |
4b7820ca ASJ |
1683 | .get_channels = i40e_get_channels, |
1684 | .set_channels = i40e_set_channels, | |
c7d05ca8 JB |
1685 | .get_ts_info = i40e_get_ts_info, |
1686 | }; | |
1687 | ||
1688 | void i40e_set_ethtool_ops(struct net_device *netdev) | |
1689 | { | |
1690 | SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops); | |
1691 | } |