blob: 9c380a8e95da4bcf25bdbb729c7347a78a7bf7d2 [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 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000752}
753
Shannon Nelson7b086392013-11-20 10:02:59 +0000754static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000755{
Shannon Nelson7b086392013-11-20 10:02:59 +0000756 struct i40e_netdev_priv *np = netdev_priv(netdev);
757 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000758
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000759 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000760 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000761
Shannon Nelson7b086392013-11-20 10:02:59 +0000762 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000763}
764
Shannon Nelson7b086392013-11-20 10:02:59 +0000765static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000766{
Shannon Nelson7b086392013-11-20 10:02:59 +0000767 struct i40e_netdev_priv *np = netdev_priv(netdev);
768 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000769 u16 swc_old = pf->sw_int_count;
770
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000771 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000772 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
773 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
774 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
775 usleep_range(1000, 2000);
776 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000777
778 return *data;
779}
780
Shannon Nelson7b086392013-11-20 10:02:59 +0000781static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000782{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000783 struct i40e_netdev_priv *np = netdev_priv(netdev);
784 struct i40e_pf *pf = np->vsi->back;
785
786 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000787 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000788
789 return *data;
790}
791
792static void i40e_diag_test(struct net_device *netdev,
793 struct ethtool_test *eth_test, u64 *data)
794{
795 struct i40e_netdev_priv *np = netdev_priv(netdev);
796 struct i40e_pf *pf = np->vsi->back;
797
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000798 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
799 /* Offline tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000800 netif_info(pf, drv, netdev, "offline testing starting\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000801
Shannon Nelsonf551b432013-11-26 10:49:12 +0000802 set_bit(__I40E_TESTING, &pf->state);
803
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000804 /* 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_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
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_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
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_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000817 eth_test->flags |= ETH_TEST_FL_FAILED;
818
Shannon Nelsonf551b432013-11-26 10:49:12 +0000819 /* run reg test last, a reset is required after it */
820 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
821 eth_test->flags |= ETH_TEST_FL_FAILED;
822
823 clear_bit(__I40E_TESTING, &pf->state);
824 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000825 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000826 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000827 netif_info(pf, drv, netdev, "online testing starting\n");
828
Shannon Nelson7b086392013-11-20 10:02:59 +0000829 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000830 eth_test->flags |= ETH_TEST_FL_FAILED;
831
832 /* Offline only tests, not run in online; pass by default */
833 data[I40E_ETH_TEST_REG] = 0;
834 data[I40E_ETH_TEST_EEPROM] = 0;
835 data[I40E_ETH_TEST_INTR] = 0;
836 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000837 }
Shannon Nelsonc140c172013-11-20 10:02:58 +0000838
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000839 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000840}
841
842static void i40e_get_wol(struct net_device *netdev,
843 struct ethtool_wolinfo *wol)
844{
845 wol->supported = 0;
846 wol->wolopts = 0;
847}
848
849static int i40e_nway_reset(struct net_device *netdev)
850{
851 /* restart autonegotiation */
852 struct i40e_netdev_priv *np = netdev_priv(netdev);
853 struct i40e_pf *pf = np->vsi->back;
854 struct i40e_hw *hw = &pf->hw;
855 i40e_status ret = 0;
856
857 ret = i40e_aq_set_link_restart_an(hw, NULL);
858 if (ret) {
859 netdev_info(netdev, "link restart failed, aq_err=%d\n",
860 pf->hw.aq.asq_last_status);
861 return -EIO;
862 }
863
864 return 0;
865}
866
867static int i40e_set_phys_id(struct net_device *netdev,
868 enum ethtool_phys_id_state state)
869{
870 struct i40e_netdev_priv *np = netdev_priv(netdev);
871 struct i40e_pf *pf = np->vsi->back;
872 struct i40e_hw *hw = &pf->hw;
873 int blink_freq = 2;
874
875 switch (state) {
876 case ETHTOOL_ID_ACTIVE:
877 pf->led_status = i40e_led_get(hw);
878 return blink_freq;
879 case ETHTOOL_ID_ON:
880 i40e_led_set(hw, 0xF);
881 break;
882 case ETHTOOL_ID_OFF:
883 i40e_led_set(hw, 0x0);
884 break;
885 case ETHTOOL_ID_INACTIVE:
886 i40e_led_set(hw, pf->led_status);
887 break;
888 }
889
890 return 0;
891}
892
893/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
894 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
895 * 125us (8000 interrupts per second) == ITR(62)
896 */
897
898static int i40e_get_coalesce(struct net_device *netdev,
899 struct ethtool_coalesce *ec)
900{
901 struct i40e_netdev_priv *np = netdev_priv(netdev);
902 struct i40e_vsi *vsi = np->vsi;
903
904 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
905 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
906
907 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
908 ec->rx_coalesce_usecs = 1;
909 else
910 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
911
912 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
913 ec->tx_coalesce_usecs = 1;
914 else
915 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
916
917 return 0;
918}
919
920static int i40e_set_coalesce(struct net_device *netdev,
921 struct ethtool_coalesce *ec)
922{
923 struct i40e_netdev_priv *np = netdev_priv(netdev);
924 struct i40e_q_vector *q_vector;
925 struct i40e_vsi *vsi = np->vsi;
926 struct i40e_pf *pf = vsi->back;
927 struct i40e_hw *hw = &pf->hw;
928 u16 vector;
929 int i;
930
931 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
932 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
933
934 switch (ec->rx_coalesce_usecs) {
935 case 0:
936 vsi->rx_itr_setting = 0;
937 break;
938 case 1:
939 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
940 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
941 break;
942 default:
943 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
944 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
945 return -EINVAL;
946 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
947 break;
948 }
949
950 switch (ec->tx_coalesce_usecs) {
951 case 0:
952 vsi->tx_itr_setting = 0;
953 break;
954 case 1:
955 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
956 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
957 break;
958 default:
959 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
960 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
961 return -EINVAL;
962 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
963 break;
964 }
965
966 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +0000967 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
968 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000969 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
970 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
971 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
972 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
973 i40e_flush(hw);
974 }
975
976 return 0;
977}
978
979/**
980 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
981 * @pf: pointer to the physical function struct
982 * @cmd: ethtool rxnfc command
983 *
984 * Returns Success if the flow is supported, else Invalid Input.
985 **/
986static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
987{
988 cmd->data = 0;
989
990 /* Report default options for RSS on i40e */
991 switch (cmd->flow_type) {
992 case TCP_V4_FLOW:
993 case UDP_V4_FLOW:
994 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
995 /* fall through to add IP fields */
996 case SCTP_V4_FLOW:
997 case AH_ESP_V4_FLOW:
998 case AH_V4_FLOW:
999 case ESP_V4_FLOW:
1000 case IPV4_FLOW:
1001 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1002 break;
1003 case TCP_V6_FLOW:
1004 case UDP_V6_FLOW:
1005 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1006 /* fall through to add IP fields */
1007 case SCTP_V6_FLOW:
1008 case AH_ESP_V6_FLOW:
1009 case AH_V6_FLOW:
1010 case ESP_V6_FLOW:
1011 case IPV6_FLOW:
1012 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1013 break;
1014 default:
1015 return -EINVAL;
1016 }
1017
1018 return 0;
1019}
1020
1021/**
1022 * i40e_get_rxnfc - command to get RX flow classification rules
1023 * @netdev: network interface device structure
1024 * @cmd: ethtool rxnfc command
1025 *
1026 * Returns Success if the command is supported.
1027 **/
1028static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1029 u32 *rule_locs)
1030{
1031 struct i40e_netdev_priv *np = netdev_priv(netdev);
1032 struct i40e_vsi *vsi = np->vsi;
1033 struct i40e_pf *pf = vsi->back;
1034 int ret = -EOPNOTSUPP;
1035
1036 switch (cmd->cmd) {
1037 case ETHTOOL_GRXRINGS:
1038 cmd->data = vsi->alloc_queue_pairs;
1039 ret = 0;
1040 break;
1041 case ETHTOOL_GRXFH:
1042 ret = i40e_get_rss_hash_opts(pf, cmd);
1043 break;
1044 case ETHTOOL_GRXCLSRLCNT:
1045 ret = 0;
1046 break;
1047 case ETHTOOL_GRXCLSRULE:
1048 ret = 0;
1049 break;
1050 case ETHTOOL_GRXCLSRLALL:
1051 cmd->data = 500;
1052 ret = 0;
1053 default:
1054 break;
1055 }
1056
1057 return ret;
1058}
1059
1060/**
1061 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1062 * @pf: pointer to the physical function struct
1063 * @cmd: ethtool rxnfc command
1064 *
1065 * Returns Success if the flow input set is supported.
1066 **/
1067static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1068{
1069 struct i40e_hw *hw = &pf->hw;
1070 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1071 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1072
1073 /* RSS does not support anything other than hashing
1074 * to queues on src and dst IPs and ports
1075 */
1076 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1077 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1078 return -EINVAL;
1079
1080 /* We need at least the IP SRC and DEST fields for hashing */
1081 if (!(nfc->data & RXH_IP_SRC) ||
1082 !(nfc->data & RXH_IP_DST))
1083 return -EINVAL;
1084
1085 switch (nfc->flow_type) {
1086 case TCP_V4_FLOW:
1087 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1088 case 0:
1089 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1090 break;
1091 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1092 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1093 break;
1094 default:
1095 return -EINVAL;
1096 }
1097 break;
1098 case TCP_V6_FLOW:
1099 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1100 case 0:
1101 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1102 break;
1103 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1104 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1105 break;
1106 default:
1107 return -EINVAL;
1108 }
1109 break;
1110 case UDP_V4_FLOW:
1111 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1112 case 0:
1113 hena &=
1114 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1115 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1116 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1117 break;
1118 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1119 hena |=
1120 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1121 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1122 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1123 break;
1124 default:
1125 return -EINVAL;
1126 }
1127 break;
1128 case UDP_V6_FLOW:
1129 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1130 case 0:
1131 hena &=
1132 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1133 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1134 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1135 break;
1136 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1137 hena |=
1138 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1139 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1140 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1141 break;
1142 default:
1143 return -EINVAL;
1144 }
1145 break;
1146 case AH_ESP_V4_FLOW:
1147 case AH_V4_FLOW:
1148 case ESP_V4_FLOW:
1149 case SCTP_V4_FLOW:
1150 if ((nfc->data & RXH_L4_B_0_1) ||
1151 (nfc->data & RXH_L4_B_2_3))
1152 return -EINVAL;
1153 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1154 break;
1155 case AH_ESP_V6_FLOW:
1156 case AH_V6_FLOW:
1157 case ESP_V6_FLOW:
1158 case SCTP_V6_FLOW:
1159 if ((nfc->data & RXH_L4_B_0_1) ||
1160 (nfc->data & RXH_L4_B_2_3))
1161 return -EINVAL;
1162 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1163 break;
1164 case IPV4_FLOW:
1165 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1166 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1167 break;
1168 case IPV6_FLOW:
1169 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1170 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1171 break;
1172 default:
1173 return -EINVAL;
1174 }
1175
1176 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1177 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1178 i40e_flush(hw);
1179
1180 return 0;
1181}
1182
1183#define IP_HEADER_OFFSET 14
1184/**
1185 * i40e_add_del_fdir_udpv4 - Add/Remove UDPv4 Flow Director filters for
1186 * a specific flow spec
1187 * @vsi: pointer to the targeted VSI
1188 * @fd_data: the flow director data required from the FDir descriptor
1189 * @ethtool_rx_flow_spec: the flow spec
1190 * @add: true adds a filter, false removes it
1191 *
1192 * Returns 0 if the filters were successfully added or removed
1193 **/
1194static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
1195 struct i40e_fdir_data *fd_data,
1196 struct ethtool_rx_flow_spec *fsp, bool add)
1197{
1198 struct i40e_pf *pf = vsi->back;
1199 struct udphdr *udp;
1200 struct iphdr *ip;
1201 bool err = false;
1202 int ret;
1203 int i;
1204
1205 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1206 udp = (struct udphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1207 + sizeof(struct iphdr));
1208
1209 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1210 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1211 udp->source = fsp->h_u.tcp_ip4_spec.psrc;
1212 udp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1213
1214 for (i = I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP;
1215 i <= I40E_FILTER_PCTYPE_NONF_IPV4_UDP; i++) {
1216 fd_data->pctype = i;
1217 ret = i40e_program_fdir_filter(fd_data, pf, add);
1218
1219 if (ret) {
1220 dev_info(&pf->pdev->dev,
1221 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1222 fd_data->pctype, ret);
1223 err = true;
1224 } else {
1225 dev_info(&pf->pdev->dev,
1226 "Filter OK for PCTYPE %d (ret = %d)\n",
1227 fd_data->pctype, ret);
1228 }
1229 }
1230
1231 return err ? -EOPNOTSUPP : 0;
1232}
1233
1234/**
1235 * i40e_add_del_fdir_tcpv4 - Add/Remove TCPv4 Flow Director filters for
1236 * a specific flow spec
1237 * @vsi: pointer to the targeted VSI
1238 * @fd_data: the flow director data required from the FDir descriptor
1239 * @ethtool_rx_flow_spec: the flow spec
1240 * @add: true adds a filter, false removes it
1241 *
1242 * Returns 0 if the filters were successfully added or removed
1243 **/
1244static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
1245 struct i40e_fdir_data *fd_data,
1246 struct ethtool_rx_flow_spec *fsp, bool add)
1247{
1248 struct i40e_pf *pf = vsi->back;
1249 struct tcphdr *tcp;
1250 struct iphdr *ip;
1251 bool err = false;
1252 int ret;
1253
1254 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1255 tcp = (struct tcphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1256 + sizeof(struct iphdr));
1257
1258 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1259 tcp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1260
1261 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN;
1262 ret = i40e_program_fdir_filter(fd_data, pf, add);
1263
1264 if (ret) {
1265 dev_info(&pf->pdev->dev,
1266 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1267 fd_data->pctype, ret);
1268 err = true;
1269 } else {
1270 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1271 fd_data->pctype, ret);
1272 }
1273
1274 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1275 tcp->source = fsp->h_u.tcp_ip4_spec.psrc;
1276
1277 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
1278
1279 ret = i40e_program_fdir_filter(fd_data, pf, add);
1280 if (ret) {
1281 dev_info(&pf->pdev->dev,
1282 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1283 fd_data->pctype, ret);
1284 err = true;
1285 } else {
1286 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1287 fd_data->pctype, ret);
1288 }
1289
1290 return err ? -EOPNOTSUPP : 0;
1291}
1292
1293/**
1294 * i40e_add_del_fdir_sctpv4 - Add/Remove SCTPv4 Flow Director filters for
1295 * a specific flow spec
1296 * @vsi: pointer to the targeted VSI
1297 * @fd_data: the flow director data required from the FDir descriptor
1298 * @ethtool_rx_flow_spec: the flow spec
1299 * @add: true adds a filter, false removes it
1300 *
1301 * Returns 0 if the filters were successfully added or removed
1302 **/
1303static int i40e_add_del_fdir_sctpv4(struct i40e_vsi *vsi,
1304 struct i40e_fdir_data *fd_data,
1305 struct ethtool_rx_flow_spec *fsp, bool add)
1306{
1307 return -EOPNOTSUPP;
1308}
1309
1310/**
1311 * i40e_add_del_fdir_ipv4 - Add/Remove IPv4 Flow Director filters for
1312 * a specific flow spec
1313 * @vsi: pointer to the targeted VSI
1314 * @fd_data: the flow director data required for the FDir descriptor
1315 * @fsp: the ethtool flow spec
1316 * @add: true adds a filter, false removes it
1317 *
1318 * Returns 0 if the filters were successfully added or removed
1319 **/
1320static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
1321 struct i40e_fdir_data *fd_data,
1322 struct ethtool_rx_flow_spec *fsp, bool add)
1323{
1324 struct i40e_pf *pf = vsi->back;
1325 struct iphdr *ip;
1326 bool err = false;
1327 int ret;
1328 int i;
1329
1330 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1331
1332 ip->saddr = fsp->h_u.usr_ip4_spec.ip4src;
1333 ip->daddr = fsp->h_u.usr_ip4_spec.ip4dst;
1334 ip->protocol = fsp->h_u.usr_ip4_spec.proto;
1335
1336 for (i = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
1337 i <= I40E_FILTER_PCTYPE_FRAG_IPV4; i++) {
1338 fd_data->pctype = i;
1339 ret = i40e_program_fdir_filter(fd_data, pf, add);
1340
1341 if (ret) {
1342 dev_info(&pf->pdev->dev,
1343 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1344 fd_data->pctype, ret);
1345 err = true;
1346 } else {
1347 dev_info(&pf->pdev->dev,
1348 "Filter OK for PCTYPE %d (ret = %d)\n",
1349 fd_data->pctype, ret);
1350 }
1351 }
1352
1353 return err ? -EOPNOTSUPP : 0;
1354}
1355
1356/**
1357 * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters for
1358 * a specific flow spec based on their protocol
1359 * @vsi: pointer to the targeted VSI
1360 * @cmd: command to get or set RX flow classification rules
1361 * @add: true adds a filter, false removes it
1362 *
1363 * Returns 0 if the filters were successfully added or removed
1364 **/
1365static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
1366 struct ethtool_rxnfc *cmd, bool add)
1367{
1368 struct i40e_fdir_data fd_data;
1369 int ret = -EINVAL;
1370 struct i40e_pf *pf;
1371 struct ethtool_rx_flow_spec *fsp =
1372 (struct ethtool_rx_flow_spec *)&cmd->fs;
1373
1374 if (!vsi)
1375 return -EINVAL;
1376
1377 pf = vsi->back;
1378
1379 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1380 (fsp->ring_cookie >= vsi->num_queue_pairs))
1381 return -EINVAL;
1382
1383 /* Populate the Flow Director that we have at the moment
1384 * and allocate the raw packet buffer for the calling functions
1385 */
1386 fd_data.raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
1387 GFP_KERNEL);
1388
1389 if (!fd_data.raw_packet) {
1390 dev_info(&pf->pdev->dev, "Could not allocate memory\n");
1391 return -ENOMEM;
1392 }
1393
1394 fd_data.q_index = fsp->ring_cookie;
1395 fd_data.flex_off = 0;
1396 fd_data.pctype = 0;
1397 fd_data.dest_vsi = vsi->id;
1398 fd_data.dest_ctl = 0;
1399 fd_data.fd_status = 0;
1400 fd_data.cnt_index = 0;
1401 fd_data.fd_id = 0;
1402
1403 switch (fsp->flow_type & ~FLOW_EXT) {
1404 case TCP_V4_FLOW:
1405 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1406 break;
1407 case UDP_V4_FLOW:
1408 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1409 break;
1410 case SCTP_V4_FLOW:
1411 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1412 break;
1413 case IPV4_FLOW:
1414 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1415 break;
1416 case IP_USER_FLOW:
1417 switch (fsp->h_u.usr_ip4_spec.proto) {
1418 case IPPROTO_TCP:
1419 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1420 break;
1421 case IPPROTO_UDP:
1422 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1423 break;
1424 case IPPROTO_SCTP:
1425 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1426 break;
1427 default:
1428 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1429 break;
1430 }
1431 break;
1432 default:
1433 dev_info(&pf->pdev->dev, "Could not specify spec type\n");
1434 ret = -EINVAL;
1435 }
1436
1437 kfree(fd_data.raw_packet);
1438 fd_data.raw_packet = NULL;
1439
1440 return ret;
1441}
1442/**
1443 * i40e_set_rxnfc - command to set RX flow classification rules
1444 * @netdev: network interface device structure
1445 * @cmd: ethtool rxnfc command
1446 *
1447 * Returns Success if the command is supported.
1448 **/
1449static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1450{
1451 struct i40e_netdev_priv *np = netdev_priv(netdev);
1452 struct i40e_vsi *vsi = np->vsi;
1453 struct i40e_pf *pf = vsi->back;
1454 int ret = -EOPNOTSUPP;
1455
1456 switch (cmd->cmd) {
1457 case ETHTOOL_SRXFH:
1458 ret = i40e_set_rss_hash_opt(pf, cmd);
1459 break;
1460 case ETHTOOL_SRXCLSRLINS:
1461 ret = i40e_add_del_fdir_ethtool(vsi, cmd, true);
1462 break;
1463 case ETHTOOL_SRXCLSRLDEL:
1464 ret = i40e_add_del_fdir_ethtool(vsi, cmd, false);
1465 break;
1466 default:
1467 break;
1468 }
1469
1470 return ret;
1471}
1472
1473static const struct ethtool_ops i40e_ethtool_ops = {
1474 .get_settings = i40e_get_settings,
1475 .get_drvinfo = i40e_get_drvinfo,
1476 .get_regs_len = i40e_get_regs_len,
1477 .get_regs = i40e_get_regs,
1478 .nway_reset = i40e_nway_reset,
1479 .get_link = ethtool_op_get_link,
1480 .get_wol = i40e_get_wol,
1481 .get_eeprom_len = i40e_get_eeprom_len,
1482 .get_eeprom = i40e_get_eeprom,
1483 .get_ringparam = i40e_get_ringparam,
1484 .set_ringparam = i40e_set_ringparam,
1485 .get_pauseparam = i40e_get_pauseparam,
1486 .get_msglevel = i40e_get_msglevel,
1487 .set_msglevel = i40e_set_msglevel,
1488 .get_rxnfc = i40e_get_rxnfc,
1489 .set_rxnfc = i40e_set_rxnfc,
1490 .self_test = i40e_diag_test,
1491 .get_strings = i40e_get_strings,
1492 .set_phys_id = i40e_set_phys_id,
1493 .get_sset_count = i40e_get_sset_count,
1494 .get_ethtool_stats = i40e_get_ethtool_stats,
1495 .get_coalesce = i40e_get_coalesce,
1496 .set_coalesce = i40e_set_coalesce,
1497 .get_ts_info = i40e_get_ts_info,
1498};
1499
1500void i40e_set_ethtool_ops(struct net_device *netdev)
1501{
1502 SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops);
1503}