blob: 0359c36b86cc1b1603f6503209834f2e67070144 [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
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000279 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000280 pause->rx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000281 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000282 pause->tx_pause = 1;
Jesse Brandeburgd52c20b2013-11-26 10:49:15 +0000283 } else if (hw->fc.current_mode == I40E_FC_FULL) {
284 pause->rx_pause = 1;
285 pause->tx_pause = 1;
286 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000287}
288
289static u32 i40e_get_msglevel(struct net_device *netdev)
290{
291 struct i40e_netdev_priv *np = netdev_priv(netdev);
292 struct i40e_pf *pf = np->vsi->back;
293
294 return pf->msg_enable;
295}
296
297static void i40e_set_msglevel(struct net_device *netdev, u32 data)
298{
299 struct i40e_netdev_priv *np = netdev_priv(netdev);
300 struct i40e_pf *pf = np->vsi->back;
301
302 if (I40E_DEBUG_USER & data)
303 pf->hw.debug_mask = data;
304 pf->msg_enable = data;
305}
306
307static int i40e_get_regs_len(struct net_device *netdev)
308{
309 int reg_count = 0;
310 int i;
311
312 for (i = 0; i40e_reg_list[i].offset != 0; i++)
313 reg_count += i40e_reg_list[i].elements;
314
315 return reg_count * sizeof(u32);
316}
317
318static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
319 void *p)
320{
321 struct i40e_netdev_priv *np = netdev_priv(netdev);
322 struct i40e_pf *pf = np->vsi->back;
323 struct i40e_hw *hw = &pf->hw;
324 u32 *reg_buf = p;
325 int i, j, ri;
326 u32 reg;
327
328 /* Tell ethtool which driver-version-specific regs output we have.
329 *
330 * At some point, if we have ethtool doing special formatting of
331 * this data, it will rely on this version number to know how to
332 * interpret things. Hence, this needs to be updated if/when the
333 * diags register table is changed.
334 */
335 regs->version = 1;
336
337 /* loop through the diags reg table for what to print */
338 ri = 0;
339 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
340 for (j = 0; j < i40e_reg_list[i].elements; j++) {
341 reg = i40e_reg_list[i].offset
342 + (j * i40e_reg_list[i].stride);
343 reg_buf[ri++] = rd32(hw, reg);
344 }
345 }
346
347}
348
349static int i40e_get_eeprom(struct net_device *netdev,
350 struct ethtool_eeprom *eeprom, u8 *bytes)
351{
352 struct i40e_netdev_priv *np = netdev_priv(netdev);
353 struct i40e_hw *hw = &np->vsi->back->hw;
354 int first_word, last_word;
355 u16 i, eeprom_len;
356 u16 *eeprom_buff;
357 int ret_val = 0;
358
359 if (eeprom->len == 0)
360 return -EINVAL;
361
362 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
363
364 first_word = eeprom->offset >> 1;
365 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
366 eeprom_len = last_word - first_word + 1;
367
368 eeprom_buff = kmalloc(sizeof(u16) * eeprom_len, GFP_KERNEL);
369 if (!eeprom_buff)
370 return -ENOMEM;
371
372 ret_val = i40e_read_nvm_buffer(hw, first_word, &eeprom_len,
373 eeprom_buff);
374 if (eeprom_len == 0) {
375 kfree(eeprom_buff);
376 return -EACCES;
377 }
378
379 /* Device's eeprom is always little-endian, word addressable */
380 for (i = 0; i < eeprom_len; i++)
381 le16_to_cpus(&eeprom_buff[i]);
382
383 memcpy(bytes, (u8 *)eeprom_buff + (eeprom->offset & 1), eeprom->len);
384 kfree(eeprom_buff);
385
386 return ret_val;
387}
388
389static int i40e_get_eeprom_len(struct net_device *netdev)
390{
391 struct i40e_netdev_priv *np = netdev_priv(netdev);
392 struct i40e_hw *hw = &np->vsi->back->hw;
393
394 return hw->nvm.sr_size * 2;
395}
396
397static void i40e_get_drvinfo(struct net_device *netdev,
398 struct ethtool_drvinfo *drvinfo)
399{
400 struct i40e_netdev_priv *np = netdev_priv(netdev);
401 struct i40e_vsi *vsi = np->vsi;
402 struct i40e_pf *pf = vsi->back;
403
404 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
405 strlcpy(drvinfo->version, i40e_driver_version_str,
406 sizeof(drvinfo->version));
407 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
408 sizeof(drvinfo->fw_version));
409 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
410 sizeof(drvinfo->bus_info));
411}
412
413static void i40e_get_ringparam(struct net_device *netdev,
414 struct ethtool_ringparam *ring)
415{
416 struct i40e_netdev_priv *np = netdev_priv(netdev);
417 struct i40e_pf *pf = np->vsi->back;
418 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
419
420 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
421 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
422 ring->rx_mini_max_pending = 0;
423 ring->rx_jumbo_max_pending = 0;
Alexander Duyck9f65e152013-09-28 06:00:58 +0000424 ring->rx_pending = vsi->rx_rings[0]->count;
425 ring->tx_pending = vsi->tx_rings[0]->count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000426 ring->rx_mini_pending = 0;
427 ring->rx_jumbo_pending = 0;
428}
429
430static int i40e_set_ringparam(struct net_device *netdev,
431 struct ethtool_ringparam *ring)
432{
433 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
434 struct i40e_netdev_priv *np = netdev_priv(netdev);
435 struct i40e_vsi *vsi = np->vsi;
436 struct i40e_pf *pf = vsi->back;
437 u32 new_rx_count, new_tx_count;
438 int i, err = 0;
439
440 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
441 return -EINVAL;
442
Shannon Nelson1fa18372013-11-20 10:03:08 +0000443 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
444 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
445 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
446 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
447 netdev_info(netdev,
448 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
449 ring->tx_pending, ring->rx_pending,
450 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
451 return -EINVAL;
452 }
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000453
Shannon Nelson1fa18372013-11-20 10:03:08 +0000454 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
455 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000456
457 /* if nothing to do return success */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000458 if ((new_tx_count == vsi->tx_rings[0]->count) &&
459 (new_rx_count == vsi->rx_rings[0]->count))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000460 return 0;
461
462 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
463 usleep_range(1000, 2000);
464
465 if (!netif_running(vsi->netdev)) {
466 /* simple case - set for the next time the netdev is started */
467 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000468 vsi->tx_rings[i]->count = new_tx_count;
469 vsi->rx_rings[i]->count = new_rx_count;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000470 }
471 goto done;
472 }
473
474 /* We can't just free everything and then setup again,
475 * because the ISRs in MSI-X mode get passed pointers
476 * to the Tx and Rx ring structs.
477 */
478
479 /* alloc updated Tx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000480 if (new_tx_count != vsi->tx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000481 netdev_info(netdev,
482 "Changing Tx descriptor count from %d to %d.\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000483 vsi->tx_rings[0]->count, new_tx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000484 tx_rings = kcalloc(vsi->alloc_queue_pairs,
485 sizeof(struct i40e_ring), GFP_KERNEL);
486 if (!tx_rings) {
487 err = -ENOMEM;
488 goto done;
489 }
490
491 for (i = 0; i < vsi->num_queue_pairs; i++) {
492 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000493 tx_rings[i] = *vsi->tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000494 tx_rings[i].count = new_tx_count;
495 err = i40e_setup_tx_descriptors(&tx_rings[i]);
496 if (err) {
497 while (i) {
498 i--;
499 i40e_free_tx_resources(&tx_rings[i]);
500 }
501 kfree(tx_rings);
502 tx_rings = NULL;
503
504 goto done;
505 }
506 }
507 }
508
509 /* alloc updated Rx resources */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000510 if (new_rx_count != vsi->rx_rings[0]->count) {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000511 netdev_info(netdev,
512 "Changing Rx descriptor count from %d to %d\n",
Alexander Duyck9f65e152013-09-28 06:00:58 +0000513 vsi->rx_rings[0]->count, new_rx_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000514 rx_rings = kcalloc(vsi->alloc_queue_pairs,
515 sizeof(struct i40e_ring), GFP_KERNEL);
516 if (!rx_rings) {
517 err = -ENOMEM;
518 goto free_tx;
519 }
520
521 for (i = 0; i < vsi->num_queue_pairs; i++) {
522 /* clone ring and setup updated count */
Alexander Duyck9f65e152013-09-28 06:00:58 +0000523 rx_rings[i] = *vsi->rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000524 rx_rings[i].count = new_rx_count;
525 err = i40e_setup_rx_descriptors(&rx_rings[i]);
526 if (err) {
527 while (i) {
528 i--;
529 i40e_free_rx_resources(&rx_rings[i]);
530 }
531 kfree(rx_rings);
532 rx_rings = NULL;
533
534 goto free_tx;
535 }
536 }
537 }
538
539 /* Bring interface down, copy in the new ring info,
540 * then restore the interface
541 */
542 i40e_down(vsi);
543
544 if (tx_rings) {
545 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000546 i40e_free_tx_resources(vsi->tx_rings[i]);
547 *vsi->tx_rings[i] = tx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000548 }
549 kfree(tx_rings);
550 tx_rings = NULL;
551 }
552
553 if (rx_rings) {
554 for (i = 0; i < vsi->num_queue_pairs; i++) {
Alexander Duyck9f65e152013-09-28 06:00:58 +0000555 i40e_free_rx_resources(vsi->rx_rings[i]);
556 *vsi->rx_rings[i] = rx_rings[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000557 }
558 kfree(rx_rings);
559 rx_rings = NULL;
560 }
561
562 i40e_up(vsi);
563
564free_tx:
565 /* error cleanup if the Rx allocations failed after getting Tx */
566 if (tx_rings) {
567 for (i = 0; i < vsi->num_queue_pairs; i++)
568 i40e_free_tx_resources(&tx_rings[i]);
569 kfree(tx_rings);
570 tx_rings = NULL;
571 }
572
573done:
574 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
575
576 return err;
577}
578
579static int i40e_get_sset_count(struct net_device *netdev, int sset)
580{
581 struct i40e_netdev_priv *np = netdev_priv(netdev);
582 struct i40e_vsi *vsi = np->vsi;
583 struct i40e_pf *pf = vsi->back;
584
585 switch (sset) {
586 case ETH_SS_TEST:
587 return I40E_TEST_LEN;
588 case ETH_SS_STATS:
589 if (vsi == pf->vsi[pf->lan_vsi])
590 return I40E_PF_STATS_LEN(netdev);
591 else
592 return I40E_VSI_STATS_LEN(netdev);
593 default:
594 return -EOPNOTSUPP;
595 }
596}
597
598static void i40e_get_ethtool_stats(struct net_device *netdev,
599 struct ethtool_stats *stats, u64 *data)
600{
601 struct i40e_netdev_priv *np = netdev_priv(netdev);
602 struct i40e_vsi *vsi = np->vsi;
603 struct i40e_pf *pf = vsi->back;
604 int i = 0;
605 char *p;
606 int j;
607 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
Alexander Duyck980e9b12013-09-28 06:01:03 +0000608 unsigned int start;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000609
610 i40e_update_stats(vsi);
611
612 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
613 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
614 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
615 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
616 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000617 rcu_read_lock();
Alexander Duycka114d0a2013-09-28 06:00:43 +0000618 for (j = 0; j < vsi->num_queue_pairs; j++, i += 4) {
Alexander Duyck980e9b12013-09-28 06:01:03 +0000619 struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
620 struct i40e_ring *rx_ring;
621
622 if (!tx_ring)
623 continue;
624
625 /* process Tx ring statistics */
626 do {
627 start = u64_stats_fetch_begin_bh(&tx_ring->syncp);
628 data[i] = tx_ring->stats.packets;
629 data[i + 1] = tx_ring->stats.bytes;
630 } while (u64_stats_fetch_retry_bh(&tx_ring->syncp, start));
631
632 /* Rx ring is the 2nd half of the queue pair */
633 rx_ring = &tx_ring[1];
634 do {
635 start = u64_stats_fetch_begin_bh(&rx_ring->syncp);
636 data[i + 2] = rx_ring->stats.packets;
637 data[i + 3] = rx_ring->stats.bytes;
638 } while (u64_stats_fetch_retry_bh(&rx_ring->syncp, start));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000639 }
Alexander Duyck980e9b12013-09-28 06:01:03 +0000640 rcu_read_unlock();
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000641 if (vsi == pf->vsi[pf->lan_vsi]) {
642 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
643 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
644 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
645 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
646 }
647 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
648 data[i++] = pf->stats.priority_xon_tx[j];
649 data[i++] = pf->stats.priority_xoff_tx[j];
650 }
651 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
652 data[i++] = pf->stats.priority_xon_rx[j];
653 data[i++] = pf->stats.priority_xoff_rx[j];
654 }
655 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
656 data[i++] = pf->stats.priority_xon_2_xoff[j];
657 }
658}
659
660static void i40e_get_strings(struct net_device *netdev, u32 stringset,
661 u8 *data)
662{
663 struct i40e_netdev_priv *np = netdev_priv(netdev);
664 struct i40e_vsi *vsi = np->vsi;
665 struct i40e_pf *pf = vsi->back;
666 char *p = (char *)data;
667 int i;
668
669 switch (stringset) {
670 case ETH_SS_TEST:
671 for (i = 0; i < I40E_TEST_LEN; i++) {
672 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
673 data += ETH_GSTRING_LEN;
674 }
675 break;
676 case ETH_SS_STATS:
677 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
678 snprintf(p, ETH_GSTRING_LEN, "%s",
679 i40e_gstrings_net_stats[i].stat_string);
680 p += ETH_GSTRING_LEN;
681 }
682 for (i = 0; i < vsi->num_queue_pairs; i++) {
683 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
684 p += ETH_GSTRING_LEN;
685 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
686 p += ETH_GSTRING_LEN;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000687 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
688 p += ETH_GSTRING_LEN;
689 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
690 p += ETH_GSTRING_LEN;
691 }
692 if (vsi == pf->vsi[pf->lan_vsi]) {
693 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
694 snprintf(p, ETH_GSTRING_LEN, "port.%s",
695 i40e_gstrings_stats[i].stat_string);
696 p += ETH_GSTRING_LEN;
697 }
698 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
699 snprintf(p, ETH_GSTRING_LEN,
700 "port.tx_priority_%u_xon", i);
701 p += ETH_GSTRING_LEN;
702 snprintf(p, ETH_GSTRING_LEN,
703 "port.tx_priority_%u_xoff", i);
704 p += ETH_GSTRING_LEN;
705 }
706 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
707 snprintf(p, ETH_GSTRING_LEN,
708 "port.rx_priority_%u_xon", i);
709 p += ETH_GSTRING_LEN;
710 snprintf(p, ETH_GSTRING_LEN,
711 "port.rx_priority_%u_xoff", i);
712 p += ETH_GSTRING_LEN;
713 }
714 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
715 snprintf(p, ETH_GSTRING_LEN,
716 "port.rx_priority_%u_xon_2_xoff", i);
717 p += ETH_GSTRING_LEN;
718 }
719 }
720 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
721 break;
722 }
723}
724
725static int i40e_get_ts_info(struct net_device *dev,
726 struct ethtool_ts_info *info)
727{
728 return ethtool_op_get_ts_info(dev, info);
729}
730
Shannon Nelson7b086392013-11-20 10:02:59 +0000731static int i40e_link_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000732{
Shannon Nelson7b086392013-11-20 10:02:59 +0000733 struct i40e_netdev_priv *np = netdev_priv(netdev);
734 struct i40e_pf *pf = np->vsi->back;
735
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000736 netif_info(pf, hw, netdev, "link test\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000737 if (i40e_get_link_status(&pf->hw))
738 *data = 0;
739 else
740 *data = 1;
741
742 return *data;
743}
744
Shannon Nelson7b086392013-11-20 10:02:59 +0000745static int i40e_reg_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000746{
Shannon Nelson7b086392013-11-20 10:02:59 +0000747 struct i40e_netdev_priv *np = netdev_priv(netdev);
748 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000749
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000750 netif_info(pf, hw, netdev, "register test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000751 *data = i40e_diag_reg_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000752
Shannon Nelson7b086392013-11-20 10:02:59 +0000753 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000754}
755
Shannon Nelson7b086392013-11-20 10:02:59 +0000756static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000757{
Shannon Nelson7b086392013-11-20 10:02:59 +0000758 struct i40e_netdev_priv *np = netdev_priv(netdev);
759 struct i40e_pf *pf = np->vsi->back;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000760
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000761 netif_info(pf, hw, netdev, "eeprom test\n");
Shannon Nelson7b086392013-11-20 10:02:59 +0000762 *data = i40e_diag_eeprom_test(&pf->hw);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000763
Shannon Nelson7b086392013-11-20 10:02:59 +0000764 return *data;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000765}
766
Shannon Nelson7b086392013-11-20 10:02:59 +0000767static int i40e_intr_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000768{
Shannon Nelson7b086392013-11-20 10:02:59 +0000769 struct i40e_netdev_priv *np = netdev_priv(netdev);
770 struct i40e_pf *pf = np->vsi->back;
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000771 u16 swc_old = pf->sw_int_count;
772
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000773 netif_info(pf, hw, netdev, "interrupt test\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000774 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
775 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
776 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
777 usleep_range(1000, 2000);
778 *data = (swc_old == pf->sw_int_count);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000779
780 return *data;
781}
782
Shannon Nelson7b086392013-11-20 10:02:59 +0000783static int i40e_loopback_test(struct net_device *netdev, u64 *data)
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000784{
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000785 struct i40e_netdev_priv *np = netdev_priv(netdev);
786 struct i40e_pf *pf = np->vsi->back;
787
788 netif_info(pf, hw, netdev, "loopback test not implemented\n");
Shannon Nelsoncd92e722013-11-16 10:00:44 +0000789 *data = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000790
791 return *data;
792}
793
794static void i40e_diag_test(struct net_device *netdev,
795 struct ethtool_test *eth_test, u64 *data)
796{
797 struct i40e_netdev_priv *np = netdev_priv(netdev);
798 struct i40e_pf *pf = np->vsi->back;
799
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000800 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
Shannon Nelsonf551b432013-11-26 10:49:12 +0000804 set_bit(__I40E_TESTING, &pf->state);
805
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000806 /* Link test performed before hardware reset
807 * so autoneg doesn't interfere with test result
808 */
Shannon Nelson7b086392013-11-20 10:02:59 +0000809 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000810 eth_test->flags |= ETH_TEST_FL_FAILED;
811
Shannon Nelson7b086392013-11-20 10:02:59 +0000812 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000813 eth_test->flags |= ETH_TEST_FL_FAILED;
814
Shannon Nelson7b086392013-11-20 10:02:59 +0000815 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000816 eth_test->flags |= ETH_TEST_FL_FAILED;
817
Shannon Nelson7b086392013-11-20 10:02:59 +0000818 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000819 eth_test->flags |= ETH_TEST_FL_FAILED;
820
Shannon Nelsonf551b432013-11-26 10:49:12 +0000821 /* run reg test last, a reset is required after it */
822 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
823 eth_test->flags |= ETH_TEST_FL_FAILED;
824
825 clear_bit(__I40E_TESTING, &pf->state);
826 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000827 } else {
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000828 /* Online tests */
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000829 netif_info(pf, drv, netdev, "online testing starting\n");
830
Shannon Nelson7b086392013-11-20 10:02:59 +0000831 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000832 eth_test->flags |= ETH_TEST_FL_FAILED;
833
834 /* Offline only tests, not run in online; pass by default */
835 data[I40E_ETH_TEST_REG] = 0;
836 data[I40E_ETH_TEST_EEPROM] = 0;
837 data[I40E_ETH_TEST_INTR] = 0;
838 data[I40E_ETH_TEST_LOOPBACK] = 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000839 }
Shannon Nelsonc140c172013-11-20 10:02:58 +0000840
Shannon Nelsonb03aaa92013-11-20 10:03:06 +0000841 netif_info(pf, drv, netdev, "testing finished\n");
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000842}
843
844static void i40e_get_wol(struct net_device *netdev,
845 struct ethtool_wolinfo *wol)
846{
Shannon Nelson8e2773a2013-11-28 06:39:22 +0000847 struct i40e_netdev_priv *np = netdev_priv(netdev);
848 struct i40e_pf *pf = np->vsi->back;
849 struct i40e_hw *hw = &pf->hw;
850 u16 wol_nvm_bits;
851
852 /* NVM bit on means WoL disabled for the port */
853 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
854 if ((1 << hw->port) & wol_nvm_bits) {
855 wol->supported = 0;
856 wol->wolopts = 0;
857 } else {
858 wol->supported = WAKE_MAGIC;
859 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
860 }
861}
862
863static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
864{
865 struct i40e_netdev_priv *np = netdev_priv(netdev);
866 struct i40e_pf *pf = np->vsi->back;
867 struct i40e_hw *hw = &pf->hw;
868 u16 wol_nvm_bits;
869
870 /* NVM bit on means WoL disabled for the port */
871 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
872 if (((1 << hw->port) & wol_nvm_bits))
873 return -EOPNOTSUPP;
874
875 /* only magic packet is supported */
876 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
877 return -EOPNOTSUPP;
878
879 /* is this a new value? */
880 if (pf->wol_en != !!wol->wolopts) {
881 pf->wol_en = !!wol->wolopts;
882 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
883 }
884
885 return 0;
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000886}
887
888static int i40e_nway_reset(struct net_device *netdev)
889{
890 /* restart autonegotiation */
891 struct i40e_netdev_priv *np = netdev_priv(netdev);
892 struct i40e_pf *pf = np->vsi->back;
893 struct i40e_hw *hw = &pf->hw;
894 i40e_status ret = 0;
895
896 ret = i40e_aq_set_link_restart_an(hw, NULL);
897 if (ret) {
898 netdev_info(netdev, "link restart failed, aq_err=%d\n",
899 pf->hw.aq.asq_last_status);
900 return -EIO;
901 }
902
903 return 0;
904}
905
906static int i40e_set_phys_id(struct net_device *netdev,
907 enum ethtool_phys_id_state state)
908{
909 struct i40e_netdev_priv *np = netdev_priv(netdev);
910 struct i40e_pf *pf = np->vsi->back;
911 struct i40e_hw *hw = &pf->hw;
912 int blink_freq = 2;
913
914 switch (state) {
915 case ETHTOOL_ID_ACTIVE:
916 pf->led_status = i40e_led_get(hw);
917 return blink_freq;
918 case ETHTOOL_ID_ON:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000919 i40e_led_set(hw, 0xF, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000920 break;
921 case ETHTOOL_ID_OFF:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000922 i40e_led_set(hw, 0x0, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000923 break;
924 case ETHTOOL_ID_INACTIVE:
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000925 i40e_led_set(hw, pf->led_status, false);
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +0000926 break;
927 }
928
929 return 0;
930}
931
932/* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
933 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
934 * 125us (8000 interrupts per second) == ITR(62)
935 */
936
937static int i40e_get_coalesce(struct net_device *netdev,
938 struct ethtool_coalesce *ec)
939{
940 struct i40e_netdev_priv *np = netdev_priv(netdev);
941 struct i40e_vsi *vsi = np->vsi;
942
943 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
944 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
945
946 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
947 ec->rx_coalesce_usecs = 1;
948 else
949 ec->rx_coalesce_usecs = vsi->rx_itr_setting;
950
951 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
952 ec->tx_coalesce_usecs = 1;
953 else
954 ec->tx_coalesce_usecs = vsi->tx_itr_setting;
955
956 return 0;
957}
958
959static int i40e_set_coalesce(struct net_device *netdev,
960 struct ethtool_coalesce *ec)
961{
962 struct i40e_netdev_priv *np = netdev_priv(netdev);
963 struct i40e_q_vector *q_vector;
964 struct i40e_vsi *vsi = np->vsi;
965 struct i40e_pf *pf = vsi->back;
966 struct i40e_hw *hw = &pf->hw;
967 u16 vector;
968 int i;
969
970 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
971 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
972
973 switch (ec->rx_coalesce_usecs) {
974 case 0:
975 vsi->rx_itr_setting = 0;
976 break;
977 case 1:
978 vsi->rx_itr_setting = (I40E_ITR_DYNAMIC |
979 ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
980 break;
981 default:
982 if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
983 (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
984 return -EINVAL;
985 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
986 break;
987 }
988
989 switch (ec->tx_coalesce_usecs) {
990 case 0:
991 vsi->tx_itr_setting = 0;
992 break;
993 case 1:
994 vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
995 ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
996 break;
997 default:
998 if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
999 (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
1000 return -EINVAL;
1001 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1002 break;
1003 }
1004
1005 vector = vsi->base_vector;
Alexander Duyck493fb302013-09-28 07:01:44 +00001006 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1007 q_vector = vsi->q_vectors[i];
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001008 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1009 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1010 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1011 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1012 i40e_flush(hw);
1013 }
1014
1015 return 0;
1016}
1017
1018/**
1019 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1020 * @pf: pointer to the physical function struct
1021 * @cmd: ethtool rxnfc command
1022 *
1023 * Returns Success if the flow is supported, else Invalid Input.
1024 **/
1025static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1026{
1027 cmd->data = 0;
1028
1029 /* Report default options for RSS on i40e */
1030 switch (cmd->flow_type) {
1031 case TCP_V4_FLOW:
1032 case UDP_V4_FLOW:
1033 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1034 /* fall through to add IP fields */
1035 case SCTP_V4_FLOW:
1036 case AH_ESP_V4_FLOW:
1037 case AH_V4_FLOW:
1038 case ESP_V4_FLOW:
1039 case IPV4_FLOW:
1040 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1041 break;
1042 case TCP_V6_FLOW:
1043 case UDP_V6_FLOW:
1044 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1045 /* fall through to add IP fields */
1046 case SCTP_V6_FLOW:
1047 case AH_ESP_V6_FLOW:
1048 case AH_V6_FLOW:
1049 case ESP_V6_FLOW:
1050 case IPV6_FLOW:
1051 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1052 break;
1053 default:
1054 return -EINVAL;
1055 }
1056
1057 return 0;
1058}
1059
1060/**
1061 * i40e_get_rxnfc - command to get RX flow classification rules
1062 * @netdev: network interface device structure
1063 * @cmd: ethtool rxnfc command
1064 *
1065 * Returns Success if the command is supported.
1066 **/
1067static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1068 u32 *rule_locs)
1069{
1070 struct i40e_netdev_priv *np = netdev_priv(netdev);
1071 struct i40e_vsi *vsi = np->vsi;
1072 struct i40e_pf *pf = vsi->back;
1073 int ret = -EOPNOTSUPP;
1074
1075 switch (cmd->cmd) {
1076 case ETHTOOL_GRXRINGS:
1077 cmd->data = vsi->alloc_queue_pairs;
1078 ret = 0;
1079 break;
1080 case ETHTOOL_GRXFH:
1081 ret = i40e_get_rss_hash_opts(pf, cmd);
1082 break;
1083 case ETHTOOL_GRXCLSRLCNT:
1084 ret = 0;
1085 break;
1086 case ETHTOOL_GRXCLSRULE:
1087 ret = 0;
1088 break;
1089 case ETHTOOL_GRXCLSRLALL:
1090 cmd->data = 500;
1091 ret = 0;
1092 default:
1093 break;
1094 }
1095
1096 return ret;
1097}
1098
1099/**
1100 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1101 * @pf: pointer to the physical function struct
1102 * @cmd: ethtool rxnfc command
1103 *
1104 * Returns Success if the flow input set is supported.
1105 **/
1106static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1107{
1108 struct i40e_hw *hw = &pf->hw;
1109 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1110 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1111
1112 /* RSS does not support anything other than hashing
1113 * to queues on src and dst IPs and ports
1114 */
1115 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1116 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1117 return -EINVAL;
1118
1119 /* We need at least the IP SRC and DEST fields for hashing */
1120 if (!(nfc->data & RXH_IP_SRC) ||
1121 !(nfc->data & RXH_IP_DST))
1122 return -EINVAL;
1123
1124 switch (nfc->flow_type) {
1125 case TCP_V4_FLOW:
1126 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1127 case 0:
1128 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1129 break;
1130 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1131 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1132 break;
1133 default:
1134 return -EINVAL;
1135 }
1136 break;
1137 case TCP_V6_FLOW:
1138 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1139 case 0:
1140 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1141 break;
1142 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1143 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1144 break;
1145 default:
1146 return -EINVAL;
1147 }
1148 break;
1149 case UDP_V4_FLOW:
1150 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1151 case 0:
1152 hena &=
1153 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1154 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1155 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1156 break;
1157 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1158 hena |=
1159 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
1160 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) |
1161 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1162 break;
1163 default:
1164 return -EINVAL;
1165 }
1166 break;
1167 case UDP_V6_FLOW:
1168 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1169 case 0:
1170 hena &=
1171 ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1172 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1173 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1174 break;
1175 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1176 hena |=
1177 (((u64)1 << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
1178 ((u64)1 << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) |
1179 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1180 break;
1181 default:
1182 return -EINVAL;
1183 }
1184 break;
1185 case AH_ESP_V4_FLOW:
1186 case AH_V4_FLOW:
1187 case ESP_V4_FLOW:
1188 case SCTP_V4_FLOW:
1189 if ((nfc->data & RXH_L4_B_0_1) ||
1190 (nfc->data & RXH_L4_B_2_3))
1191 return -EINVAL;
1192 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1193 break;
1194 case AH_ESP_V6_FLOW:
1195 case AH_V6_FLOW:
1196 case ESP_V6_FLOW:
1197 case SCTP_V6_FLOW:
1198 if ((nfc->data & RXH_L4_B_0_1) ||
1199 (nfc->data & RXH_L4_B_2_3))
1200 return -EINVAL;
1201 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1202 break;
1203 case IPV4_FLOW:
1204 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1205 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1206 break;
1207 case IPV6_FLOW:
1208 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1209 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1210 break;
1211 default:
1212 return -EINVAL;
1213 }
1214
1215 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1216 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1217 i40e_flush(hw);
1218
1219 return 0;
1220}
1221
1222#define IP_HEADER_OFFSET 14
1223/**
1224 * i40e_add_del_fdir_udpv4 - Add/Remove UDPv4 Flow Director filters for
1225 * a specific flow spec
1226 * @vsi: pointer to the targeted VSI
1227 * @fd_data: the flow director data required from the FDir descriptor
1228 * @ethtool_rx_flow_spec: the flow spec
1229 * @add: true adds a filter, false removes it
1230 *
1231 * Returns 0 if the filters were successfully added or removed
1232 **/
1233static int i40e_add_del_fdir_udpv4(struct i40e_vsi *vsi,
1234 struct i40e_fdir_data *fd_data,
1235 struct ethtool_rx_flow_spec *fsp, bool add)
1236{
1237 struct i40e_pf *pf = vsi->back;
1238 struct udphdr *udp;
1239 struct iphdr *ip;
1240 bool err = false;
1241 int ret;
1242 int i;
1243
1244 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1245 udp = (struct udphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1246 + sizeof(struct iphdr));
1247
1248 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1249 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1250 udp->source = fsp->h_u.tcp_ip4_spec.psrc;
1251 udp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1252
1253 for (i = I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP;
1254 i <= I40E_FILTER_PCTYPE_NONF_IPV4_UDP; i++) {
1255 fd_data->pctype = i;
1256 ret = i40e_program_fdir_filter(fd_data, pf, add);
1257
1258 if (ret) {
1259 dev_info(&pf->pdev->dev,
1260 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1261 fd_data->pctype, ret);
1262 err = true;
1263 } else {
1264 dev_info(&pf->pdev->dev,
1265 "Filter OK for PCTYPE %d (ret = %d)\n",
1266 fd_data->pctype, ret);
1267 }
1268 }
1269
1270 return err ? -EOPNOTSUPP : 0;
1271}
1272
1273/**
1274 * i40e_add_del_fdir_tcpv4 - Add/Remove TCPv4 Flow Director filters for
1275 * a specific flow spec
1276 * @vsi: pointer to the targeted VSI
1277 * @fd_data: the flow director data required from the FDir descriptor
1278 * @ethtool_rx_flow_spec: the flow spec
1279 * @add: true adds a filter, false removes it
1280 *
1281 * Returns 0 if the filters were successfully added or removed
1282 **/
1283static int i40e_add_del_fdir_tcpv4(struct i40e_vsi *vsi,
1284 struct i40e_fdir_data *fd_data,
1285 struct ethtool_rx_flow_spec *fsp, bool add)
1286{
1287 struct i40e_pf *pf = vsi->back;
1288 struct tcphdr *tcp;
1289 struct iphdr *ip;
1290 bool err = false;
1291 int ret;
1292
1293 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1294 tcp = (struct tcphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET
1295 + sizeof(struct iphdr));
1296
1297 ip->daddr = fsp->h_u.tcp_ip4_spec.ip4dst;
1298 tcp->dest = fsp->h_u.tcp_ip4_spec.pdst;
1299
1300 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN;
1301 ret = i40e_program_fdir_filter(fd_data, pf, add);
1302
1303 if (ret) {
1304 dev_info(&pf->pdev->dev,
1305 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1306 fd_data->pctype, ret);
1307 err = true;
1308 } else {
1309 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1310 fd_data->pctype, ret);
1311 }
1312
1313 ip->saddr = fsp->h_u.tcp_ip4_spec.ip4src;
1314 tcp->source = fsp->h_u.tcp_ip4_spec.psrc;
1315
1316 fd_data->pctype = I40E_FILTER_PCTYPE_NONF_IPV4_TCP;
1317
1318 ret = i40e_program_fdir_filter(fd_data, pf, add);
1319 if (ret) {
1320 dev_info(&pf->pdev->dev,
1321 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1322 fd_data->pctype, ret);
1323 err = true;
1324 } else {
1325 dev_info(&pf->pdev->dev, "Filter OK for PCTYPE %d (ret = %d)\n",
1326 fd_data->pctype, ret);
1327 }
1328
1329 return err ? -EOPNOTSUPP : 0;
1330}
1331
1332/**
1333 * i40e_add_del_fdir_sctpv4 - Add/Remove SCTPv4 Flow Director filters for
1334 * a specific flow spec
1335 * @vsi: pointer to the targeted VSI
1336 * @fd_data: the flow director data required from the FDir descriptor
1337 * @ethtool_rx_flow_spec: the flow spec
1338 * @add: true adds a filter, false removes it
1339 *
1340 * Returns 0 if the filters were successfully added or removed
1341 **/
1342static int i40e_add_del_fdir_sctpv4(struct i40e_vsi *vsi,
1343 struct i40e_fdir_data *fd_data,
1344 struct ethtool_rx_flow_spec *fsp, bool add)
1345{
1346 return -EOPNOTSUPP;
1347}
1348
1349/**
1350 * i40e_add_del_fdir_ipv4 - Add/Remove IPv4 Flow Director filters for
1351 * a specific flow spec
1352 * @vsi: pointer to the targeted VSI
1353 * @fd_data: the flow director data required for the FDir descriptor
1354 * @fsp: the ethtool flow spec
1355 * @add: true adds a filter, false removes it
1356 *
1357 * Returns 0 if the filters were successfully added or removed
1358 **/
1359static int i40e_add_del_fdir_ipv4(struct i40e_vsi *vsi,
1360 struct i40e_fdir_data *fd_data,
1361 struct ethtool_rx_flow_spec *fsp, bool add)
1362{
1363 struct i40e_pf *pf = vsi->back;
1364 struct iphdr *ip;
1365 bool err = false;
1366 int ret;
1367 int i;
1368
1369 ip = (struct iphdr *)(fd_data->raw_packet + IP_HEADER_OFFSET);
1370
1371 ip->saddr = fsp->h_u.usr_ip4_spec.ip4src;
1372 ip->daddr = fsp->h_u.usr_ip4_spec.ip4dst;
1373 ip->protocol = fsp->h_u.usr_ip4_spec.proto;
1374
1375 for (i = I40E_FILTER_PCTYPE_NONF_IPV4_OTHER;
1376 i <= I40E_FILTER_PCTYPE_FRAG_IPV4; i++) {
1377 fd_data->pctype = i;
1378 ret = i40e_program_fdir_filter(fd_data, pf, add);
1379
1380 if (ret) {
1381 dev_info(&pf->pdev->dev,
1382 "Filter command send failed for PCTYPE %d (ret = %d)\n",
1383 fd_data->pctype, ret);
1384 err = true;
1385 } else {
1386 dev_info(&pf->pdev->dev,
1387 "Filter OK for PCTYPE %d (ret = %d)\n",
1388 fd_data->pctype, ret);
1389 }
1390 }
1391
1392 return err ? -EOPNOTSUPP : 0;
1393}
1394
1395/**
1396 * i40e_add_del_fdir_ethtool - Add/Remove Flow Director filters for
1397 * a specific flow spec based on their protocol
1398 * @vsi: pointer to the targeted VSI
1399 * @cmd: command to get or set RX flow classification rules
1400 * @add: true adds a filter, false removes it
1401 *
1402 * Returns 0 if the filters were successfully added or removed
1403 **/
1404static int i40e_add_del_fdir_ethtool(struct i40e_vsi *vsi,
1405 struct ethtool_rxnfc *cmd, bool add)
1406{
1407 struct i40e_fdir_data fd_data;
1408 int ret = -EINVAL;
1409 struct i40e_pf *pf;
1410 struct ethtool_rx_flow_spec *fsp =
1411 (struct ethtool_rx_flow_spec *)&cmd->fs;
1412
1413 if (!vsi)
1414 return -EINVAL;
1415
1416 pf = vsi->back;
1417
1418 if ((fsp->ring_cookie != RX_CLS_FLOW_DISC) &&
1419 (fsp->ring_cookie >= vsi->num_queue_pairs))
1420 return -EINVAL;
1421
1422 /* Populate the Flow Director that we have at the moment
1423 * and allocate the raw packet buffer for the calling functions
1424 */
1425 fd_data.raw_packet = kzalloc(I40E_FDIR_MAX_RAW_PACKET_LOOKUP,
1426 GFP_KERNEL);
1427
1428 if (!fd_data.raw_packet) {
1429 dev_info(&pf->pdev->dev, "Could not allocate memory\n");
1430 return -ENOMEM;
1431 }
1432
1433 fd_data.q_index = fsp->ring_cookie;
1434 fd_data.flex_off = 0;
1435 fd_data.pctype = 0;
1436 fd_data.dest_vsi = vsi->id;
1437 fd_data.dest_ctl = 0;
1438 fd_data.fd_status = 0;
1439 fd_data.cnt_index = 0;
1440 fd_data.fd_id = 0;
1441
1442 switch (fsp->flow_type & ~FLOW_EXT) {
1443 case TCP_V4_FLOW:
1444 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1445 break;
1446 case UDP_V4_FLOW:
1447 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1448 break;
1449 case SCTP_V4_FLOW:
1450 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1451 break;
1452 case IPV4_FLOW:
1453 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1454 break;
1455 case IP_USER_FLOW:
1456 switch (fsp->h_u.usr_ip4_spec.proto) {
1457 case IPPROTO_TCP:
1458 ret = i40e_add_del_fdir_tcpv4(vsi, &fd_data, fsp, add);
1459 break;
1460 case IPPROTO_UDP:
1461 ret = i40e_add_del_fdir_udpv4(vsi, &fd_data, fsp, add);
1462 break;
1463 case IPPROTO_SCTP:
1464 ret = i40e_add_del_fdir_sctpv4(vsi, &fd_data, fsp, add);
1465 break;
1466 default:
1467 ret = i40e_add_del_fdir_ipv4(vsi, &fd_data, fsp, add);
1468 break;
1469 }
1470 break;
1471 default:
1472 dev_info(&pf->pdev->dev, "Could not specify spec type\n");
1473 ret = -EINVAL;
1474 }
1475
1476 kfree(fd_data.raw_packet);
1477 fd_data.raw_packet = NULL;
1478
1479 return ret;
1480}
1481/**
1482 * i40e_set_rxnfc - command to set RX flow classification rules
1483 * @netdev: network interface device structure
1484 * @cmd: ethtool rxnfc command
1485 *
1486 * Returns Success if the command is supported.
1487 **/
1488static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1489{
1490 struct i40e_netdev_priv *np = netdev_priv(netdev);
1491 struct i40e_vsi *vsi = np->vsi;
1492 struct i40e_pf *pf = vsi->back;
1493 int ret = -EOPNOTSUPP;
1494
1495 switch (cmd->cmd) {
1496 case ETHTOOL_SRXFH:
1497 ret = i40e_set_rss_hash_opt(pf, cmd);
1498 break;
1499 case ETHTOOL_SRXCLSRLINS:
1500 ret = i40e_add_del_fdir_ethtool(vsi, cmd, true);
1501 break;
1502 case ETHTOOL_SRXCLSRLDEL:
1503 ret = i40e_add_del_fdir_ethtool(vsi, cmd, false);
1504 break;
1505 default:
1506 break;
1507 }
1508
1509 return ret;
1510}
1511
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001512/**
1513 * i40e_max_channels - get Max number of combined channels supported
1514 * @vsi: vsi pointer
1515 **/
1516static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1517{
1518 /* TODO: This code assumes DCB and FD is disabled for now. */
1519 return vsi->alloc_queue_pairs;
1520}
1521
1522/**
1523 * i40e_get_channels - Get the current channels enabled and max supported etc.
1524 * @netdev: network interface device structure
1525 * @ch: ethtool channels structure
1526 *
1527 * We don't support separate tx and rx queues as channels. The other count
1528 * represents how many queues are being used for control. max_combined counts
1529 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1530 * q_vectors since we support a lot more queue pairs than q_vectors.
1531 **/
1532static void i40e_get_channels(struct net_device *dev,
1533 struct ethtool_channels *ch)
1534{
1535 struct i40e_netdev_priv *np = netdev_priv(dev);
1536 struct i40e_vsi *vsi = np->vsi;
1537 struct i40e_pf *pf = vsi->back;
1538
1539 /* report maximum channels */
1540 ch->max_combined = i40e_max_channels(vsi);
1541
1542 /* report info for other vector */
1543 ch->other_count = (pf->flags & I40E_FLAG_FDIR_ENABLED) ? 1 : 0;
1544 ch->max_other = ch->other_count;
1545
1546 /* Note: This code assumes DCB is disabled for now. */
1547 ch->combined_count = vsi->num_queue_pairs;
1548}
1549
1550/**
1551 * i40e_set_channels - Set the new channels count.
1552 * @netdev: network interface device structure
1553 * @ch: ethtool channels structure
1554 *
1555 * The new channels count may not be the same as requested by the user
1556 * since it gets rounded down to a power of 2 value.
1557 **/
1558static int i40e_set_channels(struct net_device *dev,
1559 struct ethtool_channels *ch)
1560{
1561 struct i40e_netdev_priv *np = netdev_priv(dev);
1562 unsigned int count = ch->combined_count;
1563 struct i40e_vsi *vsi = np->vsi;
1564 struct i40e_pf *pf = vsi->back;
1565 int new_count;
1566
1567 /* We do not support setting channels for any other VSI at present */
1568 if (vsi->type != I40E_VSI_MAIN)
1569 return -EINVAL;
1570
1571 /* verify they are not requesting separate vectors */
1572 if (!count || ch->rx_count || ch->tx_count)
1573 return -EINVAL;
1574
1575 /* verify other_count has not changed */
1576 if (ch->other_count != ((pf->flags & I40E_FLAG_FDIR_ENABLED) ? 1 : 0))
1577 return -EINVAL;
1578
1579 /* verify the number of channels does not exceed hardware limits */
1580 if (count > i40e_max_channels(vsi))
1581 return -EINVAL;
1582
1583 /* update feature limits from largest to smallest supported values */
1584 /* TODO: Flow director limit, DCB etc */
1585
1586 /* cap RSS limit */
1587 if (count > pf->rss_size_max)
1588 count = pf->rss_size_max;
1589
1590 /* use rss_reconfig to rebuild with new queue count and update traffic
1591 * class queue mapping
1592 */
1593 new_count = i40e_reconfig_rss_queues(pf, count);
1594 if (new_count > 1)
1595 return 0;
1596 else
1597 return -EINVAL;
1598}
1599
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001600static const struct ethtool_ops i40e_ethtool_ops = {
1601 .get_settings = i40e_get_settings,
1602 .get_drvinfo = i40e_get_drvinfo,
1603 .get_regs_len = i40e_get_regs_len,
1604 .get_regs = i40e_get_regs,
1605 .nway_reset = i40e_nway_reset,
1606 .get_link = ethtool_op_get_link,
1607 .get_wol = i40e_get_wol,
Shannon Nelson8e2773a2013-11-28 06:39:22 +00001608 .set_wol = i40e_set_wol,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001609 .get_eeprom_len = i40e_get_eeprom_len,
1610 .get_eeprom = i40e_get_eeprom,
1611 .get_ringparam = i40e_get_ringparam,
1612 .set_ringparam = i40e_set_ringparam,
1613 .get_pauseparam = i40e_get_pauseparam,
1614 .get_msglevel = i40e_get_msglevel,
1615 .set_msglevel = i40e_set_msglevel,
1616 .get_rxnfc = i40e_get_rxnfc,
1617 .set_rxnfc = i40e_set_rxnfc,
1618 .self_test = i40e_diag_test,
1619 .get_strings = i40e_get_strings,
1620 .set_phys_id = i40e_set_phys_id,
1621 .get_sset_count = i40e_get_sset_count,
1622 .get_ethtool_stats = i40e_get_ethtool_stats,
1623 .get_coalesce = i40e_get_coalesce,
1624 .set_coalesce = i40e_set_coalesce,
Anjali Singhai Jain4b7820c2013-11-26 11:59:30 +00001625 .get_channels = i40e_get_channels,
1626 .set_channels = i40e_set_channels,
Jesse Brandeburgc7d05ca2013-09-11 08:39:56 +00001627 .get_ts_info = i40e_get_ts_info,
1628};
1629
1630void i40e_set_ethtool_ops(struct net_device *netdev)
1631{
1632 SET_ETHTOOL_OPS(netdev, &i40e_ethtool_ops);
1633}