blob: 44d4a7f8478732191f0c5e54488d51c1d8498993 [file] [log] [blame]
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 Intel Corporation.
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 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
21 *
22 * Contact Information:
23 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *
26 ******************************************************************************/
27
28/* ethtool support for i40e */
29
30#include "i40e.h"
31#include "i40e_diag.h"
32
33struct i40e_stats {
34 char stat_string[ETH_GSTRING_LEN];
35 int sizeof_stat;
36 int stat_offset;
37};
38
39#define I40E_STAT(_type, _name, _stat) { \
40 .stat_string = _name, \
41 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
42 .stat_offset = offsetof(_type, _stat) \
43}
44#define I40E_NETDEV_STAT(_net_stat) \
45 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
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)
50
51static const struct i40e_stats i40e_gstrings_net_stats[] = {
52 I40E_NETDEV_STAT(rx_packets),
53 I40E_NETDEV_STAT(tx_packets),
54 I40E_NETDEV_STAT(rx_bytes),
55 I40E_NETDEV_STAT(tx_bytes),
56 I40E_NETDEV_STAT(rx_errors),
57 I40E_NETDEV_STAT(tx_errors),
58 I40E_NETDEV_STAT(rx_dropped),
59 I40E_NETDEV_STAT(tx_dropped),
60 I40E_NETDEV_STAT(multicast),
61 I40E_NETDEV_STAT(collisions),
62 I40E_NETDEV_STAT(rx_length_errors),
63 I40E_NETDEV_STAT(rx_crc_errors),
64};
65
66/* These PF_STATs might look like duplicates of some NETDEV_STATs,
67 * but they are separate. This device supports Virtualization, and
68 * as such might have several netdevs supporting VMDq and FCoE going
69 * through a single port. The NETDEV_STATs are for individual netdevs
70 * seen at the top of the stack, and the PF_STATs are for the physical
71 * function at the bottom of the stack hosting those netdevs.
72 *
73 * The PF_STATs are appended to the netdev stats only when ethtool -S
74 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
75 */
76static struct i40e_stats i40e_gstrings_stats[] = {
77 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
78 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
79 I40E_PF_STAT("rx_errors", stats.eth.rx_errors),
80 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
81 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
82 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
83 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
84 I40E_PF_STAT("crc_errors", stats.crc_errors),
85 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
86 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
87 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
88 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
89 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
90 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
91 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
92 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
93 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
94 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
95 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
96 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
97 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
98 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
99 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
100 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
101 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
102 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
103 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
104 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
105 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
106 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
107 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
108 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
109 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
110 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
111 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
112};
113
114#define I40E_QUEUE_STATS_LEN(n) \
115 ((((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs + \
116 ((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs) * 2)
117#define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
118#define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
119#define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
120 I40E_QUEUE_STATS_LEN((n)))
121#define I40E_PFC_STATS_LEN ( \
122 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
123 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
124 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
125 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
126 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
127 / sizeof(u64))
128#define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
129 I40E_PFC_STATS_LEN + \
130 I40E_VSI_STATS_LEN((n)))
131
132enum i40e_ethtool_test_id {
133 I40E_ETH_TEST_REG = 0,
134 I40E_ETH_TEST_EEPROM,
135 I40E_ETH_TEST_INTR,
136 I40E_ETH_TEST_LOOPBACK,
137 I40E_ETH_TEST_LINK,
138};
139
140static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
141 "Register test (offline)",
142 "Eeprom test (offline)",
143 "Interrupt test (offline)",
144 "Loopback test (offline)",
145 "Link test (on/offline)"
146};
147
148#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
149
150/**
151 * i40e_get_settings - Get Link Speed and Duplex settings
152 * @netdev: network interface device structure
153 * @ecmd: ethtool command
154 *
155 * Reports speed/duplex settings based on media_type
156 **/
157static int i40e_get_settings(struct net_device *netdev,
158 struct ethtool_cmd *ecmd)
159{
160 struct i40e_netdev_priv *np = netdev_priv(netdev);
161 struct i40e_pf *pf = np->vsi->back;
162 struct i40e_hw *hw = &pf->hw;
163 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
164 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
165 u32 link_speed = hw_link_info->link_speed;
166
167 /* hardware is either in 40G mode or 10G mode
168 * NOTE: this section initializes supported and advertising
169 */
170 switch (hw_link_info->phy_type) {
171 case I40E_PHY_TYPE_40GBASE_CR4:
172 case I40E_PHY_TYPE_40GBASE_CR4_CU:
173 ecmd->supported = SUPPORTED_40000baseCR4_Full;
174 ecmd->advertising = ADVERTISED_40000baseCR4_Full;
175 break;
176 case I40E_PHY_TYPE_40GBASE_KR4:
177 ecmd->supported = SUPPORTED_40000baseKR4_Full;
178 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
179 break;
180 case I40E_PHY_TYPE_40GBASE_SR4:
181 ecmd->supported = SUPPORTED_40000baseSR4_Full;
182 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
183 break;
184 case I40E_PHY_TYPE_40GBASE_LR4:
185 ecmd->supported = SUPPORTED_40000baseLR4_Full;
186 ecmd->advertising = ADVERTISED_40000baseLR4_Full;
187 break;
188 case I40E_PHY_TYPE_10GBASE_KX4:
189 ecmd->supported = SUPPORTED_10000baseKX4_Full;
190 ecmd->advertising = ADVERTISED_10000baseKX4_Full;
191 break;
192 case I40E_PHY_TYPE_10GBASE_KR:
193 ecmd->supported = SUPPORTED_10000baseKR_Full;
194 ecmd->advertising = ADVERTISED_10000baseKR_Full;
195 break;
196 case I40E_PHY_TYPE_10GBASE_T:
197 default:
198 ecmd->supported = SUPPORTED_10000baseT_Full;
199 ecmd->advertising = ADVERTISED_10000baseT_Full;
200 break;
201 }
202
203 /* for now just say autoneg all the time */
204 ecmd->supported |= SUPPORTED_Autoneg;
205
206 if (hw->phy.media_type == I40E_MEDIA_TYPE_BACKPLANE) {
207 ecmd->supported |= SUPPORTED_Backplane;
208 ecmd->advertising |= ADVERTISED_Backplane;
209 ecmd->port = PORT_NONE;
210 } else if (hw->phy.media_type == I40E_MEDIA_TYPE_BASET) {
211 ecmd->supported |= SUPPORTED_TP;
212 ecmd->advertising |= ADVERTISED_TP;
213 ecmd->port = PORT_TP;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000214 } else if (hw->phy.media_type == I40E_MEDIA_TYPE_DA) {
215 ecmd->supported |= SUPPORTED_FIBRE;
216 ecmd->advertising |= ADVERTISED_FIBRE;
217 ecmd->port = PORT_DA;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000218 } else {
219 ecmd->supported |= SUPPORTED_FIBRE;
220 ecmd->advertising |= ADVERTISED_FIBRE;
221 ecmd->port = PORT_FIBRE;
222 }
223
224 ecmd->transceiver = XCVR_EXTERNAL;
225
226 if (link_up) {
227 switch (link_speed) {
228 case I40E_LINK_SPEED_40GB:
229 /* need a SPEED_40000 in ethtool.h */
230 ethtool_cmd_speed_set(ecmd, 40000);
231 break;
232 case I40E_LINK_SPEED_10GB:
233 ethtool_cmd_speed_set(ecmd, SPEED_10000);
234 break;
235 default:
236 break;
237 }
238 ecmd->duplex = DUPLEX_FULL;
239 } else {
240 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
241 ecmd->duplex = DUPLEX_UNKNOWN;
242 }
243
244 return 0;
245}
246
247/**
248 * i40e_get_pauseparam - Get Flow Control status
249 * Return tx/rx-pause status
250 **/
251static void i40e_get_pauseparam(struct net_device *netdev,
252 struct ethtool_pauseparam *pause)
253{
254 struct i40e_netdev_priv *np = netdev_priv(netdev);
255 struct i40e_pf *pf = np->vsi->back;
256 struct i40e_hw *hw = &pf->hw;
257 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
258
259 pause->autoneg =
260 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
261 AUTONEG_ENABLE : AUTONEG_DISABLE);
262
263 pause->rx_pause = 0;
264 pause->tx_pause = 0;
265 if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_RX)
266 pause->rx_pause = 1;
267 if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_TX)
268 pause->tx_pause = 1;
269}
270
271static u32 i40e_get_msglevel(struct net_device *netdev)
272{
273 struct i40e_netdev_priv *np = netdev_priv(netdev);
274 struct i40e_pf *pf = np->vsi->back;
275
276 return pf->msg_enable;
277}
278
279static void i40e_set_msglevel(struct net_device *netdev, u32 data)
280{
281 struct i40e_netdev_priv *np = netdev_priv(netdev);
282 struct i40e_pf *pf = np->vsi->back;
283
284 if (I40E_DEBUG_USER & data)
285 pf->hw.debug_mask = data;
286 pf->msg_enable = data;
287}
288
289static int i40e_get_regs_len(struct net_device *netdev)
290{
291 int reg_count = 0;
292 int i;
293
294 for (i = 0; i40e_reg_list[i].offset != 0; i++)
295 reg_count += i40e_reg_list[i].elements;
296
297 return reg_count * sizeof(u32);
298}
299
300static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
301 void *p)
302{
303 struct i40e_netdev_priv *np = netdev_priv(netdev);
304 struct i40e_pf *pf = np->vsi->back;
305 struct i40e_hw *hw = &pf->hw;
306 u32 *reg_buf = p;
307 int i, j, ri;
308 u32 reg;
309
310 /* Tell ethtool which driver-version-specific regs output we have.
311 *
312 * At some point, if we have ethtool doing special formatting of
313 * this data, it will rely on this version number to know how to
314 * interpret things. Hence, this needs to be updated if/when the
315 * diags register table is changed.
316 */
317 regs->version = 1;
318
319 /* loop through the diags reg table for what to print */
320 ri = 0;
321 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
322 for (j = 0; j < i40e_reg_list[i].elements; j++) {
323 reg = i40e_reg_list[i].offset
324 + (j * i40e_reg_list[i].stride);
325 reg_buf[ri++] = rd32(hw, reg);
326 }
327 }
328
329}
330
331static int i40e_get_eeprom(struct net_device *netdev,
332 struct ethtool_eeprom *eeprom, u8 *bytes)
333{
334 struct i40e_netdev_priv *np = netdev_priv(netdev);
335 struct i40e_hw *hw = &np->vsi->back->hw;
336 int first_word, last_word;
337 u16 i, eeprom_len;
338 u16 *eeprom_buff;
339 int ret_val = 0;
340
341 if (eeprom->len == 0)
342 return -EINVAL;
343
344 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
345
346 first_word = eeprom->offset >> 1;
347 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
348 eeprom_len = last_word - first_word + 1;
349
350 eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL);
351 if (!eeprom_buff)
352 return -ENOMEM;
353
354 ret_val = i40e_read_nvm_buffer(hw, first_word, &eeprom_len,
355 eeprom_buff);
356 if (eeprom_len == 0) {
357 kfree(eeprom_buff);
358 return -EACCES;
359 }
360
361 /* Device's eeprom is always little-endian, word addressable */
362 for (i = 0; i < eeprom_len; i++)
363 le16_to_cpus(&eeprom_buff[i]);
364
365 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
366 kfree(eeprom_buff);
367
368 return ret_val;
369}
370
371static int i40e_get_eeprom_len(struct net_device *netdev)
372{
373 struct i40e_netdev_priv *np = netdev_priv(netdev);
374 struct i40e_hw *hw = &np->vsi->back->hw;
375
376 return hw->nvm.sr_size * 2;
377}
378
379static void i40e_get_drvinfo(struct net_device *netdev,
380 struct ethtool_drvinfo *drvinfo)
381{
382 struct i40e_netdev_priv *np = netdev_priv(netdev);
383 struct i40e_vsi *vsi = np->vsi;
384 struct i40e_pf *pf = vsi->back;
385
386 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
387 strlcpy(drvinfo->version, i40e_driver_version_str,
388 sizeof(drvinfo->version));
389 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
390 sizeof(drvinfo->fw_version));
391 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
392 sizeof(drvinfo->bus_info));
393}
394
395static void i40e_get_ringparam(struct net_device *netdev,
396 struct ethtool_ringparam *ring)
397{
398 struct i40e_netdev_priv *np = netdev_priv(netdev);
399 struct i40e_pf *pf = np->vsi->back;
400 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
401
402 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
403 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
404 ring->rx_mini_max_pending = 0;
405 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000406 ring->rx_pending = vsi->rx_rings[0]->count;
407 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000408 ring->rx_mini_pending = 0;
409 ring->rx_jumbo_pending = 0;
410}
411
412static int i40e_set_ringparam(struct net_device *netdev,
413 struct ethtool_ringparam *ring)
414{
415 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
416 struct i40e_netdev_priv *np = netdev_priv(netdev);
417 struct i40e_vsi *vsi = np->vsi;
418 struct i40e_pf *pf = vsi->back;
419 u32 new_rx_count, new_tx_count;
420 int i, err = 0;
421
422 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
423 return -EINVAL;
424
425 new_tx_count = clamp_t(u32, ring->tx_pending,
426 I40E_MIN_NUM_DESCRIPTORS,
427 I40E_MAX_NUM_DESCRIPTORS);
428 new_tx_count = ALIGN(new_tx_count, I40E_REQ_DESCRIPTOR_MULTIPLE);
429
430 new_rx_count = clamp_t(u32, ring->rx_pending,
431 I40E_MIN_NUM_DESCRIPTORS,
432 I40E_MAX_NUM_DESCRIPTORS);
433 new_rx_count = ALIGN(new_rx_count, I40E_REQ_DESCRIPTOR_MULTIPLE);
434
435 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000436 if ((new_tx_count == vsi->tx_rings[0]->count) &&
437 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000438 return 0;
439
440 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
441 usleep_range(1000, 2000);
442
443 if (!netif_running(vsi->netdev)) {
444 /* simple case - set for the next time the netdev is started */
445 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000446 vsi->tx_rings[i]->count = new_tx_count;
447 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000448 }
449 goto done;
450 }
451
452 /* We can't just free everything and then setup again,
453 * because the ISRs in MSI-X mode get passed pointers
454 * to the Tx and Rx ring structs.
455 */
456
457 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000458 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000459 netdev_info(netdev,
460 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000461 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000462 tx_rings = kcalloc(vsi->alloc_queue_pairs,
463 sizeof(struct i40e_ring), GFP_KERNEL);
464 if (!tx_rings) {
465 err = -ENOMEM;
466 goto done;
467 }
468
469 for (i = 0; i < vsi->num_queue_pairs; i++) {
470 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000471 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000472 tx_rings[i].count = new_tx_count;
473 err = i40e_setup_tx_descriptors(&tx_rings[i]);
474 if (err) {
475 while (i) {
476 i--;
477 i40e_free_tx_resources(&tx_rings[i]);
478 }
479 kfree(tx_rings);
480 tx_rings = NULL;
481
482 goto done;
483 }
484 }
485 }
486
487 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000488 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000489 netdev_info(netdev,
490 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000491 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000492 rx_rings = kcalloc(vsi->alloc_queue_pairs,
493 sizeof(struct i40e_ring), GFP_KERNEL);
494 if (!rx_rings) {
495 err = -ENOMEM;
496 goto free_tx;
497 }
498
499 for (i = 0; i < vsi->num_queue_pairs; i++) {
500 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000501 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000502 rx_rings[i].count = new_rx_count;
503 err = i40e_setup_rx_descriptors(&rx_rings[i]);
504 if (err) {
505 while (i) {
506 i--;
507 i40e_free_rx_resources(&rx_rings[i]);
508 }
509 kfree(rx_rings);
510 rx_rings = NULL;
511
512 goto free_tx;
513 }
514 }
515 }
516
517 /* Bring interface down, copy in the new ring info,
518 * then restore the interface
519 */
520 i40e_down(vsi);
521
522 if (tx_rings) {
523 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000524 i40e_free_tx_resources(vsi->tx_rings[i]);
525 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000526 }
527 kfree(tx_rings);
528 tx_rings = NULL;
529 }
530
531 if (rx_rings) {
532 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000533 i40e_free_rx_resources(vsi->rx_rings[i]);
534 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000535 }
536 kfree(rx_rings);
537 rx_rings = NULL;
538 }
539
540 i40e_up(vsi);
541
542free_tx:
543 /* error cleanup if the Rx allocations failed after getting Tx */
544 if (tx_rings) {
545 for (i = 0; i < vsi->num_queue_pairs; i++)
546 i40e_free_tx_resources(&tx_rings[i]);
547 kfree(tx_rings);
548 tx_rings = NULL;
549 }
550
551done:
552 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
553
554 return err;
555}
556
557static int i40e_get_sset_count(struct net_device *netdev, int sset)
558{
559 struct i40e_netdev_priv *np = netdev_priv(netdev);
560 struct i40e_vsi *vsi = np->vsi;
561 struct i40e_pf *pf = vsi->back;
562
563 switch (sset) {
564 case ETH_SS_TEST:
565 return I40E_TEST_LEN;
566 case ETH_SS_STATS:
567 if (vsi == pf->vsi[pf->lan_vsi])
568 return I40E_PF_STATS_LEN(netdev);
569 else
570 return I40E_VSI_STATS_LEN(netdev);
571 default:
572 return -EOPNOTSUPP;
573 }
574}
575
576static void i40e_get_ethtool_stats(struct net_device *netdev,
577 struct ethtool_stats *stats, u64 *data)
578{
579 struct i40e_netdev_priv *np = netdev_priv(netdev);
580 struct i40e_vsi *vsi = np->vsi;
581 struct i40e_pf *pf = vsi->back;
582 int i = 0;
583 char *p;
584 int j;
585 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000586 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000587
588 i40e_update_stats(vsi);
589
590 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
591 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
592 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
593 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
594 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000595 rcu_read_lock();
Alexander Duycka114d0a2013-09-28 06:00:43 +0000596 for (j = 0; j < vsi->num_queue_pairs; j++, i += 4) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000597 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
598 struct i40e_ring *rx_ring;
599
600 if (!tx_ring)
601 continue;
602
603 /* process Tx ring statistics */
604 do {
605 start = u64_stats_fetch_begin_bh(&tx_ring->syncp);
606 data[i] = tx_ring->stats.packets;
607 data[i + 1] = tx_ring->stats.bytes;
608 } while (u64_stats_fetch_retry_bh(&tx_ring->syncp, start));
609
610 /* Rx ring is the 2nd half of the queue pair */
611 rx_ring = &tx_ring[1];
612 do {
613 start = u64_stats_fetch_begin_bh(&rx_ring->syncp);
614 data[i + 2] = rx_ring->stats.packets;
615 data[i + 3] = rx_ring->stats.bytes;
616 } while (u64_stats_fetch_retry_bh(&rx_ring->syncp, start));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000617 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000618 rcu_read_unlock();
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000619 if (vsi == pf->vsi[pf->lan_vsi]) {
620 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
621 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
622 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
623 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
624 }
625 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
626 data[i++] = pf->stats.priority_xon_tx[j];
627 data[i++] = pf->stats.priority_xoff_tx[j];
628 }
629 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
630 data[i++] = pf->stats.priority_xon_rx[j];
631 data[i++] = pf->stats.priority_xoff_rx[j];
632 }
633 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
634 data[i++] = pf->stats.priority_xon_2_xoff[j];
635 }
636}
637
638static void i40e_get_strings(struct net_device *netdev, u32 stringset,
639 u8 *data)
640{
641 struct i40e_netdev_priv *np = netdev_priv(netdev);
642 struct i40e_vsi *vsi = np->vsi;
643 struct i40e_pf *pf = vsi->back;
644 char *p = (char *)data;
645 int i;
646
647 switch (stringset) {
648 case ETH_SS_TEST:
649 for (i = 0; i < I40E_TEST_LEN; i++) {
650 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
651 data += ETH_GSTRING_LEN;
652 }
653 break;
654 case ETH_SS_STATS:
655 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
656 snprintf(p, ETH_GSTRING_LEN, "%s",
657 i40e_gstrings_net_stats[i].stat_string);
658 p += ETH_GSTRING_LEN;
659 }
660 for (i = 0; i < vsi->num_queue_pairs; i++) {
661 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
662 p += ETH_GSTRING_LEN;
663 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
664 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000665 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
666 p += ETH_GSTRING_LEN;
667 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
668 p += ETH_GSTRING_LEN;
669 }
670 if (vsi == pf->vsi[pf->lan_vsi]) {
671 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
672 snprintf(p, ETH_GSTRING_LEN, "port.%s",
673 i40e_gstrings_stats[i].stat_string);
674 p += ETH_GSTRING_LEN;
675 }
676 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
677 snprintf(p, ETH_GSTRING_LEN,
678 "port.tx_priority_%u_xon", i);
679 p += ETH_GSTRING_LEN;
680 snprintf(p, ETH_GSTRING_LEN,
681 "port.tx_priority_%u_xoff", i);
682 p += ETH_GSTRING_LEN;
683 }
684 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
685 snprintf(p, ETH_GSTRING_LEN,
686 "port.rx_priority_%u_xon", i);
687 p += ETH_GSTRING_LEN;
688 snprintf(p, ETH_GSTRING_LEN,
689 "port.rx_priority_%u_xoff", i);
690 p += ETH_GSTRING_LEN;
691 }
692 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
693 snprintf(p, ETH_GSTRING_LEN,
694 "port.rx_priority_%u_xon_2_xoff", i);
695 p += ETH_GSTRING_LEN;
696 }
697 }
698 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
699 break;
700 }
701}
702
703static int i40e_get_ts_info(struct net_device *dev,
704 struct ethtool_ts_info *info)
705{
706 return ethtool_op_get_ts_info(dev, info);
707}
708
709static int i40e_link_test(struct i40e_pf *pf, u64 *data)
710{
711 if (i40e_get_link_status(&pf->hw))
712 *data = 0;
713 else
714 *data = 1;
715
716 return *data;
717}
718
719static int i40e_reg_test(struct i40e_pf *pf, u64 *data)
720{
721 i40e_status ret;
722
723 ret = i40e_diag_reg_test(&pf->hw);
724 *data = ret;
725
726 return ret;
727}
728
729static int i40e_eeprom_test(struct i40e_pf *pf, u64 *data)
730{
731 i40e_status ret;
732
733 ret = i40e_diag_eeprom_test(&pf->hw);
734 *data = ret;
735
736 return ret;
737}
738
739static int i40e_intr_test(struct i40e_pf *pf, u64 *data)
740{
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000741 u16 swc_old = pf->sw_int_count;
742
743 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
744 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
745 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
746 usleep_range(1000, 2000);
747 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000748
749 return *data;
750}
751
752static int i40e_loopback_test(struct i40e_pf *pf, u64 *data)
753{
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000754 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000755
756 return *data;
757}
758
759static void i40e_diag_test(struct net_device *netdev,
760 struct ethtool_test *eth_test, u64 *data)
761{
762 struct i40e_netdev_priv *np = netdev_priv(netdev);
763 struct i40e_pf *pf = np->vsi->back;
764
765 set_bit(__I40E_TESTING, &pf->state);
766 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
767 /* Offline tests */
768
769 netdev_info(netdev, "offline testing starting\n");
770
771 /* Link test performed before hardware reset
772 * so autoneg doesn't interfere with test result
773 */
774 netdev_info(netdev, "link test starting\n");
775 if (i40e_link_test(pf, &data[I40E_ETH_TEST_LINK]))
776 eth_test->flags |= ETH_TEST_FL_FAILED;
777
778 netdev_info(netdev, "register test starting\n");
779 if (i40e_reg_test(pf, &data[I40E_ETH_TEST_REG]))
780 eth_test->flags |= ETH_TEST_FL_FAILED;
781
782 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
783 netdev_info(netdev, "eeprom test starting\n");
784 if (i40e_eeprom_test(pf, &data[I40E_ETH_TEST_EEPROM]))
785 eth_test->flags |= ETH_TEST_FL_FAILED;
786
787 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
788 netdev_info(netdev, "interrupt test starting\n");
789 if (i40e_intr_test(pf, &data[I40E_ETH_TEST_INTR]))
790 eth_test->flags |= ETH_TEST_FL_FAILED;
791
792 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
793 netdev_info(netdev, "loopback test starting\n");
794 if (i40e_loopback_test(pf, &data[I40E_ETH_TEST_LOOPBACK]))
795 eth_test->flags |= ETH_TEST_FL_FAILED;
796
797 } else {
798 netdev_info(netdev, "online test starting\n");
799 /* Online tests */
800 if (i40e_link_test(pf, &data[I40E_ETH_TEST_LINK]))
801 eth_test->flags |= ETH_TEST_FL_FAILED;
802
803 /* Offline only tests, not run in online; pass by default */
804 data[I40E_ETH_TEST_REG] = 0;
805 data[I40E_ETH_TEST_EEPROM] = 0;
806 data[I40E_ETH_TEST_INTR] = 0;
807 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000808 }
Shannon Nelsonc140c172013-11-20 10:02:58 +0000809 clear_bit(__I40E_TESTING, &pf->state);
810
811 netdev_info(netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000812}
813
814static void i40e_get_wol(struct net_device *netdev,
815 struct ethtool_wolinfo *wol)
816{
817 wol->supported = 0;
818 wol->wolopts = 0;
819}
820
821static int i40e_nway_reset(struct net_device *netdev)
822{
823 /* restart autonegotiation */
824 struct i40e_netdev_priv *np = netdev_priv(netdev);
825 struct i40e_pf *pf = np->vsi->back;
826 struct i40e_hw *hw = &pf->hw;
827 i40e_status ret = 0;
828
829 ret = i40e_aq_set_link_restart_an(hw, NULL);
830 if (ret) {
831 netdev_info(netdev, "link restart failed, aq_err=%d\n",
832 pf->hw.aq.asq_last_status);
833 return -EIO;
834 }
835
836 return 0;
837}
838
839static int i40e_set_phys_id(struct net_device *netdev,
840 enum ethtool_phys_id_state state)
841{
842 struct i40e_netdev_priv *np = netdev_priv(netdev);
843 struct i40e_pf *pf = np->vsi->back;
844 struct i40e_hw *hw = &pf->hw;
845 int blink_freq = 2;
846
847 switch (state) {
848 case ETHTOOL_ID_ACTIVE:
849 pf->led_status = i40e_led_get(hw);
850 return blink_freq;
851 case ETHTOOL_ID_ON:
852 i40e_led_set(hw, 0xF);
853 break;
854 case ETHTOOL_ID_OFF:
855 i40e_led_set(hw, 0x0);
856 break;
857 case ETHTOOL_ID_INACTIVE:
858 i40e_led_set(hw, pf->led_status);
859 break;
860 }
861
862 return 0;
863}
864
865/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
866 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
867 * 125us (8000 interrupts per second) == ITR(62)
868 */
869
870static int i40e_get_coalesce(struct net_device *netdev,
871 struct ethtool_coalesce *ec)
872{
873 struct i40e_netdev_priv *np = netdev_priv(netdev);
874 struct i40e_vsi *vsi = np->vsi;
875
876 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
877 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
878
879 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
880 ec->rx_coalesce_usecs = 1;
881 else
882 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
883
884 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
885 ec->tx_coalesce_usecs = 1;
886 else
887 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
888
889 return 0;
890}
891
892static int i40e_set_coalesce(struct net_device *netdev,
893 struct ethtool_coalesce *ec)
894{
895 struct i40e_netdev_priv *np = netdev_priv(netdev);
896 struct i40e_q_vector *q_vector;
897 struct i40e_vsi *vsi = np->vsi;
898 struct i40e_pf *pf = vsi->back;
899 struct i40e_hw *hw = &pf->hw;
900 u16 vector;
901 int i;
902
903 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
904 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
905
906 switch (ec->rx_coalesce_usecs) {
907 case 0:
908 vsi->rx_itr_setting = 0;
909 break;
910 case 1:
911 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
912 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
913 break;
914 default:
915 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
916 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
917 return -EINVAL;
918 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
919 break;
920 }
921
922 switch (ec->tx_coalesce_usecs) {
923 case 0:
924 vsi->tx_itr_setting = 0;
925 break;
926 case 1:
927 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
928 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
929 break;
930 default:
931 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
932 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
933 return -EINVAL;
934 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
935 break;
936 }
937
938 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +0000939 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
940 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000941 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
942 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
943 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
944 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
945 i40e_flush(hw);
946 }
947
948 return 0;
949}
950
951/**
952 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
953 * @pf: pointer to the physical function struct
954 * @cmd: ethtool rxnfc command
955 *
956 * Returns Success if the flow is supported, else Invalid Input.
957 **/
958static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
959{
960 cmd->data = 0;
961
962 /* Report default options for RSS on i40e */
963 switch (cmd->flow_type) {
964 case TCP_V4_FLOW:
965 case UDP_V4_FLOW:
966 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
967 /* fall through to add IP fields */
968 case SCTP_V4_FLOW:
969 case AH_ESP_V4_FLOW:
970 case AH_V4_FLOW:
971 case ESP_V4_FLOW:
972 case IPV4_FLOW:
973 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
974 break;
975 case TCP_V6_FLOW:
976 case UDP_V6_FLOW:
977 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
978 /* fall through to add IP fields */
979 case SCTP_V6_FLOW:
980 case AH_ESP_V6_FLOW:
981 case AH_V6_FLOW:
982 case ESP_V6_FLOW:
983 case IPV6_FLOW:
984 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
985 break;
986 default:
987 return -EINVAL;
988 }
989
990 return 0;
991}
992
993/**
994 * i40e_get_rxnfc - command to get RX flow classification rules
995 * @netdev: network interface device structure
996 * @cmd: ethtool rxnfc command
997 *
998 * Returns Success if the command is supported.
999 **/
1000static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1001 u32 *rule_locs)
1002{
1003 struct i40e_netdev_priv *np = netdev_priv(netdev);
1004 struct i40e_vsi *vsi = np->vsi;
1005 struct i40e_pf *pf = vsi->back;
1006 int ret = -EOPNOTSUPP;
1007
1008 switch (cmd->cmd) {
1009 case ETHTOOL_GRXRINGS:
1010 cmd->data = vsi->alloc_queue_pairs;
1011 ret = 0;
1012 break;
1013 case ETHTOOL_GRXFH:
1014 ret = i40e_get_rss_hash_opts(pf, cmd);
1015 break;
1016 case ETHTOOL_GRXCLSRLCNT:
1017 ret = 0;
1018 break;
1019 case ETHTOOL_GRXCLSRULE:
1020 ret = 0;
1021 break;
1022 case ETHTOOL_GRXCLSRLALL:
1023 cmd->data = 500;
1024 ret = 0;
1025 default:
1026 break;
1027 }
1028
1029 return ret;
1030}
1031
1032/**
1033 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1034 * @pf: pointer to the physical function struct
1035 * @cmd: ethtool rxnfc command
1036 *
1037 * Returns Success if the flow input set is supported.
1038 **/
1039static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1040{
1041 struct i40e_hw *hw = &pf->hw;
1042 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1043 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1044
1045 /* RSS does not support anything other than hashing
1046 * to queues on src and dst IPs and ports
1047 */
1048 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1049 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1050 return -EINVAL;
1051
1052 /* We need at least the IP SRC and DEST fields for hashing */
1053 if (!(nfc->data & RXH_IP_SRC) ||
1054 !(nfc->data & RXH_IP_DST))
1055 return -EINVAL;
1056
1057 switch (nfc->flow_type) {
1058 case TCP_V4_FLOW:
1059 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1060 case 0:
1061 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1062 break;
1063 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1064 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1065 break;
1066 default:
1067 return -EINVAL;
1068 }
1069 break;
1070 case TCP_V6_FLOW:
1071 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1072 case 0:
1073 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1074 break;
1075 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1076 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1077 break;
1078 default:
1079 return -EINVAL;
1080 }
1081 break;
1082 case UDP_V4_FLOW:
1083 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1084 case 0:
1085 hena &=
1086 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1087 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1088 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1089 break;
1090 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1091 hena |=
1092 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1093 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1094 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1095 break;
1096 default:
1097 return -EINVAL;
1098 }
1099 break;
1100 case UDP_V6_FLOW:
1101 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1102 case 0:
1103 hena &=
1104 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1105 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1106 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1107 break;
1108 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1109 hena |=
1110 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1111 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1112 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1113 break;
1114 default:
1115 return -EINVAL;
1116 }
1117 break;
1118 case AH_ESP_V4_FLOW:
1119 case AH_V4_FLOW:
1120 case ESP_V4_FLOW:
1121 case SCTP_V4_FLOW:
1122 if ((nfc->data & RXH_L4_B_0_1) ||
1123 (nfc->data & RXH_L4_B_2_3))
1124 return -EINVAL;
1125 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1126 break;
1127 case AH_ESP_V6_FLOW:
1128 case AH_V6_FLOW:
1129 case ESP_V6_FLOW:
1130 case SCTP_V6_FLOW:
1131 if ((nfc->data & RXH_L4_B_0_1) ||
1132 (nfc->data & RXH_L4_B_2_3))
1133 return -EINVAL;
1134 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1135 break;
1136 case IPV4_FLOW:
1137 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1138 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1139 break;
1140 case IPV6_FLOW:
1141 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1142 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1143 break;
1144 default:
1145 return -EINVAL;
1146 }
1147
1148 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1149 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1150 i40e_flush(hw);
1151
1152 return 0;
1153}
1154
1155#define IP_HEADER_OFFSET 14
1156/**
1157 * i40e_add_del_fdir_udpv4 - Add/Remove UDPv4 Flow Director filters for
1158 * a specific flow spec
1159 * @vsi: pointer to the targeted VSI
1160 * @fd_data: the flow director data required from the FDir descriptor
1161 * @ethtool_rx_flow_spec: the flow spec
1162 * @add: true adds a filter, false removes it
1163 *
1164 * Returns 0 if the filters were successfully added or removed
1165 **/
1166static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
1167 struct i40e_fdir_data *fd_data,
1168 struct ethtool_rx_flow_spec *fsp, bool add)
1169{
1170 struct i40e_pf *pf = vsi->back;
1171 struct udphdr *udp;
1172 struct iphdr *ip;
1173 bool err = false;
1174 int ret;
1175 int i;
1176
1177 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1178 udp = (struct udphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1179 + sizeof(struct iphdr));
1180
1181 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1182 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1183 udp->source = fsp->h_u.tcp_ip4_spec.psrc;
1184 udp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1185
1186 for (i = I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP;
1187 i <= I40E_FILTER_PCTYPE_NONF_IPV4_UDP; i++) {
1188 fd_data->pctype = i;
1189 ret = i40e_program_fdir_filter(fd_data, pf, add);
1190
1191 if (ret) {
1192 dev_info(&pf->pdev->dev,
1193 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1194 fd_data->pctype, ret);
1195 err = true;
1196 } else {
1197 dev_info(&pf->pdev->dev,
1198 "Filter OK for PCTYPE %d (ret = %d)\n",
1199 fd_data->pctype, ret);
1200 }
1201 }
1202
1203 return err ? -EOPNOTSUPP : 0;
1204}
1205
1206/**
1207 * i40e_add_del_fdir_tcpv4 - Add/Remove TCPv4 Flow Director filters for
1208 * a specific flow spec
1209 * @vsi: pointer to the targeted VSI
1210 * @fd_data: the flow director data required from the FDir descriptor
1211 * @ethtool_rx_flow_spec: the flow spec
1212 * @add: true adds a filter, false removes it
1213 *
1214 * Returns 0 if the filters were successfully added or removed
1215 **/
1216static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
1217 struct i40e_fdir_data *fd_data,
1218 struct ethtool_rx_flow_spec *fsp, bool add)
1219{
1220 struct i40e_pf *pf = vsi->back;
1221 struct tcphdr *tcp;
1222 struct iphdr *ip;
1223 bool err = false;
1224 int ret;
1225
1226 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1227 tcp = (struct tcphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1228 + sizeof(struct iphdr));
1229
1230 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1231 tcp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1232
1233 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN;
1234 ret = i40e_program_fdir_filter(fd_data, pf, add);
1235
1236 if (ret) {
1237 dev_info(&pf->pdev->dev,
1238 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1239 fd_data->pctype, ret);
1240 err = true;
1241 } else {
1242 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1243 fd_data->pctype, ret);
1244 }
1245
1246 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1247 tcp->source = fsp->h_u.tcp_ip4_spec.psrc;
1248
1249 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
1250
1251 ret = i40e_program_fdir_filter(fd_data, pf, add);
1252 if (ret) {
1253 dev_info(&pf->pdev->dev,
1254 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1255 fd_data->pctype, ret);
1256 err = true;
1257 } else {
1258 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1259 fd_data->pctype, ret);
1260 }
1261
1262 return err ? -EOPNOTSUPP : 0;
1263}
1264
1265/**
1266 * i40e_add_del_fdir_sctpv4 - Add/Remove SCTPv4 Flow Director filters for
1267 * a specific flow spec
1268 * @vsi: pointer to the targeted VSI
1269 * @fd_data: the flow director data required from the FDir descriptor
1270 * @ethtool_rx_flow_spec: the flow spec
1271 * @add: true adds a filter, false removes it
1272 *
1273 * Returns 0 if the filters were successfully added or removed
1274 **/
1275static int i40e_add_del_fdir_sctpv4(struct i40e_vsi *vsi,
1276 struct i40e_fdir_data *fd_data,
1277 struct ethtool_rx_flow_spec *fsp, bool add)
1278{
1279 return -EOPNOTSUPP;
1280}
1281
1282/**
1283 * i40e_add_del_fdir_ipv4 - Add/Remove IPv4 Flow Director filters for
1284 * a specific flow spec
1285 * @vsi: pointer to the targeted VSI
1286 * @fd_data: the flow director data required for the FDir descriptor
1287 * @fsp: the ethtool flow spec
1288 * @add: true adds a filter, false removes it
1289 *
1290 * Returns 0 if the filters were successfully added or removed
1291 **/
1292static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
1293 struct i40e_fdir_data *fd_data,
1294 struct ethtool_rx_flow_spec *fsp, bool add)
1295{
1296 struct i40e_pf *pf = vsi->back;
1297 struct iphdr *ip;
1298 bool err = false;
1299 int ret;
1300 int i;
1301
1302 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1303
1304 ip->saddr = fsp->h_u.usr_ip4_spec.ip4src;
1305 ip->daddr = fsp->h_u.usr_ip4_spec.ip4dst;
1306 ip->protocol = fsp->h_u.usr_ip4_spec.proto;
1307
1308 for (i = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
1309 i <= I40E_FILTER_PCTYPE_FRAG_IPV4; i++) {
1310 fd_data->pctype = i;
1311 ret = i40e_program_fdir_filter(fd_data, pf, add);
1312
1313 if (ret) {
1314 dev_info(&pf->pdev->dev,
1315 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1316 fd_data->pctype, ret);
1317 err = true;
1318 } else {
1319 dev_info(&pf->pdev->dev,
1320 "Filter OK for PCTYPE %d (ret = %d)\n",
1321 fd_data->pctype, ret);
1322 }
1323 }
1324
1325 return err ? -EOPNOTSUPP : 0;
1326}
1327
1328/**
1329 * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters for
1330 * a specific flow spec based on their protocol
1331 * @vsi: pointer to the targeted VSI
1332 * @cmd: command to get or set RX flow classification rules
1333 * @add: true adds a filter, false removes it
1334 *
1335 * Returns 0 if the filters were successfully added or removed
1336 **/
1337static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
1338 struct ethtool_rxnfc *cmd, bool add)
1339{
1340 struct i40e_fdir_data fd_data;
1341 int ret = -EINVAL;
1342 struct i40e_pf *pf;
1343 struct ethtool_rx_flow_spec *fsp =
1344 (struct ethtool_rx_flow_spec *)&cmd->fs;
1345
1346 if (!vsi)
1347 return -EINVAL;
1348
1349 pf = vsi->back;
1350
1351 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1352 (fsp->ring_cookie >= vsi->num_queue_pairs))
1353 return -EINVAL;
1354
1355 /* Populate the Flow Director that we have at the moment
1356 * and allocate the raw packet buffer for the calling functions
1357 */
1358 fd_data.raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
1359 GFP_KERNEL);
1360
1361 if (!fd_data.raw_packet) {
1362 dev_info(&pf->pdev->dev, "Could not allocate memory\n");
1363 return -ENOMEM;
1364 }
1365
1366 fd_data.q_index = fsp->ring_cookie;
1367 fd_data.flex_off = 0;
1368 fd_data.pctype = 0;
1369 fd_data.dest_vsi = vsi->id;
1370 fd_data.dest_ctl = 0;
1371 fd_data.fd_status = 0;
1372 fd_data.cnt_index = 0;
1373 fd_data.fd_id = 0;
1374
1375 switch (fsp->flow_type & ~FLOW_EXT) {
1376 case TCP_V4_FLOW:
1377 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1378 break;
1379 case UDP_V4_FLOW:
1380 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1381 break;
1382 case SCTP_V4_FLOW:
1383 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1384 break;
1385 case IPV4_FLOW:
1386 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1387 break;
1388 case IP_USER_FLOW:
1389 switch (fsp->h_u.usr_ip4_spec.proto) {
1390 case IPPROTO_TCP:
1391 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1392 break;
1393 case IPPROTO_UDP:
1394 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1395 break;
1396 case IPPROTO_SCTP:
1397 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1398 break;
1399 default:
1400 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1401 break;
1402 }
1403 break;
1404 default:
1405 dev_info(&pf->pdev->dev, "Could not specify spec type\n");
1406 ret = -EINVAL;
1407 }
1408
1409 kfree(fd_data.raw_packet);
1410 fd_data.raw_packet = NULL;
1411
1412 return ret;
1413}
1414/**
1415 * i40e_set_rxnfc - command to set RX flow classification rules
1416 * @netdev: network interface device structure
1417 * @cmd: ethtool rxnfc command
1418 *
1419 * Returns Success if the command is supported.
1420 **/
1421static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1422{
1423 struct i40e_netdev_priv *np = netdev_priv(netdev);
1424 struct i40e_vsi *vsi = np->vsi;
1425 struct i40e_pf *pf = vsi->back;
1426 int ret = -EOPNOTSUPP;
1427
1428 switch (cmd->cmd) {
1429 case ETHTOOL_SRXFH:
1430 ret = i40e_set_rss_hash_opt(pf, cmd);
1431 break;
1432 case ETHTOOL_SRXCLSRLINS:
1433 ret = i40e_add_del_fdir_ethtool(vsi, cmd, true);
1434 break;
1435 case ETHTOOL_SRXCLSRLDEL:
1436 ret = i40e_add_del_fdir_ethtool(vsi, cmd, false);
1437 break;
1438 default:
1439 break;
1440 }
1441
1442 return ret;
1443}
1444
1445static const struct ethtool_ops i40e_ethtool_ops = {
1446 .get_settings = i40e_get_settings,
1447 .get_drvinfo = i40e_get_drvinfo,
1448 .get_regs_len = i40e_get_regs_len,
1449 .get_regs = i40e_get_regs,
1450 .nway_reset = i40e_nway_reset,
1451 .get_link = ethtool_op_get_link,
1452 .get_wol = i40e_get_wol,
1453 .get_eeprom_len = i40e_get_eeprom_len,
1454 .get_eeprom = i40e_get_eeprom,
1455 .get_ringparam = i40e_get_ringparam,
1456 .set_ringparam = i40e_set_ringparam,
1457 .get_pauseparam = i40e_get_pauseparam,
1458 .get_msglevel = i40e_get_msglevel,
1459 .set_msglevel = i40e_set_msglevel,
1460 .get_rxnfc = i40e_get_rxnfc,
1461 .set_rxnfc = i40e_set_rxnfc,
1462 .self_test = i40e_diag_test,
1463 .get_strings = i40e_get_strings,
1464 .set_phys_id = i40e_set_phys_id,
1465 .get_sset_count = i40e_get_sset_count,
1466 .get_ethtool_stats = i40e_get_ethtool_stats,
1467 .get_coalesce = i40e_get_coalesce,
1468 .set_coalesce = i40e_set_coalesce,
1469 .get_ts_info = i40e_get_ts_info,
1470};
1471
1472void i40e_set_ethtool_ops(struct net_device *netdev)
1473{
1474 SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops);
1475}