blob: eb343756b2c1626ad0fdb0ddc87081fcfdd4d38a [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;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000196 default:
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000197 if (i40e_is_40G_device(hw->device_id)) {
198 ecmd->supported = SUPPORTED_40000baseSR4_Full;
199 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
200 } else {
201 ecmd->supported = SUPPORTED_10000baseT_Full;
202 ecmd->advertising = ADVERTISED_10000baseT_Full;
203 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000204 break;
205 }
206
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000207 ecmd->supported |= SUPPORTED_Autoneg;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000208 ecmd->advertising |= ADVERTISED_Autoneg;
209 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
210 AUTONEG_ENABLE : AUTONEG_DISABLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000211
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000212 switch (hw->phy.media_type) {
213 case I40E_MEDIA_TYPE_BACKPLANE:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000214 ecmd->supported |= SUPPORTED_Backplane;
215 ecmd->advertising |= ADVERTISED_Backplane;
216 ecmd->port = PORT_NONE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000217 break;
218 case I40E_MEDIA_TYPE_BASET:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000219 ecmd->supported |= SUPPORTED_TP;
220 ecmd->advertising |= ADVERTISED_TP;
221 ecmd->port = PORT_TP;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000222 break;
223 case I40E_MEDIA_TYPE_DA:
224 case I40E_MEDIA_TYPE_CX4:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000225 ecmd->supported |= SUPPORTED_FIBRE;
226 ecmd->advertising |= ADVERTISED_FIBRE;
227 ecmd->port = PORT_DA;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000228 break;
229 case I40E_MEDIA_TYPE_FIBER:
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000230 ecmd->supported |= SUPPORTED_FIBRE;
231 ecmd->advertising |= ADVERTISED_FIBRE;
232 ecmd->port = PORT_FIBRE;
Jesse Brandeburgc9a3d472013-11-26 10:49:10 +0000233 break;
234 case I40E_MEDIA_TYPE_UNKNOWN:
235 default:
236 ecmd->port = PORT_OTHER;
237 break;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000238 }
239
240 ecmd->transceiver = XCVR_EXTERNAL;
241
242 if (link_up) {
243 switch (link_speed) {
244 case I40E_LINK_SPEED_40GB:
245 /* need a SPEED_40000 in ethtool.h */
246 ethtool_cmd_speed_set(ecmd, 40000);
247 break;
248 case I40E_LINK_SPEED_10GB:
249 ethtool_cmd_speed_set(ecmd, SPEED_10000);
250 break;
251 default:
252 break;
253 }
254 ecmd->duplex = DUPLEX_FULL;
255 } else {
256 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
257 ecmd->duplex = DUPLEX_UNKNOWN;
258 }
259
260 return 0;
261}
262
263/**
264 * i40e_get_pauseparam - Get Flow Control status
265 * Return tx/rx-pause status
266 **/
267static void i40e_get_pauseparam(struct net_device *netdev,
268 struct ethtool_pauseparam *pause)
269{
270 struct i40e_netdev_priv *np = netdev_priv(netdev);
271 struct i40e_pf *pf = np->vsi->back;
272 struct i40e_hw *hw = &pf->hw;
273 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
274
275 pause->autoneg =
276 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
277 AUTONEG_ENABLE : AUTONEG_DISABLE);
278
279 pause->rx_pause = 0;
280 pause->tx_pause = 0;
281 if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_RX)
282 pause->rx_pause = 1;
283 if (hw_link_info->an_info & I40E_AQ_LINK_PAUSE_TX)
284 pause->tx_pause = 1;
285}
286
287static u32 i40e_get_msglevel(struct net_device *netdev)
288{
289 struct i40e_netdev_priv *np = netdev_priv(netdev);
290 struct i40e_pf *pf = np->vsi->back;
291
292 return pf->msg_enable;
293}
294
295static void i40e_set_msglevel(struct net_device *netdev, u32 data)
296{
297 struct i40e_netdev_priv *np = netdev_priv(netdev);
298 struct i40e_pf *pf = np->vsi->back;
299
300 if (I40E_DEBUG_USER & data)
301 pf->hw.debug_mask = data;
302 pf->msg_enable = data;
303}
304
305static int i40e_get_regs_len(struct net_device *netdev)
306{
307 int reg_count = 0;
308 int i;
309
310 for (i = 0; i40e_reg_list[i].offset != 0; i++)
311 reg_count += i40e_reg_list[i].elements;
312
313 return reg_count * sizeof(u32);
314}
315
316static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
317 void *p)
318{
319 struct i40e_netdev_priv *np = netdev_priv(netdev);
320 struct i40e_pf *pf = np->vsi->back;
321 struct i40e_hw *hw = &pf->hw;
322 u32 *reg_buf = p;
323 int i, j, ri;
324 u32 reg;
325
326 /* Tell ethtool which driver-version-specific regs output we have.
327 *
328 * At some point, if we have ethtool doing special formatting of
329 * this data, it will rely on this version number to know how to
330 * interpret things. Hence, this needs to be updated if/when the
331 * diags register table is changed.
332 */
333 regs->version = 1;
334
335 /* loop through the diags reg table for what to print */
336 ri = 0;
337 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
338 for (j = 0; j < i40e_reg_list[i].elements; j++) {
339 reg = i40e_reg_list[i].offset
340 + (j * i40e_reg_list[i].stride);
341 reg_buf[ri++] = rd32(hw, reg);
342 }
343 }
344
345}
346
347static int i40e_get_eeprom(struct net_device *netdev,
348 struct ethtool_eeprom *eeprom, u8 *bytes)
349{
350 struct i40e_netdev_priv *np = netdev_priv(netdev);
351 struct i40e_hw *hw = &np->vsi->back->hw;
352 int first_word, last_word;
353 u16 i, eeprom_len;
354 u16 *eeprom_buff;
355 int ret_val = 0;
356
357 if (eeprom->len == 0)
358 return -EINVAL;
359
360 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
361
362 first_word = eeprom->offset >> 1;
363 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
364 eeprom_len = last_word - first_word + 1;
365
366 eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL);
367 if (!eeprom_buff)
368 return -ENOMEM;
369
370 ret_val = i40e_read_nvm_buffer(hw, first_word, &eeprom_len,
371 eeprom_buff);
372 if (eeprom_len == 0) {
373 kfree(eeprom_buff);
374 return -EACCES;
375 }
376
377 /* Device's eeprom is always little-endian, word addressable */
378 for (i = 0; i < eeprom_len; i++)
379 le16_to_cpus(&eeprom_buff[i]);
380
381 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
382 kfree(eeprom_buff);
383
384 return ret_val;
385}
386
387static int i40e_get_eeprom_len(struct net_device *netdev)
388{
389 struct i40e_netdev_priv *np = netdev_priv(netdev);
390 struct i40e_hw *hw = &np->vsi->back->hw;
391
392 return hw->nvm.sr_size * 2;
393}
394
395static void i40e_get_drvinfo(struct net_device *netdev,
396 struct ethtool_drvinfo *drvinfo)
397{
398 struct i40e_netdev_priv *np = netdev_priv(netdev);
399 struct i40e_vsi *vsi = np->vsi;
400 struct i40e_pf *pf = vsi->back;
401
402 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
403 strlcpy(drvinfo->version, i40e_driver_version_str,
404 sizeof(drvinfo->version));
405 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
406 sizeof(drvinfo->fw_version));
407 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
408 sizeof(drvinfo->bus_info));
409}
410
411static void i40e_get_ringparam(struct net_device *netdev,
412 struct ethtool_ringparam *ring)
413{
414 struct i40e_netdev_priv *np = netdev_priv(netdev);
415 struct i40e_pf *pf = np->vsi->back;
416 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
417
418 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
419 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
420 ring->rx_mini_max_pending = 0;
421 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000422 ring->rx_pending = vsi->rx_rings[0]->count;
423 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000424 ring->rx_mini_pending = 0;
425 ring->rx_jumbo_pending = 0;
426}
427
428static int i40e_set_ringparam(struct net_device *netdev,
429 struct ethtool_ringparam *ring)
430{
431 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
432 struct i40e_netdev_priv *np = netdev_priv(netdev);
433 struct i40e_vsi *vsi = np->vsi;
434 struct i40e_pf *pf = vsi->back;
435 u32 new_rx_count, new_tx_count;
436 int i, err = 0;
437
438 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
439 return -EINVAL;
440
Shannon Nelson1fa18372013-11-20 10:03:08 +0000441 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
442 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
443 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
444 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
445 netdev_info(netdev,
446 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
447 ring->tx_pending, ring->rx_pending,
448 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
449 return -EINVAL;
450 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000451
Shannon Nelson1fa18372013-11-20 10:03:08 +0000452 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
453 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000454
455 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000456 if ((new_tx_count == vsi->tx_rings[0]->count) &&
457 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000458 return 0;
459
460 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
461 usleep_range(1000, 2000);
462
463 if (!netif_running(vsi->netdev)) {
464 /* simple case - set for the next time the netdev is started */
465 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000466 vsi->tx_rings[i]->count = new_tx_count;
467 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000468 }
469 goto done;
470 }
471
472 /* We can't just free everything and then setup again,
473 * because the ISRs in MSI-X mode get passed pointers
474 * to the Tx and Rx ring structs.
475 */
476
477 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000478 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000479 netdev_info(netdev,
480 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000481 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000482 tx_rings = kcalloc(vsi->alloc_queue_pairs,
483 sizeof(struct i40e_ring), GFP_KERNEL);
484 if (!tx_rings) {
485 err = -ENOMEM;
486 goto done;
487 }
488
489 for (i = 0; i < vsi->num_queue_pairs; i++) {
490 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000491 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000492 tx_rings[i].count = new_tx_count;
493 err = i40e_setup_tx_descriptors(&tx_rings[i]);
494 if (err) {
495 while (i) {
496 i--;
497 i40e_free_tx_resources(&tx_rings[i]);
498 }
499 kfree(tx_rings);
500 tx_rings = NULL;
501
502 goto done;
503 }
504 }
505 }
506
507 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000508 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000509 netdev_info(netdev,
510 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000511 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000512 rx_rings = kcalloc(vsi->alloc_queue_pairs,
513 sizeof(struct i40e_ring), GFP_KERNEL);
514 if (!rx_rings) {
515 err = -ENOMEM;
516 goto free_tx;
517 }
518
519 for (i = 0; i < vsi->num_queue_pairs; i++) {
520 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000521 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000522 rx_rings[i].count = new_rx_count;
523 err = i40e_setup_rx_descriptors(&rx_rings[i]);
524 if (err) {
525 while (i) {
526 i--;
527 i40e_free_rx_resources(&rx_rings[i]);
528 }
529 kfree(rx_rings);
530 rx_rings = NULL;
531
532 goto free_tx;
533 }
534 }
535 }
536
537 /* Bring interface down, copy in the new ring info,
538 * then restore the interface
539 */
540 i40e_down(vsi);
541
542 if (tx_rings) {
543 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000544 i40e_free_tx_resources(vsi->tx_rings[i]);
545 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000546 }
547 kfree(tx_rings);
548 tx_rings = NULL;
549 }
550
551 if (rx_rings) {
552 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000553 i40e_free_rx_resources(vsi->rx_rings[i]);
554 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000555 }
556 kfree(rx_rings);
557 rx_rings = NULL;
558 }
559
560 i40e_up(vsi);
561
562free_tx:
563 /* error cleanup if the Rx allocations failed after getting Tx */
564 if (tx_rings) {
565 for (i = 0; i < vsi->num_queue_pairs; i++)
566 i40e_free_tx_resources(&tx_rings[i]);
567 kfree(tx_rings);
568 tx_rings = NULL;
569 }
570
571done:
572 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
573
574 return err;
575}
576
577static int i40e_get_sset_count(struct net_device *netdev, int sset)
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
583 switch (sset) {
584 case ETH_SS_TEST:
585 return I40E_TEST_LEN;
586 case ETH_SS_STATS:
587 if (vsi == pf->vsi[pf->lan_vsi])
588 return I40E_PF_STATS_LEN(netdev);
589 else
590 return I40E_VSI_STATS_LEN(netdev);
591 default:
592 return -EOPNOTSUPP;
593 }
594}
595
596static void i40e_get_ethtool_stats(struct net_device *netdev,
597 struct ethtool_stats *stats, u64 *data)
598{
599 struct i40e_netdev_priv *np = netdev_priv(netdev);
600 struct i40e_vsi *vsi = np->vsi;
601 struct i40e_pf *pf = vsi->back;
602 int i = 0;
603 char *p;
604 int j;
605 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000606 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000607
608 i40e_update_stats(vsi);
609
610 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
611 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
612 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
613 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
614 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000615 rcu_read_lock();
Alexander Duycka114d0a2013-09-28 06:00:43 +0000616 for (j = 0; j < vsi->num_queue_pairs; j++, i += 4) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000617 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
618 struct i40e_ring *rx_ring;
619
620 if (!tx_ring)
621 continue;
622
623 /* process Tx ring statistics */
624 do {
625 start = u64_stats_fetch_begin_bh(&tx_ring->syncp);
626 data[i] = tx_ring->stats.packets;
627 data[i + 1] = tx_ring->stats.bytes;
628 } while (u64_stats_fetch_retry_bh(&tx_ring->syncp, start));
629
630 /* Rx ring is the 2nd half of the queue pair */
631 rx_ring = &tx_ring[1];
632 do {
633 start = u64_stats_fetch_begin_bh(&rx_ring->syncp);
634 data[i + 2] = rx_ring->stats.packets;
635 data[i + 3] = rx_ring->stats.bytes;
636 } while (u64_stats_fetch_retry_bh(&rx_ring->syncp, start));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000637 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000638 rcu_read_unlock();
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000639 if (vsi == pf->vsi[pf->lan_vsi]) {
640 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
641 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
642 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
643 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
644 }
645 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
646 data[i++] = pf->stats.priority_xon_tx[j];
647 data[i++] = pf->stats.priority_xoff_tx[j];
648 }
649 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
650 data[i++] = pf->stats.priority_xon_rx[j];
651 data[i++] = pf->stats.priority_xoff_rx[j];
652 }
653 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
654 data[i++] = pf->stats.priority_xon_2_xoff[j];
655 }
656}
657
658static void i40e_get_strings(struct net_device *netdev, u32 stringset,
659 u8 *data)
660{
661 struct i40e_netdev_priv *np = netdev_priv(netdev);
662 struct i40e_vsi *vsi = np->vsi;
663 struct i40e_pf *pf = vsi->back;
664 char *p = (char *)data;
665 int i;
666
667 switch (stringset) {
668 case ETH_SS_TEST:
669 for (i = 0; i < I40E_TEST_LEN; i++) {
670 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
671 data += ETH_GSTRING_LEN;
672 }
673 break;
674 case ETH_SS_STATS:
675 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
676 snprintf(p, ETH_GSTRING_LEN, "%s",
677 i40e_gstrings_net_stats[i].stat_string);
678 p += ETH_GSTRING_LEN;
679 }
680 for (i = 0; i < vsi->num_queue_pairs; i++) {
681 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
682 p += ETH_GSTRING_LEN;
683 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
684 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000685 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
686 p += ETH_GSTRING_LEN;
687 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
688 p += ETH_GSTRING_LEN;
689 }
690 if (vsi == pf->vsi[pf->lan_vsi]) {
691 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
692 snprintf(p, ETH_GSTRING_LEN, "port.%s",
693 i40e_gstrings_stats[i].stat_string);
694 p += ETH_GSTRING_LEN;
695 }
696 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
697 snprintf(p, ETH_GSTRING_LEN,
698 "port.tx_priority_%u_xon", i);
699 p += ETH_GSTRING_LEN;
700 snprintf(p, ETH_GSTRING_LEN,
701 "port.tx_priority_%u_xoff", i);
702 p += ETH_GSTRING_LEN;
703 }
704 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
705 snprintf(p, ETH_GSTRING_LEN,
706 "port.rx_priority_%u_xon", i);
707 p += ETH_GSTRING_LEN;
708 snprintf(p, ETH_GSTRING_LEN,
709 "port.rx_priority_%u_xoff", i);
710 p += ETH_GSTRING_LEN;
711 }
712 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
713 snprintf(p, ETH_GSTRING_LEN,
714 "port.rx_priority_%u_xon_2_xoff", i);
715 p += ETH_GSTRING_LEN;
716 }
717 }
718 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
719 break;
720 }
721}
722
723static int i40e_get_ts_info(struct net_device *dev,
724 struct ethtool_ts_info *info)
725{
726 return ethtool_op_get_ts_info(dev, info);
727}
728
Shannon Nelson7b086392013-11-20 10:02:59 +0000729static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000730{
Shannon Nelson7b086392013-11-20 10:02:59 +0000731 struct i40e_netdev_priv *np = netdev_priv(netdev);
732 struct i40e_pf *pf = np->vsi->back;
733
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000734 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000735 if (i40e_get_link_status(&pf->hw))
736 *data = 0;
737 else
738 *data = 1;
739
740 return *data;
741}
742
Shannon Nelson7b086392013-11-20 10:02:59 +0000743static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000744{
Shannon Nelson7b086392013-11-20 10:02:59 +0000745 struct i40e_netdev_priv *np = netdev_priv(netdev);
746 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000747
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000748 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000749 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000750
Shannon Nelson7b086392013-11-20 10:02:59 +0000751 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
752 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000753}
754
Shannon Nelson7b086392013-11-20 10:02:59 +0000755static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000756{
Shannon Nelson7b086392013-11-20 10:02:59 +0000757 struct i40e_netdev_priv *np = netdev_priv(netdev);
758 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000759
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000760 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000761 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000762
Shannon Nelson7b086392013-11-20 10:02:59 +0000763 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000764}
765
Shannon Nelson7b086392013-11-20 10:02:59 +0000766static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000767{
Shannon Nelson7b086392013-11-20 10:02:59 +0000768 struct i40e_netdev_priv *np = netdev_priv(netdev);
769 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000770 u16 swc_old = pf->sw_int_count;
771
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000772 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000773 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
774 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
775 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
776 usleep_range(1000, 2000);
777 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000778
779 return *data;
780}
781
Shannon Nelson7b086392013-11-20 10:02:59 +0000782static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000783{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000784 struct i40e_netdev_priv *np = netdev_priv(netdev);
785 struct i40e_pf *pf = np->vsi->back;
786
787 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000788 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000789
790 return *data;
791}
792
793static void i40e_diag_test(struct net_device *netdev,
794 struct ethtool_test *eth_test, u64 *data)
795{
796 struct i40e_netdev_priv *np = netdev_priv(netdev);
797 struct i40e_pf *pf = np->vsi->back;
798
799 set_bit(__I40E_TESTING, &pf->state);
800 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
801 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000802 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000803
804 /* Link test performed before hardware reset
805 * so autoneg doesn't interfere with test result
806 */
Shannon Nelson7b086392013-11-20 10:02:59 +0000807 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000808 eth_test->flags |= ETH_TEST_FL_FAILED;
809
Shannon Nelson7b086392013-11-20 10:02:59 +0000810 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000811 eth_test->flags |= ETH_TEST_FL_FAILED;
812
Shannon Nelson7b086392013-11-20 10:02:59 +0000813 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000814 eth_test->flags |= ETH_TEST_FL_FAILED;
815
Shannon Nelson7b086392013-11-20 10:02:59 +0000816 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000817 eth_test->flags |= ETH_TEST_FL_FAILED;
818
Shannon Nelson7b086392013-11-20 10:02:59 +0000819 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000820 eth_test->flags |= ETH_TEST_FL_FAILED;
821
822 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000823 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000824 netif_info(pf, drv, netdev, "online testing starting\n");
825
Shannon Nelson7b086392013-11-20 10:02:59 +0000826 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000827 eth_test->flags |= ETH_TEST_FL_FAILED;
828
829 /* Offline only tests, not run in online; pass by default */
830 data[I40E_ETH_TEST_REG] = 0;
831 data[I40E_ETH_TEST_EEPROM] = 0;
832 data[I40E_ETH_TEST_INTR] = 0;
833 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000834 }
Shannon Nelsonc140c172013-11-20 10:02:58 +0000835 clear_bit(__I40E_TESTING, &pf->state);
836
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000837 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000838}
839
840static void i40e_get_wol(struct net_device *netdev,
841 struct ethtool_wolinfo *wol)
842{
843 wol->supported = 0;
844 wol->wolopts = 0;
845}
846
847static int i40e_nway_reset(struct net_device *netdev)
848{
849 /* restart autonegotiation */
850 struct i40e_netdev_priv *np = netdev_priv(netdev);
851 struct i40e_pf *pf = np->vsi->back;
852 struct i40e_hw *hw = &pf->hw;
853 i40e_status ret = 0;
854
855 ret = i40e_aq_set_link_restart_an(hw, NULL);
856 if (ret) {
857 netdev_info(netdev, "link restart failed, aq_err=%d\n",
858 pf->hw.aq.asq_last_status);
859 return -EIO;
860 }
861
862 return 0;
863}
864
865static int i40e_set_phys_id(struct net_device *netdev,
866 enum ethtool_phys_id_state state)
867{
868 struct i40e_netdev_priv *np = netdev_priv(netdev);
869 struct i40e_pf *pf = np->vsi->back;
870 struct i40e_hw *hw = &pf->hw;
871 int blink_freq = 2;
872
873 switch (state) {
874 case ETHTOOL_ID_ACTIVE:
875 pf->led_status = i40e_led_get(hw);
876 return blink_freq;
877 case ETHTOOL_ID_ON:
878 i40e_led_set(hw, 0xF);
879 break;
880 case ETHTOOL_ID_OFF:
881 i40e_led_set(hw, 0x0);
882 break;
883 case ETHTOOL_ID_INACTIVE:
884 i40e_led_set(hw, pf->led_status);
885 break;
886 }
887
888 return 0;
889}
890
891/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
892 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
893 * 125us (8000 interrupts per second) == ITR(62)
894 */
895
896static int i40e_get_coalesce(struct net_device *netdev,
897 struct ethtool_coalesce *ec)
898{
899 struct i40e_netdev_priv *np = netdev_priv(netdev);
900 struct i40e_vsi *vsi = np->vsi;
901
902 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
903 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
904
905 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
906 ec->rx_coalesce_usecs = 1;
907 else
908 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
909
910 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
911 ec->tx_coalesce_usecs = 1;
912 else
913 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
914
915 return 0;
916}
917
918static int i40e_set_coalesce(struct net_device *netdev,
919 struct ethtool_coalesce *ec)
920{
921 struct i40e_netdev_priv *np = netdev_priv(netdev);
922 struct i40e_q_vector *q_vector;
923 struct i40e_vsi *vsi = np->vsi;
924 struct i40e_pf *pf = vsi->back;
925 struct i40e_hw *hw = &pf->hw;
926 u16 vector;
927 int i;
928
929 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
930 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
931
932 switch (ec->rx_coalesce_usecs) {
933 case 0:
934 vsi->rx_itr_setting = 0;
935 break;
936 case 1:
937 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
938 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
939 break;
940 default:
941 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
942 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
943 return -EINVAL;
944 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
945 break;
946 }
947
948 switch (ec->tx_coalesce_usecs) {
949 case 0:
950 vsi->tx_itr_setting = 0;
951 break;
952 case 1:
953 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
954 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
955 break;
956 default:
957 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
958 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
959 return -EINVAL;
960 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
961 break;
962 }
963
964 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +0000965 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
966 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000967 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
968 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
969 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
970 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
971 i40e_flush(hw);
972 }
973
974 return 0;
975}
976
977/**
978 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
979 * @pf: pointer to the physical function struct
980 * @cmd: ethtool rxnfc command
981 *
982 * Returns Success if the flow is supported, else Invalid Input.
983 **/
984static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
985{
986 cmd->data = 0;
987
988 /* Report default options for RSS on i40e */
989 switch (cmd->flow_type) {
990 case TCP_V4_FLOW:
991 case UDP_V4_FLOW:
992 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
993 /* fall through to add IP fields */
994 case SCTP_V4_FLOW:
995 case AH_ESP_V4_FLOW:
996 case AH_V4_FLOW:
997 case ESP_V4_FLOW:
998 case IPV4_FLOW:
999 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1000 break;
1001 case TCP_V6_FLOW:
1002 case UDP_V6_FLOW:
1003 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1004 /* fall through to add IP fields */
1005 case SCTP_V6_FLOW:
1006 case AH_ESP_V6_FLOW:
1007 case AH_V6_FLOW:
1008 case ESP_V6_FLOW:
1009 case IPV6_FLOW:
1010 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1011 break;
1012 default:
1013 return -EINVAL;
1014 }
1015
1016 return 0;
1017}
1018
1019/**
1020 * i40e_get_rxnfc - command to get RX flow classification rules
1021 * @netdev: network interface device structure
1022 * @cmd: ethtool rxnfc command
1023 *
1024 * Returns Success if the command is supported.
1025 **/
1026static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1027 u32 *rule_locs)
1028{
1029 struct i40e_netdev_priv *np = netdev_priv(netdev);
1030 struct i40e_vsi *vsi = np->vsi;
1031 struct i40e_pf *pf = vsi->back;
1032 int ret = -EOPNOTSUPP;
1033
1034 switch (cmd->cmd) {
1035 case ETHTOOL_GRXRINGS:
1036 cmd->data = vsi->alloc_queue_pairs;
1037 ret = 0;
1038 break;
1039 case ETHTOOL_GRXFH:
1040 ret = i40e_get_rss_hash_opts(pf, cmd);
1041 break;
1042 case ETHTOOL_GRXCLSRLCNT:
1043 ret = 0;
1044 break;
1045 case ETHTOOL_GRXCLSRULE:
1046 ret = 0;
1047 break;
1048 case ETHTOOL_GRXCLSRLALL:
1049 cmd->data = 500;
1050 ret = 0;
1051 default:
1052 break;
1053 }
1054
1055 return ret;
1056}
1057
1058/**
1059 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1060 * @pf: pointer to the physical function struct
1061 * @cmd: ethtool rxnfc command
1062 *
1063 * Returns Success if the flow input set is supported.
1064 **/
1065static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1066{
1067 struct i40e_hw *hw = &pf->hw;
1068 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1069 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1070
1071 /* RSS does not support anything other than hashing
1072 * to queues on src and dst IPs and ports
1073 */
1074 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1075 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1076 return -EINVAL;
1077
1078 /* We need at least the IP SRC and DEST fields for hashing */
1079 if (!(nfc->data & RXH_IP_SRC) ||
1080 !(nfc->data & RXH_IP_DST))
1081 return -EINVAL;
1082
1083 switch (nfc->flow_type) {
1084 case TCP_V4_FLOW:
1085 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1086 case 0:
1087 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1088 break;
1089 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1090 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1091 break;
1092 default:
1093 return -EINVAL;
1094 }
1095 break;
1096 case TCP_V6_FLOW:
1097 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1098 case 0:
1099 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1100 break;
1101 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1102 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1103 break;
1104 default:
1105 return -EINVAL;
1106 }
1107 break;
1108 case UDP_V4_FLOW:
1109 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1110 case 0:
1111 hena &=
1112 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1113 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1114 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1115 break;
1116 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1117 hena |=
1118 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1119 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1120 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1121 break;
1122 default:
1123 return -EINVAL;
1124 }
1125 break;
1126 case UDP_V6_FLOW:
1127 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1128 case 0:
1129 hena &=
1130 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1131 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1132 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1133 break;
1134 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1135 hena |=
1136 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1137 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1138 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1139 break;
1140 default:
1141 return -EINVAL;
1142 }
1143 break;
1144 case AH_ESP_V4_FLOW:
1145 case AH_V4_FLOW:
1146 case ESP_V4_FLOW:
1147 case SCTP_V4_FLOW:
1148 if ((nfc->data & RXH_L4_B_0_1) ||
1149 (nfc->data & RXH_L4_B_2_3))
1150 return -EINVAL;
1151 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1152 break;
1153 case AH_ESP_V6_FLOW:
1154 case AH_V6_FLOW:
1155 case ESP_V6_FLOW:
1156 case SCTP_V6_FLOW:
1157 if ((nfc->data & RXH_L4_B_0_1) ||
1158 (nfc->data & RXH_L4_B_2_3))
1159 return -EINVAL;
1160 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1161 break;
1162 case IPV4_FLOW:
1163 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1164 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1165 break;
1166 case IPV6_FLOW:
1167 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1168 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1169 break;
1170 default:
1171 return -EINVAL;
1172 }
1173
1174 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1175 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1176 i40e_flush(hw);
1177
1178 return 0;
1179}
1180
1181#define IP_HEADER_OFFSET 14
1182/**
1183 * i40e_add_del_fdir_udpv4 - Add/Remove UDPv4 Flow Director filters for
1184 * a specific flow spec
1185 * @vsi: pointer to the targeted VSI
1186 * @fd_data: the flow director data required from the FDir descriptor
1187 * @ethtool_rx_flow_spec: the flow spec
1188 * @add: true adds a filter, false removes it
1189 *
1190 * Returns 0 if the filters were successfully added or removed
1191 **/
1192static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
1193 struct i40e_fdir_data *fd_data,
1194 struct ethtool_rx_flow_spec *fsp, bool add)
1195{
1196 struct i40e_pf *pf = vsi->back;
1197 struct udphdr *udp;
1198 struct iphdr *ip;
1199 bool err = false;
1200 int ret;
1201 int i;
1202
1203 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1204 udp = (struct udphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1205 + sizeof(struct iphdr));
1206
1207 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1208 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1209 udp->source = fsp->h_u.tcp_ip4_spec.psrc;
1210 udp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1211
1212 for (i = I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP;
1213 i <= I40E_FILTER_PCTYPE_NONF_IPV4_UDP; i++) {
1214 fd_data->pctype = i;
1215 ret = i40e_program_fdir_filter(fd_data, pf, add);
1216
1217 if (ret) {
1218 dev_info(&pf->pdev->dev,
1219 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1220 fd_data->pctype, ret);
1221 err = true;
1222 } else {
1223 dev_info(&pf->pdev->dev,
1224 "Filter OK for PCTYPE %d (ret = %d)\n",
1225 fd_data->pctype, ret);
1226 }
1227 }
1228
1229 return err ? -EOPNOTSUPP : 0;
1230}
1231
1232/**
1233 * i40e_add_del_fdir_tcpv4 - Add/Remove TCPv4 Flow Director filters for
1234 * a specific flow spec
1235 * @vsi: pointer to the targeted VSI
1236 * @fd_data: the flow director data required from the FDir descriptor
1237 * @ethtool_rx_flow_spec: the flow spec
1238 * @add: true adds a filter, false removes it
1239 *
1240 * Returns 0 if the filters were successfully added or removed
1241 **/
1242static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
1243 struct i40e_fdir_data *fd_data,
1244 struct ethtool_rx_flow_spec *fsp, bool add)
1245{
1246 struct i40e_pf *pf = vsi->back;
1247 struct tcphdr *tcp;
1248 struct iphdr *ip;
1249 bool err = false;
1250 int ret;
1251
1252 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1253 tcp = (struct tcphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1254 + sizeof(struct iphdr));
1255
1256 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1257 tcp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1258
1259 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN;
1260 ret = i40e_program_fdir_filter(fd_data, pf, add);
1261
1262 if (ret) {
1263 dev_info(&pf->pdev->dev,
1264 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1265 fd_data->pctype, ret);
1266 err = true;
1267 } else {
1268 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1269 fd_data->pctype, ret);
1270 }
1271
1272 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1273 tcp->source = fsp->h_u.tcp_ip4_spec.psrc;
1274
1275 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
1276
1277 ret = i40e_program_fdir_filter(fd_data, pf, add);
1278 if (ret) {
1279 dev_info(&pf->pdev->dev,
1280 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1281 fd_data->pctype, ret);
1282 err = true;
1283 } else {
1284 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1285 fd_data->pctype, ret);
1286 }
1287
1288 return err ? -EOPNOTSUPP : 0;
1289}
1290
1291/**
1292 * i40e_add_del_fdir_sctpv4 - Add/Remove SCTPv4 Flow Director filters for
1293 * a specific flow spec
1294 * @vsi: pointer to the targeted VSI
1295 * @fd_data: the flow director data required from the FDir descriptor
1296 * @ethtool_rx_flow_spec: the flow spec
1297 * @add: true adds a filter, false removes it
1298 *
1299 * Returns 0 if the filters were successfully added or removed
1300 **/
1301static int i40e_add_del_fdir_sctpv4(struct i40e_vsi *vsi,
1302 struct i40e_fdir_data *fd_data,
1303 struct ethtool_rx_flow_spec *fsp, bool add)
1304{
1305 return -EOPNOTSUPP;
1306}
1307
1308/**
1309 * i40e_add_del_fdir_ipv4 - Add/Remove IPv4 Flow Director filters for
1310 * a specific flow spec
1311 * @vsi: pointer to the targeted VSI
1312 * @fd_data: the flow director data required for the FDir descriptor
1313 * @fsp: the ethtool flow spec
1314 * @add: true adds a filter, false removes it
1315 *
1316 * Returns 0 if the filters were successfully added or removed
1317 **/
1318static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
1319 struct i40e_fdir_data *fd_data,
1320 struct ethtool_rx_flow_spec *fsp, bool add)
1321{
1322 struct i40e_pf *pf = vsi->back;
1323 struct iphdr *ip;
1324 bool err = false;
1325 int ret;
1326 int i;
1327
1328 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1329
1330 ip->saddr = fsp->h_u.usr_ip4_spec.ip4src;
1331 ip->daddr = fsp->h_u.usr_ip4_spec.ip4dst;
1332 ip->protocol = fsp->h_u.usr_ip4_spec.proto;
1333
1334 for (i = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
1335 i <= I40E_FILTER_PCTYPE_FRAG_IPV4; i++) {
1336 fd_data->pctype = i;
1337 ret = i40e_program_fdir_filter(fd_data, pf, add);
1338
1339 if (ret) {
1340 dev_info(&pf->pdev->dev,
1341 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1342 fd_data->pctype, ret);
1343 err = true;
1344 } else {
1345 dev_info(&pf->pdev->dev,
1346 "Filter OK for PCTYPE %d (ret = %d)\n",
1347 fd_data->pctype, ret);
1348 }
1349 }
1350
1351 return err ? -EOPNOTSUPP : 0;
1352}
1353
1354/**
1355 * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters for
1356 * a specific flow spec based on their protocol
1357 * @vsi: pointer to the targeted VSI
1358 * @cmd: command to get or set RX flow classification rules
1359 * @add: true adds a filter, false removes it
1360 *
1361 * Returns 0 if the filters were successfully added or removed
1362 **/
1363static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
1364 struct ethtool_rxnfc *cmd, bool add)
1365{
1366 struct i40e_fdir_data fd_data;
1367 int ret = -EINVAL;
1368 struct i40e_pf *pf;
1369 struct ethtool_rx_flow_spec *fsp =
1370 (struct ethtool_rx_flow_spec *)&cmd->fs;
1371
1372 if (!vsi)
1373 return -EINVAL;
1374
1375 pf = vsi->back;
1376
1377 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1378 (fsp->ring_cookie >= vsi->num_queue_pairs))
1379 return -EINVAL;
1380
1381 /* Populate the Flow Director that we have at the moment
1382 * and allocate the raw packet buffer for the calling functions
1383 */
1384 fd_data.raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
1385 GFP_KERNEL);
1386
1387 if (!fd_data.raw_packet) {
1388 dev_info(&pf->pdev->dev, "Could not allocate memory\n");
1389 return -ENOMEM;
1390 }
1391
1392 fd_data.q_index = fsp->ring_cookie;
1393 fd_data.flex_off = 0;
1394 fd_data.pctype = 0;
1395 fd_data.dest_vsi = vsi->id;
1396 fd_data.dest_ctl = 0;
1397 fd_data.fd_status = 0;
1398 fd_data.cnt_index = 0;
1399 fd_data.fd_id = 0;
1400
1401 switch (fsp->flow_type & ~FLOW_EXT) {
1402 case TCP_V4_FLOW:
1403 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1404 break;
1405 case UDP_V4_FLOW:
1406 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1407 break;
1408 case SCTP_V4_FLOW:
1409 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1410 break;
1411 case IPV4_FLOW:
1412 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1413 break;
1414 case IP_USER_FLOW:
1415 switch (fsp->h_u.usr_ip4_spec.proto) {
1416 case IPPROTO_TCP:
1417 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1418 break;
1419 case IPPROTO_UDP:
1420 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1421 break;
1422 case IPPROTO_SCTP:
1423 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1424 break;
1425 default:
1426 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1427 break;
1428 }
1429 break;
1430 default:
1431 dev_info(&pf->pdev->dev, "Could not specify spec type\n");
1432 ret = -EINVAL;
1433 }
1434
1435 kfree(fd_data.raw_packet);
1436 fd_data.raw_packet = NULL;
1437
1438 return ret;
1439}
1440/**
1441 * i40e_set_rxnfc - command to set RX flow classification rules
1442 * @netdev: network interface device structure
1443 * @cmd: ethtool rxnfc command
1444 *
1445 * Returns Success if the command is supported.
1446 **/
1447static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1448{
1449 struct i40e_netdev_priv *np = netdev_priv(netdev);
1450 struct i40e_vsi *vsi = np->vsi;
1451 struct i40e_pf *pf = vsi->back;
1452 int ret = -EOPNOTSUPP;
1453
1454 switch (cmd->cmd) {
1455 case ETHTOOL_SRXFH:
1456 ret = i40e_set_rss_hash_opt(pf, cmd);
1457 break;
1458 case ETHTOOL_SRXCLSRLINS:
1459 ret = i40e_add_del_fdir_ethtool(vsi, cmd, true);
1460 break;
1461 case ETHTOOL_SRXCLSRLDEL:
1462 ret = i40e_add_del_fdir_ethtool(vsi, cmd, false);
1463 break;
1464 default:
1465 break;
1466 }
1467
1468 return ret;
1469}
1470
1471static const struct ethtool_ops i40e_ethtool_ops = {
1472 .get_settings = i40e_get_settings,
1473 .get_drvinfo = i40e_get_drvinfo,
1474 .get_regs_len = i40e_get_regs_len,
1475 .get_regs = i40e_get_regs,
1476 .nway_reset = i40e_nway_reset,
1477 .get_link = ethtool_op_get_link,
1478 .get_wol = i40e_get_wol,
1479 .get_eeprom_len = i40e_get_eeprom_len,
1480 .get_eeprom = i40e_get_eeprom,
1481 .get_ringparam = i40e_get_ringparam,
1482 .set_ringparam = i40e_set_ringparam,
1483 .get_pauseparam = i40e_get_pauseparam,
1484 .get_msglevel = i40e_get_msglevel,
1485 .set_msglevel = i40e_set_msglevel,
1486 .get_rxnfc = i40e_get_rxnfc,
1487 .set_rxnfc = i40e_set_rxnfc,
1488 .self_test = i40e_diag_test,
1489 .get_strings = i40e_get_strings,
1490 .set_phys_id = i40e_set_phys_id,
1491 .get_sset_count = i40e_get_sset_count,
1492 .get_ethtool_stats = i40e_get_ethtool_stats,
1493 .get_coalesce = i40e_get_coalesce,
1494 .set_coalesce = i40e_set_coalesce,
1495 .get_ts_info = i40e_get_ts_info,
1496};
1497
1498void i40e_set_ethtool_ops(struct net_device *netdev)
1499{
1500 SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops);
1501}