blob: 2ac98d44c1e1addf555c71e8369a0dba30af77ec [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 Mintzfc48b7a2016-02-15 13:22:35 -0500242 if (!edev->dev_info.common.is_mf_default) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200243 DP_INFO(edev,
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500244 "Link parameters can not be changed in non-default mode\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
353 if (!netif_running(dev))
354 return 0;
355
356 memset(&current_link, 0, sizeof(current_link));
357 edev->ops->common->get_link(edev->cdev, &current_link);
358 if (!current_link.link_up)
359 return 0;
360
361 /* Toggle the link */
362 memset(&link_params, 0, sizeof(link_params));
363 link_params.link_up = false;
364 edev->ops->common->set_link(edev->cdev, &link_params);
365 link_params.link_up = true;
366 edev->ops->common->set_link(edev->cdev, &link_params);
367
368 return 0;
369}
370
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200371static u32 qede_get_link(struct net_device *dev)
372{
373 struct qede_dev *edev = netdev_priv(dev);
374 struct qed_link_output current_link;
375
376 memset(&current_link, 0, sizeof(current_link));
377 edev->ops->common->get_link(edev->cdev, &current_link);
378
379 return current_link.link_up;
380}
381
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200382static void qede_get_ringparam(struct net_device *dev,
383 struct ethtool_ringparam *ering)
384{
385 struct qede_dev *edev = netdev_priv(dev);
386
387 ering->rx_max_pending = NUM_RX_BDS_MAX;
388 ering->rx_pending = edev->q_num_rx_buffers;
389 ering->tx_max_pending = NUM_TX_BDS_MAX;
390 ering->tx_pending = edev->q_num_tx_buffers;
391}
392
393static int qede_set_ringparam(struct net_device *dev,
394 struct ethtool_ringparam *ering)
395{
396 struct qede_dev *edev = netdev_priv(dev);
397
398 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
399 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
400 ering->rx_pending, ering->tx_pending);
401
402 /* Validate legality of configuration */
403 if (ering->rx_pending > NUM_RX_BDS_MAX ||
404 ering->rx_pending < NUM_RX_BDS_MIN ||
405 ering->tx_pending > NUM_TX_BDS_MAX ||
406 ering->tx_pending < NUM_TX_BDS_MIN) {
407 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
408 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
409 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
410 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
411 return -EINVAL;
412 }
413
414 /* Change ring size and re-load */
415 edev->q_num_rx_buffers = ering->rx_pending;
416 edev->q_num_tx_buffers = ering->tx_pending;
417
418 if (netif_running(edev->ndev))
419 qede_reload(edev, NULL, NULL);
420
421 return 0;
422}
423
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200424static void qede_get_pauseparam(struct net_device *dev,
425 struct ethtool_pauseparam *epause)
426{
427 struct qede_dev *edev = netdev_priv(dev);
428 struct qed_link_output current_link;
429
430 memset(&current_link, 0, sizeof(current_link));
431 edev->ops->common->get_link(edev->cdev, &current_link);
432
433 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
434 epause->autoneg = true;
435 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
436 epause->rx_pause = true;
437 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
438 epause->tx_pause = true;
439
440 DP_VERBOSE(edev, QED_MSG_DEBUG,
441 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
442 epause->cmd, epause->autoneg, epause->rx_pause,
443 epause->tx_pause);
444}
445
446static int qede_set_pauseparam(struct net_device *dev,
447 struct ethtool_pauseparam *epause)
448{
449 struct qede_dev *edev = netdev_priv(dev);
450 struct qed_link_params params;
451 struct qed_link_output current_link;
452
Yuval Mintzfc48b7a2016-02-15 13:22:35 -0500453 if (!edev->dev_info.common.is_mf_default) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200454 DP_INFO(edev,
455 "Pause parameters can not be updated in non-default mode\n");
456 return -EOPNOTSUPP;
457 }
458
459 memset(&current_link, 0, sizeof(current_link));
460 edev->ops->common->get_link(edev->cdev, &current_link);
461
462 memset(&params, 0, sizeof(params));
463 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
464 if (epause->autoneg) {
465 if (!(current_link.supported_caps & SUPPORTED_Autoneg)) {
466 DP_INFO(edev, "autoneg not supported\n");
467 return -EINVAL;
468 }
469 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
470 }
471 if (epause->rx_pause)
472 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
473 if (epause->tx_pause)
474 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
475
476 params.link_up = true;
477 edev->ops->common->set_link(edev->cdev, &params);
478
479 return 0;
480}
481
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200482static void qede_update_mtu(struct qede_dev *edev, union qede_reload_args *args)
483{
484 edev->ndev->mtu = args->mtu;
485}
486
487/* Netdevice NDOs */
488#define ETH_MAX_JUMBO_PACKET_SIZE 9600
489#define ETH_MIN_PACKET_SIZE 60
490int qede_change_mtu(struct net_device *ndev, int new_mtu)
491{
492 struct qede_dev *edev = netdev_priv(ndev);
493 union qede_reload_args args;
494
495 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
496 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) {
497 DP_ERR(edev, "Can't support requested MTU size\n");
498 return -EINVAL;
499 }
500
501 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
502 "Configuring MTU size of %d\n", new_mtu);
503
504 /* Set the mtu field and re-start the interface if needed*/
505 args.mtu = new_mtu;
506
507 if (netif_running(edev->ndev))
508 qede_reload(edev, &qede_update_mtu, &args);
509
510 qede_update_mtu(edev, &args);
511
512 return 0;
513}
514
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200515static void qede_get_channels(struct net_device *dev,
516 struct ethtool_channels *channels)
517{
518 struct qede_dev *edev = netdev_priv(dev);
519
520 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
521 channels->combined_count = QEDE_RSS_CNT(edev);
522}
523
524static int qede_set_channels(struct net_device *dev,
525 struct ethtool_channels *channels)
526{
527 struct qede_dev *edev = netdev_priv(dev);
528
529 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
530 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
531 channels->rx_count, channels->tx_count,
532 channels->other_count, channels->combined_count);
533
534 /* We don't support separate rx / tx, nor `other' channels. */
535 if (channels->rx_count || channels->tx_count ||
536 channels->other_count || (channels->combined_count == 0) ||
537 (channels->combined_count > QEDE_MAX_RSS_CNT(edev))) {
538 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
539 "command parameters not supported\n");
540 return -EINVAL;
541 }
542
543 /* Check if there was a change in the active parameters */
544 if (channels->combined_count == QEDE_RSS_CNT(edev)) {
545 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
546 "No change in active parameters\n");
547 return 0;
548 }
549
550 /* We need the number of queues to be divisible between the hwfns */
551 if (channels->combined_count % edev->dev_info.common.num_hwfns) {
552 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
553 "Number of channels must be divisable by %04x\n",
554 edev->dev_info.common.num_hwfns);
555 return -EINVAL;
556 }
557
558 /* Set number of queues and reload if necessary */
559 edev->req_rss = channels->combined_count;
560 if (netif_running(dev))
561 qede_reload(edev, NULL, NULL);
562
563 return 0;
564}
565
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200566static int qede_set_phys_id(struct net_device *dev,
567 enum ethtool_phys_id_state state)
568{
569 struct qede_dev *edev = netdev_priv(dev);
570 u8 led_state = 0;
571
572 switch (state) {
573 case ETHTOOL_ID_ACTIVE:
574 return 1; /* cycle on/off once per second */
575
576 case ETHTOOL_ID_ON:
577 led_state = QED_LED_MODE_ON;
578 break;
579
580 case ETHTOOL_ID_OFF:
581 led_state = QED_LED_MODE_OFF;
582 break;
583
584 case ETHTOOL_ID_INACTIVE:
585 led_state = QED_LED_MODE_RESTORE;
586 break;
587 }
588
589 edev->ops->common->set_led(edev->cdev, led_state);
590
591 return 0;
592}
593
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300594static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
595{
596 info->data = RXH_IP_SRC | RXH_IP_DST;
597
598 switch (info->flow_type) {
599 case TCP_V4_FLOW:
600 case TCP_V6_FLOW:
601 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
602 break;
603 case UDP_V4_FLOW:
604 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
605 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
606 break;
607 case UDP_V6_FLOW:
608 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
609 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
610 break;
611 case IPV4_FLOW:
612 case IPV6_FLOW:
613 break;
614 default:
615 info->data = 0;
616 break;
617 }
618
619 return 0;
620}
621
622static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
623 u32 *rules __always_unused)
624{
625 struct qede_dev *edev = netdev_priv(dev);
626
627 switch (info->cmd) {
628 case ETHTOOL_GRXRINGS:
629 info->data = edev->num_rss;
630 return 0;
631 case ETHTOOL_GRXFH:
632 return qede_get_rss_flags(edev, info);
633 default:
634 DP_ERR(edev, "Command parameters not supported\n");
635 return -EOPNOTSUPP;
636 }
637}
638
639static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
640{
641 struct qed_update_vport_params vport_update_params;
642 u8 set_caps = 0, clr_caps = 0;
643
644 DP_VERBOSE(edev, QED_MSG_DEBUG,
645 "Set rss flags command parameters: flow type = %d, data = %llu\n",
646 info->flow_type, info->data);
647
648 switch (info->flow_type) {
649 case TCP_V4_FLOW:
650 case TCP_V6_FLOW:
651 /* For TCP only 4-tuple hash is supported */
652 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
653 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
654 DP_INFO(edev, "Command parameters not supported\n");
655 return -EINVAL;
656 }
657 return 0;
658 case UDP_V4_FLOW:
659 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
660 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
661 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
662 set_caps = QED_RSS_IPV4_UDP;
663 DP_VERBOSE(edev, QED_MSG_DEBUG,
664 "UDP 4-tuple enabled\n");
665 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
666 clr_caps = QED_RSS_IPV4_UDP;
667 DP_VERBOSE(edev, QED_MSG_DEBUG,
668 "UDP 4-tuple disabled\n");
669 } else {
670 return -EINVAL;
671 }
672 break;
673 case UDP_V6_FLOW:
674 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
675 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
676 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
677 set_caps = QED_RSS_IPV6_UDP;
678 DP_VERBOSE(edev, QED_MSG_DEBUG,
679 "UDP 4-tuple enabled\n");
680 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
681 clr_caps = QED_RSS_IPV6_UDP;
682 DP_VERBOSE(edev, QED_MSG_DEBUG,
683 "UDP 4-tuple disabled\n");
684 } else {
685 return -EINVAL;
686 }
687 break;
688 case IPV4_FLOW:
689 case IPV6_FLOW:
690 /* For IP only 2-tuple hash is supported */
691 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
692 DP_INFO(edev, "Command parameters not supported\n");
693 return -EINVAL;
694 }
695 return 0;
696 case SCTP_V4_FLOW:
697 case AH_ESP_V4_FLOW:
698 case AH_V4_FLOW:
699 case ESP_V4_FLOW:
700 case SCTP_V6_FLOW:
701 case AH_ESP_V6_FLOW:
702 case AH_V6_FLOW:
703 case ESP_V6_FLOW:
704 case IP_USER_FLOW:
705 case ETHER_FLOW:
706 /* RSS is not supported for these protocols */
707 if (info->data) {
708 DP_INFO(edev, "Command parameters not supported\n");
709 return -EINVAL;
710 }
711 return 0;
712 default:
713 return -EINVAL;
714 }
715
716 /* No action is needed if there is no change in the rss capability */
717 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
718 ~clr_caps) | set_caps))
719 return 0;
720
721 /* Update internal configuration */
722 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
723 set_caps;
724 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
725
726 /* Re-configure if possible */
727 if (netif_running(edev->ndev)) {
728 memset(&vport_update_params, 0, sizeof(vport_update_params));
729 vport_update_params.update_rss_flg = 1;
730 vport_update_params.vport_id = 0;
731 memcpy(&vport_update_params.rss_params, &edev->rss_params,
732 sizeof(vport_update_params.rss_params));
733 return edev->ops->vport_update(edev->cdev,
734 &vport_update_params);
735 }
736
737 return 0;
738}
739
740static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
741{
742 struct qede_dev *edev = netdev_priv(dev);
743
744 switch (info->cmd) {
745 case ETHTOOL_SRXFH:
746 return qede_set_rss_flags(edev, info);
747 default:
748 DP_INFO(edev, "Command parameters not supported\n");
749 return -EOPNOTSUPP;
750 }
751}
752
753static u32 qede_get_rxfh_indir_size(struct net_device *dev)
754{
755 return QED_RSS_IND_TABLE_SIZE;
756}
757
758static u32 qede_get_rxfh_key_size(struct net_device *dev)
759{
760 struct qede_dev *edev = netdev_priv(dev);
761
762 return sizeof(edev->rss_params.rss_key);
763}
764
765static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
766{
767 struct qede_dev *edev = netdev_priv(dev);
768 int i;
769
770 if (hfunc)
771 *hfunc = ETH_RSS_HASH_TOP;
772
773 if (!indir)
774 return 0;
775
776 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
777 indir[i] = edev->rss_params.rss_ind_table[i];
778
779 if (key)
780 memcpy(key, edev->rss_params.rss_key,
781 qede_get_rxfh_key_size(dev));
782
783 return 0;
784}
785
786static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
787 const u8 *key, const u8 hfunc)
788{
789 struct qed_update_vport_params vport_update_params;
790 struct qede_dev *edev = netdev_priv(dev);
791 int i;
792
793 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
794 return -EOPNOTSUPP;
795
796 if (!indir && !key)
797 return 0;
798
799 if (indir) {
800 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
801 edev->rss_params.rss_ind_table[i] = indir[i];
802 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
803 }
804
805 if (key) {
806 memcpy(&edev->rss_params.rss_key, key,
807 qede_get_rxfh_key_size(dev));
808 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
809 }
810
811 if (netif_running(edev->ndev)) {
812 memset(&vport_update_params, 0, sizeof(vport_update_params));
813 vport_update_params.update_rss_flg = 1;
814 vport_update_params.vport_id = 0;
815 memcpy(&vport_update_params.rss_params, &edev->rss_params,
816 sizeof(vport_update_params.rss_params));
817 return edev->ops->vport_update(edev->cdev,
818 &vport_update_params);
819 }
820
821 return 0;
822}
823
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200824static const struct ethtool_ops qede_ethtool_ops = {
825 .get_settings = qede_get_settings,
826 .set_settings = qede_set_settings,
827 .get_drvinfo = qede_get_drvinfo,
828 .get_msglevel = qede_get_msglevel,
829 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200830 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200831 .get_link = qede_get_link,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200832 .get_ringparam = qede_get_ringparam,
833 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200834 .get_pauseparam = qede_get_pauseparam,
835 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200836 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200837 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200838 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +0300839 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200840 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300841 .get_rxnfc = qede_get_rxnfc,
842 .set_rxnfc = qede_set_rxnfc,
843 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
844 .get_rxfh_key_size = qede_get_rxfh_key_size,
845 .get_rxfh = qede_get_rxfh,
846 .set_rxfh = qede_set_rxfh,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200847 .get_channels = qede_get_channels,
848 .set_channels = qede_set_channels,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200849};
850
851void qede_set_ethtool_ops(struct net_device *dev)
852{
853 dev->ethtool_ops = &qede_ethtool_ops;
854}