1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */
4 #include <linux/module.h>
5 #include <linux/netdevice.h>
10 #include "ionic_lif.h"
11 #include "ionic_ethtool.h"
12 #include "ionic_stats.h"
14 static const char ionic_priv_flags_strings[][ETH_GSTRING_LEN] = {
15 #define IONIC_PRIV_F_SW_DBG_STATS BIT(0)
19 #define IONIC_PRIV_FLAGS_COUNT ARRAY_SIZE(ionic_priv_flags_strings)
21 static void ionic_get_stats_strings(struct ionic_lif *lif, u8 *buf)
25 for (i = 0; i < ionic_num_stats_grps; i++)
26 ionic_stats_groups[i].get_strings(lif, &buf);
29 static void ionic_get_stats(struct net_device *netdev,
30 struct ethtool_stats *stats, u64 *buf)
32 struct ionic_lif *lif = netdev_priv(netdev);
35 if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
38 memset(buf, 0, stats->n_stats * sizeof(*buf));
39 for (i = 0; i < ionic_num_stats_grps; i++)
40 ionic_stats_groups[i].get_values(lif, &buf);
43 static int ionic_get_stats_count(struct ionic_lif *lif)
47 for (i = 0; i < ionic_num_stats_grps; i++)
48 num_stats += ionic_stats_groups[i].get_count(lif);
53 static int ionic_get_sset_count(struct net_device *netdev, int sset)
55 struct ionic_lif *lif = netdev_priv(netdev);
60 count = ionic_get_stats_count(lif);
62 case ETH_SS_PRIV_FLAGS:
63 count = IONIC_PRIV_FLAGS_COUNT;
69 static void ionic_get_strings(struct net_device *netdev,
72 struct ionic_lif *lif = netdev_priv(netdev);
76 ionic_get_stats_strings(lif, buf);
78 case ETH_SS_PRIV_FLAGS:
79 memcpy(buf, ionic_priv_flags_strings,
80 IONIC_PRIV_FLAGS_COUNT * ETH_GSTRING_LEN);
85 static void ionic_get_drvinfo(struct net_device *netdev,
86 struct ethtool_drvinfo *drvinfo)
88 struct ionic_lif *lif = netdev_priv(netdev);
89 struct ionic *ionic = lif->ionic;
91 strlcpy(drvinfo->driver, IONIC_DRV_NAME, sizeof(drvinfo->driver));
92 strlcpy(drvinfo->fw_version, ionic->idev.dev_info.fw_version,
93 sizeof(drvinfo->fw_version));
94 strlcpy(drvinfo->bus_info, ionic_bus_info(ionic),
95 sizeof(drvinfo->bus_info));
98 static int ionic_get_regs_len(struct net_device *netdev)
100 return (IONIC_DEV_INFO_REG_COUNT + IONIC_DEV_CMD_REG_COUNT) * sizeof(u32);
103 static void ionic_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
106 struct ionic_lif *lif = netdev_priv(netdev);
110 regs->version = IONIC_DEV_CMD_REG_VERSION;
113 size = IONIC_DEV_INFO_REG_COUNT * sizeof(u32);
114 memcpy_fromio(p + offset, lif->ionic->idev.dev_info_regs->words, size);
117 size = IONIC_DEV_CMD_REG_COUNT * sizeof(u32);
118 memcpy_fromio(p + offset, lif->ionic->idev.dev_cmd_regs->words, size);
121 static int ionic_get_link_ksettings(struct net_device *netdev,
122 struct ethtool_link_ksettings *ks)
124 struct ionic_lif *lif = netdev_priv(netdev);
125 struct ionic_dev *idev = &lif->ionic->idev;
128 ethtool_link_ksettings_zero_link_mode(ks, supported);
130 if (!idev->port_info) {
131 netdev_err(netdev, "port_info not initialized\n");
135 /* The port_info data is found in a DMA space that the NIC keeps
136 * up-to-date, so there's no need to request the data from the
137 * NIC, we already have it in our memory space.
140 switch (le16_to_cpu(idev->port_info->status.xcvr.pid)) {
142 case IONIC_XCVR_PID_QSFP_100G_CR4:
143 ethtool_link_ksettings_add_link_mode(ks, supported,
147 case IONIC_XCVR_PID_QSFP_40GBASE_CR4:
148 ethtool_link_ksettings_add_link_mode(ks, supported,
152 case IONIC_XCVR_PID_SFP_25GBASE_CR_S:
153 case IONIC_XCVR_PID_SFP_25GBASE_CR_L:
154 case IONIC_XCVR_PID_SFP_25GBASE_CR_N:
155 ethtool_link_ksettings_add_link_mode(ks, supported,
159 case IONIC_XCVR_PID_SFP_10GBASE_AOC:
160 case IONIC_XCVR_PID_SFP_10GBASE_CU:
161 ethtool_link_ksettings_add_link_mode(ks, supported,
167 case IONIC_XCVR_PID_QSFP_100G_SR4:
168 case IONIC_XCVR_PID_QSFP_100G_AOC:
169 ethtool_link_ksettings_add_link_mode(ks, supported,
172 case IONIC_XCVR_PID_QSFP_100G_CWDM4:
173 case IONIC_XCVR_PID_QSFP_100G_PSM4:
174 case IONIC_XCVR_PID_QSFP_100G_LR4:
175 ethtool_link_ksettings_add_link_mode(ks, supported,
176 100000baseLR4_ER4_Full);
178 case IONIC_XCVR_PID_QSFP_100G_ER4:
179 ethtool_link_ksettings_add_link_mode(ks, supported,
180 100000baseLR4_ER4_Full);
182 case IONIC_XCVR_PID_QSFP_40GBASE_SR4:
183 case IONIC_XCVR_PID_QSFP_40GBASE_AOC:
184 ethtool_link_ksettings_add_link_mode(ks, supported,
187 case IONIC_XCVR_PID_QSFP_40GBASE_LR4:
188 ethtool_link_ksettings_add_link_mode(ks, supported,
191 case IONIC_XCVR_PID_SFP_25GBASE_SR:
192 case IONIC_XCVR_PID_SFP_25GBASE_AOC:
193 case IONIC_XCVR_PID_SFP_25GBASE_ACC:
194 ethtool_link_ksettings_add_link_mode(ks, supported,
197 case IONIC_XCVR_PID_SFP_10GBASE_SR:
198 ethtool_link_ksettings_add_link_mode(ks, supported,
201 case IONIC_XCVR_PID_SFP_10GBASE_LR:
202 ethtool_link_ksettings_add_link_mode(ks, supported,
205 case IONIC_XCVR_PID_SFP_10GBASE_LRM:
206 ethtool_link_ksettings_add_link_mode(ks, supported,
209 case IONIC_XCVR_PID_SFP_10GBASE_ER:
210 ethtool_link_ksettings_add_link_mode(ks, supported,
213 case IONIC_XCVR_PID_SFP_10GBASE_T:
214 ethtool_link_ksettings_add_link_mode(ks, supported,
217 case IONIC_XCVR_PID_SFP_1000BASE_T:
218 ethtool_link_ksettings_add_link_mode(ks, supported,
221 case IONIC_XCVR_PID_UNKNOWN:
222 /* This means there's no module plugged in */
225 dev_info(lif->ionic->dev, "unknown xcvr type pid=%d / 0x%x\n",
226 idev->port_info->status.xcvr.pid,
227 idev->port_info->status.xcvr.pid);
231 bitmap_copy(ks->link_modes.advertising, ks->link_modes.supported,
232 __ETHTOOL_LINK_MODE_MASK_NBITS);
234 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
235 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
236 if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_FC)
237 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_BASER);
238 else if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_RS)
239 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
241 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
242 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
244 if (idev->port_info->status.xcvr.phy == IONIC_PHY_TYPE_COPPER ||
246 ks->base.port = PORT_DA;
247 else if (idev->port_info->status.xcvr.phy == IONIC_PHY_TYPE_FIBER)
248 ks->base.port = PORT_FIBRE;
250 ks->base.port = PORT_NONE;
252 if (ks->base.port != PORT_NONE) {
253 ks->base.speed = le32_to_cpu(lif->info->status.link_speed);
255 if (le16_to_cpu(lif->info->status.link_status))
256 ks->base.duplex = DUPLEX_FULL;
258 ks->base.duplex = DUPLEX_UNKNOWN;
260 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
262 if (idev->port_info->config.an_enable) {
263 ethtool_link_ksettings_add_link_mode(ks, advertising,
265 ks->base.autoneg = AUTONEG_ENABLE;
272 static int ionic_set_link_ksettings(struct net_device *netdev,
273 const struct ethtool_link_ksettings *ks)
275 struct ionic_lif *lif = netdev_priv(netdev);
276 struct ionic_dev *idev = &lif->ionic->idev;
277 struct ionic *ionic = lif->ionic;
280 if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
284 if (ks->base.autoneg != idev->port_info->config.an_enable) {
285 mutex_lock(&ionic->dev_cmd_lock);
286 ionic_dev_cmd_port_autoneg(idev, ks->base.autoneg);
287 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
288 mutex_unlock(&ionic->dev_cmd_lock);
294 if (ks->base.speed != le32_to_cpu(idev->port_info->config.speed)) {
295 mutex_lock(&ionic->dev_cmd_lock);
296 ionic_dev_cmd_port_speed(idev, ks->base.speed);
297 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
298 mutex_unlock(&ionic->dev_cmd_lock);
306 static void ionic_get_pauseparam(struct net_device *netdev,
307 struct ethtool_pauseparam *pause)
309 struct ionic_lif *lif = netdev_priv(netdev);
314 pause_type = lif->ionic->idev.port_info->config.pause_type;
316 pause->rx_pause = (pause_type & IONIC_PAUSE_F_RX) ? 1 : 0;
317 pause->tx_pause = (pause_type & IONIC_PAUSE_F_TX) ? 1 : 0;
321 static int ionic_set_pauseparam(struct net_device *netdev,
322 struct ethtool_pauseparam *pause)
324 struct ionic_lif *lif = netdev_priv(netdev);
325 struct ionic *ionic = lif->ionic;
329 if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
335 /* change both at the same time */
336 requested_pause = IONIC_PORT_PAUSE_TYPE_LINK;
338 requested_pause |= IONIC_PAUSE_F_RX;
340 requested_pause |= IONIC_PAUSE_F_TX;
342 if (requested_pause == lif->ionic->idev.port_info->config.pause_type)
345 mutex_lock(&ionic->dev_cmd_lock);
346 ionic_dev_cmd_port_pause(&lif->ionic->idev, requested_pause);
347 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
348 mutex_unlock(&ionic->dev_cmd_lock);
355 static int ionic_get_fecparam(struct net_device *netdev,
356 struct ethtool_fecparam *fec)
358 struct ionic_lif *lif = netdev_priv(netdev);
360 switch (lif->ionic->idev.port_info->config.fec_type) {
361 case IONIC_PORT_FEC_TYPE_NONE:
362 fec->active_fec = ETHTOOL_FEC_OFF;
364 case IONIC_PORT_FEC_TYPE_RS:
365 fec->active_fec = ETHTOOL_FEC_RS;
367 case IONIC_PORT_FEC_TYPE_FC:
368 fec->active_fec = ETHTOOL_FEC_BASER;
372 fec->fec = ETHTOOL_FEC_OFF | ETHTOOL_FEC_RS | ETHTOOL_FEC_BASER;
377 static int ionic_set_fecparam(struct net_device *netdev,
378 struct ethtool_fecparam *fec)
380 struct ionic_lif *lif = netdev_priv(netdev);
384 if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
387 if (lif->ionic->idev.port_info->config.an_enable) {
388 netdev_err(netdev, "FEC request not allowed while autoneg is enabled\n");
393 case ETHTOOL_FEC_NONE:
394 fec_type = IONIC_PORT_FEC_TYPE_NONE;
396 case ETHTOOL_FEC_OFF:
397 fec_type = IONIC_PORT_FEC_TYPE_NONE;
400 fec_type = IONIC_PORT_FEC_TYPE_RS;
402 case ETHTOOL_FEC_BASER:
403 fec_type = IONIC_PORT_FEC_TYPE_FC;
405 case ETHTOOL_FEC_AUTO:
407 netdev_err(netdev, "FEC request 0x%04x not supported\n",
412 if (fec_type != lif->ionic->idev.port_info->config.fec_type) {
413 mutex_lock(&lif->ionic->dev_cmd_lock);
414 ionic_dev_cmd_port_fec(&lif->ionic->idev, fec_type);
415 ret = ionic_dev_cmd_wait(lif->ionic, DEVCMD_TIMEOUT);
416 mutex_unlock(&lif->ionic->dev_cmd_lock);
422 static int ionic_get_coalesce(struct net_device *netdev,
423 struct ethtool_coalesce *coalesce,
424 struct kernel_ethtool_coalesce *kernel_coal,
425 struct netlink_ext_ack *extack)
427 struct ionic_lif *lif = netdev_priv(netdev);
429 coalesce->tx_coalesce_usecs = lif->tx_coalesce_usecs;
430 coalesce->rx_coalesce_usecs = lif->rx_coalesce_usecs;
432 if (test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state))
433 coalesce->use_adaptive_tx_coalesce = test_bit(IONIC_LIF_F_TX_DIM_INTR, lif->state);
435 coalesce->use_adaptive_tx_coalesce = 0;
437 coalesce->use_adaptive_rx_coalesce = test_bit(IONIC_LIF_F_RX_DIM_INTR, lif->state);
442 static int ionic_set_coalesce(struct net_device *netdev,
443 struct ethtool_coalesce *coalesce,
444 struct kernel_ethtool_coalesce *kernel_coal,
445 struct netlink_ext_ack *extack)
447 struct ionic_lif *lif = netdev_priv(netdev);
448 struct ionic_identity *ident;
453 ident = &lif->ionic->ident;
454 if (ident->dev.intr_coal_div == 0) {
455 netdev_warn(netdev, "bad HW value in dev.intr_coal_div = %d\n",
456 ident->dev.intr_coal_div);
460 /* Tx normally shares Rx interrupt, so only change Rx if not split */
461 if (!test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state) &&
462 (coalesce->tx_coalesce_usecs != lif->rx_coalesce_usecs ||
463 coalesce->use_adaptive_tx_coalesce)) {
464 netdev_warn(netdev, "only rx parameters can be changed\n");
468 /* Convert the usec request to a HW usable value. If they asked
469 * for non-zero and it resolved to zero, bump it up
471 rx_coal = ionic_coal_usec_to_hw(lif->ionic, coalesce->rx_coalesce_usecs);
472 if (!rx_coal && coalesce->rx_coalesce_usecs)
474 tx_coal = ionic_coal_usec_to_hw(lif->ionic, coalesce->tx_coalesce_usecs);
475 if (!tx_coal && coalesce->tx_coalesce_usecs)
478 if (rx_coal > IONIC_INTR_CTRL_COAL_MAX ||
479 tx_coal > IONIC_INTR_CTRL_COAL_MAX)
482 /* Save the new values */
483 lif->rx_coalesce_usecs = coalesce->rx_coalesce_usecs;
484 lif->rx_coalesce_hw = rx_coal;
486 if (test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state))
487 lif->tx_coalesce_usecs = coalesce->tx_coalesce_usecs;
489 lif->tx_coalesce_usecs = coalesce->rx_coalesce_usecs;
490 lif->tx_coalesce_hw = tx_coal;
492 if (coalesce->use_adaptive_rx_coalesce) {
493 set_bit(IONIC_LIF_F_RX_DIM_INTR, lif->state);
496 clear_bit(IONIC_LIF_F_RX_DIM_INTR, lif->state);
500 if (coalesce->use_adaptive_tx_coalesce) {
501 set_bit(IONIC_LIF_F_TX_DIM_INTR, lif->state);
504 clear_bit(IONIC_LIF_F_TX_DIM_INTR, lif->state);
508 if (test_bit(IONIC_LIF_F_UP, lif->state)) {
509 for (i = 0; i < lif->nxqs; i++) {
510 if (lif->rxqcqs[i]->flags & IONIC_QCQ_F_INTR) {
511 ionic_intr_coal_init(lif->ionic->idev.intr_ctrl,
512 lif->rxqcqs[i]->intr.index,
513 lif->rx_coalesce_hw);
514 lif->rxqcqs[i]->intr.dim_coal_hw = rx_dim;
517 if (lif->txqcqs[i]->flags & IONIC_QCQ_F_INTR) {
518 ionic_intr_coal_init(lif->ionic->idev.intr_ctrl,
519 lif->txqcqs[i]->intr.index,
520 lif->tx_coalesce_hw);
521 lif->txqcqs[i]->intr.dim_coal_hw = tx_dim;
529 static void ionic_get_ringparam(struct net_device *netdev,
530 struct ethtool_ringparam *ring)
532 struct ionic_lif *lif = netdev_priv(netdev);
534 ring->tx_max_pending = IONIC_MAX_TX_DESC;
535 ring->tx_pending = lif->ntxq_descs;
536 ring->rx_max_pending = IONIC_MAX_RX_DESC;
537 ring->rx_pending = lif->nrxq_descs;
540 static int ionic_set_ringparam(struct net_device *netdev,
541 struct ethtool_ringparam *ring)
543 struct ionic_lif *lif = netdev_priv(netdev);
544 struct ionic_queue_params qparam;
547 if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
550 ionic_init_queue_params(lif, &qparam);
552 if (ring->rx_mini_pending || ring->rx_jumbo_pending) {
553 netdev_info(netdev, "Changing jumbo or mini descriptors not supported\n");
557 if (!is_power_of_2(ring->tx_pending) ||
558 !is_power_of_2(ring->rx_pending)) {
559 netdev_info(netdev, "Descriptor count must be a power of 2\n");
563 /* if nothing to do return success */
564 if (ring->tx_pending == lif->ntxq_descs &&
565 ring->rx_pending == lif->nrxq_descs)
568 if (ring->tx_pending != lif->ntxq_descs)
569 netdev_info(netdev, "Changing Tx ring size from %d to %d\n",
570 lif->ntxq_descs, ring->tx_pending);
572 if (ring->rx_pending != lif->nrxq_descs)
573 netdev_info(netdev, "Changing Rx ring size from %d to %d\n",
574 lif->nrxq_descs, ring->rx_pending);
576 /* if we're not running, just set the values and return */
577 if (!netif_running(lif->netdev)) {
578 lif->ntxq_descs = ring->tx_pending;
579 lif->nrxq_descs = ring->rx_pending;
583 qparam.ntxq_descs = ring->tx_pending;
584 qparam.nrxq_descs = ring->rx_pending;
585 err = ionic_reconfigure_queues(lif, &qparam);
587 netdev_info(netdev, "Ring reconfiguration failed, changes canceled: %d\n", err);
592 static void ionic_get_channels(struct net_device *netdev,
593 struct ethtool_channels *ch)
595 struct ionic_lif *lif = netdev_priv(netdev);
597 /* report maximum channels */
598 ch->max_combined = lif->ionic->ntxqs_per_lif;
599 ch->max_rx = lif->ionic->ntxqs_per_lif / 2;
600 ch->max_tx = lif->ionic->ntxqs_per_lif / 2;
602 /* report current channels */
603 if (test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state)) {
604 ch->rx_count = lif->nxqs;
605 ch->tx_count = lif->nxqs;
607 ch->combined_count = lif->nxqs;
611 static int ionic_set_channels(struct net_device *netdev,
612 struct ethtool_channels *ch)
614 struct ionic_lif *lif = netdev_priv(netdev);
615 struct ionic_queue_params qparam;
619 if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
622 ionic_init_queue_params(lif, &qparam);
624 if (ch->rx_count != ch->tx_count) {
625 netdev_info(netdev, "The rx and tx count must be equal\n");
629 if (ch->combined_count && ch->rx_count) {
630 netdev_info(netdev, "Use either combined or rx and tx, not both\n");
634 max_cnt = lif->ionic->ntxqs_per_lif;
635 if (ch->combined_count) {
636 if (ch->combined_count > max_cnt)
639 if (test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state))
640 netdev_info(lif->netdev, "Sharing queue interrupts\n");
641 else if (ch->combined_count == lif->nxqs)
644 if (lif->nxqs != ch->combined_count)
645 netdev_info(netdev, "Changing queue count from %d to %d\n",
646 lif->nxqs, ch->combined_count);
648 qparam.nxqs = ch->combined_count;
649 qparam.intr_split = 0;
652 if (ch->rx_count > max_cnt)
655 if (!test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state))
656 netdev_info(lif->netdev, "Splitting queue interrupts\n");
657 else if (ch->rx_count == lif->nxqs)
660 if (lif->nxqs != ch->rx_count)
661 netdev_info(netdev, "Changing queue count from %d to %d\n",
662 lif->nxqs, ch->rx_count);
664 qparam.nxqs = ch->rx_count;
665 qparam.intr_split = 1;
668 /* if we're not running, just set the values and return */
669 if (!netif_running(lif->netdev)) {
670 lif->nxqs = qparam.nxqs;
672 if (qparam.intr_split) {
673 set_bit(IONIC_LIF_F_SPLIT_INTR, lif->state);
675 clear_bit(IONIC_LIF_F_SPLIT_INTR, lif->state);
676 lif->tx_coalesce_usecs = lif->rx_coalesce_usecs;
677 lif->tx_coalesce_hw = lif->rx_coalesce_hw;
682 err = ionic_reconfigure_queues(lif, &qparam);
684 netdev_info(netdev, "Queue reconfiguration failed, changes canceled: %d\n", err);
689 static u32 ionic_get_priv_flags(struct net_device *netdev)
691 struct ionic_lif *lif = netdev_priv(netdev);
694 if (test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state))
695 priv_flags |= IONIC_PRIV_F_SW_DBG_STATS;
700 static int ionic_set_priv_flags(struct net_device *netdev, u32 priv_flags)
702 struct ionic_lif *lif = netdev_priv(netdev);
704 clear_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state);
705 if (priv_flags & IONIC_PRIV_F_SW_DBG_STATS)
706 set_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state);
711 static int ionic_get_rxnfc(struct net_device *netdev,
712 struct ethtool_rxnfc *info, u32 *rules)
714 struct ionic_lif *lif = netdev_priv(netdev);
718 case ETHTOOL_GRXRINGS:
719 info->data = lif->nxqs;
722 netdev_err(netdev, "Command parameter %d is not supported\n",
730 static u32 ionic_get_rxfh_indir_size(struct net_device *netdev)
732 struct ionic_lif *lif = netdev_priv(netdev);
734 return le16_to_cpu(lif->ionic->ident.lif.eth.rss_ind_tbl_sz);
737 static u32 ionic_get_rxfh_key_size(struct net_device *netdev)
739 return IONIC_RSS_HASH_KEY_SIZE;
742 static int ionic_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
745 struct ionic_lif *lif = netdev_priv(netdev);
746 unsigned int i, tbl_sz;
749 tbl_sz = le16_to_cpu(lif->ionic->ident.lif.eth.rss_ind_tbl_sz);
750 for (i = 0; i < tbl_sz; i++)
751 indir[i] = lif->rss_ind_tbl[i];
755 memcpy(key, lif->rss_hash_key, IONIC_RSS_HASH_KEY_SIZE);
758 *hfunc = ETH_RSS_HASH_TOP;
763 static int ionic_set_rxfh(struct net_device *netdev, const u32 *indir,
764 const u8 *key, const u8 hfunc)
766 struct ionic_lif *lif = netdev_priv(netdev);
768 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
771 return ionic_lif_rss_config(lif, lif->rss_types, key, indir);
774 static int ionic_set_tunable(struct net_device *dev,
775 const struct ethtool_tunable *tuna,
778 struct ionic_lif *lif = netdev_priv(dev);
781 case ETHTOOL_RX_COPYBREAK:
782 lif->rx_copybreak = *(u32 *)data;
791 static int ionic_get_tunable(struct net_device *netdev,
792 const struct ethtool_tunable *tuna, void *data)
794 struct ionic_lif *lif = netdev_priv(netdev);
797 case ETHTOOL_RX_COPYBREAK:
798 *(u32 *)data = lif->rx_copybreak;
807 static int ionic_get_module_info(struct net_device *netdev,
808 struct ethtool_modinfo *modinfo)
811 struct ionic_lif *lif = netdev_priv(netdev);
812 struct ionic_dev *idev = &lif->ionic->idev;
813 struct ionic_xcvr_status *xcvr;
814 struct sfp_eeprom_base *sfp;
816 xcvr = &idev->port_info->status.xcvr;
817 sfp = (struct sfp_eeprom_base *) xcvr->sprom;
819 /* report the module data type and length */
820 switch (sfp->phys_id) {
822 modinfo->type = ETH_MODULE_SFF_8079;
823 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
825 case SFF8024_ID_QSFP_8436_8636:
826 case SFF8024_ID_QSFP28_8636:
827 modinfo->type = ETH_MODULE_SFF_8436;
828 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
831 netdev_info(netdev, "unknown xcvr type 0x%02x\n",
834 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
841 static int ionic_get_module_eeprom(struct net_device *netdev,
842 struct ethtool_eeprom *ee,
845 struct ionic_lif *lif = netdev_priv(netdev);
846 struct ionic_dev *idev = &lif->ionic->idev;
847 struct ionic_xcvr_status *xcvr;
848 char tbuf[sizeof(xcvr->sprom)];
852 /* The NIC keeps the module prom up-to-date in the DMA space
853 * so we can simply copy the module bytes into the data buffer.
855 xcvr = &idev->port_info->status.xcvr;
856 len = min_t(u32, sizeof(xcvr->sprom), ee->len);
859 memcpy(data, xcvr->sprom, len);
860 memcpy(tbuf, xcvr->sprom, len);
862 /* Let's make sure we got a consistent copy */
863 if (!memcmp(data, tbuf, len))
874 static int ionic_get_ts_info(struct net_device *netdev,
875 struct ethtool_ts_info *info)
877 struct ionic_lif *lif = netdev_priv(netdev);
878 struct ionic *ionic = lif->ionic;
881 if (!lif->phc || !lif->phc->ptp)
882 return ethtool_op_get_ts_info(netdev, info);
884 info->phc_index = ptp_clock_index(lif->phc->ptp);
886 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
887 SOF_TIMESTAMPING_RX_SOFTWARE |
888 SOF_TIMESTAMPING_SOFTWARE |
889 SOF_TIMESTAMPING_TX_HARDWARE |
890 SOF_TIMESTAMPING_RX_HARDWARE |
891 SOF_TIMESTAMPING_RAW_HARDWARE;
895 info->tx_types = BIT(HWTSTAMP_TX_OFF) |
898 mask = cpu_to_le64(BIT_ULL(IONIC_TXSTAMP_ONESTEP_SYNC));
899 if (ionic->ident.lif.eth.hwstamp_tx_modes & mask)
900 info->tx_types |= BIT(HWTSTAMP_TX_ONESTEP_SYNC);
902 mask = cpu_to_le64(BIT_ULL(IONIC_TXSTAMP_ONESTEP_P2P));
903 if (ionic->ident.lif.eth.hwstamp_tx_modes & mask)
904 info->tx_types |= BIT(HWTSTAMP_TX_ONESTEP_P2P);
908 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
909 BIT(HWTSTAMP_FILTER_ALL);
911 mask = cpu_to_le64(IONIC_PKT_CLS_NTP_ALL);
912 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
913 info->rx_filters |= BIT(HWTSTAMP_FILTER_NTP_ALL);
915 mask = cpu_to_le64(IONIC_PKT_CLS_PTP1_SYNC);
916 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
917 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC);
919 mask = cpu_to_le64(IONIC_PKT_CLS_PTP1_DREQ);
920 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
921 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ);
923 mask = cpu_to_le64(IONIC_PKT_CLS_PTP1_ALL);
924 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
925 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT);
927 mask = cpu_to_le64(IONIC_PKT_CLS_PTP2_L4_SYNC);
928 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
929 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC);
931 mask = cpu_to_le64(IONIC_PKT_CLS_PTP2_L4_DREQ);
932 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
933 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
935 mask = cpu_to_le64(IONIC_PKT_CLS_PTP2_L4_ALL);
936 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
937 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT);
939 mask = cpu_to_le64(IONIC_PKT_CLS_PTP2_L2_SYNC);
940 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
941 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC);
943 mask = cpu_to_le64(IONIC_PKT_CLS_PTP2_L2_DREQ);
944 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
945 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
947 mask = cpu_to_le64(IONIC_PKT_CLS_PTP2_L2_ALL);
948 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
949 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT);
951 mask = cpu_to_le64(IONIC_PKT_CLS_PTP2_SYNC);
952 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
953 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V2_SYNC);
955 mask = cpu_to_le64(IONIC_PKT_CLS_PTP2_DREQ);
956 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
957 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ);
959 mask = cpu_to_le64(IONIC_PKT_CLS_PTP2_ALL);
960 if ((ionic->ident.lif.eth.hwstamp_rx_filters & mask) == mask)
961 info->rx_filters |= BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
966 static int ionic_nway_reset(struct net_device *netdev)
968 struct ionic_lif *lif = netdev_priv(netdev);
969 struct ionic *ionic = lif->ionic;
972 if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
975 /* flap the link to force auto-negotiation */
977 mutex_lock(&ionic->dev_cmd_lock);
979 ionic_dev_cmd_port_state(&ionic->idev, IONIC_PORT_ADMIN_STATE_DOWN);
980 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
983 ionic_dev_cmd_port_state(&ionic->idev, IONIC_PORT_ADMIN_STATE_UP);
984 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
987 mutex_unlock(&ionic->dev_cmd_lock);
992 static const struct ethtool_ops ionic_ethtool_ops = {
993 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
994 ETHTOOL_COALESCE_USE_ADAPTIVE_RX |
995 ETHTOOL_COALESCE_USE_ADAPTIVE_TX,
996 .get_drvinfo = ionic_get_drvinfo,
997 .get_regs_len = ionic_get_regs_len,
998 .get_regs = ionic_get_regs,
999 .get_link = ethtool_op_get_link,
1000 .get_link_ksettings = ionic_get_link_ksettings,
1001 .set_link_ksettings = ionic_set_link_ksettings,
1002 .get_coalesce = ionic_get_coalesce,
1003 .set_coalesce = ionic_set_coalesce,
1004 .get_ringparam = ionic_get_ringparam,
1005 .set_ringparam = ionic_set_ringparam,
1006 .get_channels = ionic_get_channels,
1007 .set_channels = ionic_set_channels,
1008 .get_strings = ionic_get_strings,
1009 .get_ethtool_stats = ionic_get_stats,
1010 .get_sset_count = ionic_get_sset_count,
1011 .get_priv_flags = ionic_get_priv_flags,
1012 .set_priv_flags = ionic_set_priv_flags,
1013 .get_rxnfc = ionic_get_rxnfc,
1014 .get_rxfh_indir_size = ionic_get_rxfh_indir_size,
1015 .get_rxfh_key_size = ionic_get_rxfh_key_size,
1016 .get_rxfh = ionic_get_rxfh,
1017 .set_rxfh = ionic_set_rxfh,
1018 .get_tunable = ionic_get_tunable,
1019 .set_tunable = ionic_set_tunable,
1020 .get_module_info = ionic_get_module_info,
1021 .get_module_eeprom = ionic_get_module_eeprom,
1022 .get_pauseparam = ionic_get_pauseparam,
1023 .set_pauseparam = ionic_set_pauseparam,
1024 .get_fecparam = ionic_get_fecparam,
1025 .set_fecparam = ionic_set_fecparam,
1026 .get_ts_info = ionic_get_ts_info,
1027 .nway_reset = ionic_nway_reset,
1030 void ionic_ethtool_set_ops(struct net_device *netdev)
1032 netdev->ethtool_ops = &ionic_ethtool_ops;