blob: e25a05ba02493ddafc8dacc3610d4d2160a6a2c8 [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 Reddy Kalluru3044a022016-04-28 20:20:53 -0400128enum qede_ethtool_tests {
129 QEDE_ETHTOOL_INTERRUPT_TEST,
130 QEDE_ETHTOOL_MEMORY_TEST,
131 QEDE_ETHTOOL_REGISTER_TEST,
132 QEDE_ETHTOOL_CLOCK_TEST,
133 QEDE_ETHTOOL_TEST_MAX
134};
135
136static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
137 "Interrupt (online)\t",
138 "Memory (online)\t\t",
139 "Register (online)\t",
140 "Clock (online)\t\t",
141};
142
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200143static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
144{
145 int i, j, k;
146
147 for (i = 0, j = 0; i < QEDE_NUM_STATS; i++) {
148 strcpy(buf + j * ETH_GSTRING_LEN,
149 qede_stats_arr[i].string);
150 j++;
151 }
152
153 for (k = 0; k < QEDE_NUM_RQSTATS; k++, j++)
154 strcpy(buf + j * ETH_GSTRING_LEN,
155 qede_rqstats_arr[k].string);
156}
157
158static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
159{
160 struct qede_dev *edev = netdev_priv(dev);
161
162 switch (stringset) {
163 case ETH_SS_STATS:
164 qede_get_strings_stats(edev, buf);
165 break;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300166 case ETH_SS_PRIV_FLAGS:
167 memcpy(buf, qede_private_arr,
168 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
169 break;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400170 case ETH_SS_TEST:
171 memcpy(buf, qede_tests_str_arr,
172 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
173 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200174 default:
175 DP_VERBOSE(edev, QED_MSG_DEBUG,
176 "Unsupported stringset 0x%08x\n", stringset);
177 }
178}
179
180static void qede_get_ethtool_stats(struct net_device *dev,
181 struct ethtool_stats *stats, u64 *buf)
182{
183 struct qede_dev *edev = netdev_priv(dev);
184 int sidx, cnt = 0;
185 int qid;
186
187 qede_fill_by_demand_stats(edev);
188
189 mutex_lock(&edev->qede_lock);
190
191 for (sidx = 0; sidx < QEDE_NUM_STATS; sidx++)
192 buf[cnt++] = QEDE_STATS_DATA(edev, sidx);
193
194 for (sidx = 0; sidx < QEDE_NUM_RQSTATS; sidx++) {
195 buf[cnt] = 0;
196 for (qid = 0; qid < edev->num_rss; qid++)
197 buf[cnt] += QEDE_RQSTATS_DATA(edev, sidx, qid);
198 cnt++;
199 }
200
201 mutex_unlock(&edev->qede_lock);
202}
203
204static int qede_get_sset_count(struct net_device *dev, int stringset)
205{
206 struct qede_dev *edev = netdev_priv(dev);
207 int num_stats = QEDE_NUM_STATS;
208
209 switch (stringset) {
210 case ETH_SS_STATS:
211 return num_stats + QEDE_NUM_RQSTATS;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300212 case ETH_SS_PRIV_FLAGS:
213 return QEDE_PRI_FLAG_LEN;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400214 case ETH_SS_TEST:
215 return QEDE_ETHTOOL_TEST_MAX;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200216 default:
217 DP_VERBOSE(edev, QED_MSG_DEBUG,
218 "Unsupported stringset 0x%08x\n", stringset);
219 return -EINVAL;
220 }
221}
222
Yuval Mintzf3e72102016-04-22 08:41:02 +0300223static u32 qede_get_priv_flags(struct net_device *dev)
224{
225 struct qede_dev *edev = netdev_priv(dev);
226
227 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
228}
229
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200230static int qede_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
231{
232 struct qede_dev *edev = netdev_priv(dev);
233 struct qed_link_output current_link;
234
235 memset(&current_link, 0, sizeof(current_link));
236 edev->ops->common->get_link(edev->cdev, &current_link);
237
238 cmd->supported = current_link.supported_caps;
239 cmd->advertising = current_link.advertised_caps;
240 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
241 ethtool_cmd_speed_set(cmd, current_link.speed);
242 cmd->duplex = current_link.duplex;
243 } else {
244 cmd->duplex = DUPLEX_UNKNOWN;
245 ethtool_cmd_speed_set(cmd, SPEED_UNKNOWN);
246 }
247 cmd->port = current_link.port;
248 cmd->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
249 AUTONEG_DISABLE;
250 cmd->lp_advertising = current_link.lp_caps;
251
252 return 0;
253}
254
255static int qede_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
256{
257 struct qede_dev *edev = netdev_priv(dev);
258 struct qed_link_output current_link;
259 struct qed_link_params params;
260 u32 speed;
261
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300262 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200263 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300264 "Link settings are not allowed to be changed\n");
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200265 return -EOPNOTSUPP;
266 }
267
268 memset(&current_link, 0, sizeof(current_link));
269 memset(&params, 0, sizeof(params));
270 edev->ops->common->get_link(edev->cdev, &current_link);
271
272 speed = ethtool_cmd_speed(cmd);
273 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
274 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
275 if (cmd->autoneg == AUTONEG_ENABLE) {
276 params.autoneg = true;
277 params.forced_speed = 0;
278 params.adv_speeds = cmd->advertising;
279 } else { /* forced speed */
280 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
281 params.autoneg = false;
282 params.forced_speed = speed;
283 switch (speed) {
284 case SPEED_10000:
285 if (!(current_link.supported_caps &
286 SUPPORTED_10000baseKR_Full)) {
287 DP_INFO(edev, "10G speed not supported\n");
288 return -EINVAL;
289 }
290 params.adv_speeds = SUPPORTED_10000baseKR_Full;
291 break;
292 case SPEED_40000:
293 if (!(current_link.supported_caps &
294 SUPPORTED_40000baseLR4_Full)) {
295 DP_INFO(edev, "40G speed not supported\n");
296 return -EINVAL;
297 }
298 params.adv_speeds = SUPPORTED_40000baseLR4_Full;
299 break;
300 default:
301 DP_INFO(edev, "Unsupported speed %u\n", speed);
302 return -EINVAL;
303 }
304 }
305
306 params.link_up = true;
307 edev->ops->common->set_link(edev->cdev, &params);
308
309 return 0;
310}
311
312static void qede_get_drvinfo(struct net_device *ndev,
313 struct ethtool_drvinfo *info)
314{
315 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
316 struct qede_dev *edev = netdev_priv(ndev);
317
318 strlcpy(info->driver, "qede", sizeof(info->driver));
319 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
320
321 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
322 edev->dev_info.common.fw_major,
323 edev->dev_info.common.fw_minor,
324 edev->dev_info.common.fw_rev,
325 edev->dev_info.common.fw_eng);
326
327 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
328 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
329 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
330 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
331 edev->dev_info.common.mfw_rev & 0xFF);
332
333 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
334 sizeof(info->fw_version)) {
335 snprintf(info->fw_version, sizeof(info->fw_version),
336 "mfw %s storm %s", mfw, storm);
337 } else {
338 snprintf(info->fw_version, sizeof(info->fw_version),
339 "%s %s", mfw, storm);
340 }
341
342 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
343}
344
345static u32 qede_get_msglevel(struct net_device *ndev)
346{
347 struct qede_dev *edev = netdev_priv(ndev);
348
349 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) |
350 edev->dp_module;
351}
352
353static void qede_set_msglevel(struct net_device *ndev, u32 level)
354{
355 struct qede_dev *edev = netdev_priv(ndev);
356 u32 dp_module = 0;
357 u8 dp_level = 0;
358
359 qede_config_debug(level, &dp_module, &dp_level);
360
361 edev->dp_level = dp_level;
362 edev->dp_module = dp_module;
363 edev->ops->common->update_msglvl(edev->cdev,
364 dp_module, dp_level);
365}
366
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200367static int qede_nway_reset(struct net_device *dev)
368{
369 struct qede_dev *edev = netdev_priv(dev);
370 struct qed_link_output current_link;
371 struct qed_link_params link_params;
372
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300373 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
374 DP_INFO(edev,
375 "Link settings are not allowed to be changed\n");
376 return -EOPNOTSUPP;
377 }
378
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200379 if (!netif_running(dev))
380 return 0;
381
382 memset(&current_link, 0, sizeof(current_link));
383 edev->ops->common->get_link(edev->cdev, &current_link);
384 if (!current_link.link_up)
385 return 0;
386
387 /* Toggle the link */
388 memset(&link_params, 0, sizeof(link_params));
389 link_params.link_up = false;
390 edev->ops->common->set_link(edev->cdev, &link_params);
391 link_params.link_up = true;
392 edev->ops->common->set_link(edev->cdev, &link_params);
393
394 return 0;
395}
396
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200397static u32 qede_get_link(struct net_device *dev)
398{
399 struct qede_dev *edev = netdev_priv(dev);
400 struct qed_link_output current_link;
401
402 memset(&current_link, 0, sizeof(current_link));
403 edev->ops->common->get_link(edev->cdev, &current_link);
404
405 return current_link.link_up;
406}
407
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200408static void qede_get_ringparam(struct net_device *dev,
409 struct ethtool_ringparam *ering)
410{
411 struct qede_dev *edev = netdev_priv(dev);
412
413 ering->rx_max_pending = NUM_RX_BDS_MAX;
414 ering->rx_pending = edev->q_num_rx_buffers;
415 ering->tx_max_pending = NUM_TX_BDS_MAX;
416 ering->tx_pending = edev->q_num_tx_buffers;
417}
418
419static int qede_set_ringparam(struct net_device *dev,
420 struct ethtool_ringparam *ering)
421{
422 struct qede_dev *edev = netdev_priv(dev);
423
424 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
425 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
426 ering->rx_pending, ering->tx_pending);
427
428 /* Validate legality of configuration */
429 if (ering->rx_pending > NUM_RX_BDS_MAX ||
430 ering->rx_pending < NUM_RX_BDS_MIN ||
431 ering->tx_pending > NUM_TX_BDS_MAX ||
432 ering->tx_pending < NUM_TX_BDS_MIN) {
433 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
434 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
435 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
436 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
437 return -EINVAL;
438 }
439
440 /* Change ring size and re-load */
441 edev->q_num_rx_buffers = ering->rx_pending;
442 edev->q_num_tx_buffers = ering->tx_pending;
443
444 if (netif_running(edev->ndev))
445 qede_reload(edev, NULL, NULL);
446
447 return 0;
448}
449
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200450static void qede_get_pauseparam(struct net_device *dev,
451 struct ethtool_pauseparam *epause)
452{
453 struct qede_dev *edev = netdev_priv(dev);
454 struct qed_link_output current_link;
455
456 memset(&current_link, 0, sizeof(current_link));
457 edev->ops->common->get_link(edev->cdev, &current_link);
458
459 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
460 epause->autoneg = true;
461 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
462 epause->rx_pause = true;
463 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
464 epause->tx_pause = true;
465
466 DP_VERBOSE(edev, QED_MSG_DEBUG,
467 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
468 epause->cmd, epause->autoneg, epause->rx_pause,
469 epause->tx_pause);
470}
471
472static int qede_set_pauseparam(struct net_device *dev,
473 struct ethtool_pauseparam *epause)
474{
475 struct qede_dev *edev = netdev_priv(dev);
476 struct qed_link_params params;
477 struct qed_link_output current_link;
478
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300479 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200480 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300481 "Pause settings are not allowed to be changed\n");
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200482 return -EOPNOTSUPP;
483 }
484
485 memset(&current_link, 0, sizeof(current_link));
486 edev->ops->common->get_link(edev->cdev, &current_link);
487
488 memset(&params, 0, sizeof(params));
489 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
490 if (epause->autoneg) {
491 if (!(current_link.supported_caps & SUPPORTED_Autoneg)) {
492 DP_INFO(edev, "autoneg not supported\n");
493 return -EINVAL;
494 }
495 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
496 }
497 if (epause->rx_pause)
498 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
499 if (epause->tx_pause)
500 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
501
502 params.link_up = true;
503 edev->ops->common->set_link(edev->cdev, &params);
504
505 return 0;
506}
507
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200508static void qede_update_mtu(struct qede_dev *edev, union qede_reload_args *args)
509{
510 edev->ndev->mtu = args->mtu;
511}
512
513/* Netdevice NDOs */
514#define ETH_MAX_JUMBO_PACKET_SIZE 9600
515#define ETH_MIN_PACKET_SIZE 60
516int qede_change_mtu(struct net_device *ndev, int new_mtu)
517{
518 struct qede_dev *edev = netdev_priv(ndev);
519 union qede_reload_args args;
520
521 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
522 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) {
523 DP_ERR(edev, "Can't support requested MTU size\n");
524 return -EINVAL;
525 }
526
527 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
528 "Configuring MTU size of %d\n", new_mtu);
529
530 /* Set the mtu field and re-start the interface if needed*/
531 args.mtu = new_mtu;
532
533 if (netif_running(edev->ndev))
534 qede_reload(edev, &qede_update_mtu, &args);
535
536 qede_update_mtu(edev, &args);
537
538 return 0;
539}
540
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200541static void qede_get_channels(struct net_device *dev,
542 struct ethtool_channels *channels)
543{
544 struct qede_dev *edev = netdev_priv(dev);
545
546 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
547 channels->combined_count = QEDE_RSS_CNT(edev);
548}
549
550static int qede_set_channels(struct net_device *dev,
551 struct ethtool_channels *channels)
552{
553 struct qede_dev *edev = netdev_priv(dev);
554
555 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
556 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
557 channels->rx_count, channels->tx_count,
558 channels->other_count, channels->combined_count);
559
560 /* We don't support separate rx / tx, nor `other' channels. */
561 if (channels->rx_count || channels->tx_count ||
562 channels->other_count || (channels->combined_count == 0) ||
563 (channels->combined_count > QEDE_MAX_RSS_CNT(edev))) {
564 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
565 "command parameters not supported\n");
566 return -EINVAL;
567 }
568
569 /* Check if there was a change in the active parameters */
570 if (channels->combined_count == QEDE_RSS_CNT(edev)) {
571 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
572 "No change in active parameters\n");
573 return 0;
574 }
575
576 /* We need the number of queues to be divisible between the hwfns */
577 if (channels->combined_count % edev->dev_info.common.num_hwfns) {
578 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
579 "Number of channels must be divisable by %04x\n",
580 edev->dev_info.common.num_hwfns);
581 return -EINVAL;
582 }
583
584 /* Set number of queues and reload if necessary */
585 edev->req_rss = channels->combined_count;
586 if (netif_running(dev))
587 qede_reload(edev, NULL, NULL);
588
589 return 0;
590}
591
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200592static int qede_set_phys_id(struct net_device *dev,
593 enum ethtool_phys_id_state state)
594{
595 struct qede_dev *edev = netdev_priv(dev);
596 u8 led_state = 0;
597
598 switch (state) {
599 case ETHTOOL_ID_ACTIVE:
600 return 1; /* cycle on/off once per second */
601
602 case ETHTOOL_ID_ON:
603 led_state = QED_LED_MODE_ON;
604 break;
605
606 case ETHTOOL_ID_OFF:
607 led_state = QED_LED_MODE_OFF;
608 break;
609
610 case ETHTOOL_ID_INACTIVE:
611 led_state = QED_LED_MODE_RESTORE;
612 break;
613 }
614
615 edev->ops->common->set_led(edev->cdev, led_state);
616
617 return 0;
618}
619
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300620static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
621{
622 info->data = RXH_IP_SRC | RXH_IP_DST;
623
624 switch (info->flow_type) {
625 case TCP_V4_FLOW:
626 case TCP_V6_FLOW:
627 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
628 break;
629 case UDP_V4_FLOW:
630 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
631 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
632 break;
633 case UDP_V6_FLOW:
634 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
635 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
636 break;
637 case IPV4_FLOW:
638 case IPV6_FLOW:
639 break;
640 default:
641 info->data = 0;
642 break;
643 }
644
645 return 0;
646}
647
648static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
649 u32 *rules __always_unused)
650{
651 struct qede_dev *edev = netdev_priv(dev);
652
653 switch (info->cmd) {
654 case ETHTOOL_GRXRINGS:
655 info->data = edev->num_rss;
656 return 0;
657 case ETHTOOL_GRXFH:
658 return qede_get_rss_flags(edev, info);
659 default:
660 DP_ERR(edev, "Command parameters not supported\n");
661 return -EOPNOTSUPP;
662 }
663}
664
665static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
666{
667 struct qed_update_vport_params vport_update_params;
668 u8 set_caps = 0, clr_caps = 0;
669
670 DP_VERBOSE(edev, QED_MSG_DEBUG,
671 "Set rss flags command parameters: flow type = %d, data = %llu\n",
672 info->flow_type, info->data);
673
674 switch (info->flow_type) {
675 case TCP_V4_FLOW:
676 case TCP_V6_FLOW:
677 /* For TCP only 4-tuple hash is supported */
678 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
679 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
680 DP_INFO(edev, "Command parameters not supported\n");
681 return -EINVAL;
682 }
683 return 0;
684 case UDP_V4_FLOW:
685 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
686 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
687 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
688 set_caps = QED_RSS_IPV4_UDP;
689 DP_VERBOSE(edev, QED_MSG_DEBUG,
690 "UDP 4-tuple enabled\n");
691 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
692 clr_caps = QED_RSS_IPV4_UDP;
693 DP_VERBOSE(edev, QED_MSG_DEBUG,
694 "UDP 4-tuple disabled\n");
695 } else {
696 return -EINVAL;
697 }
698 break;
699 case UDP_V6_FLOW:
700 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
701 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
702 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
703 set_caps = QED_RSS_IPV6_UDP;
704 DP_VERBOSE(edev, QED_MSG_DEBUG,
705 "UDP 4-tuple enabled\n");
706 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
707 clr_caps = QED_RSS_IPV6_UDP;
708 DP_VERBOSE(edev, QED_MSG_DEBUG,
709 "UDP 4-tuple disabled\n");
710 } else {
711 return -EINVAL;
712 }
713 break;
714 case IPV4_FLOW:
715 case IPV6_FLOW:
716 /* For IP only 2-tuple hash is supported */
717 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
718 DP_INFO(edev, "Command parameters not supported\n");
719 return -EINVAL;
720 }
721 return 0;
722 case SCTP_V4_FLOW:
723 case AH_ESP_V4_FLOW:
724 case AH_V4_FLOW:
725 case ESP_V4_FLOW:
726 case SCTP_V6_FLOW:
727 case AH_ESP_V6_FLOW:
728 case AH_V6_FLOW:
729 case ESP_V6_FLOW:
730 case IP_USER_FLOW:
731 case ETHER_FLOW:
732 /* RSS is not supported for these protocols */
733 if (info->data) {
734 DP_INFO(edev, "Command parameters not supported\n");
735 return -EINVAL;
736 }
737 return 0;
738 default:
739 return -EINVAL;
740 }
741
742 /* No action is needed if there is no change in the rss capability */
743 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
744 ~clr_caps) | set_caps))
745 return 0;
746
747 /* Update internal configuration */
748 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
749 set_caps;
750 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
751
752 /* Re-configure if possible */
753 if (netif_running(edev->ndev)) {
754 memset(&vport_update_params, 0, sizeof(vport_update_params));
755 vport_update_params.update_rss_flg = 1;
756 vport_update_params.vport_id = 0;
757 memcpy(&vport_update_params.rss_params, &edev->rss_params,
758 sizeof(vport_update_params.rss_params));
759 return edev->ops->vport_update(edev->cdev,
760 &vport_update_params);
761 }
762
763 return 0;
764}
765
766static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
767{
768 struct qede_dev *edev = netdev_priv(dev);
769
770 switch (info->cmd) {
771 case ETHTOOL_SRXFH:
772 return qede_set_rss_flags(edev, info);
773 default:
774 DP_INFO(edev, "Command parameters not supported\n");
775 return -EOPNOTSUPP;
776 }
777}
778
779static u32 qede_get_rxfh_indir_size(struct net_device *dev)
780{
781 return QED_RSS_IND_TABLE_SIZE;
782}
783
784static u32 qede_get_rxfh_key_size(struct net_device *dev)
785{
786 struct qede_dev *edev = netdev_priv(dev);
787
788 return sizeof(edev->rss_params.rss_key);
789}
790
791static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
792{
793 struct qede_dev *edev = netdev_priv(dev);
794 int i;
795
796 if (hfunc)
797 *hfunc = ETH_RSS_HASH_TOP;
798
799 if (!indir)
800 return 0;
801
802 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
803 indir[i] = edev->rss_params.rss_ind_table[i];
804
805 if (key)
806 memcpy(key, edev->rss_params.rss_key,
807 qede_get_rxfh_key_size(dev));
808
809 return 0;
810}
811
812static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
813 const u8 *key, const u8 hfunc)
814{
815 struct qed_update_vport_params vport_update_params;
816 struct qede_dev *edev = netdev_priv(dev);
817 int i;
818
819 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
820 return -EOPNOTSUPP;
821
822 if (!indir && !key)
823 return 0;
824
825 if (indir) {
826 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
827 edev->rss_params.rss_ind_table[i] = indir[i];
828 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
829 }
830
831 if (key) {
832 memcpy(&edev->rss_params.rss_key, key,
833 qede_get_rxfh_key_size(dev));
834 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
835 }
836
837 if (netif_running(edev->ndev)) {
838 memset(&vport_update_params, 0, sizeof(vport_update_params));
839 vport_update_params.update_rss_flg = 1;
840 vport_update_params.vport_id = 0;
841 memcpy(&vport_update_params.rss_params, &edev->rss_params,
842 sizeof(vport_update_params.rss_params));
843 return edev->ops->vport_update(edev->cdev,
844 &vport_update_params);
845 }
846
847 return 0;
848}
849
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400850static void qede_self_test(struct net_device *dev,
851 struct ethtool_test *etest, u64 *buf)
852{
853 struct qede_dev *edev = netdev_priv(dev);
854
855 DP_VERBOSE(edev, QED_MSG_DEBUG,
856 "Self-test command parameters: offline = %d, external_lb = %d\n",
857 (etest->flags & ETH_TEST_FL_OFFLINE),
858 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
859
860 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
861
862 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
863 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
864 etest->flags |= ETH_TEST_FL_FAILED;
865 }
866
867 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
868 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
869 etest->flags |= ETH_TEST_FL_FAILED;
870 }
871
872 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
873 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
874 etest->flags |= ETH_TEST_FL_FAILED;
875 }
876
877 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
878 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
879 etest->flags |= ETH_TEST_FL_FAILED;
880 }
881}
882
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200883static const struct ethtool_ops qede_ethtool_ops = {
884 .get_settings = qede_get_settings,
885 .set_settings = qede_set_settings,
886 .get_drvinfo = qede_get_drvinfo,
887 .get_msglevel = qede_get_msglevel,
888 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200889 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200890 .get_link = qede_get_link,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200891 .get_ringparam = qede_get_ringparam,
892 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200893 .get_pauseparam = qede_get_pauseparam,
894 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200895 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200896 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200897 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +0300898 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200899 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300900 .get_rxnfc = qede_get_rxnfc,
901 .set_rxnfc = qede_set_rxnfc,
902 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
903 .get_rxfh_key_size = qede_get_rxfh_key_size,
904 .get_rxfh = qede_get_rxfh,
905 .set_rxfh = qede_set_rxfh,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200906 .get_channels = qede_get_channels,
907 .set_channels = qede_set_channels,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400908 .self_test = qede_self_test,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200909};
910
911void qede_set_ethtool_ops(struct net_device *dev)
912{
913 dev->ethtool_ops = &qede_ethtool_ops;
914}