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
),
40 QEDE_RQSTAT(rx_ip_frags
),
43 #define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
44 #define QEDE_RQSTATS_DATA(dev, sindex, rqindex) \
45 (*((u64 *)(((char *)(dev->fp_array[(rqindex)].rxq)) +\
46 qede_rqstats_arr[(sindex)].offset)))
49 char string
[ETH_GSTRING_LEN
];
51 } qede_stats_arr
[] = {
52 QEDE_STAT(rx_ucast_bytes
),
53 QEDE_STAT(rx_mcast_bytes
),
54 QEDE_STAT(rx_bcast_bytes
),
55 QEDE_STAT(rx_ucast_pkts
),
56 QEDE_STAT(rx_mcast_pkts
),
57 QEDE_STAT(rx_bcast_pkts
),
59 QEDE_STAT(tx_ucast_bytes
),
60 QEDE_STAT(tx_mcast_bytes
),
61 QEDE_STAT(tx_bcast_bytes
),
62 QEDE_STAT(tx_ucast_pkts
),
63 QEDE_STAT(tx_mcast_pkts
),
64 QEDE_STAT(tx_bcast_pkts
),
66 QEDE_PF_STAT(rx_64_byte_packets
),
67 QEDE_PF_STAT(rx_65_to_127_byte_packets
),
68 QEDE_PF_STAT(rx_128_to_255_byte_packets
),
69 QEDE_PF_STAT(rx_256_to_511_byte_packets
),
70 QEDE_PF_STAT(rx_512_to_1023_byte_packets
),
71 QEDE_PF_STAT(rx_1024_to_1518_byte_packets
),
72 QEDE_PF_STAT(rx_1519_to_1522_byte_packets
),
73 QEDE_PF_STAT(rx_1519_to_2047_byte_packets
),
74 QEDE_PF_STAT(rx_2048_to_4095_byte_packets
),
75 QEDE_PF_STAT(rx_4096_to_9216_byte_packets
),
76 QEDE_PF_STAT(rx_9217_to_16383_byte_packets
),
77 QEDE_PF_STAT(tx_64_byte_packets
),
78 QEDE_PF_STAT(tx_65_to_127_byte_packets
),
79 QEDE_PF_STAT(tx_128_to_255_byte_packets
),
80 QEDE_PF_STAT(tx_256_to_511_byte_packets
),
81 QEDE_PF_STAT(tx_512_to_1023_byte_packets
),
82 QEDE_PF_STAT(tx_1024_to_1518_byte_packets
),
83 QEDE_PF_STAT(tx_1519_to_2047_byte_packets
),
84 QEDE_PF_STAT(tx_2048_to_4095_byte_packets
),
85 QEDE_PF_STAT(tx_4096_to_9216_byte_packets
),
86 QEDE_PF_STAT(tx_9217_to_16383_byte_packets
),
88 QEDE_PF_STAT(rx_mac_crtl_frames
),
89 QEDE_PF_STAT(tx_mac_ctrl_frames
),
90 QEDE_PF_STAT(rx_pause_frames
),
91 QEDE_PF_STAT(tx_pause_frames
),
92 QEDE_PF_STAT(rx_pfc_frames
),
93 QEDE_PF_STAT(tx_pfc_frames
),
95 QEDE_PF_STAT(rx_crc_errors
),
96 QEDE_PF_STAT(rx_align_errors
),
97 QEDE_PF_STAT(rx_carrier_errors
),
98 QEDE_PF_STAT(rx_oversize_packets
),
99 QEDE_PF_STAT(rx_jabbers
),
100 QEDE_PF_STAT(rx_undersize_packets
),
101 QEDE_PF_STAT(rx_fragments
),
102 QEDE_PF_STAT(tx_lpi_entry_count
),
103 QEDE_PF_STAT(tx_total_collisions
),
104 QEDE_PF_STAT(brb_truncates
),
105 QEDE_PF_STAT(brb_discards
),
106 QEDE_STAT(no_buff_discards
),
107 QEDE_PF_STAT(mftag_filter_discards
),
108 QEDE_PF_STAT(mac_filter_discards
),
109 QEDE_STAT(tx_err_drop_pkts
),
111 QEDE_STAT(coalesced_pkts
),
112 QEDE_STAT(coalesced_events
),
113 QEDE_STAT(coalesced_aborts_num
),
114 QEDE_STAT(non_coalesced_pkts
),
115 QEDE_STAT(coalesced_bytes
),
118 #define QEDE_STATS_DATA(dev, index) \
119 (*((u64 *)(((char *)(dev)) + offsetof(struct qede_dev, stats) \
120 + qede_stats_arr[(index)].offset)))
122 #define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
129 static const char qede_private_arr
[QEDE_PRI_FLAG_LEN
][ETH_GSTRING_LEN
] = {
133 enum qede_ethtool_tests
{
134 QEDE_ETHTOOL_INT_LOOPBACK
,
135 QEDE_ETHTOOL_INTERRUPT_TEST
,
136 QEDE_ETHTOOL_MEMORY_TEST
,
137 QEDE_ETHTOOL_REGISTER_TEST
,
138 QEDE_ETHTOOL_CLOCK_TEST
,
139 QEDE_ETHTOOL_TEST_MAX
142 static const char qede_tests_str_arr
[QEDE_ETHTOOL_TEST_MAX
][ETH_GSTRING_LEN
] = {
143 "Internal loopback (offline)",
144 "Interrupt (online)\t",
145 "Memory (online)\t\t",
146 "Register (online)\t",
147 "Clock (online)\t\t",
150 static void qede_get_strings_stats(struct qede_dev
*edev
, u8
*buf
)
154 for (i
= 0, j
= 0; i
< QEDE_NUM_STATS
; i
++) {
155 if (IS_VF(edev
) && qede_stats_arr
[i
].pf_only
)
157 strcpy(buf
+ j
* ETH_GSTRING_LEN
,
158 qede_stats_arr
[i
].string
);
162 for (k
= 0; k
< QEDE_NUM_RQSTATS
; k
++, j
++)
163 strcpy(buf
+ j
* ETH_GSTRING_LEN
,
164 qede_rqstats_arr
[k
].string
);
167 static void qede_get_strings(struct net_device
*dev
, u32 stringset
, u8
*buf
)
169 struct qede_dev
*edev
= netdev_priv(dev
);
173 qede_get_strings_stats(edev
, buf
);
175 case ETH_SS_PRIV_FLAGS
:
176 memcpy(buf
, qede_private_arr
,
177 ETH_GSTRING_LEN
* QEDE_PRI_FLAG_LEN
);
180 memcpy(buf
, qede_tests_str_arr
,
181 ETH_GSTRING_LEN
* QEDE_ETHTOOL_TEST_MAX
);
184 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
185 "Unsupported stringset 0x%08x\n", stringset
);
189 static void qede_get_ethtool_stats(struct net_device
*dev
,
190 struct ethtool_stats
*stats
, u64
*buf
)
192 struct qede_dev
*edev
= netdev_priv(dev
);
196 qede_fill_by_demand_stats(edev
);
198 mutex_lock(&edev
->qede_lock
);
200 for (sidx
= 0; sidx
< QEDE_NUM_STATS
; sidx
++) {
201 if (IS_VF(edev
) && qede_stats_arr
[sidx
].pf_only
)
203 buf
[cnt
++] = QEDE_STATS_DATA(edev
, sidx
);
206 for (sidx
= 0; sidx
< QEDE_NUM_RQSTATS
; sidx
++) {
208 for (qid
= 0; qid
< edev
->num_rss
; qid
++)
209 buf
[cnt
] += QEDE_RQSTATS_DATA(edev
, sidx
, qid
);
213 mutex_unlock(&edev
->qede_lock
);
216 static int qede_get_sset_count(struct net_device
*dev
, int stringset
)
218 struct qede_dev
*edev
= netdev_priv(dev
);
219 int num_stats
= QEDE_NUM_STATS
;
226 for (i
= 0; i
< QEDE_NUM_STATS
; i
++)
227 if (qede_stats_arr
[i
].pf_only
)
230 return num_stats
+ QEDE_NUM_RQSTATS
;
231 case ETH_SS_PRIV_FLAGS
:
232 return QEDE_PRI_FLAG_LEN
;
235 return QEDE_ETHTOOL_TEST_MAX
;
239 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
240 "Unsupported stringset 0x%08x\n", stringset
);
245 static u32
qede_get_priv_flags(struct net_device
*dev
)
247 struct qede_dev
*edev
= netdev_priv(dev
);
249 return (!!(edev
->dev_info
.common
.num_hwfns
> 1)) << QEDE_PRI_FLAG_CMT
;
252 static int qede_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
254 struct qede_dev
*edev
= netdev_priv(dev
);
255 struct qed_link_output current_link
;
257 memset(¤t_link
, 0, sizeof(current_link
));
258 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
260 cmd
->supported
= current_link
.supported_caps
;
261 cmd
->advertising
= current_link
.advertised_caps
;
262 if ((edev
->state
== QEDE_STATE_OPEN
) && (current_link
.link_up
)) {
263 ethtool_cmd_speed_set(cmd
, current_link
.speed
);
264 cmd
->duplex
= current_link
.duplex
;
266 cmd
->duplex
= DUPLEX_UNKNOWN
;
267 ethtool_cmd_speed_set(cmd
, SPEED_UNKNOWN
);
269 cmd
->port
= current_link
.port
;
270 cmd
->autoneg
= (current_link
.autoneg
) ? AUTONEG_ENABLE
:
272 cmd
->lp_advertising
= current_link
.lp_caps
;
277 static int qede_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
279 struct qede_dev
*edev
= netdev_priv(dev
);
280 struct qed_link_output current_link
;
281 struct qed_link_params params
;
284 if (!edev
->ops
|| !edev
->ops
->common
->can_link_change(edev
->cdev
)) {
286 "Link settings are not allowed to be changed\n");
290 memset(¤t_link
, 0, sizeof(current_link
));
291 memset(¶ms
, 0, sizeof(params
));
292 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
294 speed
= ethtool_cmd_speed(cmd
);
295 params
.override_flags
|= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS
;
296 params
.override_flags
|= QED_LINK_OVERRIDE_SPEED_AUTONEG
;
297 if (cmd
->autoneg
== AUTONEG_ENABLE
) {
298 params
.autoneg
= true;
299 params
.forced_speed
= 0;
300 params
.adv_speeds
= cmd
->advertising
;
301 } else { /* forced speed */
302 params
.override_flags
|= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED
;
303 params
.autoneg
= false;
304 params
.forced_speed
= speed
;
307 if (!(current_link
.supported_caps
&
308 SUPPORTED_10000baseKR_Full
)) {
309 DP_INFO(edev
, "10G speed not supported\n");
312 params
.adv_speeds
= SUPPORTED_10000baseKR_Full
;
315 if (!(current_link
.supported_caps
&
316 SUPPORTED_40000baseLR4_Full
)) {
317 DP_INFO(edev
, "40G speed not supported\n");
320 params
.adv_speeds
= SUPPORTED_40000baseLR4_Full
;
323 DP_INFO(edev
, "Unsupported speed %u\n", speed
);
328 params
.link_up
= true;
329 edev
->ops
->common
->set_link(edev
->cdev
, ¶ms
);
334 static void qede_get_drvinfo(struct net_device
*ndev
,
335 struct ethtool_drvinfo
*info
)
337 char mfw
[ETHTOOL_FWVERS_LEN
], storm
[ETHTOOL_FWVERS_LEN
];
338 struct qede_dev
*edev
= netdev_priv(ndev
);
340 strlcpy(info
->driver
, "qede", sizeof(info
->driver
));
341 strlcpy(info
->version
, DRV_MODULE_VERSION
, sizeof(info
->version
));
343 snprintf(storm
, ETHTOOL_FWVERS_LEN
, "%d.%d.%d.%d",
344 edev
->dev_info
.common
.fw_major
,
345 edev
->dev_info
.common
.fw_minor
,
346 edev
->dev_info
.common
.fw_rev
,
347 edev
->dev_info
.common
.fw_eng
);
349 snprintf(mfw
, ETHTOOL_FWVERS_LEN
, "%d.%d.%d.%d",
350 (edev
->dev_info
.common
.mfw_rev
>> 24) & 0xFF,
351 (edev
->dev_info
.common
.mfw_rev
>> 16) & 0xFF,
352 (edev
->dev_info
.common
.mfw_rev
>> 8) & 0xFF,
353 edev
->dev_info
.common
.mfw_rev
& 0xFF);
355 if ((strlen(storm
) + strlen(mfw
) + strlen("mfw storm ")) <
356 sizeof(info
->fw_version
)) {
357 snprintf(info
->fw_version
, sizeof(info
->fw_version
),
358 "mfw %s storm %s", mfw
, storm
);
360 snprintf(info
->fw_version
, sizeof(info
->fw_version
),
361 "%s %s", mfw
, storm
);
364 strlcpy(info
->bus_info
, pci_name(edev
->pdev
), sizeof(info
->bus_info
));
367 static u32
qede_get_msglevel(struct net_device
*ndev
)
369 struct qede_dev
*edev
= netdev_priv(ndev
);
371 return ((u32
)edev
->dp_level
<< QED_LOG_LEVEL_SHIFT
) |
375 static void qede_set_msglevel(struct net_device
*ndev
, u32 level
)
377 struct qede_dev
*edev
= netdev_priv(ndev
);
381 qede_config_debug(level
, &dp_module
, &dp_level
);
383 edev
->dp_level
= dp_level
;
384 edev
->dp_module
= dp_module
;
385 edev
->ops
->common
->update_msglvl(edev
->cdev
,
386 dp_module
, dp_level
);
389 static int qede_nway_reset(struct net_device
*dev
)
391 struct qede_dev
*edev
= netdev_priv(dev
);
392 struct qed_link_output current_link
;
393 struct qed_link_params link_params
;
395 if (!edev
->ops
|| !edev
->ops
->common
->can_link_change(edev
->cdev
)) {
397 "Link settings are not allowed to be changed\n");
401 if (!netif_running(dev
))
404 memset(¤t_link
, 0, sizeof(current_link
));
405 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
406 if (!current_link
.link_up
)
409 /* Toggle the link */
410 memset(&link_params
, 0, sizeof(link_params
));
411 link_params
.link_up
= false;
412 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
413 link_params
.link_up
= true;
414 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
419 static u32
qede_get_link(struct net_device
*dev
)
421 struct qede_dev
*edev
= netdev_priv(dev
);
422 struct qed_link_output current_link
;
424 memset(¤t_link
, 0, sizeof(current_link
));
425 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
427 return current_link
.link_up
;
430 static int qede_get_coalesce(struct net_device
*dev
,
431 struct ethtool_coalesce
*coal
)
433 struct qede_dev
*edev
= netdev_priv(dev
);
436 memset(coal
, 0, sizeof(struct ethtool_coalesce
));
437 edev
->ops
->common
->get_coalesce(edev
->cdev
, &rxc
, &txc
);
439 coal
->rx_coalesce_usecs
= rxc
;
440 coal
->tx_coalesce_usecs
= txc
;
445 static int qede_set_coalesce(struct net_device
*dev
,
446 struct ethtool_coalesce
*coal
)
448 struct qede_dev
*edev
= netdev_priv(dev
);
453 if (!netif_running(dev
)) {
454 DP_INFO(edev
, "Interface is down\n");
458 if (coal
->rx_coalesce_usecs
> QED_COALESCE_MAX
||
459 coal
->tx_coalesce_usecs
> QED_COALESCE_MAX
) {
461 "Can't support requested %s coalesce value [max supported value %d]\n",
462 coal
->rx_coalesce_usecs
> QED_COALESCE_MAX
? "rx"
468 rxc
= (u16
)coal
->rx_coalesce_usecs
;
469 txc
= (u16
)coal
->tx_coalesce_usecs
;
471 sb_id
= edev
->fp_array
[i
].sb_info
->igu_sb_id
;
472 rc
= edev
->ops
->common
->set_coalesce(edev
->cdev
, rxc
, txc
,
475 DP_INFO(edev
, "Set coalesce error, rc = %d\n", rc
);
483 static void qede_get_ringparam(struct net_device
*dev
,
484 struct ethtool_ringparam
*ering
)
486 struct qede_dev
*edev
= netdev_priv(dev
);
488 ering
->rx_max_pending
= NUM_RX_BDS_MAX
;
489 ering
->rx_pending
= edev
->q_num_rx_buffers
;
490 ering
->tx_max_pending
= NUM_TX_BDS_MAX
;
491 ering
->tx_pending
= edev
->q_num_tx_buffers
;
494 static int qede_set_ringparam(struct net_device
*dev
,
495 struct ethtool_ringparam
*ering
)
497 struct qede_dev
*edev
= netdev_priv(dev
);
499 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
500 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
501 ering
->rx_pending
, ering
->tx_pending
);
503 /* Validate legality of configuration */
504 if (ering
->rx_pending
> NUM_RX_BDS_MAX
||
505 ering
->rx_pending
< NUM_RX_BDS_MIN
||
506 ering
->tx_pending
> NUM_TX_BDS_MAX
||
507 ering
->tx_pending
< NUM_TX_BDS_MIN
) {
508 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
509 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
510 NUM_RX_BDS_MIN
, NUM_RX_BDS_MAX
,
511 NUM_TX_BDS_MIN
, NUM_TX_BDS_MAX
);
515 /* Change ring size and re-load */
516 edev
->q_num_rx_buffers
= ering
->rx_pending
;
517 edev
->q_num_tx_buffers
= ering
->tx_pending
;
519 if (netif_running(edev
->ndev
))
520 qede_reload(edev
, NULL
, NULL
);
525 static void qede_get_pauseparam(struct net_device
*dev
,
526 struct ethtool_pauseparam
*epause
)
528 struct qede_dev
*edev
= netdev_priv(dev
);
529 struct qed_link_output current_link
;
531 memset(¤t_link
, 0, sizeof(current_link
));
532 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
534 if (current_link
.pause_config
& QED_LINK_PAUSE_AUTONEG_ENABLE
)
535 epause
->autoneg
= true;
536 if (current_link
.pause_config
& QED_LINK_PAUSE_RX_ENABLE
)
537 epause
->rx_pause
= true;
538 if (current_link
.pause_config
& QED_LINK_PAUSE_TX_ENABLE
)
539 epause
->tx_pause
= true;
541 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
542 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
543 epause
->cmd
, epause
->autoneg
, epause
->rx_pause
,
547 static int qede_set_pauseparam(struct net_device
*dev
,
548 struct ethtool_pauseparam
*epause
)
550 struct qede_dev
*edev
= netdev_priv(dev
);
551 struct qed_link_params params
;
552 struct qed_link_output current_link
;
554 if (!edev
->ops
|| !edev
->ops
->common
->can_link_change(edev
->cdev
)) {
556 "Pause settings are not allowed to be changed\n");
560 memset(¤t_link
, 0, sizeof(current_link
));
561 edev
->ops
->common
->get_link(edev
->cdev
, ¤t_link
);
563 memset(¶ms
, 0, sizeof(params
));
564 params
.override_flags
|= QED_LINK_OVERRIDE_PAUSE_CONFIG
;
565 if (epause
->autoneg
) {
566 if (!(current_link
.supported_caps
& SUPPORTED_Autoneg
)) {
567 DP_INFO(edev
, "autoneg not supported\n");
570 params
.pause_config
|= QED_LINK_PAUSE_AUTONEG_ENABLE
;
572 if (epause
->rx_pause
)
573 params
.pause_config
|= QED_LINK_PAUSE_RX_ENABLE
;
574 if (epause
->tx_pause
)
575 params
.pause_config
|= QED_LINK_PAUSE_TX_ENABLE
;
577 params
.link_up
= true;
578 edev
->ops
->common
->set_link(edev
->cdev
, ¶ms
);
583 static void qede_update_mtu(struct qede_dev
*edev
, union qede_reload_args
*args
)
585 edev
->ndev
->mtu
= args
->mtu
;
589 #define ETH_MAX_JUMBO_PACKET_SIZE 9600
590 #define ETH_MIN_PACKET_SIZE 60
591 int qede_change_mtu(struct net_device
*ndev
, int new_mtu
)
593 struct qede_dev
*edev
= netdev_priv(ndev
);
594 union qede_reload_args args
;
596 if ((new_mtu
> ETH_MAX_JUMBO_PACKET_SIZE
) ||
597 ((new_mtu
+ ETH_HLEN
) < ETH_MIN_PACKET_SIZE
)) {
598 DP_ERR(edev
, "Can't support requested MTU size\n");
602 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
603 "Configuring MTU size of %d\n", new_mtu
);
605 /* Set the mtu field and re-start the interface if needed*/
608 if (netif_running(edev
->ndev
))
609 qede_reload(edev
, &qede_update_mtu
, &args
);
611 qede_update_mtu(edev
, &args
);
616 static void qede_get_channels(struct net_device
*dev
,
617 struct ethtool_channels
*channels
)
619 struct qede_dev
*edev
= netdev_priv(dev
);
621 channels
->max_combined
= QEDE_MAX_RSS_CNT(edev
);
622 channels
->combined_count
= QEDE_RSS_CNT(edev
);
625 static int qede_set_channels(struct net_device
*dev
,
626 struct ethtool_channels
*channels
)
628 struct qede_dev
*edev
= netdev_priv(dev
);
630 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
631 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
632 channels
->rx_count
, channels
->tx_count
,
633 channels
->other_count
, channels
->combined_count
);
635 /* We don't support separate rx / tx, nor `other' channels. */
636 if (channels
->rx_count
|| channels
->tx_count
||
637 channels
->other_count
|| (channels
->combined_count
== 0) ||
638 (channels
->combined_count
> QEDE_MAX_RSS_CNT(edev
))) {
639 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
640 "command parameters not supported\n");
644 /* Check if there was a change in the active parameters */
645 if (channels
->combined_count
== QEDE_RSS_CNT(edev
)) {
646 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
647 "No change in active parameters\n");
651 /* We need the number of queues to be divisible between the hwfns */
652 if (channels
->combined_count
% edev
->dev_info
.common
.num_hwfns
) {
653 DP_VERBOSE(edev
, (NETIF_MSG_IFUP
| NETIF_MSG_IFDOWN
),
654 "Number of channels must be divisable by %04x\n",
655 edev
->dev_info
.common
.num_hwfns
);
659 /* Set number of queues and reload if necessary */
660 edev
->req_rss
= channels
->combined_count
;
661 if (netif_running(dev
))
662 qede_reload(edev
, NULL
, NULL
);
667 static int qede_set_phys_id(struct net_device
*dev
,
668 enum ethtool_phys_id_state state
)
670 struct qede_dev
*edev
= netdev_priv(dev
);
674 case ETHTOOL_ID_ACTIVE
:
675 return 1; /* cycle on/off once per second */
678 led_state
= QED_LED_MODE_ON
;
682 led_state
= QED_LED_MODE_OFF
;
685 case ETHTOOL_ID_INACTIVE
:
686 led_state
= QED_LED_MODE_RESTORE
;
690 edev
->ops
->common
->set_led(edev
->cdev
, led_state
);
695 static int qede_get_rss_flags(struct qede_dev
*edev
, struct ethtool_rxnfc
*info
)
697 info
->data
= RXH_IP_SRC
| RXH_IP_DST
;
699 switch (info
->flow_type
) {
702 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
705 if (edev
->rss_params
.rss_caps
& QED_RSS_IPV4_UDP
)
706 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
709 if (edev
->rss_params
.rss_caps
& QED_RSS_IPV6_UDP
)
710 info
->data
|= RXH_L4_B_0_1
| RXH_L4_B_2_3
;
723 static int qede_get_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*info
,
724 u32
*rules __always_unused
)
726 struct qede_dev
*edev
= netdev_priv(dev
);
729 case ETHTOOL_GRXRINGS
:
730 info
->data
= edev
->num_rss
;
733 return qede_get_rss_flags(edev
, info
);
735 DP_ERR(edev
, "Command parameters not supported\n");
740 static int qede_set_rss_flags(struct qede_dev
*edev
, struct ethtool_rxnfc
*info
)
742 struct qed_update_vport_params vport_update_params
;
743 u8 set_caps
= 0, clr_caps
= 0;
745 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
746 "Set rss flags command parameters: flow type = %d, data = %llu\n",
747 info
->flow_type
, info
->data
);
749 switch (info
->flow_type
) {
752 /* For TCP only 4-tuple hash is supported */
753 if (info
->data
^ (RXH_IP_SRC
| RXH_IP_DST
|
754 RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
755 DP_INFO(edev
, "Command parameters not supported\n");
760 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
761 if (info
->data
== (RXH_IP_SRC
| RXH_IP_DST
|
762 RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
763 set_caps
= QED_RSS_IPV4_UDP
;
764 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
765 "UDP 4-tuple enabled\n");
766 } else if (info
->data
== (RXH_IP_SRC
| RXH_IP_DST
)) {
767 clr_caps
= QED_RSS_IPV4_UDP
;
768 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
769 "UDP 4-tuple disabled\n");
775 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
776 if (info
->data
== (RXH_IP_SRC
| RXH_IP_DST
|
777 RXH_L4_B_0_1
| RXH_L4_B_2_3
)) {
778 set_caps
= QED_RSS_IPV6_UDP
;
779 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
780 "UDP 4-tuple enabled\n");
781 } else if (info
->data
== (RXH_IP_SRC
| RXH_IP_DST
)) {
782 clr_caps
= QED_RSS_IPV6_UDP
;
783 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
784 "UDP 4-tuple disabled\n");
791 /* For IP only 2-tuple hash is supported */
792 if (info
->data
^ (RXH_IP_SRC
| RXH_IP_DST
)) {
793 DP_INFO(edev
, "Command parameters not supported\n");
807 /* RSS is not supported for these protocols */
809 DP_INFO(edev
, "Command parameters not supported\n");
817 /* No action is needed if there is no change in the rss capability */
818 if (edev
->rss_params
.rss_caps
== ((edev
->rss_params
.rss_caps
&
819 ~clr_caps
) | set_caps
))
822 /* Update internal configuration */
823 edev
->rss_params
.rss_caps
= (edev
->rss_params
.rss_caps
& ~clr_caps
) |
825 edev
->rss_params_inited
|= QEDE_RSS_CAPS_INITED
;
827 /* Re-configure if possible */
828 if (netif_running(edev
->ndev
)) {
829 memset(&vport_update_params
, 0, sizeof(vport_update_params
));
830 vport_update_params
.update_rss_flg
= 1;
831 vport_update_params
.vport_id
= 0;
832 memcpy(&vport_update_params
.rss_params
, &edev
->rss_params
,
833 sizeof(vport_update_params
.rss_params
));
834 return edev
->ops
->vport_update(edev
->cdev
,
835 &vport_update_params
);
841 static int qede_set_rxnfc(struct net_device
*dev
, struct ethtool_rxnfc
*info
)
843 struct qede_dev
*edev
= netdev_priv(dev
);
847 return qede_set_rss_flags(edev
, info
);
849 DP_INFO(edev
, "Command parameters not supported\n");
854 static u32
qede_get_rxfh_indir_size(struct net_device
*dev
)
856 return QED_RSS_IND_TABLE_SIZE
;
859 static u32
qede_get_rxfh_key_size(struct net_device
*dev
)
861 struct qede_dev
*edev
= netdev_priv(dev
);
863 return sizeof(edev
->rss_params
.rss_key
);
866 static int qede_get_rxfh(struct net_device
*dev
, u32
*indir
, u8
*key
, u8
*hfunc
)
868 struct qede_dev
*edev
= netdev_priv(dev
);
872 *hfunc
= ETH_RSS_HASH_TOP
;
877 for (i
= 0; i
< QED_RSS_IND_TABLE_SIZE
; i
++)
878 indir
[i
] = edev
->rss_params
.rss_ind_table
[i
];
881 memcpy(key
, edev
->rss_params
.rss_key
,
882 qede_get_rxfh_key_size(dev
));
887 static int qede_set_rxfh(struct net_device
*dev
, const u32
*indir
,
888 const u8
*key
, const u8 hfunc
)
890 struct qed_update_vport_params vport_update_params
;
891 struct qede_dev
*edev
= netdev_priv(dev
);
894 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
)
901 for (i
= 0; i
< QED_RSS_IND_TABLE_SIZE
; i
++)
902 edev
->rss_params
.rss_ind_table
[i
] = indir
[i
];
903 edev
->rss_params_inited
|= QEDE_RSS_INDIR_INITED
;
907 memcpy(&edev
->rss_params
.rss_key
, key
,
908 qede_get_rxfh_key_size(dev
));
909 edev
->rss_params_inited
|= QEDE_RSS_KEY_INITED
;
912 if (netif_running(edev
->ndev
)) {
913 memset(&vport_update_params
, 0, sizeof(vport_update_params
));
914 vport_update_params
.update_rss_flg
= 1;
915 vport_update_params
.vport_id
= 0;
916 memcpy(&vport_update_params
.rss_params
, &edev
->rss_params
,
917 sizeof(vport_update_params
.rss_params
));
918 return edev
->ops
->vport_update(edev
->cdev
,
919 &vport_update_params
);
925 /* This function enables the interrupt generation and the NAPI on the device */
926 static void qede_netif_start(struct qede_dev
*edev
)
930 if (!netif_running(edev
->ndev
))
934 /* Update and reenable interrupts */
935 qed_sb_ack(edev
->fp_array
[i
].sb_info
, IGU_INT_ENABLE
, 1);
936 napi_enable(&edev
->fp_array
[i
].napi
);
940 /* This function disables the NAPI and the interrupt generation on the device */
941 static void qede_netif_stop(struct qede_dev
*edev
)
946 napi_disable(&edev
->fp_array
[i
].napi
);
947 /* Disable interrupts */
948 qed_sb_ack(edev
->fp_array
[i
].sb_info
, IGU_INT_DISABLE
, 0);
952 static int qede_selftest_transmit_traffic(struct qede_dev
*edev
,
955 struct qede_tx_queue
*txq
= &edev
->fp_array
[0].txqs
[0];
956 struct eth_tx_1st_bd
*first_bd
;
960 /* Fill the entry in the SW ring and the BDs in the FW ring */
961 idx
= txq
->sw_tx_prod
& NUM_TX_BDS_MAX
;
962 txq
->sw_tx_ring
[idx
].skb
= skb
;
963 first_bd
= qed_chain_produce(&txq
->tx_pbl
);
964 memset(first_bd
, 0, sizeof(*first_bd
));
965 val
= 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT
;
966 first_bd
->data
.bd_flags
.bitfields
= val
;
967 val
= skb
->len
& ETH_TX_DATA_1ST_BD_PKT_LEN_MASK
;
968 first_bd
->data
.bitfields
|= (val
<< ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT
);
970 /* Map skb linear data for DMA and set in the first BD */
971 mapping
= dma_map_single(&edev
->pdev
->dev
, skb
->data
,
972 skb_headlen(skb
), DMA_TO_DEVICE
);
973 if (unlikely(dma_mapping_error(&edev
->pdev
->dev
, mapping
))) {
974 DP_NOTICE(edev
, "SKB mapping failed\n");
977 BD_SET_UNMAP_ADDR_LEN(first_bd
, mapping
, skb_headlen(skb
));
979 /* update the first BD with the actual num BDs */
980 first_bd
->data
.nbds
= 1;
982 /* 'next page' entries are counted in the producer value */
983 val
= cpu_to_le16(qed_chain_get_prod_idx(&txq
->tx_pbl
));
984 txq
->tx_db
.data
.bd_prod
= val
;
986 /* wmb makes sure that the BDs data is updated before updating the
987 * producer, otherwise FW may read old data from the BDs.
991 writel(txq
->tx_db
.raw
, txq
->doorbell_addr
);
993 /* mmiowb is needed to synchronize doorbell writes from more than one
994 * processor. It guarantees that the write arrives to the device before
995 * the queue lock is released and another start_xmit is called (possibly
996 * on another CPU). Without this barrier, the next doorbell can bypass
997 * this doorbell. This is applicable to IA64/Altix systems.
1001 for (i
= 0; i
< QEDE_SELFTEST_POLL_COUNT
; i
++) {
1002 if (qede_txq_has_work(txq
))
1004 usleep_range(100, 200);
1007 if (!qede_txq_has_work(txq
)) {
1008 DP_NOTICE(edev
, "Tx completion didn't happen\n");
1012 first_bd
= (struct eth_tx_1st_bd
*)qed_chain_consume(&txq
->tx_pbl
);
1013 dma_unmap_page(&edev
->pdev
->dev
, BD_UNMAP_ADDR(first_bd
),
1014 BD_UNMAP_LEN(first_bd
), DMA_TO_DEVICE
);
1016 txq
->sw_tx_ring
[idx
].skb
= NULL
;
1021 static int qede_selftest_receive_traffic(struct qede_dev
*edev
)
1023 struct qede_rx_queue
*rxq
= edev
->fp_array
[0].rxq
;
1024 u16 hw_comp_cons
, sw_comp_cons
, sw_rx_index
, len
;
1025 struct eth_fast_path_rx_reg_cqe
*fp_cqe
;
1026 struct sw_rx_data
*sw_rx_data
;
1027 union eth_rx_cqe
*cqe
;
1031 /* The packet is expected to receive on rx-queue 0 even though RSS is
1032 * enabled. This is because the queue 0 is configured as the default
1033 * queue and that the loopback traffic is not IP.
1035 for (i
= 0; i
< QEDE_SELFTEST_POLL_COUNT
; i
++) {
1036 if (qede_has_rx_work(rxq
))
1038 usleep_range(100, 200);
1041 if (!qede_has_rx_work(rxq
)) {
1042 DP_NOTICE(edev
, "Failed to receive the traffic\n");
1046 hw_comp_cons
= le16_to_cpu(*rxq
->hw_cons_ptr
);
1047 sw_comp_cons
= qed_chain_get_cons_idx(&rxq
->rx_comp_ring
);
1049 /* Memory barrier to prevent the CPU from doing speculative reads of CQE
1050 * / BD before reading hw_comp_cons. If the CQE is read before it is
1051 * written by FW, then FW writes CQE and SB, and then the CPU reads the
1052 * hw_comp_cons, it will use an old CQE.
1056 /* Get the CQE from the completion ring */
1057 cqe
= (union eth_rx_cqe
*)qed_chain_consume(&rxq
->rx_comp_ring
);
1059 /* Get the data from the SW ring */
1060 sw_rx_index
= rxq
->sw_rx_cons
& NUM_RX_BDS_MAX
;
1061 sw_rx_data
= &rxq
->sw_rx_ring
[sw_rx_index
];
1062 fp_cqe
= &cqe
->fast_path_regular
;
1063 len
= le16_to_cpu(fp_cqe
->len_on_first_bd
);
1064 data_ptr
= (u8
*)(page_address(sw_rx_data
->data
) +
1065 fp_cqe
->placement_offset
+ sw_rx_data
->page_offset
);
1066 for (i
= ETH_HLEN
; i
< len
; i
++)
1067 if (data_ptr
[i
] != (unsigned char)(i
& 0xff)) {
1068 DP_NOTICE(edev
, "Loopback test failed\n");
1069 qede_recycle_rx_bd_ring(rxq
, edev
, 1);
1073 qede_recycle_rx_bd_ring(rxq
, edev
, 1);
1078 static int qede_selftest_run_loopback(struct qede_dev
*edev
, u32 loopback_mode
)
1080 struct qed_link_params link_params
;
1081 struct sk_buff
*skb
= NULL
;
1086 if (!netif_running(edev
->ndev
)) {
1087 DP_NOTICE(edev
, "Interface is down\n");
1091 qede_netif_stop(edev
);
1093 /* Bring up the link in Loopback mode */
1094 memset(&link_params
, 0, sizeof(link_params
));
1095 link_params
.link_up
= true;
1096 link_params
.override_flags
= QED_LINK_OVERRIDE_LOOPBACK_MODE
;
1097 link_params
.loopback_mode
= loopback_mode
;
1098 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
1100 /* Wait for loopback configuration to apply */
1101 msleep_interruptible(500);
1103 /* prepare the loopback packet */
1104 pkt_size
= edev
->ndev
->mtu
+ ETH_HLEN
;
1106 skb
= netdev_alloc_skb(edev
->ndev
, pkt_size
);
1108 DP_INFO(edev
, "Can't allocate skb\n");
1110 goto test_loopback_exit
;
1112 packet
= skb_put(skb
, pkt_size
);
1113 ether_addr_copy(packet
, edev
->ndev
->dev_addr
);
1114 ether_addr_copy(packet
+ ETH_ALEN
, edev
->ndev
->dev_addr
);
1115 memset(packet
+ (2 * ETH_ALEN
), 0x77, (ETH_HLEN
- (2 * ETH_ALEN
)));
1116 for (i
= ETH_HLEN
; i
< pkt_size
; i
++)
1117 packet
[i
] = (unsigned char)(i
& 0xff);
1119 rc
= qede_selftest_transmit_traffic(edev
, skb
);
1121 goto test_loopback_exit
;
1123 rc
= qede_selftest_receive_traffic(edev
);
1125 goto test_loopback_exit
;
1127 DP_VERBOSE(edev
, NETIF_MSG_RX_STATUS
, "Loopback test successful\n");
1132 /* Bring up the link in Normal mode */
1133 memset(&link_params
, 0, sizeof(link_params
));
1134 link_params
.link_up
= true;
1135 link_params
.override_flags
= QED_LINK_OVERRIDE_LOOPBACK_MODE
;
1136 link_params
.loopback_mode
= QED_LINK_LOOPBACK_NONE
;
1137 edev
->ops
->common
->set_link(edev
->cdev
, &link_params
);
1139 /* Wait for loopback configuration to apply */
1140 msleep_interruptible(500);
1142 qede_netif_start(edev
);
1147 static void qede_self_test(struct net_device
*dev
,
1148 struct ethtool_test
*etest
, u64
*buf
)
1150 struct qede_dev
*edev
= netdev_priv(dev
);
1152 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
1153 "Self-test command parameters: offline = %d, external_lb = %d\n",
1154 (etest
->flags
& ETH_TEST_FL_OFFLINE
),
1155 (etest
->flags
& ETH_TEST_FL_EXTERNAL_LB
) >> 2);
1157 memset(buf
, 0, sizeof(u64
) * QEDE_ETHTOOL_TEST_MAX
);
1159 if (etest
->flags
& ETH_TEST_FL_OFFLINE
) {
1160 if (qede_selftest_run_loopback(edev
,
1161 QED_LINK_LOOPBACK_INT_PHY
)) {
1162 buf
[QEDE_ETHTOOL_INT_LOOPBACK
] = 1;
1163 etest
->flags
|= ETH_TEST_FL_FAILED
;
1167 if (edev
->ops
->common
->selftest
->selftest_interrupt(edev
->cdev
)) {
1168 buf
[QEDE_ETHTOOL_INTERRUPT_TEST
] = 1;
1169 etest
->flags
|= ETH_TEST_FL_FAILED
;
1172 if (edev
->ops
->common
->selftest
->selftest_memory(edev
->cdev
)) {
1173 buf
[QEDE_ETHTOOL_MEMORY_TEST
] = 1;
1174 etest
->flags
|= ETH_TEST_FL_FAILED
;
1177 if (edev
->ops
->common
->selftest
->selftest_register(edev
->cdev
)) {
1178 buf
[QEDE_ETHTOOL_REGISTER_TEST
] = 1;
1179 etest
->flags
|= ETH_TEST_FL_FAILED
;
1182 if (edev
->ops
->common
->selftest
->selftest_clock(edev
->cdev
)) {
1183 buf
[QEDE_ETHTOOL_CLOCK_TEST
] = 1;
1184 etest
->flags
|= ETH_TEST_FL_FAILED
;
1188 static int qede_set_tunable(struct net_device
*dev
,
1189 const struct ethtool_tunable
*tuna
,
1192 struct qede_dev
*edev
= netdev_priv(dev
);
1196 case ETHTOOL_RX_COPYBREAK
:
1198 if (val
< QEDE_MIN_PKT_LEN
|| val
> QEDE_RX_HDR_SIZE
) {
1199 DP_VERBOSE(edev
, QED_MSG_DEBUG
,
1200 "Invalid rx copy break value, range is [%u, %u]",
1201 QEDE_MIN_PKT_LEN
, QEDE_RX_HDR_SIZE
);
1205 edev
->rx_copybreak
= *(u32
*)data
;
1214 static int qede_get_tunable(struct net_device
*dev
,
1215 const struct ethtool_tunable
*tuna
, void *data
)
1217 struct qede_dev
*edev
= netdev_priv(dev
);
1220 case ETHTOOL_RX_COPYBREAK
:
1221 *(u32
*)data
= edev
->rx_copybreak
;
1230 static const struct ethtool_ops qede_ethtool_ops
= {
1231 .get_settings
= qede_get_settings
,
1232 .set_settings
= qede_set_settings
,
1233 .get_drvinfo
= qede_get_drvinfo
,
1234 .get_msglevel
= qede_get_msglevel
,
1235 .set_msglevel
= qede_set_msglevel
,
1236 .nway_reset
= qede_nway_reset
,
1237 .get_link
= qede_get_link
,
1238 .get_coalesce
= qede_get_coalesce
,
1239 .set_coalesce
= qede_set_coalesce
,
1240 .get_ringparam
= qede_get_ringparam
,
1241 .set_ringparam
= qede_set_ringparam
,
1242 .get_pauseparam
= qede_get_pauseparam
,
1243 .set_pauseparam
= qede_set_pauseparam
,
1244 .get_strings
= qede_get_strings
,
1245 .set_phys_id
= qede_set_phys_id
,
1246 .get_ethtool_stats
= qede_get_ethtool_stats
,
1247 .get_priv_flags
= qede_get_priv_flags
,
1248 .get_sset_count
= qede_get_sset_count
,
1249 .get_rxnfc
= qede_get_rxnfc
,
1250 .set_rxnfc
= qede_set_rxnfc
,
1251 .get_rxfh_indir_size
= qede_get_rxfh_indir_size
,
1252 .get_rxfh_key_size
= qede_get_rxfh_key_size
,
1253 .get_rxfh
= qede_get_rxfh
,
1254 .set_rxfh
= qede_set_rxfh
,
1255 .get_channels
= qede_get_channels
,
1256 .set_channels
= qede_set_channels
,
1257 .self_test
= qede_self_test
,
1258 .get_tunable
= qede_get_tunable
,
1259 .set_tunable
= qede_set_tunable
,
1262 static const struct ethtool_ops qede_vf_ethtool_ops
= {
1263 .get_settings
= qede_get_settings
,
1264 .get_drvinfo
= qede_get_drvinfo
,
1265 .get_msglevel
= qede_get_msglevel
,
1266 .set_msglevel
= qede_set_msglevel
,
1267 .get_link
= qede_get_link
,
1268 .get_ringparam
= qede_get_ringparam
,
1269 .set_ringparam
= qede_set_ringparam
,
1270 .get_strings
= qede_get_strings
,
1271 .get_ethtool_stats
= qede_get_ethtool_stats
,
1272 .get_priv_flags
= qede_get_priv_flags
,
1273 .get_sset_count
= qede_get_sset_count
,
1274 .get_rxnfc
= qede_get_rxnfc
,
1275 .set_rxnfc
= qede_set_rxnfc
,
1276 .get_rxfh_indir_size
= qede_get_rxfh_indir_size
,
1277 .get_rxfh_key_size
= qede_get_rxfh_key_size
,
1278 .get_rxfh
= qede_get_rxfh
,
1279 .set_rxfh
= qede_set_rxfh
,
1280 .get_channels
= qede_get_channels
,
1281 .set_channels
= qede_set_channels
,
1282 .get_tunable
= qede_get_tunable
,
1283 .set_tunable
= qede_set_tunable
,
1286 void qede_set_ethtool_ops(struct net_device
*dev
)
1288 struct qede_dev
*edev
= netdev_priv(dev
);
1291 dev
->ethtool_ops
= &qede_vf_ethtool_ops
;
1293 dev
->ethtool_ops
= &qede_ethtool_ops
;