blob: f1dd25ac555207769d1492fc4d3e4be4d6a06159 [file] [log] [blame]
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001/* QLogic qede NIC Driver
2* Copyright (c) 2015 QLogic Corporation
3*
4* This software is available under the terms of the GNU General Public License
5* (GPL) Version 2, available from the file COPYING in the main directory of
6* this source tree.
7*/
8
9#include <linux/version.h>
10#include <linux/types.h>
11#include <linux/netdevice.h>
12#include <linux/ethtool.h>
13#include <linux/string.h>
14#include <linux/pci.h>
15#include <linux/capability.h>
16#include "qede.h"
17
18#define QEDE_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
19#define QEDE_STAT_STRING(stat_name) (#stat_name)
20#define _QEDE_STAT(stat_name, pf_only) \
21 {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
22#define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
23#define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
24
25#define QEDE_RQSTAT_OFFSET(stat_name) \
26 (offsetof(struct qede_rx_queue, stat_name))
27#define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
28#define QEDE_RQSTAT(stat_name) \
29 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
30static const struct {
31 u64 offset;
32 char string[ETH_GSTRING_LEN];
33} qede_rqstats_arr[] = {
34 QEDE_RQSTAT(rx_hw_errors),
35 QEDE_RQSTAT(rx_alloc_errors),
36};
37
38#define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
39#define QEDE_RQSTATS_DATA(dev, sindex, rqindex) \
40 (*((u64 *)(((char *)(dev->fp_array[(rqindex)].rxq)) +\
41 qede_rqstats_arr[(sindex)].offset)))
42static const struct {
43 u64 offset;
44 char string[ETH_GSTRING_LEN];
45 bool pf_only;
46} qede_stats_arr[] = {
47 QEDE_STAT(rx_ucast_bytes),
48 QEDE_STAT(rx_mcast_bytes),
49 QEDE_STAT(rx_bcast_bytes),
50 QEDE_STAT(rx_ucast_pkts),
51 QEDE_STAT(rx_mcast_pkts),
52 QEDE_STAT(rx_bcast_pkts),
53
54 QEDE_STAT(tx_ucast_bytes),
55 QEDE_STAT(tx_mcast_bytes),
56 QEDE_STAT(tx_bcast_bytes),
57 QEDE_STAT(tx_ucast_pkts),
58 QEDE_STAT(tx_mcast_pkts),
59 QEDE_STAT(tx_bcast_pkts),
60
61 QEDE_PF_STAT(rx_64_byte_packets),
Yuval Mintzd4967cf2016-04-22 08:41:01 +030062 QEDE_PF_STAT(rx_65_to_127_byte_packets),
63 QEDE_PF_STAT(rx_128_to_255_byte_packets),
64 QEDE_PF_STAT(rx_256_to_511_byte_packets),
65 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
66 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
67 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
68 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
69 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
70 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
71 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020072 QEDE_PF_STAT(tx_64_byte_packets),
73 QEDE_PF_STAT(tx_65_to_127_byte_packets),
74 QEDE_PF_STAT(tx_128_to_255_byte_packets),
75 QEDE_PF_STAT(tx_256_to_511_byte_packets),
76 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
77 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
78 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
79 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
80 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
81 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
82
83 QEDE_PF_STAT(rx_mac_crtl_frames),
84 QEDE_PF_STAT(tx_mac_ctrl_frames),
85 QEDE_PF_STAT(rx_pause_frames),
86 QEDE_PF_STAT(tx_pause_frames),
87 QEDE_PF_STAT(rx_pfc_frames),
88 QEDE_PF_STAT(tx_pfc_frames),
89
90 QEDE_PF_STAT(rx_crc_errors),
91 QEDE_PF_STAT(rx_align_errors),
92 QEDE_PF_STAT(rx_carrier_errors),
93 QEDE_PF_STAT(rx_oversize_packets),
94 QEDE_PF_STAT(rx_jabbers),
95 QEDE_PF_STAT(rx_undersize_packets),
96 QEDE_PF_STAT(rx_fragments),
97 QEDE_PF_STAT(tx_lpi_entry_count),
98 QEDE_PF_STAT(tx_total_collisions),
99 QEDE_PF_STAT(brb_truncates),
100 QEDE_PF_STAT(brb_discards),
101 QEDE_STAT(no_buff_discards),
102 QEDE_PF_STAT(mftag_filter_discards),
103 QEDE_PF_STAT(mac_filter_discards),
104 QEDE_STAT(tx_err_drop_pkts),
105
106 QEDE_STAT(coalesced_pkts),
107 QEDE_STAT(coalesced_events),
108 QEDE_STAT(coalesced_aborts_num),
109 QEDE_STAT(non_coalesced_pkts),
110 QEDE_STAT(coalesced_bytes),
111};
112
113#define QEDE_STATS_DATA(dev, index) \
114 (*((u64 *)(((char *)(dev)) + offsetof(struct qede_dev, stats) \
115 + qede_stats_arr[(index)].offset)))
116
117#define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
118
Yuval Mintzf3e72102016-04-22 08:41:02 +0300119enum {
120 QEDE_PRI_FLAG_CMT,
121 QEDE_PRI_FLAG_LEN,
122};
123
124static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
125 "Coupled-Function",
126};
127
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200128static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
129{
130 int i, j, k;
131
132 for (i = 0, j = 0; i < QEDE_NUM_STATS; i++) {
133 strcpy(buf + j * ETH_GSTRING_LEN,
134 qede_stats_arr[i].string);
135 j++;
136 }
137
138 for (k = 0; k < QEDE_NUM_RQSTATS; k++, j++)
139 strcpy(buf + j * ETH_GSTRING_LEN,
140 qede_rqstats_arr[k].string);
141}
142
143static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
144{
145 struct qede_dev *edev = netdev_priv(dev);
146
147 switch (stringset) {
148 case ETH_SS_STATS:
149 qede_get_strings_stats(edev, buf);
150 break;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300151 case ETH_SS_PRIV_FLAGS:
152 memcpy(buf, qede_private_arr,
153 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
154 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200155 default:
156 DP_VERBOSE(edev, QED_MSG_DEBUG,
157 "Unsupported stringset 0x%08x\n", stringset);
158 }
159}
160
161static void qede_get_ethtool_stats(struct net_device *dev,
162 struct ethtool_stats *stats, u64 *buf)
163{
164 struct qede_dev *edev = netdev_priv(dev);
165 int sidx, cnt = 0;
166 int qid;
167
168 qede_fill_by_demand_stats(edev);
169
170 mutex_lock(&edev->qede_lock);
171
172 for (sidx = 0; sidx < QEDE_NUM_STATS; sidx++)
173 buf[cnt++] = QEDE_STATS_DATA(edev, sidx);
174
175 for (sidx = 0; sidx < QEDE_NUM_RQSTATS; sidx++) {
176 buf[cnt] = 0;
177 for (qid = 0; qid < edev->num_rss; qid++)
178 buf[cnt] += QEDE_RQSTATS_DATA(edev, sidx, qid);
179 cnt++;
180 }
181
182 mutex_unlock(&edev->qede_lock);
183}
184
185static int qede_get_sset_count(struct net_device *dev, int stringset)
186{
187 struct qede_dev *edev = netdev_priv(dev);
188 int num_stats = QEDE_NUM_STATS;
189
190 switch (stringset) {
191 case ETH_SS_STATS:
192 return num_stats + QEDE_NUM_RQSTATS;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300193 case ETH_SS_PRIV_FLAGS:
194 return QEDE_PRI_FLAG_LEN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200195
196 default:
197 DP_VERBOSE(edev, QED_MSG_DEBUG,
198 "Unsupported stringset 0x%08x\n", stringset);
199 return -EINVAL;
200 }
201}
202
Yuval Mintzf3e72102016-04-22 08:41:02 +0300203static u32 qede_get_priv_flags(struct net_device *dev)
204{
205 struct qede_dev *edev = netdev_priv(dev);
206
207 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
208}
209
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200210static int qede_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
211{
212 struct qede_dev *edev = netdev_priv(dev);
213 struct qed_link_output current_link;
214
215 memset(&current_link, 0, sizeof(current_link));
216 edev->ops->common->get_link(edev->cdev, &current_link);
217
218 cmd->supported = current_link.supported_caps;
219 cmd->advertising = current_link.advertised_caps;
220 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
221 ethtool_cmd_speed_set(cmd, current_link.speed);
222 cmd->duplex = current_link.duplex;
223 } else {
224 cmd->duplex = DUPLEX_UNKNOWN;
225 ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
226 }
227 cmd->port = current_link.port;
228 cmd->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
229 AUTONEG_DISABLE;
230 cmd->lp_advertising = current_link.lp_caps;
231
232 return 0;
233}
234
235static int qede_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
236{
237 struct qede_dev *edev = netdev_priv(dev);
238 struct qed_link_output current_link;
239 struct qed_link_params params;
240 u32 speed;
241
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300242 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200243 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300244 "Link settings are not allowed to be changed\n");
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200245 return -EOPNOTSUPP;
246 }
247
248 memset(&current_link, 0, sizeof(current_link));
249 memset(&params, 0, sizeof(params));
250 edev->ops->common->get_link(edev->cdev, &current_link);
251
252 speed = ethtool_cmd_speed(cmd);
253 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
254 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
255 if (cmd->autoneg == AUTONEG_ENABLE) {
256 params.autoneg = true;
257 params.forced_speed = 0;
258 params.adv_speeds = cmd->advertising;
259 } else { /* forced speed */
260 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
261 params.autoneg = false;
262 params.forced_speed = speed;
263 switch (speed) {
264 case SPEED_10000:
265 if (!(current_link.supported_caps &
266 SUPPORTED_10000baseKR_Full)) {
267 DP_INFO(edev, "10G speed not supported\n");
268 return -EINVAL;
269 }
270 params.adv_speeds = SUPPORTED_10000baseKR_Full;
271 break;
272 case SPEED_40000:
273 if (!(current_link.supported_caps &
274 SUPPORTED_40000baseLR4_Full)) {
275 DP_INFO(edev, "40G speed not supported\n");
276 return -EINVAL;
277 }
278 params.adv_speeds = SUPPORTED_40000baseLR4_Full;
279 break;
280 default:
281 DP_INFO(edev, "Unsupported speed %u\n", speed);
282 return -EINVAL;
283 }
284 }
285
286 params.link_up = true;
287 edev->ops->common->set_link(edev->cdev, &params);
288
289 return 0;
290}
291
292static void qede_get_drvinfo(struct net_device *ndev,
293 struct ethtool_drvinfo *info)
294{
295 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
296 struct qede_dev *edev = netdev_priv(ndev);
297
298 strlcpy(info->driver, "qede", sizeof(info->driver));
299 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
300
301 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
302 edev->dev_info.common.fw_major,
303 edev->dev_info.common.fw_minor,
304 edev->dev_info.common.fw_rev,
305 edev->dev_info.common.fw_eng);
306
307 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
308 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
309 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
310 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
311 edev->dev_info.common.mfw_rev & 0xFF);
312
313 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
314 sizeof(info->fw_version)) {
315 snprintf(info->fw_version, sizeof(info->fw_version),
316 "mfw %s storm %s", mfw, storm);
317 } else {
318 snprintf(info->fw_version, sizeof(info->fw_version),
319 "%s %s", mfw, storm);
320 }
321
322 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
323}
324
325static u32 qede_get_msglevel(struct net_device *ndev)
326{
327 struct qede_dev *edev = netdev_priv(ndev);
328
329 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) |
330 edev->dp_module;
331}
332
333static void qede_set_msglevel(struct net_device *ndev, u32 level)
334{
335 struct qede_dev *edev = netdev_priv(ndev);
336 u32 dp_module = 0;
337 u8 dp_level = 0;
338
339 qede_config_debug(level, &dp_module, &dp_level);
340
341 edev->dp_level = dp_level;
342 edev->dp_module = dp_module;
343 edev->ops->common->update_msglvl(edev->cdev,
344 dp_module, dp_level);
345}
346
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200347static int qede_nway_reset(struct net_device *dev)
348{
349 struct qede_dev *edev = netdev_priv(dev);
350 struct qed_link_output current_link;
351 struct qed_link_params link_params;
352
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300353 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
354 DP_INFO(edev,
355 "Link settings are not allowed to be changed\n");
356 return -EOPNOTSUPP;
357 }
358
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200359 if (!netif_running(dev))
360 return 0;
361
362 memset(&current_link, 0, sizeof(current_link));
363 edev->ops->common->get_link(edev->cdev, &current_link);
364 if (!current_link.link_up)
365 return 0;
366
367 /* Toggle the link */
368 memset(&link_params, 0, sizeof(link_params));
369 link_params.link_up = false;
370 edev->ops->common->set_link(edev->cdev, &link_params);
371 link_params.link_up = true;
372 edev->ops->common->set_link(edev->cdev, &link_params);
373
374 return 0;
375}
376
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200377static u32 qede_get_link(struct net_device *dev)
378{
379 struct qede_dev *edev = netdev_priv(dev);
380 struct qed_link_output current_link;
381
382 memset(&current_link, 0, sizeof(current_link));
383 edev->ops->common->get_link(edev->cdev, &current_link);
384
385 return current_link.link_up;
386}
387
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200388static void qede_get_ringparam(struct net_device *dev,
389 struct ethtool_ringparam *ering)
390{
391 struct qede_dev *edev = netdev_priv(dev);
392
393 ering->rx_max_pending = NUM_RX_BDS_MAX;
394 ering->rx_pending = edev->q_num_rx_buffers;
395 ering->tx_max_pending = NUM_TX_BDS_MAX;
396 ering->tx_pending = edev->q_num_tx_buffers;
397}
398
399static int qede_set_ringparam(struct net_device *dev,
400 struct ethtool_ringparam *ering)
401{
402 struct qede_dev *edev = netdev_priv(dev);
403
404 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
405 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
406 ering->rx_pending, ering->tx_pending);
407
408 /* Validate legality of configuration */
409 if (ering->rx_pending > NUM_RX_BDS_MAX ||
410 ering->rx_pending < NUM_RX_BDS_MIN ||
411 ering->tx_pending > NUM_TX_BDS_MAX ||
412 ering->tx_pending < NUM_TX_BDS_MIN) {
413 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
414 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
415 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
416 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
417 return -EINVAL;
418 }
419
420 /* Change ring size and re-load */
421 edev->q_num_rx_buffers = ering->rx_pending;
422 edev->q_num_tx_buffers = ering->tx_pending;
423
424 if (netif_running(edev->ndev))
425 qede_reload(edev, NULL, NULL);
426
427 return 0;
428}
429
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200430static void qede_get_pauseparam(struct net_device *dev,
431 struct ethtool_pauseparam *epause)
432{
433 struct qede_dev *edev = netdev_priv(dev);
434 struct qed_link_output current_link;
435
436 memset(&current_link, 0, sizeof(current_link));
437 edev->ops->common->get_link(edev->cdev, &current_link);
438
439 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
440 epause->autoneg = true;
441 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
442 epause->rx_pause = true;
443 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
444 epause->tx_pause = true;
445
446 DP_VERBOSE(edev, QED_MSG_DEBUG,
447 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
448 epause->cmd, epause->autoneg, epause->rx_pause,
449 epause->tx_pause);
450}
451
452static int qede_set_pauseparam(struct net_device *dev,
453 struct ethtool_pauseparam *epause)
454{
455 struct qede_dev *edev = netdev_priv(dev);
456 struct qed_link_params params;
457 struct qed_link_output current_link;
458
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300459 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200460 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300461 "Pause settings are not allowed to be changed\n");
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200462 return -EOPNOTSUPP;
463 }
464
465 memset(&current_link, 0, sizeof(current_link));
466 edev->ops->common->get_link(edev->cdev, &current_link);
467
468 memset(&params, 0, sizeof(params));
469 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
470 if (epause->autoneg) {
471 if (!(current_link.supported_caps & SUPPORTED_Autoneg)) {
472 DP_INFO(edev, "autoneg not supported\n");
473 return -EINVAL;
474 }
475 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
476 }
477 if (epause->rx_pause)
478 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
479 if (epause->tx_pause)
480 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
481
482 params.link_up = true;
483 edev->ops->common->set_link(edev->cdev, &params);
484
485 return 0;
486}
487
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200488static void qede_update_mtu(struct qede_dev *edev, union qede_reload_args *args)
489{
490 edev->ndev->mtu = args->mtu;
491}
492
493/* Netdevice NDOs */
494#define ETH_MAX_JUMBO_PACKET_SIZE 9600
495#define ETH_MIN_PACKET_SIZE 60
496int qede_change_mtu(struct net_device *ndev, int new_mtu)
497{
498 struct qede_dev *edev = netdev_priv(ndev);
499 union qede_reload_args args;
500
501 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
502 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) {
503 DP_ERR(edev, "Can't support requested MTU size\n");
504 return -EINVAL;
505 }
506
507 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
508 "Configuring MTU size of %d\n", new_mtu);
509
510 /* Set the mtu field and re-start the interface if needed*/
511 args.mtu = new_mtu;
512
513 if (netif_running(edev->ndev))
514 qede_reload(edev, &qede_update_mtu, &args);
515
516 qede_update_mtu(edev, &args);
517
518 return 0;
519}
520
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200521static void qede_get_channels(struct net_device *dev,
522 struct ethtool_channels *channels)
523{
524 struct qede_dev *edev = netdev_priv(dev);
525
526 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
527 channels->combined_count = QEDE_RSS_CNT(edev);
528}
529
530static int qede_set_channels(struct net_device *dev,
531 struct ethtool_channels *channels)
532{
533 struct qede_dev *edev = netdev_priv(dev);
534
535 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
536 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
537 channels->rx_count, channels->tx_count,
538 channels->other_count, channels->combined_count);
539
540 /* We don't support separate rx / tx, nor `other' channels. */
541 if (channels->rx_count || channels->tx_count ||
542 channels->other_count || (channels->combined_count == 0) ||
543 (channels->combined_count > QEDE_MAX_RSS_CNT(edev))) {
544 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
545 "command parameters not supported\n");
546 return -EINVAL;
547 }
548
549 /* Check if there was a change in the active parameters */
550 if (channels->combined_count == QEDE_RSS_CNT(edev)) {
551 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
552 "No change in active parameters\n");
553 return 0;
554 }
555
556 /* We need the number of queues to be divisible between the hwfns */
557 if (channels->combined_count % edev->dev_info.common.num_hwfns) {
558 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
559 "Number of channels must be divisable by %04x\n",
560 edev->dev_info.common.num_hwfns);
561 return -EINVAL;
562 }
563
564 /* Set number of queues and reload if necessary */
565 edev->req_rss = channels->combined_count;
566 if (netif_running(dev))
567 qede_reload(edev, NULL, NULL);
568
569 return 0;
570}
571
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200572static int qede_set_phys_id(struct net_device *dev,
573 enum ethtool_phys_id_state state)
574{
575 struct qede_dev *edev = netdev_priv(dev);
576 u8 led_state = 0;
577
578 switch (state) {
579 case ETHTOOL_ID_ACTIVE:
580 return 1; /* cycle on/off once per second */
581
582 case ETHTOOL_ID_ON:
583 led_state = QED_LED_MODE_ON;
584 break;
585
586 case ETHTOOL_ID_OFF:
587 led_state = QED_LED_MODE_OFF;
588 break;
589
590 case ETHTOOL_ID_INACTIVE:
591 led_state = QED_LED_MODE_RESTORE;
592 break;
593 }
594
595 edev->ops->common->set_led(edev->cdev, led_state);
596
597 return 0;
598}
599
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300600static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
601{
602 info->data = RXH_IP_SRC | RXH_IP_DST;
603
604 switch (info->flow_type) {
605 case TCP_V4_FLOW:
606 case TCP_V6_FLOW:
607 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
608 break;
609 case UDP_V4_FLOW:
610 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
611 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
612 break;
613 case UDP_V6_FLOW:
614 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
615 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
616 break;
617 case IPV4_FLOW:
618 case IPV6_FLOW:
619 break;
620 default:
621 info->data = 0;
622 break;
623 }
624
625 return 0;
626}
627
628static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
629 u32 *rules __always_unused)
630{
631 struct qede_dev *edev = netdev_priv(dev);
632
633 switch (info->cmd) {
634 case ETHTOOL_GRXRINGS:
635 info->data = edev->num_rss;
636 return 0;
637 case ETHTOOL_GRXFH:
638 return qede_get_rss_flags(edev, info);
639 default:
640 DP_ERR(edev, "Command parameters not supported\n");
641 return -EOPNOTSUPP;
642 }
643}
644
645static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
646{
647 struct qed_update_vport_params vport_update_params;
648 u8 set_caps = 0, clr_caps = 0;
649
650 DP_VERBOSE(edev, QED_MSG_DEBUG,
651 "Set rss flags command parameters: flow type = %d, data = %llu\n",
652 info->flow_type, info->data);
653
654 switch (info->flow_type) {
655 case TCP_V4_FLOW:
656 case TCP_V6_FLOW:
657 /* For TCP only 4-tuple hash is supported */
658 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
659 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
660 DP_INFO(edev, "Command parameters not supported\n");
661 return -EINVAL;
662 }
663 return 0;
664 case UDP_V4_FLOW:
665 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
666 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
667 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
668 set_caps = QED_RSS_IPV4_UDP;
669 DP_VERBOSE(edev, QED_MSG_DEBUG,
670 "UDP 4-tuple enabled\n");
671 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
672 clr_caps = QED_RSS_IPV4_UDP;
673 DP_VERBOSE(edev, QED_MSG_DEBUG,
674 "UDP 4-tuple disabled\n");
675 } else {
676 return -EINVAL;
677 }
678 break;
679 case UDP_V6_FLOW:
680 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
681 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
682 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
683 set_caps = QED_RSS_IPV6_UDP;
684 DP_VERBOSE(edev, QED_MSG_DEBUG,
685 "UDP 4-tuple enabled\n");
686 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
687 clr_caps = QED_RSS_IPV6_UDP;
688 DP_VERBOSE(edev, QED_MSG_DEBUG,
689 "UDP 4-tuple disabled\n");
690 } else {
691 return -EINVAL;
692 }
693 break;
694 case IPV4_FLOW:
695 case IPV6_FLOW:
696 /* For IP only 2-tuple hash is supported */
697 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
698 DP_INFO(edev, "Command parameters not supported\n");
699 return -EINVAL;
700 }
701 return 0;
702 case SCTP_V4_FLOW:
703 case AH_ESP_V4_FLOW:
704 case AH_V4_FLOW:
705 case ESP_V4_FLOW:
706 case SCTP_V6_FLOW:
707 case AH_ESP_V6_FLOW:
708 case AH_V6_FLOW:
709 case ESP_V6_FLOW:
710 case IP_USER_FLOW:
711 case ETHER_FLOW:
712 /* RSS is not supported for these protocols */
713 if (info->data) {
714 DP_INFO(edev, "Command parameters not supported\n");
715 return -EINVAL;
716 }
717 return 0;
718 default:
719 return -EINVAL;
720 }
721
722 /* No action is needed if there is no change in the rss capability */
723 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
724 ~clr_caps) | set_caps))
725 return 0;
726
727 /* Update internal configuration */
728 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
729 set_caps;
730 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
731
732 /* Re-configure if possible */
733 if (netif_running(edev->ndev)) {
734 memset(&vport_update_params, 0, sizeof(vport_update_params));
735 vport_update_params.update_rss_flg = 1;
736 vport_update_params.vport_id = 0;
737 memcpy(&vport_update_params.rss_params, &edev->rss_params,
738 sizeof(vport_update_params.rss_params));
739 return edev->ops->vport_update(edev->cdev,
740 &vport_update_params);
741 }
742
743 return 0;
744}
745
746static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
747{
748 struct qede_dev *edev = netdev_priv(dev);
749
750 switch (info->cmd) {
751 case ETHTOOL_SRXFH:
752 return qede_set_rss_flags(edev, info);
753 default:
754 DP_INFO(edev, "Command parameters not supported\n");
755 return -EOPNOTSUPP;
756 }
757}
758
759static u32 qede_get_rxfh_indir_size(struct net_device *dev)
760{
761 return QED_RSS_IND_TABLE_SIZE;
762}
763
764static u32 qede_get_rxfh_key_size(struct net_device *dev)
765{
766 struct qede_dev *edev = netdev_priv(dev);
767
768 return sizeof(edev->rss_params.rss_key);
769}
770
771static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
772{
773 struct qede_dev *edev = netdev_priv(dev);
774 int i;
775
776 if (hfunc)
777 *hfunc = ETH_RSS_HASH_TOP;
778
779 if (!indir)
780 return 0;
781
782 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
783 indir[i] = edev->rss_params.rss_ind_table[i];
784
785 if (key)
786 memcpy(key, edev->rss_params.rss_key,
787 qede_get_rxfh_key_size(dev));
788
789 return 0;
790}
791
792static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
793 const u8 *key, const u8 hfunc)
794{
795 struct qed_update_vport_params vport_update_params;
796 struct qede_dev *edev = netdev_priv(dev);
797 int i;
798
799 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
800 return -EOPNOTSUPP;
801
802 if (!indir && !key)
803 return 0;
804
805 if (indir) {
806 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
807 edev->rss_params.rss_ind_table[i] = indir[i];
808 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
809 }
810
811 if (key) {
812 memcpy(&edev->rss_params.rss_key, key,
813 qede_get_rxfh_key_size(dev));
814 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
815 }
816
817 if (netif_running(edev->ndev)) {
818 memset(&vport_update_params, 0, sizeof(vport_update_params));
819 vport_update_params.update_rss_flg = 1;
820 vport_update_params.vport_id = 0;
821 memcpy(&vport_update_params.rss_params, &edev->rss_params,
822 sizeof(vport_update_params.rss_params));
823 return edev->ops->vport_update(edev->cdev,
824 &vport_update_params);
825 }
826
827 return 0;
828}
829
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200830static const struct ethtool_ops qede_ethtool_ops = {
831 .get_settings = qede_get_settings,
832 .set_settings = qede_set_settings,
833 .get_drvinfo = qede_get_drvinfo,
834 .get_msglevel = qede_get_msglevel,
835 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200836 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200837 .get_link = qede_get_link,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200838 .get_ringparam = qede_get_ringparam,
839 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200840 .get_pauseparam = qede_get_pauseparam,
841 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200842 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200843 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200844 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +0300845 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200846 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300847 .get_rxnfc = qede_get_rxnfc,
848 .set_rxnfc = qede_set_rxnfc,
849 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
850 .get_rxfh_key_size = qede_get_rxfh_key_size,
851 .get_rxfh = qede_get_rxfh,
852 .set_rxfh = qede_set_rxfh,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200853 .get_channels = qede_get_channels,
854 .set_channels = qede_set_channels,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200855};
856
857void qede_set_ethtool_ops(struct net_device *dev)
858{
859 dev->ethtool_ops = &qede_ethtool_ops;
860}