2 * Copyright (C) 2015 Cavium, Inc.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License
6 * as published by the Free Software Foundation.
9 /* ETHTOOL Support for VNIC_VF Device*/
11 #include <linux/pci.h>
12 #include <linux/net_tstamp.h>
16 #include "nicvf_queues.h"
18 #include "thunder_bgx.h"
19 #include "../common/cavium_ptp.h"
21 #define DRV_NAME "nicvf"
22 #define DRV_VERSION "1.0"
25 char name[ETH_GSTRING_LEN];
29 #define NICVF_HW_STAT(stat) { \
31 .index = offsetof(struct nicvf_hw_stats, stat) / sizeof(u64), \
34 #define NICVF_DRV_STAT(stat) { \
36 .index = offsetof(struct nicvf_drv_stats, stat) / sizeof(u64), \
39 static const struct nicvf_stat nicvf_hw_stats[] = {
40 NICVF_HW_STAT(rx_bytes),
41 NICVF_HW_STAT(rx_frames),
42 NICVF_HW_STAT(rx_ucast_frames),
43 NICVF_HW_STAT(rx_bcast_frames),
44 NICVF_HW_STAT(rx_mcast_frames),
45 NICVF_HW_STAT(rx_drops),
46 NICVF_HW_STAT(rx_drop_red),
47 NICVF_HW_STAT(rx_drop_red_bytes),
48 NICVF_HW_STAT(rx_drop_overrun),
49 NICVF_HW_STAT(rx_drop_overrun_bytes),
50 NICVF_HW_STAT(rx_drop_bcast),
51 NICVF_HW_STAT(rx_drop_mcast),
52 NICVF_HW_STAT(rx_drop_l3_bcast),
53 NICVF_HW_STAT(rx_drop_l3_mcast),
54 NICVF_HW_STAT(rx_fcs_errors),
55 NICVF_HW_STAT(rx_l2_errors),
56 NICVF_HW_STAT(tx_bytes),
57 NICVF_HW_STAT(tx_frames),
58 NICVF_HW_STAT(tx_ucast_frames),
59 NICVF_HW_STAT(tx_bcast_frames),
60 NICVF_HW_STAT(tx_mcast_frames),
61 NICVF_HW_STAT(tx_drops),
64 static const struct nicvf_stat nicvf_drv_stats[] = {
65 NICVF_DRV_STAT(rx_bgx_truncated_pkts),
66 NICVF_DRV_STAT(rx_jabber_errs),
67 NICVF_DRV_STAT(rx_fcs_errs),
68 NICVF_DRV_STAT(rx_bgx_errs),
69 NICVF_DRV_STAT(rx_prel2_errs),
70 NICVF_DRV_STAT(rx_l2_hdr_malformed),
71 NICVF_DRV_STAT(rx_oversize),
72 NICVF_DRV_STAT(rx_undersize),
73 NICVF_DRV_STAT(rx_l2_len_mismatch),
74 NICVF_DRV_STAT(rx_l2_pclp),
75 NICVF_DRV_STAT(rx_ip_ver_errs),
76 NICVF_DRV_STAT(rx_ip_csum_errs),
77 NICVF_DRV_STAT(rx_ip_hdr_malformed),
78 NICVF_DRV_STAT(rx_ip_payload_malformed),
79 NICVF_DRV_STAT(rx_ip_ttl_errs),
80 NICVF_DRV_STAT(rx_l3_pclp),
81 NICVF_DRV_STAT(rx_l4_malformed),
82 NICVF_DRV_STAT(rx_l4_csum_errs),
83 NICVF_DRV_STAT(rx_udp_len_errs),
84 NICVF_DRV_STAT(rx_l4_port_errs),
85 NICVF_DRV_STAT(rx_tcp_flag_errs),
86 NICVF_DRV_STAT(rx_tcp_offset_errs),
87 NICVF_DRV_STAT(rx_l4_pclp),
88 NICVF_DRV_STAT(rx_truncated_pkts),
90 NICVF_DRV_STAT(tx_desc_fault),
91 NICVF_DRV_STAT(tx_hdr_cons_err),
92 NICVF_DRV_STAT(tx_subdesc_err),
93 NICVF_DRV_STAT(tx_max_size_exceeded),
94 NICVF_DRV_STAT(tx_imm_size_oflow),
95 NICVF_DRV_STAT(tx_data_seq_err),
96 NICVF_DRV_STAT(tx_mem_seq_err),
97 NICVF_DRV_STAT(tx_lock_viol),
98 NICVF_DRV_STAT(tx_data_fault),
99 NICVF_DRV_STAT(tx_tstmp_conflict),
100 NICVF_DRV_STAT(tx_tstmp_timeout),
101 NICVF_DRV_STAT(tx_mem_fault),
102 NICVF_DRV_STAT(tx_csum_overlap),
103 NICVF_DRV_STAT(tx_csum_overflow),
105 NICVF_DRV_STAT(tx_tso),
106 NICVF_DRV_STAT(tx_timeout),
107 NICVF_DRV_STAT(txq_stop),
108 NICVF_DRV_STAT(txq_wake),
109 NICVF_DRV_STAT(rcv_buffer_alloc_failures),
110 NICVF_DRV_STAT(page_alloc),
113 static const struct nicvf_stat nicvf_queue_stats[] = {
118 static const unsigned int nicvf_n_hw_stats = ARRAY_SIZE(nicvf_hw_stats);
119 static const unsigned int nicvf_n_drv_stats = ARRAY_SIZE(nicvf_drv_stats);
120 static const unsigned int nicvf_n_queue_stats = ARRAY_SIZE(nicvf_queue_stats);
122 static int nicvf_get_link_ksettings(struct net_device *netdev,
123 struct ethtool_link_ksettings *cmd)
125 struct nicvf *nic = netdev_priv(netdev);
126 u32 supported, advertising;
132 cmd->base.duplex = DUPLEX_UNKNOWN;
133 cmd->base.speed = SPEED_UNKNOWN;
137 switch (nic->speed) {
139 cmd->base.port = PORT_MII | PORT_TP;
140 cmd->base.autoneg = AUTONEG_ENABLE;
141 supported |= SUPPORTED_MII | SUPPORTED_TP;
142 supported |= SUPPORTED_1000baseT_Full |
143 SUPPORTED_1000baseT_Half |
144 SUPPORTED_100baseT_Full |
145 SUPPORTED_100baseT_Half |
146 SUPPORTED_10baseT_Full |
147 SUPPORTED_10baseT_Half;
148 supported |= SUPPORTED_Autoneg;
149 advertising |= ADVERTISED_1000baseT_Full |
150 ADVERTISED_1000baseT_Half |
151 ADVERTISED_100baseT_Full |
152 ADVERTISED_100baseT_Half |
153 ADVERTISED_10baseT_Full |
154 ADVERTISED_10baseT_Half;
157 if (nic->mac_type == BGX_MODE_RXAUI) {
158 cmd->base.port = PORT_TP;
159 supported |= SUPPORTED_TP;
161 cmd->base.port = PORT_FIBRE;
162 supported |= SUPPORTED_FIBRE;
164 cmd->base.autoneg = AUTONEG_DISABLE;
165 supported |= SUPPORTED_10000baseT_Full;
168 cmd->base.port = PORT_FIBRE;
169 cmd->base.autoneg = AUTONEG_DISABLE;
170 supported |= SUPPORTED_FIBRE;
171 supported |= SUPPORTED_40000baseCR4_Full;
174 cmd->base.duplex = nic->duplex;
175 cmd->base.speed = nic->speed;
177 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
179 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
185 static u32 nicvf_get_link(struct net_device *netdev)
187 struct nicvf *nic = netdev_priv(netdev);
192 static void nicvf_get_drvinfo(struct net_device *netdev,
193 struct ethtool_drvinfo *info)
195 struct nicvf *nic = netdev_priv(netdev);
197 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
198 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
199 strlcpy(info->bus_info, pci_name(nic->pdev), sizeof(info->bus_info));
202 static u32 nicvf_get_msglevel(struct net_device *netdev)
204 struct nicvf *nic = netdev_priv(netdev);
206 return nic->msg_enable;
209 static void nicvf_set_msglevel(struct net_device *netdev, u32 lvl)
211 struct nicvf *nic = netdev_priv(netdev);
213 nic->msg_enable = lvl;
216 static void nicvf_get_qset_strings(struct nicvf *nic, u8 **data, int qset)
219 int start_qidx = qset * MAX_RCV_QUEUES_PER_QS;
221 for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
222 for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
223 sprintf(*data, "rxq%d: %s", qidx + start_qidx,
224 nicvf_queue_stats[stats].name);
225 *data += ETH_GSTRING_LEN;
229 for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
230 for (stats = 0; stats < nicvf_n_queue_stats; stats++) {
231 sprintf(*data, "txq%d: %s", qidx + start_qidx,
232 nicvf_queue_stats[stats].name);
233 *data += ETH_GSTRING_LEN;
238 static void nicvf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
240 struct nicvf *nic = netdev_priv(netdev);
244 if (sset != ETH_SS_STATS)
247 for (stats = 0; stats < nicvf_n_hw_stats; stats++) {
248 memcpy(data, nicvf_hw_stats[stats].name, ETH_GSTRING_LEN);
249 data += ETH_GSTRING_LEN;
252 for (stats = 0; stats < nicvf_n_drv_stats; stats++) {
253 memcpy(data, nicvf_drv_stats[stats].name, ETH_GSTRING_LEN);
254 data += ETH_GSTRING_LEN;
257 nicvf_get_qset_strings(nic, &data, 0);
259 for (sqs = 0; sqs < nic->sqs_count; sqs++) {
260 if (!nic->snicvf[sqs])
262 nicvf_get_qset_strings(nic->snicvf[sqs], &data, sqs + 1);
265 for (stats = 0; stats < BGX_RX_STATS_COUNT; stats++) {
266 sprintf(data, "bgx_rxstat%d: ", stats);
267 data += ETH_GSTRING_LEN;
270 for (stats = 0; stats < BGX_TX_STATS_COUNT; stats++) {
271 sprintf(data, "bgx_txstat%d: ", stats);
272 data += ETH_GSTRING_LEN;
276 static int nicvf_get_sset_count(struct net_device *netdev, int sset)
278 struct nicvf *nic = netdev_priv(netdev);
282 if (sset != ETH_SS_STATS)
285 qstats_count = nicvf_n_queue_stats *
286 (nic->qs->rq_cnt + nic->qs->sq_cnt);
287 for (sqs = 0; sqs < nic->sqs_count; sqs++) {
290 snic = nic->snicvf[sqs];
293 qstats_count += nicvf_n_queue_stats *
294 (snic->qs->rq_cnt + snic->qs->sq_cnt);
297 return nicvf_n_hw_stats + nicvf_n_drv_stats +
299 BGX_RX_STATS_COUNT + BGX_TX_STATS_COUNT;
302 static void nicvf_get_qset_stats(struct nicvf *nic,
303 struct ethtool_stats *stats, u64 **data)
310 for (qidx = 0; qidx < nic->qs->rq_cnt; qidx++) {
311 nicvf_update_rq_stats(nic, qidx);
312 for (stat = 0; stat < nicvf_n_queue_stats; stat++)
313 *((*data)++) = ((u64 *)&nic->qs->rq[qidx].stats)
314 [nicvf_queue_stats[stat].index];
317 for (qidx = 0; qidx < nic->qs->sq_cnt; qidx++) {
318 nicvf_update_sq_stats(nic, qidx);
319 for (stat = 0; stat < nicvf_n_queue_stats; stat++)
320 *((*data)++) = ((u64 *)&nic->qs->sq[qidx].stats)
321 [nicvf_queue_stats[stat].index];
325 static void nicvf_get_ethtool_stats(struct net_device *netdev,
326 struct ethtool_stats *stats, u64 *data)
328 struct nicvf *nic = netdev_priv(netdev);
332 nicvf_update_stats(nic);
334 /* Update LMAC stats */
335 nicvf_update_lmac_stats(nic);
337 for (stat = 0; stat < nicvf_n_hw_stats; stat++)
338 *(data++) = ((u64 *)&nic->hw_stats)
339 [nicvf_hw_stats[stat].index];
340 for (stat = 0; stat < nicvf_n_drv_stats; stat++) {
342 for_each_possible_cpu(cpu)
343 tmp_stats += ((u64 *)per_cpu_ptr(nic->drv_stats, cpu))
344 [nicvf_drv_stats[stat].index];
345 *(data++) = tmp_stats;
348 nicvf_get_qset_stats(nic, stats, &data);
350 for (sqs = 0; sqs < nic->sqs_count; sqs++) {
351 if (!nic->snicvf[sqs])
353 nicvf_get_qset_stats(nic->snicvf[sqs], stats, &data);
356 for (stat = 0; stat < BGX_RX_STATS_COUNT; stat++)
357 *(data++) = nic->bgx_stats.rx_stats[stat];
358 for (stat = 0; stat < BGX_TX_STATS_COUNT; stat++)
359 *(data++) = nic->bgx_stats.tx_stats[stat];
362 static int nicvf_get_regs_len(struct net_device *dev)
364 return sizeof(u64) * NIC_VF_REG_COUNT;
367 static void nicvf_get_regs(struct net_device *dev,
368 struct ethtool_regs *regs, void *reg)
370 struct nicvf *nic = netdev_priv(dev);
373 int mbox, key, stat, q;
377 memset(p, 0, NIC_VF_REG_COUNT);
379 p[i++] = nicvf_reg_read(nic, NIC_VNIC_CFG);
380 /* Mailbox registers */
381 for (mbox = 0; mbox < NIC_PF_VF_MAILBOX_SIZE; mbox++)
382 p[i++] = nicvf_reg_read(nic,
383 NIC_VF_PF_MAILBOX_0_1 | (mbox << 3));
385 p[i++] = nicvf_reg_read(nic, NIC_VF_INT);
386 p[i++] = nicvf_reg_read(nic, NIC_VF_INT_W1S);
387 p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1C);
388 p[i++] = nicvf_reg_read(nic, NIC_VF_ENA_W1S);
389 p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
391 for (key = 0; key < RSS_HASH_KEY_SIZE; key++)
392 p[i++] = nicvf_reg_read(nic, NIC_VNIC_RSS_KEY_0_4 | (key << 3));
394 /* Tx/Rx statistics */
395 for (stat = 0; stat < TX_STATS_ENUM_LAST; stat++)
396 p[i++] = nicvf_reg_read(nic,
397 NIC_VNIC_TX_STAT_0_4 | (stat << 3));
399 for (i = 0; i < RX_STATS_ENUM_LAST; i++)
400 p[i++] = nicvf_reg_read(nic,
401 NIC_VNIC_RX_STAT_0_13 | (stat << 3));
403 p[i++] = nicvf_reg_read(nic, NIC_QSET_RQ_GEN_CFG);
405 /* All completion queue's registers */
406 for (q = 0; q < MAX_CMP_QUEUES_PER_QS; q++) {
407 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG, q);
408 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_CFG2, q);
409 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_THRESH, q);
410 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_BASE, q);
411 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_HEAD, q);
412 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_TAIL, q);
413 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DOOR, q);
414 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS, q);
415 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_STATUS2, q);
416 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_CQ_0_7_DEBUG, q);
419 /* All receive queue's registers */
420 for (q = 0; q < MAX_RCV_QUEUES_PER_QS; q++) {
421 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RQ_0_7_CFG, q);
422 p[i++] = nicvf_queue_reg_read(nic,
423 NIC_QSET_RQ_0_7_STAT_0_1, q);
424 reg_offset = NIC_QSET_RQ_0_7_STAT_0_1 | (1 << 3);
425 p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
428 for (q = 0; q < MAX_SND_QUEUES_PER_QS; q++) {
429 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_CFG, q);
430 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_THRESH, q);
431 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_BASE, q);
432 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_HEAD, q);
433 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_TAIL, q);
434 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DOOR, q);
435 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STATUS, q);
436 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_DEBUG, q);
437 /* Padding, was NIC_QSET_SQ_0_7_CNM_CHG, which
438 * produces bus errors when read
441 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_SQ_0_7_STAT_0_1, q);
442 reg_offset = NIC_QSET_SQ_0_7_STAT_0_1 | (1 << 3);
443 p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
446 for (q = 0; q < MAX_RCV_BUF_DESC_RINGS_PER_QS; q++) {
447 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_CFG, q);
448 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_THRESH, q);
449 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_BASE, q);
450 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_HEAD, q);
451 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_TAIL, q);
452 p[i++] = nicvf_queue_reg_read(nic, NIC_QSET_RBDR_0_1_DOOR, q);
453 p[i++] = nicvf_queue_reg_read(nic,
454 NIC_QSET_RBDR_0_1_STATUS0, q);
455 p[i++] = nicvf_queue_reg_read(nic,
456 NIC_QSET_RBDR_0_1_STATUS1, q);
457 reg_offset = NIC_QSET_RBDR_0_1_PREFETCH_STATUS;
458 p[i++] = nicvf_queue_reg_read(nic, reg_offset, q);
462 static int nicvf_get_coalesce(struct net_device *netdev,
463 struct ethtool_coalesce *cmd)
465 struct nicvf *nic = netdev_priv(netdev);
467 cmd->rx_coalesce_usecs = nic->cq_coalesce_usecs;
471 static void nicvf_get_ringparam(struct net_device *netdev,
472 struct ethtool_ringparam *ring)
474 struct nicvf *nic = netdev_priv(netdev);
475 struct queue_set *qs = nic->qs;
477 ring->rx_max_pending = MAX_CMP_QUEUE_LEN;
478 ring->rx_pending = qs->cq_len;
479 ring->tx_max_pending = MAX_SND_QUEUE_LEN;
480 ring->tx_pending = qs->sq_len;
483 static int nicvf_set_ringparam(struct net_device *netdev,
484 struct ethtool_ringparam *ring)
486 struct nicvf *nic = netdev_priv(netdev);
487 struct queue_set *qs = nic->qs;
488 u32 rx_count, tx_count;
490 /* Due to HW errata this is not supported on T88 pass 1.x silicon */
491 if (pass1_silicon(nic->pdev))
494 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
497 tx_count = clamp_t(u32, ring->tx_pending,
498 MIN_SND_QUEUE_LEN, MAX_SND_QUEUE_LEN);
499 rx_count = clamp_t(u32, ring->rx_pending,
500 MIN_CMP_QUEUE_LEN, MAX_CMP_QUEUE_LEN);
502 if ((tx_count == qs->sq_len) && (rx_count == qs->cq_len))
505 /* Permitted lengths are 1K, 2K, 4K, 8K, 16K, 32K, 64K */
506 qs->sq_len = rounddown_pow_of_two(tx_count);
507 qs->cq_len = rounddown_pow_of_two(rx_count);
509 if (netif_running(netdev)) {
517 static int nicvf_get_rss_hash_opts(struct nicvf *nic,
518 struct ethtool_rxnfc *info)
522 switch (info->flow_type) {
529 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
533 info->data |= RXH_IP_SRC | RXH_IP_DST;
542 static int nicvf_get_rxnfc(struct net_device *dev,
543 struct ethtool_rxnfc *info, u32 *rules)
545 struct nicvf *nic = netdev_priv(dev);
546 int ret = -EOPNOTSUPP;
549 case ETHTOOL_GRXRINGS:
550 info->data = nic->rx_queues;
554 return nicvf_get_rss_hash_opts(nic, info);
561 static int nicvf_set_rss_hash_opts(struct nicvf *nic,
562 struct ethtool_rxnfc *info)
564 struct nicvf_rss_info *rss = &nic->rss_info;
565 u64 rss_cfg = nicvf_reg_read(nic, NIC_VNIC_RSS_CFG);
568 netdev_err(nic->netdev,
569 "RSS is disabled, hash cannot be set\n");
571 netdev_info(nic->netdev, "Set RSS flow type = %d, data = %lld\n",
572 info->flow_type, info->data);
574 if (!(info->data & RXH_IP_SRC) || !(info->data & RXH_IP_DST))
577 switch (info->flow_type) {
580 switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
582 rss_cfg &= ~(1ULL << RSS_HASH_TCP);
584 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
585 rss_cfg |= (1ULL << RSS_HASH_TCP);
593 switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
595 rss_cfg &= ~(1ULL << RSS_HASH_UDP);
597 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
598 rss_cfg |= (1ULL << RSS_HASH_UDP);
606 switch (info->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
608 rss_cfg &= ~(1ULL << RSS_HASH_L4ETC);
610 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
611 rss_cfg |= (1ULL << RSS_HASH_L4ETC);
619 rss_cfg = RSS_HASH_IP;
625 nicvf_reg_write(nic, NIC_VNIC_RSS_CFG, rss_cfg);
629 static int nicvf_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
631 struct nicvf *nic = netdev_priv(dev);
635 return nicvf_set_rss_hash_opts(nic, info);
642 static u32 nicvf_get_rxfh_key_size(struct net_device *netdev)
644 return RSS_HASH_KEY_SIZE * sizeof(u64);
647 static u32 nicvf_get_rxfh_indir_size(struct net_device *dev)
649 struct nicvf *nic = netdev_priv(dev);
651 return nic->rss_info.rss_size;
654 static int nicvf_get_rxfh(struct net_device *dev, u32 *indir, u8 *hkey,
657 struct nicvf *nic = netdev_priv(dev);
658 struct nicvf_rss_info *rss = &nic->rss_info;
662 for (idx = 0; idx < rss->rss_size; idx++)
663 indir[idx] = rss->ind_tbl[idx];
667 memcpy(hkey, rss->key, RSS_HASH_KEY_SIZE * sizeof(u64));
670 *hfunc = ETH_RSS_HASH_TOP;
675 static int nicvf_set_rxfh(struct net_device *dev, const u32 *indir,
676 const u8 *hkey, const u8 hfunc)
678 struct nicvf *nic = netdev_priv(dev);
679 struct nicvf_rss_info *rss = &nic->rss_info;
682 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
686 netdev_err(nic->netdev,
687 "RSS is disabled, cannot change settings\n");
692 for (idx = 0; idx < rss->rss_size; idx++)
693 rss->ind_tbl[idx] = indir[idx];
697 memcpy(rss->key, hkey, RSS_HASH_KEY_SIZE * sizeof(u64));
698 nicvf_set_rss_key(nic);
701 nicvf_config_rss(nic);
705 /* Get no of queues device supports and current queue count */
706 static void nicvf_get_channels(struct net_device *dev,
707 struct ethtool_channels *channel)
709 struct nicvf *nic = netdev_priv(dev);
711 memset(channel, 0, sizeof(*channel));
713 channel->max_rx = nic->max_queues;
714 channel->max_tx = nic->max_queues;
716 channel->rx_count = nic->rx_queues;
717 channel->tx_count = nic->tx_queues;
720 /* Set no of Tx, Rx queues to be used */
721 static int nicvf_set_channels(struct net_device *dev,
722 struct ethtool_channels *channel)
724 struct nicvf *nic = netdev_priv(dev);
726 bool if_up = netif_running(dev);
727 u8 cqcount, txq_count;
729 if (!channel->rx_count || !channel->tx_count)
731 if (channel->rx_count > nic->max_queues)
733 if (channel->tx_count > nic->max_queues)
737 ((channel->tx_count + channel->rx_count) > nic->max_queues)) {
738 netdev_err(nic->netdev,
739 "XDP mode, RXQs + TXQs > Max %d\n",
747 nic->rx_queues = channel->rx_count;
748 nic->tx_queues = channel->tx_count;
750 nic->xdp_tx_queues = 0;
752 nic->xdp_tx_queues = channel->rx_count;
754 txq_count = nic->xdp_tx_queues + nic->tx_queues;
755 cqcount = max(nic->rx_queues, txq_count);
757 if (cqcount > MAX_CMP_QUEUES_PER_QS) {
758 nic->sqs_count = roundup(cqcount, MAX_CMP_QUEUES_PER_QS);
759 nic->sqs_count = (nic->sqs_count / MAX_CMP_QUEUES_PER_QS) - 1;
764 nic->qs->rq_cnt = min_t(u8, nic->rx_queues, MAX_RCV_QUEUES_PER_QS);
765 nic->qs->sq_cnt = min_t(u8, txq_count, MAX_SND_QUEUES_PER_QS);
766 nic->qs->cq_cnt = max(nic->qs->rq_cnt, nic->qs->sq_cnt);
768 err = nicvf_set_real_num_queues(dev, nic->tx_queues, nic->rx_queues);
775 netdev_info(dev, "Setting num Tx rings to %d, Rx rings to %d success\n",
776 nic->tx_queues, nic->rx_queues);
781 static void nicvf_get_pauseparam(struct net_device *dev,
782 struct ethtool_pauseparam *pause)
784 struct nicvf *nic = netdev_priv(dev);
785 union nic_mbx mbx = {};
787 /* Supported only for 10G/40G interfaces */
788 if ((nic->mac_type == BGX_MODE_SGMII) ||
789 (nic->mac_type == BGX_MODE_QSGMII) ||
790 (nic->mac_type == BGX_MODE_RGMII))
793 mbx.pfc.msg = NIC_MBOX_MSG_PFC;
795 if (!nicvf_send_msg_to_pf(nic, &mbx)) {
796 pause->autoneg = nic->pfc.autoneg;
797 pause->rx_pause = nic->pfc.fc_rx;
798 pause->tx_pause = nic->pfc.fc_tx;
802 static int nicvf_set_pauseparam(struct net_device *dev,
803 struct ethtool_pauseparam *pause)
805 struct nicvf *nic = netdev_priv(dev);
806 union nic_mbx mbx = {};
808 /* Supported only for 10G/40G interfaces */
809 if ((nic->mac_type == BGX_MODE_SGMII) ||
810 (nic->mac_type == BGX_MODE_QSGMII) ||
811 (nic->mac_type == BGX_MODE_RGMII))
817 mbx.pfc.msg = NIC_MBOX_MSG_PFC;
819 mbx.pfc.fc_rx = pause->rx_pause;
820 mbx.pfc.fc_tx = pause->tx_pause;
821 if (nicvf_send_msg_to_pf(nic, &mbx))
824 nic->pfc.fc_rx = pause->rx_pause;
825 nic->pfc.fc_tx = pause->tx_pause;
830 static int nicvf_get_ts_info(struct net_device *netdev,
831 struct ethtool_ts_info *info)
833 struct nicvf *nic = netdev_priv(netdev);
836 return ethtool_op_get_ts_info(netdev, info);
838 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
839 SOF_TIMESTAMPING_RX_SOFTWARE |
840 SOF_TIMESTAMPING_SOFTWARE |
841 SOF_TIMESTAMPING_TX_HARDWARE |
842 SOF_TIMESTAMPING_RX_HARDWARE |
843 SOF_TIMESTAMPING_RAW_HARDWARE;
845 info->phc_index = cavium_ptp_clock_index(nic->ptp_clock);
847 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
849 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
850 (1 << HWTSTAMP_FILTER_ALL);
855 static const struct ethtool_ops nicvf_ethtool_ops = {
856 .get_link = nicvf_get_link,
857 .get_drvinfo = nicvf_get_drvinfo,
858 .get_msglevel = nicvf_get_msglevel,
859 .set_msglevel = nicvf_set_msglevel,
860 .get_strings = nicvf_get_strings,
861 .get_sset_count = nicvf_get_sset_count,
862 .get_ethtool_stats = nicvf_get_ethtool_stats,
863 .get_regs_len = nicvf_get_regs_len,
864 .get_regs = nicvf_get_regs,
865 .get_coalesce = nicvf_get_coalesce,
866 .get_ringparam = nicvf_get_ringparam,
867 .set_ringparam = nicvf_set_ringparam,
868 .get_rxnfc = nicvf_get_rxnfc,
869 .set_rxnfc = nicvf_set_rxnfc,
870 .get_rxfh_key_size = nicvf_get_rxfh_key_size,
871 .get_rxfh_indir_size = nicvf_get_rxfh_indir_size,
872 .get_rxfh = nicvf_get_rxfh,
873 .set_rxfh = nicvf_set_rxfh,
874 .get_channels = nicvf_get_channels,
875 .set_channels = nicvf_set_channels,
876 .get_pauseparam = nicvf_get_pauseparam,
877 .set_pauseparam = nicvf_set_pauseparam,
878 .get_ts_info = nicvf_get_ts_info,
879 .get_link_ksettings = nicvf_get_link_ksettings,
882 void nicvf_set_ethtool_ops(struct net_device *netdev)
884 netdev->ethtool_ops = &nicvf_ethtool_ops;