1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013-2015 Chelsio Communications. All rights reserved.
6 #include <linux/firmware.h>
7 #include <linux/mdio.h>
12 #include "cxgb4_cudbg.h"
14 #define EEPROM_MAGIC 0x38E2F10C
16 static u32 get_msglevel(struct net_device *dev)
18 return netdev2adap(dev)->msg_enable;
21 static void set_msglevel(struct net_device *dev, u32 val)
23 netdev2adap(dev)->msg_enable = val;
26 static const char stats_strings[][ETH_GSTRING_LEN] = {
29 "tx_broadcast_frames ",
30 "tx_multicast_frames ",
35 "tx_frames_65_to_127 ",
36 "tx_frames_128_to_255 ",
37 "tx_frames_256_to_511 ",
38 "tx_frames_512_to_1023 ",
39 "tx_frames_1024_to_1518 ",
40 "tx_frames_1519_to_max ",
55 "rx_broadcast_frames ",
56 "rx_multicast_frames ",
59 "rx_frames_too_long ",
67 "rx_frames_65_to_127 ",
68 "rx_frames_128_to_255 ",
69 "rx_frames_256_to_511 ",
70 "rx_frames_512_to_1023 ",
71 "rx_frames_1024_to_1518 ",
72 "rx_frames_1519_to_max ",
84 "rx_bg0_frames_dropped ",
85 "rx_bg1_frames_dropped ",
86 "rx_bg2_frames_dropped ",
87 "rx_bg3_frames_dropped ",
88 "rx_bg0_frames_trunc ",
89 "rx_bg1_frames_trunc ",
90 "rx_bg2_frames_trunc ",
91 "rx_bg3_frames_trunc ",
102 static char adapter_stats_strings[][ETH_GSTRING_LEN] = {
106 "write_coal_success ",
110 static char loopback_stats_strings[][ETH_GSTRING_LEN] = {
111 "-------Loopback----------- ",
120 "frames_128_to_255 ",
121 "frames_256_to_511 ",
122 "frames_512_to_1023 ",
123 "frames_1024_to_1518 ",
124 "frames_1519_to_max ",
126 "bg0_frames_dropped ",
127 "bg1_frames_dropped ",
128 "bg2_frames_dropped ",
129 "bg3_frames_dropped ",
136 static const char cxgb4_priv_flags_strings[][ETH_GSTRING_LEN] = {
137 [PRIV_FLAG_PORT_TX_VM_BIT] = "port_tx_vm_wr",
140 static int get_sset_count(struct net_device *dev, int sset)
144 return ARRAY_SIZE(stats_strings) +
145 ARRAY_SIZE(adapter_stats_strings) +
146 ARRAY_SIZE(loopback_stats_strings);
147 case ETH_SS_PRIV_FLAGS:
148 return ARRAY_SIZE(cxgb4_priv_flags_strings);
154 static int get_regs_len(struct net_device *dev)
156 struct adapter *adap = netdev2adap(dev);
158 return t4_get_regs_len(adap);
161 static int get_eeprom_len(struct net_device *dev)
166 static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
168 struct adapter *adapter = netdev2adap(dev);
171 strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
172 strlcpy(info->version, cxgb4_driver_version,
173 sizeof(info->version));
174 strlcpy(info->bus_info, pci_name(adapter->pdev),
175 sizeof(info->bus_info));
176 info->regdump_len = get_regs_len(dev);
178 if (!adapter->params.fw_vers)
179 strcpy(info->fw_version, "N/A");
181 snprintf(info->fw_version, sizeof(info->fw_version),
182 "%u.%u.%u.%u, TP %u.%u.%u.%u",
183 FW_HDR_FW_VER_MAJOR_G(adapter->params.fw_vers),
184 FW_HDR_FW_VER_MINOR_G(adapter->params.fw_vers),
185 FW_HDR_FW_VER_MICRO_G(adapter->params.fw_vers),
186 FW_HDR_FW_VER_BUILD_G(adapter->params.fw_vers),
187 FW_HDR_FW_VER_MAJOR_G(adapter->params.tp_vers),
188 FW_HDR_FW_VER_MINOR_G(adapter->params.tp_vers),
189 FW_HDR_FW_VER_MICRO_G(adapter->params.tp_vers),
190 FW_HDR_FW_VER_BUILD_G(adapter->params.tp_vers));
192 if (!t4_get_exprom_version(adapter, &exprom_vers))
193 snprintf(info->erom_version, sizeof(info->erom_version),
195 FW_HDR_FW_VER_MAJOR_G(exprom_vers),
196 FW_HDR_FW_VER_MINOR_G(exprom_vers),
197 FW_HDR_FW_VER_MICRO_G(exprom_vers),
198 FW_HDR_FW_VER_BUILD_G(exprom_vers));
199 info->n_priv_flags = ARRAY_SIZE(cxgb4_priv_flags_strings);
202 static void get_strings(struct net_device *dev, u32 stringset, u8 *data)
204 if (stringset == ETH_SS_STATS) {
205 memcpy(data, stats_strings, sizeof(stats_strings));
206 data += sizeof(stats_strings);
207 memcpy(data, adapter_stats_strings,
208 sizeof(adapter_stats_strings));
209 data += sizeof(adapter_stats_strings);
210 memcpy(data, loopback_stats_strings,
211 sizeof(loopback_stats_strings));
212 } else if (stringset == ETH_SS_PRIV_FLAGS) {
213 memcpy(data, cxgb4_priv_flags_strings,
214 sizeof(cxgb4_priv_flags_strings));
218 /* port stats maintained per queue of the port. They should be in the same
219 * order as in stats_strings above.
221 struct queue_port_stats {
231 struct adapter_stats {
239 static void collect_sge_port_stats(const struct adapter *adap,
240 const struct port_info *p,
241 struct queue_port_stats *s)
244 const struct sge_eth_txq *tx = &adap->sge.ethtxq[p->first_qset];
245 const struct sge_eth_rxq *rx = &adap->sge.ethrxq[p->first_qset];
247 memset(s, 0, sizeof(*s));
248 for (i = 0; i < p->nqsets; i++, rx++, tx++) {
250 s->tx_csum += tx->tx_cso;
251 s->rx_csum += rx->stats.rx_cso;
252 s->vlan_ex += rx->stats.vlan_ex;
253 s->vlan_ins += tx->vlan_ins;
254 s->gro_pkts += rx->stats.lro_pkts;
255 s->gro_merged += rx->stats.lro_merged;
259 static void collect_adapter_stats(struct adapter *adap, struct adapter_stats *s)
263 memset(s, 0, sizeof(*s));
265 s->db_drop = adap->db_stats.db_drop;
266 s->db_full = adap->db_stats.db_full;
267 s->db_empty = adap->db_stats.db_empty;
269 if (!is_t4(adap->params.chip)) {
272 v = t4_read_reg(adap, SGE_STAT_CFG_A);
273 if (STATSOURCE_T5_G(v) == 7) {
274 val2 = t4_read_reg(adap, SGE_STAT_MATCH_A);
275 val1 = t4_read_reg(adap, SGE_STAT_TOTAL_A);
276 s->wc_success = val1 - val2;
282 static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
285 struct port_info *pi = netdev_priv(dev);
286 struct adapter *adapter = pi->adapter;
287 struct lb_port_stats s;
291 t4_get_port_stats_offset(adapter, pi->tx_chan,
292 (struct port_stats *)data,
295 data += sizeof(struct port_stats) / sizeof(u64);
296 collect_sge_port_stats(adapter, pi, (struct queue_port_stats *)data);
297 data += sizeof(struct queue_port_stats) / sizeof(u64);
298 collect_adapter_stats(adapter, (struct adapter_stats *)data);
299 data += sizeof(struct adapter_stats) / sizeof(u64);
301 *data++ = (u64)pi->port_id;
302 memset(&s, 0, sizeof(s));
303 t4_get_lb_stats(adapter, pi->port_id, &s);
306 for (i = 0; i < ARRAY_SIZE(loopback_stats_strings) - 1; i++)
307 *data++ = (unsigned long long)*p0++;
310 static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
313 struct adapter *adap = netdev2adap(dev);
316 buf_size = t4_get_regs_len(adap);
317 regs->version = mk_adap_vers(adap);
318 t4_get_regs(adap, buf, buf_size);
321 static int restart_autoneg(struct net_device *dev)
323 struct port_info *p = netdev_priv(dev);
325 if (!netif_running(dev))
327 if (p->link_cfg.autoneg != AUTONEG_ENABLE)
329 t4_restart_aneg(p->adapter, p->adapter->pf, p->tx_chan);
333 static int identify_port(struct net_device *dev,
334 enum ethtool_phys_id_state state)
337 struct adapter *adap = netdev2adap(dev);
339 if (state == ETHTOOL_ID_ACTIVE)
341 else if (state == ETHTOOL_ID_INACTIVE)
346 return t4_identify_port(adap, adap->pf, netdev2pinfo(dev)->viid, val);
350 * from_fw_port_mod_type - translate Firmware Port/Module type to Ethtool
351 * @port_type: Firmware Port Type
352 * @mod_type: Firmware Module Type
354 * Translate Firmware Port/Module type to Ethtool Port Type.
356 static int from_fw_port_mod_type(enum fw_port_type port_type,
357 enum fw_port_module_type mod_type)
359 if (port_type == FW_PORT_TYPE_BT_SGMII ||
360 port_type == FW_PORT_TYPE_BT_XFI ||
361 port_type == FW_PORT_TYPE_BT_XAUI) {
363 } else if (port_type == FW_PORT_TYPE_FIBER_XFI ||
364 port_type == FW_PORT_TYPE_FIBER_XAUI) {
366 } else if (port_type == FW_PORT_TYPE_SFP ||
367 port_type == FW_PORT_TYPE_QSFP_10G ||
368 port_type == FW_PORT_TYPE_QSA ||
369 port_type == FW_PORT_TYPE_QSFP ||
370 port_type == FW_PORT_TYPE_CR4_QSFP ||
371 port_type == FW_PORT_TYPE_CR_QSFP ||
372 port_type == FW_PORT_TYPE_CR2_QSFP ||
373 port_type == FW_PORT_TYPE_SFP28) {
374 if (mod_type == FW_PORT_MOD_TYPE_LR ||
375 mod_type == FW_PORT_MOD_TYPE_SR ||
376 mod_type == FW_PORT_MOD_TYPE_ER ||
377 mod_type == FW_PORT_MOD_TYPE_LRM)
379 else if (mod_type == FW_PORT_MOD_TYPE_TWINAX_PASSIVE ||
380 mod_type == FW_PORT_MOD_TYPE_TWINAX_ACTIVE)
384 } else if (port_type == FW_PORT_TYPE_KR4_100G ||
385 port_type == FW_PORT_TYPE_KR_SFP28 ||
386 port_type == FW_PORT_TYPE_KR_XLAUI) {
394 * speed_to_fw_caps - translate Port Speed to Firmware Port Capabilities
395 * @speed: speed in Kb/s
397 * Translates a specific Port Speed into a Firmware Port Capabilities
400 static unsigned int speed_to_fw_caps(int speed)
403 return FW_PORT_CAP32_SPEED_100M;
405 return FW_PORT_CAP32_SPEED_1G;
407 return FW_PORT_CAP32_SPEED_10G;
409 return FW_PORT_CAP32_SPEED_25G;
411 return FW_PORT_CAP32_SPEED_40G;
413 return FW_PORT_CAP32_SPEED_50G;
415 return FW_PORT_CAP32_SPEED_100G;
417 return FW_PORT_CAP32_SPEED_200G;
419 return FW_PORT_CAP32_SPEED_400G;
424 * fw_caps_to_lmm - translate Firmware to ethtool Link Mode Mask
425 * @port_type: Firmware Port Type
426 * @fw_caps: Firmware Port Capabilities
427 * @link_mode_mask: ethtool Link Mode Mask
429 * Translate a Firmware Port Capabilities specification to an ethtool
432 static void fw_caps_to_lmm(enum fw_port_type port_type,
433 fw_port_cap32_t fw_caps,
434 unsigned long *link_mode_mask)
436 #define SET_LMM(__lmm_name) \
438 __set_bit(ETHTOOL_LINK_MODE_ ## __lmm_name ## _BIT, \
442 #define FW_CAPS_TO_LMM(__fw_name, __lmm_name) \
444 if (fw_caps & FW_PORT_CAP32_ ## __fw_name) \
445 SET_LMM(__lmm_name); \
449 case FW_PORT_TYPE_BT_SGMII:
450 case FW_PORT_TYPE_BT_XFI:
451 case FW_PORT_TYPE_BT_XAUI:
453 FW_CAPS_TO_LMM(SPEED_100M, 100baseT_Full);
454 FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
455 FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
458 case FW_PORT_TYPE_KX4:
459 case FW_PORT_TYPE_KX:
461 FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
462 FW_CAPS_TO_LMM(SPEED_10G, 10000baseKX4_Full);
465 case FW_PORT_TYPE_KR:
467 FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
470 case FW_PORT_TYPE_BP_AP:
472 FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
473 FW_CAPS_TO_LMM(SPEED_10G, 10000baseR_FEC);
474 FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
477 case FW_PORT_TYPE_BP4_AP:
479 FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
480 FW_CAPS_TO_LMM(SPEED_10G, 10000baseR_FEC);
481 FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
482 FW_CAPS_TO_LMM(SPEED_10G, 10000baseKX4_Full);
485 case FW_PORT_TYPE_FIBER_XFI:
486 case FW_PORT_TYPE_FIBER_XAUI:
487 case FW_PORT_TYPE_SFP:
488 case FW_PORT_TYPE_QSFP_10G:
489 case FW_PORT_TYPE_QSA:
491 FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
492 FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
495 case FW_PORT_TYPE_BP40_BA:
496 case FW_PORT_TYPE_QSFP:
498 FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
499 FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
500 FW_CAPS_TO_LMM(SPEED_40G, 40000baseSR4_Full);
503 case FW_PORT_TYPE_CR_QSFP:
504 case FW_PORT_TYPE_SFP28:
506 FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
507 FW_CAPS_TO_LMM(SPEED_10G, 10000baseT_Full);
508 FW_CAPS_TO_LMM(SPEED_25G, 25000baseCR_Full);
511 case FW_PORT_TYPE_KR_SFP28:
513 FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
514 FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
515 FW_CAPS_TO_LMM(SPEED_25G, 25000baseKR_Full);
518 case FW_PORT_TYPE_KR_XLAUI:
520 FW_CAPS_TO_LMM(SPEED_1G, 1000baseKX_Full);
521 FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
522 FW_CAPS_TO_LMM(SPEED_40G, 40000baseKR4_Full);
525 case FW_PORT_TYPE_CR2_QSFP:
527 FW_CAPS_TO_LMM(SPEED_50G, 50000baseSR2_Full);
530 case FW_PORT_TYPE_KR4_100G:
531 case FW_PORT_TYPE_CR4_QSFP:
533 FW_CAPS_TO_LMM(SPEED_1G, 1000baseT_Full);
534 FW_CAPS_TO_LMM(SPEED_10G, 10000baseKR_Full);
535 FW_CAPS_TO_LMM(SPEED_40G, 40000baseSR4_Full);
536 FW_CAPS_TO_LMM(SPEED_25G, 25000baseCR_Full);
537 FW_CAPS_TO_LMM(SPEED_50G, 50000baseCR2_Full);
538 FW_CAPS_TO_LMM(SPEED_100G, 100000baseCR4_Full);
545 if (fw_caps & FW_PORT_CAP32_FEC_V(FW_PORT_CAP32_FEC_M)) {
546 FW_CAPS_TO_LMM(FEC_RS, FEC_RS);
547 FW_CAPS_TO_LMM(FEC_BASER_RS, FEC_BASER);
552 FW_CAPS_TO_LMM(ANEG, Autoneg);
553 FW_CAPS_TO_LMM(802_3_PAUSE, Pause);
554 FW_CAPS_TO_LMM(802_3_ASM_DIR, Asym_Pause);
556 #undef FW_CAPS_TO_LMM
561 * lmm_to_fw_caps - translate ethtool Link Mode Mask to Firmware
563 * @et_lmm: ethtool Link Mode Mask
565 * Translate ethtool Link Mode Mask into a Firmware Port capabilities
568 static unsigned int lmm_to_fw_caps(const unsigned long *link_mode_mask)
570 unsigned int fw_caps = 0;
572 #define LMM_TO_FW_CAPS(__lmm_name, __fw_name) \
574 if (test_bit(ETHTOOL_LINK_MODE_ ## __lmm_name ## _BIT, \
576 fw_caps |= FW_PORT_CAP32_ ## __fw_name; \
579 LMM_TO_FW_CAPS(100baseT_Full, SPEED_100M);
580 LMM_TO_FW_CAPS(1000baseT_Full, SPEED_1G);
581 LMM_TO_FW_CAPS(10000baseT_Full, SPEED_10G);
582 LMM_TO_FW_CAPS(40000baseSR4_Full, SPEED_40G);
583 LMM_TO_FW_CAPS(25000baseCR_Full, SPEED_25G);
584 LMM_TO_FW_CAPS(50000baseCR2_Full, SPEED_50G);
585 LMM_TO_FW_CAPS(100000baseCR4_Full, SPEED_100G);
587 #undef LMM_TO_FW_CAPS
592 static int get_link_ksettings(struct net_device *dev,
593 struct ethtool_link_ksettings *link_ksettings)
595 struct port_info *pi = netdev_priv(dev);
596 struct ethtool_link_settings *base = &link_ksettings->base;
598 /* For the nonce, the Firmware doesn't send up Port State changes
599 * when the Virtual Interface attached to the Port is down. So
600 * if it's down, let's grab any changes.
602 if (!netif_running(dev))
603 (void)t4_update_port_info(pi);
605 ethtool_link_ksettings_zero_link_mode(link_ksettings, supported);
606 ethtool_link_ksettings_zero_link_mode(link_ksettings, advertising);
607 ethtool_link_ksettings_zero_link_mode(link_ksettings, lp_advertising);
609 base->port = from_fw_port_mod_type(pi->port_type, pi->mod_type);
611 if (pi->mdio_addr >= 0) {
612 base->phy_address = pi->mdio_addr;
613 base->mdio_support = (pi->port_type == FW_PORT_TYPE_BT_SGMII
614 ? ETH_MDIO_SUPPORTS_C22
615 : ETH_MDIO_SUPPORTS_C45);
617 base->phy_address = 255;
618 base->mdio_support = 0;
621 fw_caps_to_lmm(pi->port_type, pi->link_cfg.pcaps,
622 link_ksettings->link_modes.supported);
623 fw_caps_to_lmm(pi->port_type,
624 t4_link_acaps(pi->adapter,
627 link_ksettings->link_modes.advertising);
628 fw_caps_to_lmm(pi->port_type, pi->link_cfg.lpacaps,
629 link_ksettings->link_modes.lp_advertising);
631 base->speed = (netif_carrier_ok(dev)
634 base->duplex = DUPLEX_FULL;
636 base->autoneg = pi->link_cfg.autoneg;
637 if (pi->link_cfg.pcaps & FW_PORT_CAP32_ANEG)
638 ethtool_link_ksettings_add_link_mode(link_ksettings,
640 if (pi->link_cfg.autoneg)
641 ethtool_link_ksettings_add_link_mode(link_ksettings,
642 advertising, Autoneg);
647 static int set_link_ksettings(struct net_device *dev,
648 const struct ethtool_link_ksettings *link_ksettings)
650 struct port_info *pi = netdev_priv(dev);
651 struct link_config *lc = &pi->link_cfg;
652 const struct ethtool_link_settings *base = &link_ksettings->base;
653 struct link_config old_lc;
654 unsigned int fw_caps;
657 /* only full-duplex supported */
658 if (base->duplex != DUPLEX_FULL)
662 if (!(lc->pcaps & FW_PORT_CAP32_ANEG) ||
663 base->autoneg == AUTONEG_DISABLE) {
664 fw_caps = speed_to_fw_caps(base->speed);
666 /* Speed must be supported by Physical Port Capabilities. */
667 if (!(lc->pcaps & fw_caps))
670 lc->speed_caps = fw_caps;
674 lmm_to_fw_caps(link_ksettings->link_modes.advertising);
675 if (!(lc->pcaps & fw_caps))
678 lc->acaps = fw_caps | FW_PORT_CAP32_ANEG;
680 lc->autoneg = base->autoneg;
682 /* If the firmware rejects the Link Configuration request, back out
683 * the changes and report the error.
685 ret = t4_link_l1cfg(pi->adapter, pi->adapter->mbox, pi->tx_chan, lc);
692 /* Translate the Firmware FEC value into the ethtool value. */
693 static inline unsigned int fwcap_to_eth_fec(unsigned int fw_fec)
695 unsigned int eth_fec = 0;
697 if (fw_fec & FW_PORT_CAP32_FEC_RS)
698 eth_fec |= ETHTOOL_FEC_RS;
699 if (fw_fec & FW_PORT_CAP32_FEC_BASER_RS)
700 eth_fec |= ETHTOOL_FEC_BASER;
702 /* if nothing is set, then FEC is off */
704 eth_fec = ETHTOOL_FEC_OFF;
709 /* Translate Common Code FEC value into ethtool value. */
710 static inline unsigned int cc_to_eth_fec(unsigned int cc_fec)
712 unsigned int eth_fec = 0;
714 if (cc_fec & FEC_AUTO)
715 eth_fec |= ETHTOOL_FEC_AUTO;
717 eth_fec |= ETHTOOL_FEC_RS;
718 if (cc_fec & FEC_BASER_RS)
719 eth_fec |= ETHTOOL_FEC_BASER;
721 /* if nothing is set, then FEC is off */
723 eth_fec = ETHTOOL_FEC_OFF;
728 /* Translate ethtool FEC value into Common Code value. */
729 static inline unsigned int eth_to_cc_fec(unsigned int eth_fec)
731 unsigned int cc_fec = 0;
733 if (eth_fec & ETHTOOL_FEC_OFF)
736 if (eth_fec & ETHTOOL_FEC_AUTO)
738 if (eth_fec & ETHTOOL_FEC_RS)
740 if (eth_fec & ETHTOOL_FEC_BASER)
741 cc_fec |= FEC_BASER_RS;
746 static int get_fecparam(struct net_device *dev, struct ethtool_fecparam *fec)
748 const struct port_info *pi = netdev_priv(dev);
749 const struct link_config *lc = &pi->link_cfg;
751 /* Translate the Firmware FEC Support into the ethtool value. We
752 * always support IEEE 802.3 "automatic" selection of Link FEC type if
753 * any FEC is supported.
755 fec->fec = fwcap_to_eth_fec(lc->pcaps);
756 if (fec->fec != ETHTOOL_FEC_OFF)
757 fec->fec |= ETHTOOL_FEC_AUTO;
759 /* Translate the current internal FEC parameters into the
762 fec->active_fec = cc_to_eth_fec(lc->fec);
767 static int set_fecparam(struct net_device *dev, struct ethtool_fecparam *fec)
769 struct port_info *pi = netdev_priv(dev);
770 struct link_config *lc = &pi->link_cfg;
771 struct link_config old_lc;
774 /* Save old Link Configuration in case the L1 Configure below
779 /* Try to perform the L1 Configure and return the result of that
780 * effort. If it fails, revert the attempted change.
782 lc->requested_fec = eth_to_cc_fec(fec->fec);
783 ret = t4_link_l1cfg(pi->adapter, pi->adapter->mbox,
790 static void get_pauseparam(struct net_device *dev,
791 struct ethtool_pauseparam *epause)
793 struct port_info *p = netdev_priv(dev);
795 epause->autoneg = (p->link_cfg.requested_fc & PAUSE_AUTONEG) != 0;
796 epause->rx_pause = (p->link_cfg.fc & PAUSE_RX) != 0;
797 epause->tx_pause = (p->link_cfg.fc & PAUSE_TX) != 0;
800 static int set_pauseparam(struct net_device *dev,
801 struct ethtool_pauseparam *epause)
803 struct port_info *p = netdev_priv(dev);
804 struct link_config *lc = &p->link_cfg;
806 if (epause->autoneg == AUTONEG_DISABLE)
807 lc->requested_fc = 0;
808 else if (lc->pcaps & FW_PORT_CAP32_ANEG)
809 lc->requested_fc = PAUSE_AUTONEG;
813 if (epause->rx_pause)
814 lc->requested_fc |= PAUSE_RX;
815 if (epause->tx_pause)
816 lc->requested_fc |= PAUSE_TX;
817 if (netif_running(dev))
818 return t4_link_l1cfg(p->adapter, p->adapter->mbox, p->tx_chan,
823 static void get_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
825 const struct port_info *pi = netdev_priv(dev);
826 const struct sge *s = &pi->adapter->sge;
828 e->rx_max_pending = MAX_RX_BUFFERS;
829 e->rx_mini_max_pending = MAX_RSPQ_ENTRIES;
830 e->rx_jumbo_max_pending = 0;
831 e->tx_max_pending = MAX_TXQ_ENTRIES;
833 e->rx_pending = s->ethrxq[pi->first_qset].fl.size - 8;
834 e->rx_mini_pending = s->ethrxq[pi->first_qset].rspq.size;
835 e->rx_jumbo_pending = 0;
836 e->tx_pending = s->ethtxq[pi->first_qset].q.size;
839 static int set_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
842 const struct port_info *pi = netdev_priv(dev);
843 struct adapter *adapter = pi->adapter;
844 struct sge *s = &adapter->sge;
846 if (e->rx_pending > MAX_RX_BUFFERS || e->rx_jumbo_pending ||
847 e->tx_pending > MAX_TXQ_ENTRIES ||
848 e->rx_mini_pending > MAX_RSPQ_ENTRIES ||
849 e->rx_mini_pending < MIN_RSPQ_ENTRIES ||
850 e->rx_pending < MIN_FL_ENTRIES || e->tx_pending < MIN_TXQ_ENTRIES)
853 if (adapter->flags & CXGB4_FULL_INIT_DONE)
856 for (i = 0; i < pi->nqsets; ++i) {
857 s->ethtxq[pi->first_qset + i].q.size = e->tx_pending;
858 s->ethrxq[pi->first_qset + i].fl.size = e->rx_pending + 8;
859 s->ethrxq[pi->first_qset + i].rspq.size = e->rx_mini_pending;
865 * set_rx_intr_params - set a net devices's RX interrupt holdoff paramete!
866 * @dev: the network device
867 * @us: the hold-off time in us, or 0 to disable timer
868 * @cnt: the hold-off packet count, or 0 to disable counter
870 * Set the RX interrupt hold-off parameters for a network device.
872 static int set_rx_intr_params(struct net_device *dev,
873 unsigned int us, unsigned int cnt)
876 struct port_info *pi = netdev_priv(dev);
877 struct adapter *adap = pi->adapter;
878 struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
880 for (i = 0; i < pi->nqsets; i++, q++) {
881 err = cxgb4_set_rspq_intr_params(&q->rspq, us, cnt);
888 static int set_adaptive_rx_setting(struct net_device *dev, int adaptive_rx)
891 struct port_info *pi = netdev_priv(dev);
892 struct adapter *adap = pi->adapter;
893 struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
895 for (i = 0; i < pi->nqsets; i++, q++)
896 q->rspq.adaptive_rx = adaptive_rx;
901 static int get_adaptive_rx_setting(struct net_device *dev)
903 struct port_info *pi = netdev_priv(dev);
904 struct adapter *adap = pi->adapter;
905 struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
907 return q->rspq.adaptive_rx;
910 /* Return the current global Adapter SGE Doorbell Queue Timer Tick for all
911 * Ethernet TX Queues.
913 static int get_dbqtimer_tick(struct net_device *dev)
915 struct port_info *pi = netdev_priv(dev);
916 struct adapter *adap = pi->adapter;
918 if (!(adap->flags & CXGB4_SGE_DBQ_TIMER))
921 return adap->sge.dbqtimer_tick;
924 /* Return the SGE Doorbell Queue Timer Value for the Ethernet TX Queues
925 * associated with a Network Device.
927 static int get_dbqtimer(struct net_device *dev)
929 struct port_info *pi = netdev_priv(dev);
930 struct adapter *adap = pi->adapter;
931 struct sge_eth_txq *txq;
933 txq = &adap->sge.ethtxq[pi->first_qset];
935 if (!(adap->flags & CXGB4_SGE_DBQ_TIMER))
938 /* all of the TX Queues use the same Timer Index */
939 return adap->sge.dbqtimer_val[txq->dbqtimerix];
942 /* Set the global Adapter SGE Doorbell Queue Timer Tick for all Ethernet TX
943 * Queues. This is the fundamental "Tick" that sets the scale of values which
944 * can be used. Individual Ethernet TX Queues index into a relatively small
945 * array of Tick Multipliers. Changing the base Tick will thus change all of
946 * the resulting Timer Values associated with those multipliers for all
947 * Ethernet TX Queues.
949 static int set_dbqtimer_tick(struct net_device *dev, int usecs)
951 struct port_info *pi = netdev_priv(dev);
952 struct adapter *adap = pi->adapter;
953 struct sge *s = &adap->sge;
957 if (!(adap->flags & CXGB4_SGE_DBQ_TIMER))
960 /* return early if it's the same Timer Tick we're already using */
961 if (s->dbqtimer_tick == usecs)
964 /* attempt to set the new Timer Tick value */
965 param = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
966 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_DBQ_TIMERTICK));
968 ret = t4_set_params(adap, adap->mbox, adap->pf, 0, 1, ¶m, &val);
971 s->dbqtimer_tick = usecs;
973 /* if successful, reread resulting dependent Timer values */
974 ret = t4_read_sge_dbqtimers(adap, ARRAY_SIZE(s->dbqtimer_val),
979 /* Set the SGE Doorbell Queue Timer Value for the Ethernet TX Queues
980 * associated with a Network Device. There is a relatively small array of
981 * possible Timer Values so we need to pick the closest value available.
983 static int set_dbqtimer(struct net_device *dev, int usecs)
985 int qix, timerix, min_timerix, delta, min_delta;
986 struct port_info *pi = netdev_priv(dev);
987 struct adapter *adap = pi->adapter;
988 struct sge *s = &adap->sge;
989 struct sge_eth_txq *txq;
993 if (!(adap->flags & CXGB4_SGE_DBQ_TIMER))
996 /* Find the SGE Doorbell Timer Value that's closest to the requested
1001 for (timerix = 0; timerix < ARRAY_SIZE(s->dbqtimer_val); timerix++) {
1002 delta = s->dbqtimer_val[timerix] - usecs;
1005 if (delta < min_delta) {
1007 min_timerix = timerix;
1011 /* Return early if it's the same Timer Index we're already using.
1012 * We use the same Timer Index for all of the TX Queues for an
1013 * interface so it's only necessary to check the first one.
1015 txq = &s->ethtxq[pi->first_qset];
1016 if (txq->dbqtimerix == min_timerix)
1019 for (qix = 0; qix < pi->nqsets; qix++, txq++) {
1020 if (adap->flags & CXGB4_FULL_INIT_DONE) {
1022 (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
1023 FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DMAQ_EQ_TIMERIX) |
1024 FW_PARAMS_PARAM_YZ_V(txq->q.cntxt_id));
1026 ret = t4_set_params(adap, adap->mbox, adap->pf, 0,
1031 txq->dbqtimerix = min_timerix;
1036 /* Set the global Adapter SGE Doorbell Queue Timer Tick for all Ethernet TX
1037 * Queues and the Timer Value for the Ethernet TX Queues associated with a
1038 * Network Device. Since changing the global Tick changes all of the
1039 * available Timer Values, we need to do this first before selecting the
1040 * resulting closest Timer Value. Moreover, since the Tick is global,
1041 * changing it affects the Timer Values for all Network Devices on the
1042 * adapter. So, before changing the Tick, we grab all of the current Timer
1043 * Values for other Network Devices on this Adapter and then attempt to select
1044 * new Timer Values which are close to the old values ...
1046 static int set_dbqtimer_tickval(struct net_device *dev,
1047 int tick_usecs, int timer_usecs)
1049 struct port_info *pi = netdev_priv(dev);
1050 struct adapter *adap = pi->adapter;
1051 int timer[MAX_NPORTS];
1055 /* Grab the other adapter Network Interface current timers and fill in
1056 * the new one for this Network Interface.
1058 for_each_port(adap, port)
1059 if (port == pi->port_id)
1060 timer[port] = timer_usecs;
1062 timer[port] = get_dbqtimer(adap->port[port]);
1064 /* Change the global Tick first ... */
1065 ret = set_dbqtimer_tick(dev, tick_usecs);
1069 /* ... and then set all of the Network Interface Timer Values ... */
1070 for_each_port(adap, port) {
1071 ret = set_dbqtimer(adap->port[port], timer[port]);
1079 static int set_coalesce(struct net_device *dev,
1080 struct ethtool_coalesce *coalesce)
1084 set_adaptive_rx_setting(dev, coalesce->use_adaptive_rx_coalesce);
1086 ret = set_rx_intr_params(dev, coalesce->rx_coalesce_usecs,
1087 coalesce->rx_max_coalesced_frames);
1091 return set_dbqtimer_tickval(dev,
1092 coalesce->tx_coalesce_usecs_irq,
1093 coalesce->tx_coalesce_usecs);
1096 static int get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
1098 const struct port_info *pi = netdev_priv(dev);
1099 const struct adapter *adap = pi->adapter;
1100 const struct sge_rspq *rq = &adap->sge.ethrxq[pi->first_qset].rspq;
1102 c->rx_coalesce_usecs = qtimer_val(adap, rq);
1103 c->rx_max_coalesced_frames = (rq->intr_params & QINTR_CNT_EN_F) ?
1104 adap->sge.counter_val[rq->pktcnt_idx] : 0;
1105 c->use_adaptive_rx_coalesce = get_adaptive_rx_setting(dev);
1106 c->tx_coalesce_usecs_irq = get_dbqtimer_tick(dev);
1107 c->tx_coalesce_usecs = get_dbqtimer(dev);
1111 /* The next two routines implement eeprom read/write from physical addresses.
1113 static int eeprom_rd_phys(struct adapter *adap, unsigned int phys_addr, u32 *v)
1115 int vaddr = t4_eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
1118 vaddr = pci_read_vpd(adap->pdev, vaddr, sizeof(u32), v);
1119 return vaddr < 0 ? vaddr : 0;
1122 static int eeprom_wr_phys(struct adapter *adap, unsigned int phys_addr, u32 v)
1124 int vaddr = t4_eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
1127 vaddr = pci_write_vpd(adap->pdev, vaddr, sizeof(u32), &v);
1128 return vaddr < 0 ? vaddr : 0;
1131 #define EEPROM_MAGIC 0x38E2F10C
1133 static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *e,
1137 struct adapter *adapter = netdev2adap(dev);
1138 u8 *buf = kvzalloc(EEPROMSIZE, GFP_KERNEL);
1143 e->magic = EEPROM_MAGIC;
1144 for (i = e->offset & ~3; !err && i < e->offset + e->len; i += 4)
1145 err = eeprom_rd_phys(adapter, i, (u32 *)&buf[i]);
1148 memcpy(data, buf + e->offset, e->len);
1153 static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
1158 u32 aligned_offset, aligned_len, *p;
1159 struct adapter *adapter = netdev2adap(dev);
1161 if (eeprom->magic != EEPROM_MAGIC)
1164 aligned_offset = eeprom->offset & ~3;
1165 aligned_len = (eeprom->len + (eeprom->offset & 3) + 3) & ~3;
1167 if (adapter->pf > 0) {
1168 u32 start = 1024 + adapter->pf * EEPROMPFSIZE;
1170 if (aligned_offset < start ||
1171 aligned_offset + aligned_len > start + EEPROMPFSIZE)
1175 if (aligned_offset != eeprom->offset || aligned_len != eeprom->len) {
1176 /* RMW possibly needed for first or last words.
1178 buf = kvzalloc(aligned_len, GFP_KERNEL);
1181 err = eeprom_rd_phys(adapter, aligned_offset, (u32 *)buf);
1182 if (!err && aligned_len > 4)
1183 err = eeprom_rd_phys(adapter,
1184 aligned_offset + aligned_len - 4,
1185 (u32 *)&buf[aligned_len - 4]);
1188 memcpy(buf + (eeprom->offset & 3), data, eeprom->len);
1193 err = t4_seeprom_wp(adapter, false);
1197 for (p = (u32 *)buf; !err && aligned_len; aligned_len -= 4, p++) {
1198 err = eeprom_wr_phys(adapter, aligned_offset, *p);
1199 aligned_offset += 4;
1203 err = t4_seeprom_wp(adapter, true);
1210 static int set_flash(struct net_device *netdev, struct ethtool_flash *ef)
1213 const struct firmware *fw;
1214 struct adapter *adap = netdev2adap(netdev);
1215 unsigned int mbox = PCIE_FW_MASTER_M + 1;
1217 unsigned int master;
1220 pcie_fw = t4_read_reg(adap, PCIE_FW_A);
1221 master = PCIE_FW_MASTER_G(pcie_fw);
1222 if (pcie_fw & PCIE_FW_MASTER_VLD_F)
1224 /* if csiostor is the master return */
1225 if (master_vld && (master != adap->pf)) {
1226 dev_warn(adap->pdev_dev,
1227 "cxgb4 driver needs to be loaded as MASTER to support FW flash\n");
1231 ef->data[sizeof(ef->data) - 1] = '\0';
1232 ret = request_firmware(&fw, ef->data, adap->pdev_dev);
1236 /* If the adapter has been fully initialized then we'll go ahead and
1237 * try to get the firmware's cooperation in upgrading to the new
1238 * firmware image otherwise we'll try to do the entire job from the
1239 * host ... and we always "force" the operation in this path.
1241 if (adap->flags & CXGB4_FULL_INIT_DONE)
1244 ret = t4_fw_upgrade(adap, mbox, fw->data, fw->size, 1);
1245 release_firmware(fw);
1247 dev_info(adap->pdev_dev,
1248 "loaded firmware %s, reload cxgb4 driver\n", ef->data);
1252 static int get_ts_info(struct net_device *dev, struct ethtool_ts_info *ts_info)
1254 struct port_info *pi = netdev_priv(dev);
1255 struct adapter *adapter = pi->adapter;
1257 ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1258 SOF_TIMESTAMPING_RX_SOFTWARE |
1259 SOF_TIMESTAMPING_SOFTWARE;
1261 ts_info->so_timestamping |= SOF_TIMESTAMPING_RX_HARDWARE |
1262 SOF_TIMESTAMPING_TX_HARDWARE |
1263 SOF_TIMESTAMPING_RAW_HARDWARE;
1265 ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) |
1266 (1 << HWTSTAMP_TX_ON);
1268 ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1269 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1270 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1271 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1272 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1273 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
1275 if (adapter->ptp_clock)
1276 ts_info->phc_index = ptp_clock_index(adapter->ptp_clock);
1278 ts_info->phc_index = -1;
1283 static u32 get_rss_table_size(struct net_device *dev)
1285 const struct port_info *pi = netdev_priv(dev);
1287 return pi->rss_size;
1290 static int get_rss_table(struct net_device *dev, u32 *p, u8 *key, u8 *hfunc)
1292 const struct port_info *pi = netdev_priv(dev);
1293 unsigned int n = pi->rss_size;
1296 *hfunc = ETH_RSS_HASH_TOP;
1304 static int set_rss_table(struct net_device *dev, const u32 *p, const u8 *key,
1308 struct port_info *pi = netdev_priv(dev);
1310 /* We require at least one supported parameter to be changed and no
1311 * change in any of the unsupported parameters
1314 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
1319 /* Interface must be brought up atleast once */
1320 if (pi->adapter->flags & CXGB4_FULL_INIT_DONE) {
1321 for (i = 0; i < pi->rss_size; i++)
1324 return cxgb4_write_rss(pi, pi->rss);
1330 static int get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1333 const struct port_info *pi = netdev_priv(dev);
1335 switch (info->cmd) {
1336 case ETHTOOL_GRXFH: {
1337 unsigned int v = pi->rss_mode;
1340 switch (info->flow_type) {
1342 if (v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F)
1343 info->data = RXH_IP_SRC | RXH_IP_DST |
1344 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1345 else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
1346 info->data = RXH_IP_SRC | RXH_IP_DST;
1349 if ((v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F) &&
1350 (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
1351 info->data = RXH_IP_SRC | RXH_IP_DST |
1352 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1353 else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
1354 info->data = RXH_IP_SRC | RXH_IP_DST;
1357 case AH_ESP_V4_FLOW:
1359 if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
1360 info->data = RXH_IP_SRC | RXH_IP_DST;
1363 if (v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F)
1364 info->data = RXH_IP_SRC | RXH_IP_DST |
1365 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1366 else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
1367 info->data = RXH_IP_SRC | RXH_IP_DST;
1370 if ((v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F) &&
1371 (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
1372 info->data = RXH_IP_SRC | RXH_IP_DST |
1373 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1374 else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
1375 info->data = RXH_IP_SRC | RXH_IP_DST;
1378 case AH_ESP_V6_FLOW:
1380 if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
1381 info->data = RXH_IP_SRC | RXH_IP_DST;
1386 case ETHTOOL_GRXRINGS:
1387 info->data = pi->nqsets;
1393 static int set_dump(struct net_device *dev, struct ethtool_dump *eth_dump)
1395 struct adapter *adapter = netdev2adap(dev);
1398 len = sizeof(struct cudbg_hdr) +
1399 sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY;
1400 len += cxgb4_get_dump_length(adapter, eth_dump->flag);
1402 adapter->eth_dump.flag = eth_dump->flag;
1403 adapter->eth_dump.len = len;
1407 static int get_dump_flag(struct net_device *dev, struct ethtool_dump *eth_dump)
1409 struct adapter *adapter = netdev2adap(dev);
1411 eth_dump->flag = adapter->eth_dump.flag;
1412 eth_dump->len = adapter->eth_dump.len;
1413 eth_dump->version = adapter->eth_dump.version;
1417 static int get_dump_data(struct net_device *dev, struct ethtool_dump *eth_dump,
1420 struct adapter *adapter = netdev2adap(dev);
1424 if (adapter->eth_dump.flag == CXGB4_ETH_DUMP_NONE)
1427 len = sizeof(struct cudbg_hdr) +
1428 sizeof(struct cudbg_entity_hdr) * CUDBG_MAX_ENTITY;
1429 len += cxgb4_get_dump_length(adapter, adapter->eth_dump.flag);
1430 if (eth_dump->len < len)
1433 ret = cxgb4_cudbg_collect(adapter, buf, &len, adapter->eth_dump.flag);
1437 eth_dump->flag = adapter->eth_dump.flag;
1438 eth_dump->len = len;
1439 eth_dump->version = adapter->eth_dump.version;
1443 static int cxgb4_get_module_info(struct net_device *dev,
1444 struct ethtool_modinfo *modinfo)
1446 struct port_info *pi = netdev_priv(dev);
1447 u8 sff8472_comp, sff_diag_type, sff_rev;
1448 struct adapter *adapter = pi->adapter;
1451 if (!t4_is_inserted_mod_type(pi->mod_type))
1454 switch (pi->port_type) {
1455 case FW_PORT_TYPE_SFP:
1456 case FW_PORT_TYPE_QSA:
1457 case FW_PORT_TYPE_SFP28:
1458 ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
1459 I2C_DEV_ADDR_A0, SFF_8472_COMP_ADDR,
1460 SFF_8472_COMP_LEN, &sff8472_comp);
1463 ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
1464 I2C_DEV_ADDR_A0, SFP_DIAG_TYPE_ADDR,
1465 SFP_DIAG_TYPE_LEN, &sff_diag_type);
1469 if (!sff8472_comp || (sff_diag_type & 4)) {
1470 modinfo->type = ETH_MODULE_SFF_8079;
1471 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
1473 modinfo->type = ETH_MODULE_SFF_8472;
1474 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1478 case FW_PORT_TYPE_QSFP:
1479 case FW_PORT_TYPE_QSFP_10G:
1480 case FW_PORT_TYPE_CR_QSFP:
1481 case FW_PORT_TYPE_CR2_QSFP:
1482 case FW_PORT_TYPE_CR4_QSFP:
1483 ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
1484 I2C_DEV_ADDR_A0, SFF_REV_ADDR,
1485 SFF_REV_LEN, &sff_rev);
1486 /* For QSFP type ports, revision value >= 3
1487 * means the SFP is 8636 compliant.
1491 if (sff_rev >= 0x3) {
1492 modinfo->type = ETH_MODULE_SFF_8636;
1493 modinfo->eeprom_len = ETH_MODULE_SFF_8636_LEN;
1495 modinfo->type = ETH_MODULE_SFF_8436;
1496 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1507 static int cxgb4_get_module_eeprom(struct net_device *dev,
1508 struct ethtool_eeprom *eprom, u8 *data)
1510 int ret = 0, offset = eprom->offset, len = eprom->len;
1511 struct port_info *pi = netdev_priv(dev);
1512 struct adapter *adapter = pi->adapter;
1514 memset(data, 0, eprom->len);
1515 if (offset + len <= I2C_PAGE_SIZE)
1516 return t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
1517 I2C_DEV_ADDR_A0, offset, len, data);
1519 /* offset + len spans 0xa0 and 0xa1 pages */
1520 if (offset <= I2C_PAGE_SIZE) {
1521 /* read 0xa0 page */
1522 len = I2C_PAGE_SIZE - offset;
1523 ret = t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan,
1524 I2C_DEV_ADDR_A0, offset, len, data);
1527 offset = I2C_PAGE_SIZE;
1528 /* Remaining bytes to be read from second page =
1529 * Total length - bytes read from first page
1531 len = eprom->len - len;
1533 /* Read additional optical diagnostics from page 0xa2 if supported */
1534 return t4_i2c_rd(adapter, adapter->mbox, pi->tx_chan, I2C_DEV_ADDR_A2,
1535 offset, len, &data[eprom->len - len]);
1538 static u32 cxgb4_get_priv_flags(struct net_device *netdev)
1540 struct port_info *pi = netdev_priv(netdev);
1541 struct adapter *adapter = pi->adapter;
1543 return (adapter->eth_flags | pi->eth_flags);
1547 * set_flags - set/unset specified flags if passed in new_flags
1548 * @cur_flags: pointer to current flags
1549 * @new_flags: new incoming flags
1550 * @flags: set of flags to set/unset
1552 static inline void set_flags(u32 *cur_flags, u32 new_flags, u32 flags)
1554 *cur_flags = (*cur_flags & ~flags) | (new_flags & flags);
1557 static int cxgb4_set_priv_flags(struct net_device *netdev, u32 flags)
1559 struct port_info *pi = netdev_priv(netdev);
1560 struct adapter *adapter = pi->adapter;
1562 set_flags(&adapter->eth_flags, flags, PRIV_FLAGS_ADAP);
1563 set_flags(&pi->eth_flags, flags, PRIV_FLAGS_PORT);
1568 static const struct ethtool_ops cxgb_ethtool_ops = {
1569 .get_link_ksettings = get_link_ksettings,
1570 .set_link_ksettings = set_link_ksettings,
1571 .get_fecparam = get_fecparam,
1572 .set_fecparam = set_fecparam,
1573 .get_drvinfo = get_drvinfo,
1574 .get_msglevel = get_msglevel,
1575 .set_msglevel = set_msglevel,
1576 .get_ringparam = get_sge_param,
1577 .set_ringparam = set_sge_param,
1578 .get_coalesce = get_coalesce,
1579 .set_coalesce = set_coalesce,
1580 .get_eeprom_len = get_eeprom_len,
1581 .get_eeprom = get_eeprom,
1582 .set_eeprom = set_eeprom,
1583 .get_pauseparam = get_pauseparam,
1584 .set_pauseparam = set_pauseparam,
1585 .get_link = ethtool_op_get_link,
1586 .get_strings = get_strings,
1587 .set_phys_id = identify_port,
1588 .nway_reset = restart_autoneg,
1589 .get_sset_count = get_sset_count,
1590 .get_ethtool_stats = get_stats,
1591 .get_regs_len = get_regs_len,
1592 .get_regs = get_regs,
1593 .get_rxnfc = get_rxnfc,
1594 .get_rxfh_indir_size = get_rss_table_size,
1595 .get_rxfh = get_rss_table,
1596 .set_rxfh = set_rss_table,
1597 .flash_device = set_flash,
1598 .get_ts_info = get_ts_info,
1599 .set_dump = set_dump,
1600 .get_dump_flag = get_dump_flag,
1601 .get_dump_data = get_dump_data,
1602 .get_module_info = cxgb4_get_module_info,
1603 .get_module_eeprom = cxgb4_get_module_eeprom,
1604 .get_priv_flags = cxgb4_get_priv_flags,
1605 .set_priv_flags = cxgb4_set_priv_flags,
1608 void cxgb4_set_ethtool_ops(struct net_device *netdev)
1610 netdev->ethtool_ops = &cxgb_ethtool_ops;