1 /* QLogic qede NIC Driver
2 * Copyright (c) 2015 QLogic Corporation
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
9 #include <linux/version.h>
10 #include <linux/types.h>
11 #include <linux/netdevice.h>
12 #include <linux/etherdevice.h>
13 #include <linux/ethtool.h>
14 #include <linux/string.h>
15 #include <linux/pci.h>
16 #include <linux/capability.h>
19 #define QEDE_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
20 #define QEDE_STAT_STRING(stat_name) (#stat_name)
21 #define _QEDE_STAT(stat_name, pf_only) \
22 {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
23 #define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
24 #define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
26 #define QEDE_RQSTAT_OFFSET(stat_name) \
27 (offsetof(struct qede_rx_queue, stat_name))
28 #define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
29 #define QEDE_RQSTAT(stat_name) \
30 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
32 #define QEDE_SELFTEST_POLL_COUNT 100
36 char string
[ETH_GSTRING_LEN
];
37 } qede_rqstats_arr
[] = {
38 QEDE_RQSTAT(rx_hw_errors
),
39 QEDE_RQSTAT(rx_alloc_errors
),
42 #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
43 #define QEDE_RQSTATS_DATA(dev, sindex, rqindex) \
44 (*((u64 *)(((char *)(dev->fp_array[(rqindex)].rxq)) +\
45 qede_rqstats_arr[(sindex)].offset)))
48 char string
[ETH_GSTRING_LEN
];
50 } qede_stats_arr
[] = {
51 QEDE_STAT(rx_ucast_bytes
),
52 QEDE_STAT(rx_mcast_bytes
),
53 QEDE_STAT(rx_bcast_bytes
),
54 QEDE_STAT(rx_ucast_pkts
),
55 QEDE_STAT(rx_mcast_pkts
),
56 QEDE_STAT(rx_bcast_pkts
),
58 QEDE_STAT(tx_ucast_bytes
),
59 QEDE_STAT(tx_mcast_bytes
),
60 QEDE_STAT(tx_bcast_bytes
),
61 QEDE_STAT(tx_ucast_pkts
),
62 QEDE_STAT(tx_mcast_pkts
),
63 QEDE_STAT(tx_bcast_pkts
),
65 QEDE_PF_STAT(rx_64_byte_packets
),
66 QEDE_PF_STAT(rx_65_to_127_byte_packets
),
67 QEDE_PF_STAT(rx_128_to_255_byte_packets
),
68 QEDE_PF_STAT(rx_256_to_511_byte_packets
),
69 QEDE_PF_STAT(rx_512_to_1023_byte_packets
),
70 QEDE_PF_STAT(rx_1024_to_1518_byte_packets
),
71 QEDE_PF_STAT(rx_1519_to_1522_byte_packets
),
72 QEDE_PF_STAT(rx_1519_to_2047_byte_packets
),
73 QEDE_PF_STAT(rx_2048_to_4095_byte_packets
),
74 QEDE_PF_STAT(rx_4096_to_9216_byte_packets
),
75 QEDE_PF_STAT(rx_9217_to_16383_byte_packets
),
76 QEDE_PF_STAT(tx_64_byte_packets
),
77 QEDE_PF_STAT(tx_65_to_127_byte_packets
),
78 QEDE_PF_STAT(tx_128_to_255_byte_packets
),
79 QEDE_PF_STAT(tx_256_to_511_byte_packets
),
80 QEDE_PF_STAT(tx_512_to_1023_byte_packets
),
81 QEDE_PF_STAT(tx_1024_to_1518_byte_packets
),
82 QEDE_PF_STAT(tx_1519_to_2047_byte_packets
),
83 QEDE_PF_STAT(tx_2048_to_4095_byte_packets
),
84 QEDE_PF_STAT(tx_4096_to_9216_byte_packets
),
85 QEDE_PF_STAT(tx_9217_to_16383_byte_packets
),
87 QEDE_PF_STAT(rx_mac_crtl_frames
),
88 QEDE_PF_STAT(tx_mac_ctrl_frames
),
89 QEDE_PF_STAT(rx_pause_frames
),
90 QEDE_PF_STAT(tx_pause_frames
),
91 QEDE_PF_STAT(rx_pfc_frames
),
92 QEDE_PF_STAT(tx_pfc_frames
),
94 QEDE_PF_STAT(rx_crc_errors
),
95 QEDE_PF_STAT(rx_align_errors
),
96 QEDE_PF_STAT(rx_carrier_errors
),
97 QEDE_PF_STAT(rx_oversize_packets
),
98 QEDE_PF_STAT(rx_jabbers
),
99 QEDE_PF_STAT(rx_undersize_packets
),
100 QEDE_PF_STAT(rx_fragments
),
101 QEDE_PF_STAT(tx_lpi_entry_count
),
102 QEDE_PF_STAT(tx_total_collisions
),
103 QEDE_PF_STAT(brb_truncates
),
104 QEDE_PF_STAT(brb_discards
),
105 QEDE_STAT(no_buff_discards
),
106 QEDE_PF_STAT(mftag_filter_discards
),
107 QEDE_PF_STAT(mac_filter_discards
),
108 QEDE_STAT(tx_err_drop_pkts
),
110 QEDE_STAT(coalesced_pkts
),
111 QEDE_STAT(coalesced_events
),
112 QEDE_STAT(coalesced_aborts_num
),
113 QEDE_STAT(non_coalesced_pkts
),
114 QEDE_STAT(coalesced_bytes
),
117 #define QEDE_STATS_DATA(dev, index) \
118 (*((u64 *)(((char *)(dev)) + offsetof(struct qede_dev, stats) \
119 + qede_stats_arr[(index)].offset)))
121 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
128 static const char qede_private_arr
[QEDE_PRI_FLAG_LEN
][ETH_GSTRING_LEN
] = {
132 enum qede_ethtool_tests
{
133 QEDE_ETHTOOL_INT_LOOPBACK
,
134 QEDE_ETHTOOL_INTERRUPT_TEST
,
135 QEDE_ETHTOOL_MEMORY_TEST
,
136 QEDE_ETHTOOL_REGISTER_TEST
,
137 QEDE_ETHTOOL_CLOCK_TEST
,
138 QEDE_ETHTOOL_TEST_MAX
141 static const char qede_tests_str_arr
[QEDE_ETHTOOL_TEST_MAX
][ETH_GSTRING_LEN
] = {
142 "Internal loopback (offline)",
143 "Interrupt (online)\t",
144 "Memory (online)\t\t",
145 "Register (online)\t",
146 "Clock (online)\t\t",
149 static void qede_get_strings_stats(struct qede_dev
*edev
, u8
*buf
)
153 for (i
= 0, j
= 0; i
< QEDE_NUM_STATS
; i
++) {
154 if (IS_VF(edev
) && qede_stats_arr
[i
].pf_only
)
156 strcpy(buf
+ j
* ETH_GSTRING_LEN
,
157 qede_stats_arr
[i
].string
);
161 for (k
= 0; k
< QEDE_NUM_RQSTATS
; k
++, j
++)
162 strcpy(buf
+ j
* ETH_GSTRING_LEN
,
163 qede_rqstats_arr
[k
].string
);
166 static void qede_get_strings(struct net_device
*dev
, u32 stringset
, u8
*buf
)
168 struct qede_dev
*edev
= netdev_priv(dev
);
172 qede_get_strings_stats(edev
, buf
);
174 case ETH_SS_PRIV_FLAGS
:
175 memcpy(buf
, qede_private_arr
,
176 ETH_GSTRING_LEN
* QEDE_PRI_FLAG_LEN
);
179 memcpy(buf
, qede_tests_str_arr
,
180 ETH_GSTRING_LEN
* QEDE_ETHTOOL_TEST_MAX
);
183 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
184 "Unsupported stringset 0x%08x\n", stringset
);
188 static void qede_get_ethtool_stats(struct net_device
*dev
,
189 struct ethtool_stats
*stats
, u64
*buf
)
191 struct qede_dev
*edev
= netdev_priv(dev
);
195 qede_fill_by_demand_stats(edev
);
197 mutex_lock(&edev
->qede_lock
);
199 for (sidx
= 0; sidx
< QEDE_NUM_STATS
; sidx
++) {
200 if (IS_VF(edev
) && qede_stats_arr
[sidx
].pf_only
)
202 buf
[cnt
++] = QEDE_STATS_DATA(edev
, sidx
);
205 for (sidx
= 0; sidx
< QEDE_NUM_RQSTATS
; sidx
++) {
207 for (qid
= 0; qid
< edev
->num_rss
; qid
++)
208 buf
[cnt
] += QEDE_RQSTATS_DATA(edev
, sidx
, qid
);
212 mutex_unlock(&edev
->qede_lock
);
215 static int qede_get_sset_count(struct net_device
*dev
, int stringset
)
217 struct qede_dev
*edev
= netdev_priv(dev
);
218 int num_stats
= QEDE_NUM_STATS
;
225 for (i
= 0; i
< QEDE_NUM_STATS
; i
++)
226 if (qede_stats_arr
[i
].pf_only
)
229 return num_stats
+ QEDE_NUM_RQSTATS
;
230 case ETH_SS_PRIV_FLAGS
:
231 return QEDE_PRI_FLAG_LEN
;
234 return QEDE_ETHTOOL_TEST_MAX
;
238 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
239 "Unsupported stringset 0x%08x\n", stringset
);
244 static u32
qede_get_priv_flags(struct net_device
*dev
)
246 struct qede_dev
*edev
= netdev_priv(dev
);
248 return (!!(edev
->dev_info
.common
.num_hwfns
> 1)) << QEDE_PRI_FLAG_CMT
;
251 static int qede_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
253 struct qede_dev
*edev
= netdev_priv(dev
);
254 struct qed_link_output current_link
;
256 memset(¤t_link
, 0, sizeof(current_link
));
257 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
259 cmd
->supported
= current_link
.supported_caps
;
260 cmd
->advertising
= current_link
.advertised_caps
;
261 if ((edev
->state
== QEDE_STATE_OPEN
) && (current_link
.link_up
)) {
262 ethtool_cmd_speed_set(cmd
, current_link
.speed
);
263 cmd
->duplex
= current_link
.duplex
;
265 cmd
->duplex
= DUPLEX_UNKNOWN
;
266 ethtool_cmd_speed_set(cmd
, SPEED_UNKNOWN
);
268 cmd
->port
= current_link
.port
;
269 cmd
->autoneg
= (current_link
.autoneg
) ? AUTONEG_ENABLE
:
271 cmd
->lp_advertising
= current_link
.lp_caps
;
276 static int qede_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
278 struct qede_dev
*edev
= netdev_priv(dev
);
279 struct qed_link_output current_link
;
280 struct qed_link_params params
;
283 if (!edev
->ops
|| !edev
->ops
->common
->can_link_change(edev
->cdev
)) {
285 "Link settings are not allowed to be changed\n");
289 memset(¤t_link
, 0, sizeof(current_link
));
290 memset(¶ms
, 0, sizeof(params
));
291 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
293 speed
= ethtool_cmd_speed(cmd
);
294 params
.override_flags
|= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS
;
295 params
.override_flags
|= QED_LINK_OVERRIDE_SPEED_AUTONEG
;
296 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
297 params
.autoneg
= true;
298 params
.forced_speed
= 0;
299 params
.adv_speeds
= cmd
->advertising
;
300 } else { /* forced speed */
301 params
.override_flags
|= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED
;
302 params
.autoneg
= false;
303 params
.forced_speed
= speed
;
306 if (!(current_link
.supported_caps
&
307 SUPPORTED_10000baseKR_Full
)) {
308 DP_INFO(edev
, "10G speed not supported\n");
311 params
.adv_speeds
= SUPPORTED_10000baseKR_Full
;
314 if (!(current_link
.supported_caps
&
315 SUPPORTED_40000baseLR4_Full
)) {
316 DP_INFO(edev
, "40G speed not supported\n");
319 params
.adv_speeds
= SUPPORTED_40000baseLR4_Full
;
322 DP_INFO(edev
, "Unsupported speed %u\n", speed
);
327 params
.link_up
= true;
328 edev
->ops
->common
->set_link(edev
->cdev
, ¶ms
);
333 static void qede_get_drvinfo(struct net_device
*ndev
,
334 struct ethtool_drvinfo
*info
)
336 char mfw
[ETHTOOL_FWVERS_LEN
], storm
[ETHTOOL_FWVERS_LEN
];
337 struct qede_dev
*edev
= netdev_priv(ndev
);
339 strlcpy(info
->driver
, "qede", sizeof(info
->driver
));
340 strlcpy(info
->version
, DRV_MODULE_VERSION
, sizeof(info
->version
));
342 snprintf(storm
, ETHTOOL_FWVERS_LEN
, "%d.%d.%d.%d",
343 edev
->dev_info
.common
.fw_major
,
344 edev
->dev_info
.common
.fw_minor
,
345 edev
->dev_info
.common
.fw_rev
,
346 edev
->dev_info
.common
.fw_eng
);
348 snprintf(mfw
, ETHTOOL_FWVERS_LEN
, "%d.%d.%d.%d",
349 (edev
->dev_info
.common
.mfw_rev
>> 24) & 0xFF,
350 (edev
->dev_info
.common
.mfw_rev
>> 16) & 0xFF,
351 (edev
->dev_info
.common
.mfw_rev
>> 8) & 0xFF,
352 edev
->dev_info
.common
.mfw_rev
& 0xFF);
354 if ((strlen(storm
) + strlen(mfw
) + strlen("mfw storm ")) <
355 sizeof(info
->fw_version
)) {
356 snprintf(info
->fw_version
, sizeof(info
->fw_version
),
357 "mfw %s storm %s", mfw
, storm
);
359 snprintf(info
->fw_version
, sizeof(info
->fw_version
),
360 "%s %s", mfw
, storm
);
363 strlcpy(info
->bus_info
, pci_name(edev
->pdev
), sizeof(info
->bus_info
));
366 static u32
qede_get_msglevel(struct net_device
*ndev
)
368 struct qede_dev
*edev
= netdev_priv(ndev
);
370 return ((u32
)edev
->dp_level
<< QED_LOG_LEVEL_SHIFT
) |
374 static void qede_set_msglevel(struct net_device
*ndev
, u32 level
)
376 struct qede_dev
*edev
= netdev_priv(ndev
);
380 qede_config_debug(level
, &dp_module
, &dp_level
);
382 edev
->dp_level
= dp_level
;
383 edev
->dp_module
= dp_module
;
384 edev
->ops
->common
->update_msglvl(edev
->cdev
,
385 dp_module
, dp_level
);
388 static int qede_nway_reset(struct net_device
*dev
)
390 struct qede_dev
*edev
= netdev_priv(dev
);
391 struct qed_link_output current_link
;
392 struct qed_link_params link_params
;
394 if (!edev
->ops
|| !edev
->ops
->common
->can_link_change(edev
->cdev
)) {
396 "Link settings are not allowed to be changed\n");
400 if (!netif_running(dev
))
403 memset(¤t_link
, 0, sizeof(current_link
));
404 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
405 if (!current_link
.link_up
)
408 /* Toggle the link */
409 memset(&link_params
, 0, sizeof(link_params
));
410 link_params
.link_up
= false;
411 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
412 link_params
.link_up
= true;
413 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
418 static u32
qede_get_link(struct net_device
*dev
)
420 struct qede_dev
*edev
= netdev_priv(dev
);
421 struct qed_link_output current_link
;
423 memset(¤t_link
, 0, sizeof(current_link
));
424 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
426 return current_link
.link_up
;
429 static void qede_get_ringparam(struct net_device
*dev
,
430 struct ethtool_ringparam
*ering
)
432 struct qede_dev
*edev
= netdev_priv(dev
);
434 ering
->rx_max_pending
= NUM_RX_BDS_MAX
;
435 ering
->rx_pending
= edev
->q_num_rx_buffers
;
436 ering
->tx_max_pending
= NUM_TX_BDS_MAX
;
437 ering
->tx_pending
= edev
->q_num_tx_buffers
;
440 static int qede_set_ringparam(struct net_device
*dev
,
441 struct ethtool_ringparam
*ering
)
443 struct qede_dev
*edev
= netdev_priv(dev
);
445 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
446 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
447 ering
->rx_pending
, ering
->tx_pending
);
449 /* Validate legality of configuration */
450 if (ering
->rx_pending
> NUM_RX_BDS_MAX
||
451 ering
->rx_pending
< NUM_RX_BDS_MIN
||
452 ering
->tx_pending
> NUM_TX_BDS_MAX
||
453 ering
->tx_pending
< NUM_TX_BDS_MIN
) {
454 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
455 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
456 NUM_RX_BDS_MIN
, NUM_RX_BDS_MAX
,
457 NUM_TX_BDS_MIN
, NUM_TX_BDS_MAX
);
461 /* Change ring size and re-load */
462 edev
->q_num_rx_buffers
= ering
->rx_pending
;
463 edev
->q_num_tx_buffers
= ering
->tx_pending
;
465 if (netif_running(edev
->ndev
))
466 qede_reload(edev
, NULL
, NULL
);
471 static void qede_get_pauseparam(struct net_device
*dev
,
472 struct ethtool_pauseparam
*epause
)
474 struct qede_dev
*edev
= netdev_priv(dev
);
475 struct qed_link_output current_link
;
477 memset(¤t_link
, 0, sizeof(current_link
));
478 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
480 if (current_link
.pause_config
& QED_LINK_PAUSE_AUTONEG_ENABLE
)
481 epause
->autoneg
= true;
482 if (current_link
.pause_config
& QED_LINK_PAUSE_RX_ENABLE
)
483 epause
->rx_pause
= true;
484 if (current_link
.pause_config
& QED_LINK_PAUSE_TX_ENABLE
)
485 epause
->tx_pause
= true;
487 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
488 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
489 epause
->cmd
, epause
->autoneg
, epause
->rx_pause
,
493 static int qede_set_pauseparam(struct net_device
*dev
,
494 struct ethtool_pauseparam
*epause
)
496 struct qede_dev
*edev
= netdev_priv(dev
);
497 struct qed_link_params params
;
498 struct qed_link_output current_link
;
500 if (!edev
->ops
|| !edev
->ops
->common
->can_link_change(edev
->cdev
)) {
502 "Pause settings are not allowed to be changed\n");
506 memset(¤t_link
, 0, sizeof(current_link
));
507 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
509 memset(¶ms
, 0, sizeof(params
));
510 params
.override_flags
|= QED_LINK_OVERRIDE_PAUSE_CONFIG
;
511 if (epause
->autoneg
) {
512 if (!(current_link
.supported_caps
& SUPPORTED_Autoneg
)) {
513 DP_INFO(edev
, "autoneg not supported\n");
516 params
.pause_config
|= QED_LINK_PAUSE_AUTONEG_ENABLE
;
518 if (epause
->rx_pause
)
519 params
.pause_config
|= QED_LINK_PAUSE_RX_ENABLE
;
520 if (epause
->tx_pause
)
521 params
.pause_config
|= QED_LINK_PAUSE_TX_ENABLE
;
523 params
.link_up
= true;
524 edev
->ops
->common
->set_link(edev
->cdev
, ¶ms
);
529 static void qede_update_mtu(struct qede_dev
*edev
, union qede_reload_args
*args
)
531 edev
->ndev
->mtu
= args
->mtu
;
535 #define ETH_MAX_JUMBO_PACKET_SIZE 9600
536 #define ETH_MIN_PACKET_SIZE 60
537 int qede_change_mtu(struct net_device
*ndev
, int new_mtu
)
539 struct qede_dev
*edev
= netdev_priv(ndev
);
540 union qede_reload_args args
;
542 if ((new_mtu
> ETH_MAX_JUMBO_PACKET_SIZE
) ||
543 ((new_mtu
+ ETH_HLEN
) < ETH_MIN_PACKET_SIZE
)) {
544 DP_ERR(edev
, "Can't support requested MTU size\n");
548 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
549 "Configuring MTU size of %d\n", new_mtu
);
551 /* Set the mtu field and re-start the interface if needed*/
554 if (netif_running(edev
->ndev
))
555 qede_reload(edev
, &qede_update_mtu
, &args
);
557 qede_update_mtu(edev
, &args
);
562 static void qede_get_channels(struct net_device
*dev
,
563 struct ethtool_channels
*channels
)
565 struct qede_dev
*edev
= netdev_priv(dev
);
567 channels
->max_combined
= QEDE_MAX_RSS_CNT(edev
);
568 channels
->combined_count
= QEDE_RSS_CNT(edev
);
571 static int qede_set_channels(struct net_device
*dev
,
572 struct ethtool_channels
*channels
)
574 struct qede_dev
*edev
= netdev_priv(dev
);
576 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
577 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
578 channels
->rx_count
, channels
->tx_count
,
579 channels
->other_count
, channels
->combined_count
);
581 /* We don't support separate rx / tx, nor `other' channels. */
582 if (channels
->rx_count
|| channels
->tx_count
||
583 channels
->other_count
|| (channels
->combined_count
== 0) ||
584 (channels
->combined_count
> QEDE_MAX_RSS_CNT(edev
))) {
585 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
586 "command parameters not supported\n");
590 /* Check if there was a change in the active parameters */
591 if (channels
->combined_count
== QEDE_RSS_CNT(edev
)) {
592 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
593 "No change in active parameters\n");
597 /* We need the number of queues to be divisible between the hwfns */
598 if (channels
->combined_count
% edev
->dev_info
.common
.num_hwfns
) {
599 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
600 "Number of channels must be divisable by %04x\n",
601 edev
->dev_info
.common
.num_hwfns
);
605 /* Set number of queues and reload if necessary */
606 edev
->req_rss
= channels
->combined_count
;
607 if (netif_running(dev
))
608 qede_reload(edev
, NULL
, NULL
);
613 static int qede_set_phys_id(struct net_device
*dev
,
614 enum ethtool_phys_id_state state
)
616 struct qede_dev
*edev
= netdev_priv(dev
);
620 case ETHTOOL_ID_ACTIVE
:
621 return 1; /* cycle on/off once per second */
624 led_state
= QED_LED_MODE_ON
;
628 led_state
= QED_LED_MODE_OFF
;
631 case ETHTOOL_ID_INACTIVE
:
632 led_state
= QED_LED_MODE_RESTORE
;
636 edev
->ops
->common
->set_led(edev
->cdev
, led_state
);
641 static int qede_get_rss_flags(struct qede_dev
*edev
, struct ethtool_rxnfc
*info
)
643 info
->data
= RXH_IP_SRC
| RXH_IP_DST
;
645 switch (info
->flow_type
) {
648 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
651 if (edev
->rss_params
.rss_caps
& QED_RSS_IPV4_UDP
)
652 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
655 if (edev
->rss_params
.rss_caps
& QED_RSS_IPV6_UDP
)
656 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
669 static int qede_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*info
,
670 u32
*rules __always_unused
)
672 struct qede_dev
*edev
= netdev_priv(dev
);
675 case ETHTOOL_GRXRINGS
:
676 info
->data
= edev
->num_rss
;
679 return qede_get_rss_flags(edev
, info
);
681 DP_ERR(edev
, "Command parameters not supported\n");
686 static int qede_set_rss_flags(struct qede_dev
*edev
, struct ethtool_rxnfc
*info
)
688 struct qed_update_vport_params vport_update_params
;
689 u8 set_caps
= 0, clr_caps
= 0;
691 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
692 "Set rss flags command parameters: flow type = %d, data = %llu\n",
693 info
->flow_type
, info
->data
);
695 switch (info
->flow_type
) {
698 /* For TCP only 4-tuple hash is supported */
699 if (info
->data
^ (RXH_IP_SRC
| RXH_IP_DST
|
700 RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
701 DP_INFO(edev
, "Command parameters not supported\n");
706 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
707 if (info
->data
== (RXH_IP_SRC
| RXH_IP_DST
|
708 RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
709 set_caps
= QED_RSS_IPV4_UDP
;
710 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
711 "UDP 4-tuple enabled\n");
712 } else if (info
->data
== (RXH_IP_SRC
| RXH_IP_DST
)) {
713 clr_caps
= QED_RSS_IPV4_UDP
;
714 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
715 "UDP 4-tuple disabled\n");
721 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
722 if (info
->data
== (RXH_IP_SRC
| RXH_IP_DST
|
723 RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
724 set_caps
= QED_RSS_IPV6_UDP
;
725 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
726 "UDP 4-tuple enabled\n");
727 } else if (info
->data
== (RXH_IP_SRC
| RXH_IP_DST
)) {
728 clr_caps
= QED_RSS_IPV6_UDP
;
729 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
730 "UDP 4-tuple disabled\n");
737 /* For IP only 2-tuple hash is supported */
738 if (info
->data
^ (RXH_IP_SRC
| RXH_IP_DST
)) {
739 DP_INFO(edev
, "Command parameters not supported\n");
753 /* RSS is not supported for these protocols */
755 DP_INFO(edev
, "Command parameters not supported\n");
763 /* No action is needed if there is no change in the rss capability */
764 if (edev
->rss_params
.rss_caps
== ((edev
->rss_params
.rss_caps
&
765 ~clr_caps
) | set_caps
))
768 /* Update internal configuration */
769 edev
->rss_params
.rss_caps
= (edev
->rss_params
.rss_caps
& ~clr_caps
) |
771 edev
->rss_params_inited
|= QEDE_RSS_CAPS_INITED
;
773 /* Re-configure if possible */
774 if (netif_running(edev
->ndev
)) {
775 memset(&vport_update_params
, 0, sizeof(vport_update_params
));
776 vport_update_params
.update_rss_flg
= 1;
777 vport_update_params
.vport_id
= 0;
778 memcpy(&vport_update_params
.rss_params
, &edev
->rss_params
,
779 sizeof(vport_update_params
.rss_params
));
780 return edev
->ops
->vport_update(edev
->cdev
,
781 &vport_update_params
);
787 static int qede_set_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*info
)
789 struct qede_dev
*edev
= netdev_priv(dev
);
793 return qede_set_rss_flags(edev
, info
);
795 DP_INFO(edev
, "Command parameters not supported\n");
800 static u32
qede_get_rxfh_indir_size(struct net_device
*dev
)
802 return QED_RSS_IND_TABLE_SIZE
;
805 static u32
qede_get_rxfh_key_size(struct net_device
*dev
)
807 struct qede_dev
*edev
= netdev_priv(dev
);
809 return sizeof(edev
->rss_params
.rss_key
);
812 static int qede_get_rxfh(struct net_device
*dev
, u32
*indir
, u8
*key
, u8
*hfunc
)
814 struct qede_dev
*edev
= netdev_priv(dev
);
818 *hfunc
= ETH_RSS_HASH_TOP
;
823 for (i
= 0; i
< QED_RSS_IND_TABLE_SIZE
; i
++)
824 indir
[i
] = edev
->rss_params
.rss_ind_table
[i
];
827 memcpy(key
, edev
->rss_params
.rss_key
,
828 qede_get_rxfh_key_size(dev
));
833 static int qede_set_rxfh(struct net_device
*dev
, const u32
*indir
,
834 const u8
*key
, const u8 hfunc
)
836 struct qed_update_vport_params vport_update_params
;
837 struct qede_dev
*edev
= netdev_priv(dev
);
840 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
)
847 for (i
= 0; i
< QED_RSS_IND_TABLE_SIZE
; i
++)
848 edev
->rss_params
.rss_ind_table
[i
] = indir
[i
];
849 edev
->rss_params_inited
|= QEDE_RSS_INDIR_INITED
;
853 memcpy(&edev
->rss_params
.rss_key
, key
,
854 qede_get_rxfh_key_size(dev
));
855 edev
->rss_params_inited
|= QEDE_RSS_KEY_INITED
;
858 if (netif_running(edev
->ndev
)) {
859 memset(&vport_update_params
, 0, sizeof(vport_update_params
));
860 vport_update_params
.update_rss_flg
= 1;
861 vport_update_params
.vport_id
= 0;
862 memcpy(&vport_update_params
.rss_params
, &edev
->rss_params
,
863 sizeof(vport_update_params
.rss_params
));
864 return edev
->ops
->vport_update(edev
->cdev
,
865 &vport_update_params
);
871 /* This function enables the interrupt generation and the NAPI on the device */
872 static void qede_netif_start(struct qede_dev
*edev
)
876 if (!netif_running(edev
->ndev
))
880 /* Update and reenable interrupts */
881 qed_sb_ack(edev
->fp_array
[i
].sb_info
, IGU_INT_ENABLE
, 1);
882 napi_enable(&edev
->fp_array
[i
].napi
);
886 /* This function disables the NAPI and the interrupt generation on the device */
887 static void qede_netif_stop(struct qede_dev
*edev
)
892 napi_disable(&edev
->fp_array
[i
].napi
);
893 /* Disable interrupts */
894 qed_sb_ack(edev
->fp_array
[i
].sb_info
, IGU_INT_DISABLE
, 0);
898 static int qede_selftest_transmit_traffic(struct qede_dev
*edev
,
901 struct qede_tx_queue
*txq
= &edev
->fp_array
[0].txqs
[0];
902 struct eth_tx_1st_bd
*first_bd
;
906 /* Fill the entry in the SW ring and the BDs in the FW ring */
907 idx
= txq
->sw_tx_prod
& NUM_TX_BDS_MAX
;
908 txq
->sw_tx_ring
[idx
].skb
= skb
;
909 first_bd
= qed_chain_produce(&txq
->tx_pbl
);
910 memset(first_bd
, 0, sizeof(*first_bd
));
911 val
= 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT
;
912 first_bd
->data
.bd_flags
.bitfields
= val
;
913 val
= skb
->len
& ETH_TX_DATA_1ST_BD_PKT_LEN_MASK
;
914 first_bd
->data
.bitfields
|= (val
<< ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT
);
916 /* Map skb linear data for DMA and set in the first BD */
917 mapping
= dma_map_single(&edev
->pdev
->dev
, skb
->data
,
918 skb_headlen(skb
), DMA_TO_DEVICE
);
919 if (unlikely(dma_mapping_error(&edev
->pdev
->dev
, mapping
))) {
920 DP_NOTICE(edev
, "SKB mapping failed\n");
923 BD_SET_UNMAP_ADDR_LEN(first_bd
, mapping
, skb_headlen(skb
));
925 /* update the first BD with the actual num BDs */
926 first_bd
->data
.nbds
= 1;
928 /* 'next page' entries are counted in the producer value */
929 val
= cpu_to_le16(qed_chain_get_prod_idx(&txq
->tx_pbl
));
930 txq
->tx_db
.data
.bd_prod
= val
;
932 /* wmb makes sure that the BDs data is updated before updating the
933 * producer, otherwise FW may read old data from the BDs.
937 writel(txq
->tx_db
.raw
, txq
->doorbell_addr
);
939 /* mmiowb is needed to synchronize doorbell writes from more than one
940 * processor. It guarantees that the write arrives to the device before
941 * the queue lock is released and another start_xmit is called (possibly
942 * on another CPU). Without this barrier, the next doorbell can bypass
943 * this doorbell. This is applicable to IA64/Altix systems.
947 for (i
= 0; i
< QEDE_SELFTEST_POLL_COUNT
; i
++) {
948 if (qede_txq_has_work(txq
))
950 usleep_range(100, 200);
953 if (!qede_txq_has_work(txq
)) {
954 DP_NOTICE(edev
, "Tx completion didn't happen\n");
958 first_bd
= (struct eth_tx_1st_bd
*)qed_chain_consume(&txq
->tx_pbl
);
959 dma_unmap_page(&edev
->pdev
->dev
, BD_UNMAP_ADDR(first_bd
),
960 BD_UNMAP_LEN(first_bd
), DMA_TO_DEVICE
);
962 txq
->sw_tx_ring
[idx
].skb
= NULL
;
967 static int qede_selftest_receive_traffic(struct qede_dev
*edev
)
969 struct qede_rx_queue
*rxq
= edev
->fp_array
[0].rxq
;
970 u16 hw_comp_cons
, sw_comp_cons
, sw_rx_index
, len
;
971 struct eth_fast_path_rx_reg_cqe
*fp_cqe
;
972 struct sw_rx_data
*sw_rx_data
;
973 union eth_rx_cqe
*cqe
;
977 /* The packet is expected to receive on rx-queue 0 even though RSS is
978 * enabled. This is because the queue 0 is configured as the default
979 * queue and that the loopback traffic is not IP.
981 for (i
= 0; i
< QEDE_SELFTEST_POLL_COUNT
; i
++) {
982 if (qede_has_rx_work(rxq
))
984 usleep_range(100, 200);
987 if (!qede_has_rx_work(rxq
)) {
988 DP_NOTICE(edev
, "Failed to receive the traffic\n");
992 hw_comp_cons
= le16_to_cpu(*rxq
->hw_cons_ptr
);
993 sw_comp_cons
= qed_chain_get_cons_idx(&rxq
->rx_comp_ring
);
995 /* Memory barrier to prevent the CPU from doing speculative reads of CQE
996 * / BD before reading hw_comp_cons. If the CQE is read before it is
997 * written by FW, then FW writes CQE and SB, and then the CPU reads the
998 * hw_comp_cons, it will use an old CQE.
1002 /* Get the CQE from the completion ring */
1003 cqe
= (union eth_rx_cqe
*)qed_chain_consume(&rxq
->rx_comp_ring
);
1005 /* Get the data from the SW ring */
1006 sw_rx_index
= rxq
->sw_rx_cons
& NUM_RX_BDS_MAX
;
1007 sw_rx_data
= &rxq
->sw_rx_ring
[sw_rx_index
];
1008 fp_cqe
= &cqe
->fast_path_regular
;
1009 len
= le16_to_cpu(fp_cqe
->len_on_first_bd
);
1010 data_ptr
= (u8
*)(page_address(sw_rx_data
->data
) +
1011 fp_cqe
->placement_offset
+ sw_rx_data
->page_offset
);
1012 for (i
= ETH_HLEN
; i
< len
; i
++)
1013 if (data_ptr
[i
] != (unsigned char)(i
& 0xff)) {
1014 DP_NOTICE(edev
, "Loopback test failed\n");
1015 qede_recycle_rx_bd_ring(rxq
, edev
, 1);
1019 qede_recycle_rx_bd_ring(rxq
, edev
, 1);
1024 static int qede_selftest_run_loopback(struct qede_dev
*edev
, u32 loopback_mode
)
1026 struct qed_link_params link_params
;
1027 struct sk_buff
*skb
= NULL
;
1032 if (!netif_running(edev
->ndev
)) {
1033 DP_NOTICE(edev
, "Interface is down\n");
1037 qede_netif_stop(edev
);
1039 /* Bring up the link in Loopback mode */
1040 memset(&link_params
, 0, sizeof(link_params
));
1041 link_params
.link_up
= true;
1042 link_params
.override_flags
= QED_LINK_OVERRIDE_LOOPBACK_MODE
;
1043 link_params
.loopback_mode
= loopback_mode
;
1044 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
1046 /* Wait for loopback configuration to apply */
1047 msleep_interruptible(500);
1049 /* prepare the loopback packet */
1050 pkt_size
= edev
->ndev
->mtu
+ ETH_HLEN
;
1052 skb
= netdev_alloc_skb(edev
->ndev
, pkt_size
);
1054 DP_INFO(edev
, "Can't allocate skb\n");
1056 goto test_loopback_exit
;
1058 packet
= skb_put(skb
, pkt_size
);
1059 ether_addr_copy(packet
, edev
->ndev
->dev_addr
);
1060 ether_addr_copy(packet
+ ETH_ALEN
, edev
->ndev
->dev_addr
);
1061 memset(packet
+ (2 * ETH_ALEN
), 0x77, (ETH_HLEN
- (2 * ETH_ALEN
)));
1062 for (i
= ETH_HLEN
; i
< pkt_size
; i
++)
1063 packet
[i
] = (unsigned char)(i
& 0xff);
1065 rc
= qede_selftest_transmit_traffic(edev
, skb
);
1067 goto test_loopback_exit
;
1069 rc
= qede_selftest_receive_traffic(edev
);
1071 goto test_loopback_exit
;
1073 DP_VERBOSE(edev
, NETIF_MSG_RX_STATUS
, "Loopback test successful\n");
1078 /* Bring up the link in Normal mode */
1079 memset(&link_params
, 0, sizeof(link_params
));
1080 link_params
.link_up
= true;
1081 link_params
.override_flags
= QED_LINK_OVERRIDE_LOOPBACK_MODE
;
1082 link_params
.loopback_mode
= QED_LINK_LOOPBACK_NONE
;
1083 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
1085 /* Wait for loopback configuration to apply */
1086 msleep_interruptible(500);
1088 qede_netif_start(edev
);
1093 static void qede_self_test(struct net_device
*dev
,
1094 struct ethtool_test
*etest
, u64
*buf
)
1096 struct qede_dev
*edev
= netdev_priv(dev
);
1098 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
1099 "Self-test command parameters: offline = %d, external_lb = %d\n",
1100 (etest
->flags
& ETH_TEST_FL_OFFLINE
),
1101 (etest
->flags
& ETH_TEST_FL_EXTERNAL_LB
) >> 2);
1103 memset(buf
, 0, sizeof(u64
) * QEDE_ETHTOOL_TEST_MAX
);
1105 if (etest
->flags
& ETH_TEST_FL_OFFLINE
) {
1106 if (qede_selftest_run_loopback(edev
,
1107 QED_LINK_LOOPBACK_INT_PHY
)) {
1108 buf
[QEDE_ETHTOOL_INT_LOOPBACK
] = 1;
1109 etest
->flags
|= ETH_TEST_FL_FAILED
;
1113 if (edev
->ops
->common
->selftest
->selftest_interrupt(edev
->cdev
)) {
1114 buf
[QEDE_ETHTOOL_INTERRUPT_TEST
] = 1;
1115 etest
->flags
|= ETH_TEST_FL_FAILED
;
1118 if (edev
->ops
->common
->selftest
->selftest_memory(edev
->cdev
)) {
1119 buf
[QEDE_ETHTOOL_MEMORY_TEST
] = 1;
1120 etest
->flags
|= ETH_TEST_FL_FAILED
;
1123 if (edev
->ops
->common
->selftest
->selftest_register(edev
->cdev
)) {
1124 buf
[QEDE_ETHTOOL_REGISTER_TEST
] = 1;
1125 etest
->flags
|= ETH_TEST_FL_FAILED
;
1128 if (edev
->ops
->common
->selftest
->selftest_clock(edev
->cdev
)) {
1129 buf
[QEDE_ETHTOOL_CLOCK_TEST
] = 1;
1130 etest
->flags
|= ETH_TEST_FL_FAILED
;
1134 static const struct ethtool_ops qede_ethtool_ops
= {
1135 .get_settings
= qede_get_settings
,
1136 .set_settings
= qede_set_settings
,
1137 .get_drvinfo
= qede_get_drvinfo
,
1138 .get_msglevel
= qede_get_msglevel
,
1139 .set_msglevel
= qede_set_msglevel
,
1140 .nway_reset
= qede_nway_reset
,
1141 .get_link
= qede_get_link
,
1142 .get_ringparam
= qede_get_ringparam
,
1143 .set_ringparam
= qede_set_ringparam
,
1144 .get_pauseparam
= qede_get_pauseparam
,
1145 .set_pauseparam
= qede_set_pauseparam
,
1146 .get_strings
= qede_get_strings
,
1147 .set_phys_id
= qede_set_phys_id
,
1148 .get_ethtool_stats
= qede_get_ethtool_stats
,
1149 .get_priv_flags
= qede_get_priv_flags
,
1150 .get_sset_count
= qede_get_sset_count
,
1151 .get_rxnfc
= qede_get_rxnfc
,
1152 .set_rxnfc
= qede_set_rxnfc
,
1153 .get_rxfh_indir_size
= qede_get_rxfh_indir_size
,
1154 .get_rxfh_key_size
= qede_get_rxfh_key_size
,
1155 .get_rxfh
= qede_get_rxfh
,
1156 .set_rxfh
= qede_set_rxfh
,
1157 .get_channels
= qede_get_channels
,
1158 .set_channels
= qede_set_channels
,
1159 .self_test
= qede_self_test
,
1162 static const struct ethtool_ops qede_vf_ethtool_ops
= {
1163 .get_settings
= qede_get_settings
,
1164 .get_drvinfo
= qede_get_drvinfo
,
1165 .get_msglevel
= qede_get_msglevel
,
1166 .set_msglevel
= qede_set_msglevel
,
1167 .get_link
= qede_get_link
,
1168 .get_ringparam
= qede_get_ringparam
,
1169 .set_ringparam
= qede_set_ringparam
,
1170 .get_strings
= qede_get_strings
,
1171 .get_ethtool_stats
= qede_get_ethtool_stats
,
1172 .get_priv_flags
= qede_get_priv_flags
,
1173 .get_sset_count
= qede_get_sset_count
,
1174 .get_rxnfc
= qede_get_rxnfc
,
1175 .set_rxnfc
= qede_set_rxnfc
,
1176 .get_rxfh_indir_size
= qede_get_rxfh_indir_size
,
1177 .get_rxfh_key_size
= qede_get_rxfh_key_size
,
1178 .get_rxfh
= qede_get_rxfh
,
1179 .set_rxfh
= qede_set_rxfh
,
1180 .get_channels
= qede_get_channels
,
1181 .set_channels
= qede_set_channels
,
1184 void qede_set_ethtool_ops(struct net_device
*dev
)
1186 struct qede_dev
*edev
= netdev_priv(dev
);
1189 dev
->ethtool_ops
= &qede_vf_ethtool_ops
;
1191 dev
->ethtool_ops
= &qede_ethtool_ops
;