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;
35 lif = netdev_priv(netdev);
37 memset(buf, 0, stats->n_stats * sizeof(*buf));
38 for (i = 0; i < ionic_num_stats_grps; i++)
39 ionic_stats_groups[i].get_values(lif, &buf);
42 static int ionic_get_stats_count(struct ionic_lif *lif)
46 for (i = 0; i < ionic_num_stats_grps; i++)
47 num_stats += ionic_stats_groups[i].get_count(lif);
52 static int ionic_get_sset_count(struct net_device *netdev, int sset)
54 struct ionic_lif *lif = netdev_priv(netdev);
59 count = ionic_get_stats_count(lif);
61 case ETH_SS_PRIV_FLAGS:
62 count = IONIC_PRIV_FLAGS_COUNT;
68 static void ionic_get_strings(struct net_device *netdev,
71 struct ionic_lif *lif = netdev_priv(netdev);
75 ionic_get_stats_strings(lif, buf);
77 case ETH_SS_PRIV_FLAGS:
78 memcpy(buf, ionic_priv_flags_strings,
79 IONIC_PRIV_FLAGS_COUNT * ETH_GSTRING_LEN);
84 static void ionic_get_drvinfo(struct net_device *netdev,
85 struct ethtool_drvinfo *drvinfo)
87 struct ionic_lif *lif = netdev_priv(netdev);
88 struct ionic *ionic = lif->ionic;
90 strlcpy(drvinfo->driver, IONIC_DRV_NAME, sizeof(drvinfo->driver));
91 strlcpy(drvinfo->fw_version, ionic->idev.dev_info.fw_version,
92 sizeof(drvinfo->fw_version));
93 strlcpy(drvinfo->bus_info, ionic_bus_info(ionic),
94 sizeof(drvinfo->bus_info));
97 static int ionic_get_regs_len(struct net_device *netdev)
99 return (IONIC_DEV_INFO_REG_COUNT + IONIC_DEV_CMD_REG_COUNT) * sizeof(u32);
102 static void ionic_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
105 struct ionic_lif *lif = netdev_priv(netdev);
109 regs->version = IONIC_DEV_CMD_REG_VERSION;
112 size = IONIC_DEV_INFO_REG_COUNT * sizeof(u32);
113 memcpy_fromio(p + offset, lif->ionic->idev.dev_info_regs->words, size);
116 size = IONIC_DEV_CMD_REG_COUNT * sizeof(u32);
117 memcpy_fromio(p + offset, lif->ionic->idev.dev_cmd_regs->words, size);
120 static int ionic_get_link_ksettings(struct net_device *netdev,
121 struct ethtool_link_ksettings *ks)
123 struct ionic_lif *lif = netdev_priv(netdev);
124 struct ionic_dev *idev = &lif->ionic->idev;
127 ethtool_link_ksettings_zero_link_mode(ks, supported);
129 /* The port_info data is found in a DMA space that the NIC keeps
130 * up-to-date, so there's no need to request the data from the
131 * NIC, we already have it in our memory space.
134 switch (le16_to_cpu(idev->port_info->status.xcvr.pid)) {
136 case IONIC_XCVR_PID_QSFP_100G_CR4:
137 ethtool_link_ksettings_add_link_mode(ks, supported,
141 case IONIC_XCVR_PID_QSFP_40GBASE_CR4:
142 ethtool_link_ksettings_add_link_mode(ks, supported,
146 case IONIC_XCVR_PID_SFP_25GBASE_CR_S:
147 case IONIC_XCVR_PID_SFP_25GBASE_CR_L:
148 case IONIC_XCVR_PID_SFP_25GBASE_CR_N:
149 ethtool_link_ksettings_add_link_mode(ks, supported,
153 case IONIC_XCVR_PID_SFP_10GBASE_AOC:
154 case IONIC_XCVR_PID_SFP_10GBASE_CU:
155 ethtool_link_ksettings_add_link_mode(ks, supported,
161 case IONIC_XCVR_PID_QSFP_100G_SR4:
162 case IONIC_XCVR_PID_QSFP_100G_AOC:
163 ethtool_link_ksettings_add_link_mode(ks, supported,
166 case IONIC_XCVR_PID_QSFP_100G_CWDM4:
167 case IONIC_XCVR_PID_QSFP_100G_PSM4:
168 case IONIC_XCVR_PID_QSFP_100G_LR4:
169 ethtool_link_ksettings_add_link_mode(ks, supported,
170 100000baseLR4_ER4_Full);
172 case IONIC_XCVR_PID_QSFP_100G_ER4:
173 ethtool_link_ksettings_add_link_mode(ks, supported,
174 100000baseLR4_ER4_Full);
176 case IONIC_XCVR_PID_QSFP_40GBASE_SR4:
177 case IONIC_XCVR_PID_QSFP_40GBASE_AOC:
178 ethtool_link_ksettings_add_link_mode(ks, supported,
181 case IONIC_XCVR_PID_QSFP_40GBASE_LR4:
182 ethtool_link_ksettings_add_link_mode(ks, supported,
185 case IONIC_XCVR_PID_SFP_25GBASE_SR:
186 case IONIC_XCVR_PID_SFP_25GBASE_AOC:
187 case IONIC_XCVR_PID_SFP_25GBASE_ACC:
188 ethtool_link_ksettings_add_link_mode(ks, supported,
191 case IONIC_XCVR_PID_SFP_10GBASE_SR:
192 ethtool_link_ksettings_add_link_mode(ks, supported,
195 case IONIC_XCVR_PID_SFP_10GBASE_LR:
196 ethtool_link_ksettings_add_link_mode(ks, supported,
199 case IONIC_XCVR_PID_SFP_10GBASE_LRM:
200 ethtool_link_ksettings_add_link_mode(ks, supported,
203 case IONIC_XCVR_PID_SFP_10GBASE_ER:
204 ethtool_link_ksettings_add_link_mode(ks, supported,
207 case IONIC_XCVR_PID_UNKNOWN:
208 /* This means there's no module plugged in */
211 dev_info(lif->ionic->dev, "unknown xcvr type pid=%d / 0x%x\n",
212 idev->port_info->status.xcvr.pid,
213 idev->port_info->status.xcvr.pid);
217 bitmap_copy(ks->link_modes.advertising, ks->link_modes.supported,
218 __ETHTOOL_LINK_MODE_MASK_NBITS);
220 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
221 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
222 if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_FC)
223 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_BASER);
224 else if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_RS)
225 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
227 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
228 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
230 if (idev->port_info->status.xcvr.phy == IONIC_PHY_TYPE_COPPER ||
232 ks->base.port = PORT_DA;
233 else if (idev->port_info->status.xcvr.phy == IONIC_PHY_TYPE_FIBER)
234 ks->base.port = PORT_FIBRE;
236 ks->base.port = PORT_NONE;
238 if (ks->base.port != PORT_NONE) {
239 ks->base.speed = le32_to_cpu(lif->info->status.link_speed);
241 if (le16_to_cpu(lif->info->status.link_status))
242 ks->base.duplex = DUPLEX_FULL;
244 ks->base.duplex = DUPLEX_UNKNOWN;
246 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
248 if (idev->port_info->config.an_enable) {
249 ethtool_link_ksettings_add_link_mode(ks, advertising,
251 ks->base.autoneg = AUTONEG_ENABLE;
258 static int ionic_set_link_ksettings(struct net_device *netdev,
259 const struct ethtool_link_ksettings *ks)
261 struct ionic_lif *lif = netdev_priv(netdev);
262 struct ionic *ionic = lif->ionic;
263 struct ionic_dev *idev;
266 idev = &lif->ionic->idev;
269 if (ks->base.autoneg != idev->port_info->config.an_enable) {
270 mutex_lock(&ionic->dev_cmd_lock);
271 ionic_dev_cmd_port_autoneg(idev, ks->base.autoneg);
272 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
273 mutex_unlock(&ionic->dev_cmd_lock);
279 if (ks->base.speed != le32_to_cpu(idev->port_info->config.speed)) {
280 mutex_lock(&ionic->dev_cmd_lock);
281 ionic_dev_cmd_port_speed(idev, ks->base.speed);
282 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
283 mutex_unlock(&ionic->dev_cmd_lock);
291 static void ionic_get_pauseparam(struct net_device *netdev,
292 struct ethtool_pauseparam *pause)
294 struct ionic_lif *lif = netdev_priv(netdev);
299 pause_type = lif->ionic->idev.port_info->config.pause_type;
301 pause->rx_pause = (pause_type & IONIC_PAUSE_F_RX) ? 1 : 0;
302 pause->tx_pause = (pause_type & IONIC_PAUSE_F_TX) ? 1 : 0;
306 static int ionic_set_pauseparam(struct net_device *netdev,
307 struct ethtool_pauseparam *pause)
309 struct ionic_lif *lif = netdev_priv(netdev);
310 struct ionic *ionic = lif->ionic;
317 /* change both at the same time */
318 requested_pause = IONIC_PORT_PAUSE_TYPE_LINK;
320 requested_pause |= IONIC_PAUSE_F_RX;
322 requested_pause |= IONIC_PAUSE_F_TX;
324 if (requested_pause == lif->ionic->idev.port_info->config.pause_type)
327 mutex_lock(&ionic->dev_cmd_lock);
328 ionic_dev_cmd_port_pause(&lif->ionic->idev, requested_pause);
329 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
330 mutex_unlock(&ionic->dev_cmd_lock);
337 static int ionic_get_fecparam(struct net_device *netdev,
338 struct ethtool_fecparam *fec)
340 struct ionic_lif *lif = netdev_priv(netdev);
342 switch (lif->ionic->idev.port_info->config.fec_type) {
343 case IONIC_PORT_FEC_TYPE_NONE:
344 fec->active_fec = ETHTOOL_FEC_OFF;
346 case IONIC_PORT_FEC_TYPE_RS:
347 fec->active_fec = ETHTOOL_FEC_RS;
349 case IONIC_PORT_FEC_TYPE_FC:
350 fec->active_fec = ETHTOOL_FEC_BASER;
354 fec->fec = ETHTOOL_FEC_OFF | ETHTOOL_FEC_RS | ETHTOOL_FEC_BASER;
359 static int ionic_set_fecparam(struct net_device *netdev,
360 struct ethtool_fecparam *fec)
362 struct ionic_lif *lif = netdev_priv(netdev);
366 if (lif->ionic->idev.port_info->config.an_enable) {
367 netdev_err(netdev, "FEC request not allowed while autoneg is enabled\n");
372 case ETHTOOL_FEC_NONE:
373 fec_type = IONIC_PORT_FEC_TYPE_NONE;
375 case ETHTOOL_FEC_OFF:
376 fec_type = IONIC_PORT_FEC_TYPE_NONE;
379 fec_type = IONIC_PORT_FEC_TYPE_RS;
381 case ETHTOOL_FEC_BASER:
382 fec_type = IONIC_PORT_FEC_TYPE_FC;
384 case ETHTOOL_FEC_AUTO:
386 netdev_err(netdev, "FEC request 0x%04x not supported\n",
391 if (fec_type != lif->ionic->idev.port_info->config.fec_type) {
392 mutex_lock(&lif->ionic->dev_cmd_lock);
393 ionic_dev_cmd_port_fec(&lif->ionic->idev, fec_type);
394 ret = ionic_dev_cmd_wait(lif->ionic, DEVCMD_TIMEOUT);
395 mutex_unlock(&lif->ionic->dev_cmd_lock);
401 static int ionic_get_coalesce(struct net_device *netdev,
402 struct ethtool_coalesce *coalesce)
404 struct ionic_lif *lif = netdev_priv(netdev);
406 coalesce->tx_coalesce_usecs = lif->tx_coalesce_usecs;
407 coalesce->rx_coalesce_usecs = lif->rx_coalesce_usecs;
412 static int ionic_set_coalesce(struct net_device *netdev,
413 struct ethtool_coalesce *coalesce)
415 struct ionic_lif *lif = netdev_priv(netdev);
416 struct ionic_identity *ident;
417 struct ionic_qcq *qcq;
422 ident = &lif->ionic->ident;
423 if (ident->dev.intr_coal_div == 0) {
424 netdev_warn(netdev, "bad HW value in dev.intr_coal_div = %d\n",
425 ident->dev.intr_coal_div);
429 /* Tx normally shares Rx interrupt, so only change Rx */
430 if (!test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state) &&
431 coalesce->tx_coalesce_usecs != lif->rx_coalesce_usecs) {
432 netdev_warn(netdev, "only the rx-usecs can be changed\n");
436 /* Convert the usec request to a HW usable value. If they asked
437 * for non-zero and it resolved to zero, bump it up
439 rx_coal = ionic_coal_usec_to_hw(lif->ionic, coalesce->rx_coalesce_usecs);
440 if (!rx_coal && coalesce->rx_coalesce_usecs)
442 tx_coal = ionic_coal_usec_to_hw(lif->ionic, coalesce->tx_coalesce_usecs);
443 if (!tx_coal && coalesce->tx_coalesce_usecs)
446 if (rx_coal > IONIC_INTR_CTRL_COAL_MAX ||
447 tx_coal > IONIC_INTR_CTRL_COAL_MAX)
450 /* Save the new values */
451 lif->rx_coalesce_usecs = coalesce->rx_coalesce_usecs;
452 if (rx_coal != lif->rx_coalesce_hw) {
453 lif->rx_coalesce_hw = rx_coal;
455 if (test_bit(IONIC_LIF_F_UP, lif->state)) {
456 for (i = 0; i < lif->nxqs; i++) {
457 qcq = lif->rxqcqs[i];
458 ionic_intr_coal_init(lif->ionic->idev.intr_ctrl,
460 lif->rx_coalesce_hw);
465 if (test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state))
466 lif->tx_coalesce_usecs = coalesce->tx_coalesce_usecs;
468 lif->tx_coalesce_usecs = coalesce->rx_coalesce_usecs;
469 if (tx_coal != lif->tx_coalesce_hw) {
470 lif->tx_coalesce_hw = tx_coal;
472 if (test_bit(IONIC_LIF_F_UP, lif->state)) {
473 for (i = 0; i < lif->nxqs; i++) {
474 qcq = lif->txqcqs[i];
475 ionic_intr_coal_init(lif->ionic->idev.intr_ctrl,
477 lif->tx_coalesce_hw);
485 static void ionic_get_ringparam(struct net_device *netdev,
486 struct ethtool_ringparam *ring)
488 struct ionic_lif *lif = netdev_priv(netdev);
490 ring->tx_max_pending = IONIC_MAX_TX_DESC;
491 ring->tx_pending = lif->ntxq_descs;
492 ring->rx_max_pending = IONIC_MAX_RX_DESC;
493 ring->rx_pending = lif->nrxq_descs;
496 static int ionic_set_ringparam(struct net_device *netdev,
497 struct ethtool_ringparam *ring)
499 struct ionic_lif *lif = netdev_priv(netdev);
500 struct ionic_queue_params qparam;
503 ionic_init_queue_params(lif, &qparam);
505 if (ring->rx_mini_pending || ring->rx_jumbo_pending) {
506 netdev_info(netdev, "Changing jumbo or mini descriptors not supported\n");
510 if (!is_power_of_2(ring->tx_pending) ||
511 !is_power_of_2(ring->rx_pending)) {
512 netdev_info(netdev, "Descriptor count must be a power of 2\n");
516 /* if nothing to do return success */
517 if (ring->tx_pending == lif->ntxq_descs &&
518 ring->rx_pending == lif->nrxq_descs)
521 if (ring->tx_pending != lif->ntxq_descs)
522 netdev_info(netdev, "Changing Tx ring size from %d to %d\n",
523 lif->ntxq_descs, ring->tx_pending);
525 if (ring->rx_pending != lif->nrxq_descs)
526 netdev_info(netdev, "Changing Rx ring size from %d to %d\n",
527 lif->nrxq_descs, ring->rx_pending);
529 /* if we're not running, just set the values and return */
530 if (!netif_running(lif->netdev)) {
531 lif->ntxq_descs = ring->tx_pending;
532 lif->nrxq_descs = ring->rx_pending;
536 qparam.ntxq_descs = ring->tx_pending;
537 qparam.nrxq_descs = ring->rx_pending;
538 err = ionic_reconfigure_queues(lif, &qparam);
540 netdev_info(netdev, "Ring reconfiguration failed, changes canceled: %d\n", err);
545 static void ionic_get_channels(struct net_device *netdev,
546 struct ethtool_channels *ch)
548 struct ionic_lif *lif = netdev_priv(netdev);
550 /* report maximum channels */
551 ch->max_combined = lif->ionic->ntxqs_per_lif;
552 ch->max_rx = lif->ionic->ntxqs_per_lif / 2;
553 ch->max_tx = lif->ionic->ntxqs_per_lif / 2;
555 /* report current channels */
556 if (test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state)) {
557 ch->rx_count = lif->nxqs;
558 ch->tx_count = lif->nxqs;
560 ch->combined_count = lif->nxqs;
564 static int ionic_set_channels(struct net_device *netdev,
565 struct ethtool_channels *ch)
567 struct ionic_lif *lif = netdev_priv(netdev);
568 struct ionic_queue_params qparam;
572 ionic_init_queue_params(lif, &qparam);
574 if (ch->rx_count != ch->tx_count) {
575 netdev_info(netdev, "The rx and tx count must be equal\n");
579 if (ch->combined_count && ch->rx_count) {
580 netdev_info(netdev, "Use either combined or rx and tx, not both\n");
584 max_cnt = lif->ionic->ntxqs_per_lif;
585 if (ch->combined_count) {
586 if (ch->combined_count > max_cnt)
589 if (test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state))
590 netdev_info(lif->netdev, "Sharing queue interrupts\n");
591 else if (ch->combined_count == lif->nxqs)
594 if (lif->nxqs != ch->combined_count)
595 netdev_info(netdev, "Changing queue count from %d to %d\n",
596 lif->nxqs, ch->combined_count);
598 qparam.nxqs = ch->combined_count;
599 qparam.intr_split = 0;
602 if (ch->rx_count > max_cnt)
605 if (!test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state))
606 netdev_info(lif->netdev, "Splitting queue interrupts\n");
607 else if (ch->rx_count == lif->nxqs)
610 if (lif->nxqs != ch->rx_count)
611 netdev_info(netdev, "Changing queue count from %d to %d\n",
612 lif->nxqs, ch->rx_count);
614 qparam.nxqs = ch->rx_count;
615 qparam.intr_split = 1;
618 /* if we're not running, just set the values and return */
619 if (!netif_running(lif->netdev)) {
620 lif->nxqs = qparam.nxqs;
622 if (qparam.intr_split) {
623 set_bit(IONIC_LIF_F_SPLIT_INTR, lif->state);
625 clear_bit(IONIC_LIF_F_SPLIT_INTR, lif->state);
626 lif->tx_coalesce_usecs = lif->rx_coalesce_usecs;
627 lif->tx_coalesce_hw = lif->rx_coalesce_hw;
632 err = ionic_reconfigure_queues(lif, &qparam);
634 netdev_info(netdev, "Queue reconfiguration failed, changes canceled: %d\n", err);
639 static u32 ionic_get_priv_flags(struct net_device *netdev)
641 struct ionic_lif *lif = netdev_priv(netdev);
644 if (test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state))
645 priv_flags |= IONIC_PRIV_F_SW_DBG_STATS;
650 static int ionic_set_priv_flags(struct net_device *netdev, u32 priv_flags)
652 struct ionic_lif *lif = netdev_priv(netdev);
654 clear_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state);
655 if (priv_flags & IONIC_PRIV_F_SW_DBG_STATS)
656 set_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state);
661 static int ionic_get_rxnfc(struct net_device *netdev,
662 struct ethtool_rxnfc *info, u32 *rules)
664 struct ionic_lif *lif = netdev_priv(netdev);
668 case ETHTOOL_GRXRINGS:
669 info->data = lif->nxqs;
672 netdev_err(netdev, "Command parameter %d is not supported\n",
680 static u32 ionic_get_rxfh_indir_size(struct net_device *netdev)
682 struct ionic_lif *lif = netdev_priv(netdev);
684 return le16_to_cpu(lif->ionic->ident.lif.eth.rss_ind_tbl_sz);
687 static u32 ionic_get_rxfh_key_size(struct net_device *netdev)
689 return IONIC_RSS_HASH_KEY_SIZE;
692 static int ionic_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
695 struct ionic_lif *lif = netdev_priv(netdev);
696 unsigned int i, tbl_sz;
699 tbl_sz = le16_to_cpu(lif->ionic->ident.lif.eth.rss_ind_tbl_sz);
700 for (i = 0; i < tbl_sz; i++)
701 indir[i] = lif->rss_ind_tbl[i];
705 memcpy(key, lif->rss_hash_key, IONIC_RSS_HASH_KEY_SIZE);
708 *hfunc = ETH_RSS_HASH_TOP;
713 static int ionic_set_rxfh(struct net_device *netdev, const u32 *indir,
714 const u8 *key, const u8 hfunc)
716 struct ionic_lif *lif = netdev_priv(netdev);
719 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
722 err = ionic_lif_rss_config(lif, lif->rss_types, key, indir);
729 static int ionic_set_tunable(struct net_device *dev,
730 const struct ethtool_tunable *tuna,
733 struct ionic_lif *lif = netdev_priv(dev);
736 case ETHTOOL_RX_COPYBREAK:
737 lif->rx_copybreak = *(u32 *)data;
746 static int ionic_get_tunable(struct net_device *netdev,
747 const struct ethtool_tunable *tuna, void *data)
749 struct ionic_lif *lif = netdev_priv(netdev);
752 case ETHTOOL_RX_COPYBREAK:
753 *(u32 *)data = lif->rx_copybreak;
762 static int ionic_get_module_info(struct net_device *netdev,
763 struct ethtool_modinfo *modinfo)
766 struct ionic_lif *lif = netdev_priv(netdev);
767 struct ionic_dev *idev = &lif->ionic->idev;
768 struct ionic_xcvr_status *xcvr;
769 struct sfp_eeprom_base *sfp;
771 xcvr = &idev->port_info->status.xcvr;
772 sfp = (struct sfp_eeprom_base *) xcvr->sprom;
774 /* report the module data type and length */
775 switch (sfp->phys_id) {
777 modinfo->type = ETH_MODULE_SFF_8079;
778 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
780 case SFF8024_ID_QSFP_8436_8636:
781 case SFF8024_ID_QSFP28_8636:
782 modinfo->type = ETH_MODULE_SFF_8436;
783 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
786 netdev_info(netdev, "unknown xcvr type 0x%02x\n",
789 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
796 static int ionic_get_module_eeprom(struct net_device *netdev,
797 struct ethtool_eeprom *ee,
800 struct ionic_lif *lif = netdev_priv(netdev);
801 struct ionic_dev *idev = &lif->ionic->idev;
802 struct ionic_xcvr_status *xcvr;
803 char tbuf[sizeof(xcvr->sprom)];
807 /* The NIC keeps the module prom up-to-date in the DMA space
808 * so we can simply copy the module bytes into the data buffer.
810 xcvr = &idev->port_info->status.xcvr;
811 len = min_t(u32, sizeof(xcvr->sprom), ee->len);
814 memcpy(data, xcvr->sprom, len);
815 memcpy(tbuf, xcvr->sprom, len);
817 /* Let's make sure we got a consistent copy */
818 if (!memcmp(data, tbuf, len))
829 static int ionic_nway_reset(struct net_device *netdev)
831 struct ionic_lif *lif = netdev_priv(netdev);
832 struct ionic *ionic = lif->ionic;
835 /* flap the link to force auto-negotiation */
837 mutex_lock(&ionic->dev_cmd_lock);
839 ionic_dev_cmd_port_state(&ionic->idev, IONIC_PORT_ADMIN_STATE_DOWN);
840 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
843 ionic_dev_cmd_port_state(&ionic->idev, IONIC_PORT_ADMIN_STATE_UP);
844 err = ionic_dev_cmd_wait(ionic, DEVCMD_TIMEOUT);
847 mutex_unlock(&ionic->dev_cmd_lock);
852 static const struct ethtool_ops ionic_ethtool_ops = {
853 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
854 .get_drvinfo = ionic_get_drvinfo,
855 .get_regs_len = ionic_get_regs_len,
856 .get_regs = ionic_get_regs,
857 .get_link = ethtool_op_get_link,
858 .get_link_ksettings = ionic_get_link_ksettings,
859 .set_link_ksettings = ionic_set_link_ksettings,
860 .get_coalesce = ionic_get_coalesce,
861 .set_coalesce = ionic_set_coalesce,
862 .get_ringparam = ionic_get_ringparam,
863 .set_ringparam = ionic_set_ringparam,
864 .get_channels = ionic_get_channels,
865 .set_channels = ionic_set_channels,
866 .get_strings = ionic_get_strings,
867 .get_ethtool_stats = ionic_get_stats,
868 .get_sset_count = ionic_get_sset_count,
869 .get_priv_flags = ionic_get_priv_flags,
870 .set_priv_flags = ionic_set_priv_flags,
871 .get_rxnfc = ionic_get_rxnfc,
872 .get_rxfh_indir_size = ionic_get_rxfh_indir_size,
873 .get_rxfh_key_size = ionic_get_rxfh_key_size,
874 .get_rxfh = ionic_get_rxfh,
875 .set_rxfh = ionic_set_rxfh,
876 .get_tunable = ionic_get_tunable,
877 .set_tunable = ionic_set_tunable,
878 .get_module_info = ionic_get_module_info,
879 .get_module_eeprom = ionic_get_module_eeprom,
880 .get_pauseparam = ionic_get_pauseparam,
881 .set_pauseparam = ionic_set_pauseparam,
882 .get_fecparam = ionic_get_fecparam,
883 .set_fecparam = ionic_set_fecparam,
884 .nway_reset = ionic_nway_reset,
887 void ionic_ethtool_set_ops(struct net_device *netdev)
889 netdev->ethtool_ops = &ionic_ethtool_ops;