2 * Copyright (C) 2013-2015 Chelsio Communications. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
18 #include <linux/firmware.h>
19 #include <linux/mdio.h>
25 #define EEPROM_MAGIC 0x38E2F10C
27 static u32 get_msglevel(struct net_device *dev)
29 return netdev2adap(dev)->msg_enable;
32 static void set_msglevel(struct net_device *dev, u32 val)
34 netdev2adap(dev)->msg_enable = val;
37 static const char stats_strings[][ETH_GSTRING_LEN] = {
50 "TxFrames1024To1518 ",
82 "RxFrames1024To1518 ",
95 "RxBG0FramesDropped ",
96 "RxBG1FramesDropped ",
97 "RxBG2FramesDropped ",
98 "RxBG3FramesDropped ",
113 static char adapter_stats_strings[][ETH_GSTRING_LEN] = {
117 "tcp_ipv4_out_rsts ",
119 "tcp_ipv4_out_segs ",
120 "tcp_ipv4_retrans_segs ",
121 "tcp_ipv6_out_rsts ",
123 "tcp_ipv6_out_segs ",
124 "tcp_ipv6_retrans_segs ",
128 "rdma_no_rqe_mod_defer ",
129 "rdma_no_rqe_pkt_defer ",
130 "tp_err_ofld_no_neigh ",
131 "tp_err_ofld_cong_defer ",
132 "write_coal_success ",
136 static char channel_stats_strings[][ETH_GSTRING_LEN] = {
137 "--------Channel--------- ",
144 "tp_tnl_cong_drops ",
146 "tp_ofld_vlan_drops ",
147 "tp_ofld_chan_drops ",
153 static int get_sset_count(struct net_device *dev, int sset)
157 return ARRAY_SIZE(stats_strings) +
158 ARRAY_SIZE(adapter_stats_strings) +
159 ARRAY_SIZE(channel_stats_strings);
165 static int get_regs_len(struct net_device *dev)
167 struct adapter *adap = netdev2adap(dev);
169 return t4_get_regs_len(adap);
172 static int get_eeprom_len(struct net_device *dev)
177 static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
179 struct adapter *adapter = netdev2adap(dev);
182 strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
183 strlcpy(info->version, cxgb4_driver_version,
184 sizeof(info->version));
185 strlcpy(info->bus_info, pci_name(adapter->pdev),
186 sizeof(info->bus_info));
188 if (adapter->params.fw_vers)
189 snprintf(info->fw_version, sizeof(info->fw_version),
190 "%u.%u.%u.%u, TP %u.%u.%u.%u",
191 FW_HDR_FW_VER_MAJOR_G(adapter->params.fw_vers),
192 FW_HDR_FW_VER_MINOR_G(adapter->params.fw_vers),
193 FW_HDR_FW_VER_MICRO_G(adapter->params.fw_vers),
194 FW_HDR_FW_VER_BUILD_G(adapter->params.fw_vers),
195 FW_HDR_FW_VER_MAJOR_G(adapter->params.tp_vers),
196 FW_HDR_FW_VER_MINOR_G(adapter->params.tp_vers),
197 FW_HDR_FW_VER_MICRO_G(adapter->params.tp_vers),
198 FW_HDR_FW_VER_BUILD_G(adapter->params.tp_vers));
200 if (!t4_get_exprom_version(adapter, &exprom_vers))
201 snprintf(info->erom_version, sizeof(info->erom_version),
203 FW_HDR_FW_VER_MAJOR_G(exprom_vers),
204 FW_HDR_FW_VER_MINOR_G(exprom_vers),
205 FW_HDR_FW_VER_MICRO_G(exprom_vers),
206 FW_HDR_FW_VER_BUILD_G(exprom_vers));
209 static void get_strings(struct net_device *dev, u32 stringset, u8 *data)
211 if (stringset == ETH_SS_STATS) {
212 memcpy(data, stats_strings, sizeof(stats_strings));
213 data += sizeof(stats_strings);
214 memcpy(data, adapter_stats_strings,
215 sizeof(adapter_stats_strings));
216 data += sizeof(adapter_stats_strings);
217 memcpy(data, channel_stats_strings,
218 sizeof(channel_stats_strings));
222 /* port stats maintained per queue of the port. They should be in the same
223 * order as in stats_strings above.
225 struct queue_port_stats {
235 struct adapter_stats {
242 u64 tcp_v4_retrans_segs;
246 u64 tcp_v6_retrans_segs;
258 struct channel_stats {
274 static void collect_sge_port_stats(const struct adapter *adap,
275 const struct port_info *p,
276 struct queue_port_stats *s)
279 const struct sge_eth_txq *tx = &adap->sge.ethtxq[p->first_qset];
280 const struct sge_eth_rxq *rx = &adap->sge.ethrxq[p->first_qset];
282 memset(s, 0, sizeof(*s));
283 for (i = 0; i < p->nqsets; i++, rx++, tx++) {
285 s->tx_csum += tx->tx_cso;
286 s->rx_csum += rx->stats.rx_cso;
287 s->vlan_ex += rx->stats.vlan_ex;
288 s->vlan_ins += tx->vlan_ins;
289 s->gro_pkts += rx->stats.lro_pkts;
290 s->gro_merged += rx->stats.lro_merged;
294 static void collect_adapter_stats(struct adapter *adap, struct adapter_stats *s)
296 struct tp_tcp_stats v4, v6;
297 struct tp_rdma_stats rdma_stats;
298 struct tp_err_stats err_stats;
299 struct tp_usm_stats usm_stats;
302 memset(s, 0, sizeof(*s));
304 spin_lock(&adap->stats_lock);
305 t4_tp_get_tcp_stats(adap, &v4, &v6);
306 t4_tp_get_rdma_stats(adap, &rdma_stats);
307 t4_get_usm_stats(adap, &usm_stats);
308 t4_tp_get_err_stats(adap, &err_stats);
309 spin_unlock(&adap->stats_lock);
311 s->db_drop = adap->db_stats.db_drop;
312 s->db_full = adap->db_stats.db_full;
313 s->db_empty = adap->db_stats.db_empty;
315 s->tcp_v4_out_rsts = v4.tcp_out_rsts;
316 s->tcp_v4_in_segs = v4.tcp_in_segs;
317 s->tcp_v4_out_segs = v4.tcp_out_segs;
318 s->tcp_v4_retrans_segs = v4.tcp_retrans_segs;
319 s->tcp_v6_out_rsts = v6.tcp_out_rsts;
320 s->tcp_v6_in_segs = v6.tcp_in_segs;
321 s->tcp_v6_out_segs = v6.tcp_out_segs;
322 s->tcp_v6_retrans_segs = v6.tcp_retrans_segs;
324 if (is_offload(adap)) {
325 s->frames = usm_stats.frames;
326 s->octets = usm_stats.octets;
327 s->drops = usm_stats.drops;
328 s->rqe_dfr_mod = rdma_stats.rqe_dfr_mod;
329 s->rqe_dfr_pkt = rdma_stats.rqe_dfr_pkt;
332 s->ofld_no_neigh = err_stats.ofld_no_neigh;
333 s->ofld_cong_defer = err_stats.ofld_cong_defer;
335 if (!is_t4(adap->params.chip)) {
338 v = t4_read_reg(adap, SGE_STAT_CFG_A);
339 if (STATSOURCE_T5_G(v) == 7) {
340 val2 = t4_read_reg(adap, SGE_STAT_MATCH_A);
341 val1 = t4_read_reg(adap, SGE_STAT_TOTAL_A);
342 s->wc_success = val1 - val2;
348 static void collect_channel_stats(struct adapter *adap, struct channel_stats *s,
351 struct tp_cpl_stats cpl_stats;
352 struct tp_err_stats err_stats;
353 struct tp_fcoe_stats fcoe_stats;
355 memset(s, 0, sizeof(*s));
357 spin_lock(&adap->stats_lock);
358 t4_tp_get_cpl_stats(adap, &cpl_stats);
359 t4_tp_get_err_stats(adap, &err_stats);
360 t4_get_fcoe_stats(adap, i, &fcoe_stats);
361 spin_unlock(&adap->stats_lock);
363 s->cpl_req = cpl_stats.req[i];
364 s->cpl_rsp = cpl_stats.rsp[i];
365 s->mac_in_errs = err_stats.mac_in_errs[i];
366 s->hdr_in_errs = err_stats.hdr_in_errs[i];
367 s->tcp_in_errs = err_stats.tcp_in_errs[i];
368 s->tcp6_in_errs = err_stats.tcp6_in_errs[i];
369 s->tnl_cong_drops = err_stats.tnl_cong_drops[i];
370 s->tnl_tx_drops = err_stats.tnl_tx_drops[i];
371 s->ofld_vlan_drops = err_stats.ofld_vlan_drops[i];
372 s->ofld_chan_drops = err_stats.ofld_chan_drops[i];
373 s->octets_ddp = fcoe_stats.octets_ddp;
374 s->frames_ddp = fcoe_stats.frames_ddp;
375 s->frames_drop = fcoe_stats.frames_drop;
378 static void get_stats(struct net_device *dev, struct ethtool_stats *stats,
381 struct port_info *pi = netdev_priv(dev);
382 struct adapter *adapter = pi->adapter;
384 t4_get_port_stats_offset(adapter, pi->tx_chan,
385 (struct port_stats *)data,
388 data += sizeof(struct port_stats) / sizeof(u64);
389 collect_sge_port_stats(adapter, pi, (struct queue_port_stats *)data);
390 data += sizeof(struct queue_port_stats) / sizeof(u64);
391 collect_adapter_stats(adapter, (struct adapter_stats *)data);
392 data += sizeof(struct adapter_stats) / sizeof(u64);
394 *data++ = (u64)pi->port_id;
395 collect_channel_stats(adapter, (struct channel_stats *)data,
400 static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
403 struct adapter *adap = netdev2adap(dev);
406 buf_size = t4_get_regs_len(adap);
407 regs->version = mk_adap_vers(adap);
408 t4_get_regs(adap, buf, buf_size);
411 static int restart_autoneg(struct net_device *dev)
413 struct port_info *p = netdev_priv(dev);
415 if (!netif_running(dev))
417 if (p->link_cfg.autoneg != AUTONEG_ENABLE)
419 t4_restart_aneg(p->adapter, p->adapter->pf, p->tx_chan);
423 static int identify_port(struct net_device *dev,
424 enum ethtool_phys_id_state state)
427 struct adapter *adap = netdev2adap(dev);
429 if (state == ETHTOOL_ID_ACTIVE)
431 else if (state == ETHTOOL_ID_INACTIVE)
436 return t4_identify_port(adap, adap->pf, netdev2pinfo(dev)->viid, val);
439 static unsigned int from_fw_linkcaps(enum fw_port_type type, unsigned int caps)
443 if (type == FW_PORT_TYPE_BT_SGMII || type == FW_PORT_TYPE_BT_XFI ||
444 type == FW_PORT_TYPE_BT_XAUI) {
446 if (caps & FW_PORT_CAP_SPEED_100M)
447 v |= SUPPORTED_100baseT_Full;
448 if (caps & FW_PORT_CAP_SPEED_1G)
449 v |= SUPPORTED_1000baseT_Full;
450 if (caps & FW_PORT_CAP_SPEED_10G)
451 v |= SUPPORTED_10000baseT_Full;
452 } else if (type == FW_PORT_TYPE_KX4 || type == FW_PORT_TYPE_KX) {
453 v |= SUPPORTED_Backplane;
454 if (caps & FW_PORT_CAP_SPEED_1G)
455 v |= SUPPORTED_1000baseKX_Full;
456 if (caps & FW_PORT_CAP_SPEED_10G)
457 v |= SUPPORTED_10000baseKX4_Full;
458 } else if (type == FW_PORT_TYPE_KR) {
459 v |= SUPPORTED_Backplane | SUPPORTED_10000baseKR_Full;
460 } else if (type == FW_PORT_TYPE_BP_AP) {
461 v |= SUPPORTED_Backplane | SUPPORTED_10000baseR_FEC |
462 SUPPORTED_10000baseKR_Full | SUPPORTED_1000baseKX_Full;
463 } else if (type == FW_PORT_TYPE_BP4_AP) {
464 v |= SUPPORTED_Backplane | SUPPORTED_10000baseR_FEC |
465 SUPPORTED_10000baseKR_Full | SUPPORTED_1000baseKX_Full |
466 SUPPORTED_10000baseKX4_Full;
467 } else if (type == FW_PORT_TYPE_FIBER_XFI ||
468 type == FW_PORT_TYPE_FIBER_XAUI ||
469 type == FW_PORT_TYPE_SFP ||
470 type == FW_PORT_TYPE_QSFP_10G ||
471 type == FW_PORT_TYPE_QSA) {
472 v |= SUPPORTED_FIBRE;
473 if (caps & FW_PORT_CAP_SPEED_1G)
474 v |= SUPPORTED_1000baseT_Full;
475 if (caps & FW_PORT_CAP_SPEED_10G)
476 v |= SUPPORTED_10000baseT_Full;
477 } else if (type == FW_PORT_TYPE_BP40_BA ||
478 type == FW_PORT_TYPE_QSFP) {
479 v |= SUPPORTED_40000baseSR4_Full;
480 v |= SUPPORTED_FIBRE;
483 if (caps & FW_PORT_CAP_ANEG)
484 v |= SUPPORTED_Autoneg;
488 static unsigned int to_fw_linkcaps(unsigned int caps)
492 if (caps & ADVERTISED_100baseT_Full)
493 v |= FW_PORT_CAP_SPEED_100M;
494 if (caps & ADVERTISED_1000baseT_Full)
495 v |= FW_PORT_CAP_SPEED_1G;
496 if (caps & ADVERTISED_10000baseT_Full)
497 v |= FW_PORT_CAP_SPEED_10G;
498 if (caps & ADVERTISED_40000baseSR4_Full)
499 v |= FW_PORT_CAP_SPEED_40G;
503 static int get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
505 const struct port_info *p = netdev_priv(dev);
507 if (p->port_type == FW_PORT_TYPE_BT_SGMII ||
508 p->port_type == FW_PORT_TYPE_BT_XFI ||
509 p->port_type == FW_PORT_TYPE_BT_XAUI) {
511 } else if (p->port_type == FW_PORT_TYPE_FIBER_XFI ||
512 p->port_type == FW_PORT_TYPE_FIBER_XAUI) {
513 cmd->port = PORT_FIBRE;
514 } else if (p->port_type == FW_PORT_TYPE_SFP ||
515 p->port_type == FW_PORT_TYPE_QSFP_10G ||
516 p->port_type == FW_PORT_TYPE_QSA ||
517 p->port_type == FW_PORT_TYPE_QSFP) {
518 if (p->mod_type == FW_PORT_MOD_TYPE_LR ||
519 p->mod_type == FW_PORT_MOD_TYPE_SR ||
520 p->mod_type == FW_PORT_MOD_TYPE_ER ||
521 p->mod_type == FW_PORT_MOD_TYPE_LRM)
522 cmd->port = PORT_FIBRE;
523 else if (p->mod_type == FW_PORT_MOD_TYPE_TWINAX_PASSIVE ||
524 p->mod_type == FW_PORT_MOD_TYPE_TWINAX_ACTIVE)
527 cmd->port = PORT_OTHER;
529 cmd->port = PORT_OTHER;
532 if (p->mdio_addr >= 0) {
533 cmd->phy_address = p->mdio_addr;
534 cmd->transceiver = XCVR_EXTERNAL;
535 cmd->mdio_support = p->port_type == FW_PORT_TYPE_BT_SGMII ?
536 MDIO_SUPPORTS_C22 : MDIO_SUPPORTS_C45;
538 cmd->phy_address = 0; /* not really, but no better option */
539 cmd->transceiver = XCVR_INTERNAL;
540 cmd->mdio_support = 0;
543 cmd->supported = from_fw_linkcaps(p->port_type, p->link_cfg.supported);
544 cmd->advertising = from_fw_linkcaps(p->port_type,
545 p->link_cfg.advertising);
546 ethtool_cmd_speed_set(cmd,
547 netif_carrier_ok(dev) ? p->link_cfg.speed : 0);
548 cmd->duplex = DUPLEX_FULL;
549 cmd->autoneg = p->link_cfg.autoneg;
555 static unsigned int speed_to_caps(int speed)
558 return FW_PORT_CAP_SPEED_100M;
560 return FW_PORT_CAP_SPEED_1G;
562 return FW_PORT_CAP_SPEED_10G;
564 return FW_PORT_CAP_SPEED_40G;
568 static int set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
571 struct port_info *p = netdev_priv(dev);
572 struct link_config *lc = &p->link_cfg;
573 u32 speed = ethtool_cmd_speed(cmd);
575 if (cmd->duplex != DUPLEX_FULL) /* only full-duplex supported */
578 if (!(lc->supported & FW_PORT_CAP_ANEG)) {
579 /* PHY offers a single speed. See if that's what's
582 if (cmd->autoneg == AUTONEG_DISABLE &&
583 (lc->supported & speed_to_caps(speed)))
588 if (cmd->autoneg == AUTONEG_DISABLE) {
589 cap = speed_to_caps(speed);
591 if (!(lc->supported & cap) ||
596 lc->requested_speed = cap;
599 cap = to_fw_linkcaps(cmd->advertising);
600 if (!(lc->supported & cap))
602 lc->requested_speed = 0;
603 lc->advertising = cap | FW_PORT_CAP_ANEG;
605 lc->autoneg = cmd->autoneg;
607 if (netif_running(dev))
608 return t4_link_start(p->adapter, p->adapter->pf, p->tx_chan,
613 static void get_pauseparam(struct net_device *dev,
614 struct ethtool_pauseparam *epause)
616 struct port_info *p = netdev_priv(dev);
618 epause->autoneg = (p->link_cfg.requested_fc & PAUSE_AUTONEG) != 0;
619 epause->rx_pause = (p->link_cfg.fc & PAUSE_RX) != 0;
620 epause->tx_pause = (p->link_cfg.fc & PAUSE_TX) != 0;
623 static int set_pauseparam(struct net_device *dev,
624 struct ethtool_pauseparam *epause)
626 struct port_info *p = netdev_priv(dev);
627 struct link_config *lc = &p->link_cfg;
629 if (epause->autoneg == AUTONEG_DISABLE)
630 lc->requested_fc = 0;
631 else if (lc->supported & FW_PORT_CAP_ANEG)
632 lc->requested_fc = PAUSE_AUTONEG;
636 if (epause->rx_pause)
637 lc->requested_fc |= PAUSE_RX;
638 if (epause->tx_pause)
639 lc->requested_fc |= PAUSE_TX;
640 if (netif_running(dev))
641 return t4_link_start(p->adapter, p->adapter->pf, p->tx_chan,
646 static void get_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
648 const struct port_info *pi = netdev_priv(dev);
649 const struct sge *s = &pi->adapter->sge;
651 e->rx_max_pending = MAX_RX_BUFFERS;
652 e->rx_mini_max_pending = MAX_RSPQ_ENTRIES;
653 e->rx_jumbo_max_pending = 0;
654 e->tx_max_pending = MAX_TXQ_ENTRIES;
656 e->rx_pending = s->ethrxq[pi->first_qset].fl.size - 8;
657 e->rx_mini_pending = s->ethrxq[pi->first_qset].rspq.size;
658 e->rx_jumbo_pending = 0;
659 e->tx_pending = s->ethtxq[pi->first_qset].q.size;
662 static int set_sge_param(struct net_device *dev, struct ethtool_ringparam *e)
665 const struct port_info *pi = netdev_priv(dev);
666 struct adapter *adapter = pi->adapter;
667 struct sge *s = &adapter->sge;
669 if (e->rx_pending > MAX_RX_BUFFERS || e->rx_jumbo_pending ||
670 e->tx_pending > MAX_TXQ_ENTRIES ||
671 e->rx_mini_pending > MAX_RSPQ_ENTRIES ||
672 e->rx_mini_pending < MIN_RSPQ_ENTRIES ||
673 e->rx_pending < MIN_FL_ENTRIES || e->tx_pending < MIN_TXQ_ENTRIES)
676 if (adapter->flags & FULL_INIT_DONE)
679 for (i = 0; i < pi->nqsets; ++i) {
680 s->ethtxq[pi->first_qset + i].q.size = e->tx_pending;
681 s->ethrxq[pi->first_qset + i].fl.size = e->rx_pending + 8;
682 s->ethrxq[pi->first_qset + i].rspq.size = e->rx_mini_pending;
688 * set_rx_intr_params - set a net devices's RX interrupt holdoff paramete!
689 * @dev: the network device
690 * @us: the hold-off time in us, or 0 to disable timer
691 * @cnt: the hold-off packet count, or 0 to disable counter
693 * Set the RX interrupt hold-off parameters for a network device.
695 static int set_rx_intr_params(struct net_device *dev,
696 unsigned int us, unsigned int cnt)
699 struct port_info *pi = netdev_priv(dev);
700 struct adapter *adap = pi->adapter;
701 struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
703 for (i = 0; i < pi->nqsets; i++, q++) {
704 err = cxgb4_set_rspq_intr_params(&q->rspq, us, cnt);
711 static int set_adaptive_rx_setting(struct net_device *dev, int adaptive_rx)
714 struct port_info *pi = netdev_priv(dev);
715 struct adapter *adap = pi->adapter;
716 struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
718 for (i = 0; i < pi->nqsets; i++, q++)
719 q->rspq.adaptive_rx = adaptive_rx;
724 static int get_adaptive_rx_setting(struct net_device *dev)
726 struct port_info *pi = netdev_priv(dev);
727 struct adapter *adap = pi->adapter;
728 struct sge_eth_rxq *q = &adap->sge.ethrxq[pi->first_qset];
730 return q->rspq.adaptive_rx;
733 static int set_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
735 set_adaptive_rx_setting(dev, c->use_adaptive_rx_coalesce);
736 return set_rx_intr_params(dev, c->rx_coalesce_usecs,
737 c->rx_max_coalesced_frames);
740 static int get_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
742 const struct port_info *pi = netdev_priv(dev);
743 const struct adapter *adap = pi->adapter;
744 const struct sge_rspq *rq = &adap->sge.ethrxq[pi->first_qset].rspq;
746 c->rx_coalesce_usecs = qtimer_val(adap, rq);
747 c->rx_max_coalesced_frames = (rq->intr_params & QINTR_CNT_EN_F) ?
748 adap->sge.counter_val[rq->pktcnt_idx] : 0;
749 c->use_adaptive_rx_coalesce = get_adaptive_rx_setting(dev);
754 * eeprom_ptov - translate a physical EEPROM address to virtual
755 * @phys_addr: the physical EEPROM address
756 * @fn: the PCI function number
757 * @sz: size of function-specific area
759 * Translate a physical EEPROM address to virtual. The first 1K is
760 * accessed through virtual addresses starting at 31K, the rest is
761 * accessed through virtual addresses starting at 0.
763 * The mapping is as follows:
764 * [0..1K) -> [31K..32K)
765 * [1K..1K+A) -> [31K-A..31K)
766 * [1K+A..ES) -> [0..ES-A-1K)
768 * where A = @fn * @sz, and ES = EEPROM size.
770 static int eeprom_ptov(unsigned int phys_addr, unsigned int fn, unsigned int sz)
773 if (phys_addr < 1024)
774 return phys_addr + (31 << 10);
775 if (phys_addr < 1024 + fn)
776 return 31744 - fn + phys_addr - 1024;
777 if (phys_addr < EEPROMSIZE)
778 return phys_addr - 1024 - fn;
782 /* The next two routines implement eeprom read/write from physical addresses.
784 static int eeprom_rd_phys(struct adapter *adap, unsigned int phys_addr, u32 *v)
786 int vaddr = eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
789 vaddr = pci_read_vpd(adap->pdev, vaddr, sizeof(u32), v);
790 return vaddr < 0 ? vaddr : 0;
793 static int eeprom_wr_phys(struct adapter *adap, unsigned int phys_addr, u32 v)
795 int vaddr = eeprom_ptov(phys_addr, adap->pf, EEPROMPFSIZE);
798 vaddr = pci_write_vpd(adap->pdev, vaddr, sizeof(u32), &v);
799 return vaddr < 0 ? vaddr : 0;
802 #define EEPROM_MAGIC 0x38E2F10C
804 static int get_eeprom(struct net_device *dev, struct ethtool_eeprom *e,
808 struct adapter *adapter = netdev2adap(dev);
809 u8 *buf = kmalloc(EEPROMSIZE, GFP_KERNEL);
814 e->magic = EEPROM_MAGIC;
815 for (i = e->offset & ~3; !err && i < e->offset + e->len; i += 4)
816 err = eeprom_rd_phys(adapter, i, (u32 *)&buf[i]);
819 memcpy(data, buf + e->offset, e->len);
824 static int set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
829 u32 aligned_offset, aligned_len, *p;
830 struct adapter *adapter = netdev2adap(dev);
832 if (eeprom->magic != EEPROM_MAGIC)
835 aligned_offset = eeprom->offset & ~3;
836 aligned_len = (eeprom->len + (eeprom->offset & 3) + 3) & ~3;
838 if (adapter->pf > 0) {
839 u32 start = 1024 + adapter->pf * EEPROMPFSIZE;
841 if (aligned_offset < start ||
842 aligned_offset + aligned_len > start + EEPROMPFSIZE)
846 if (aligned_offset != eeprom->offset || aligned_len != eeprom->len) {
847 /* RMW possibly needed for first or last words.
849 buf = kmalloc(aligned_len, GFP_KERNEL);
852 err = eeprom_rd_phys(adapter, aligned_offset, (u32 *)buf);
853 if (!err && aligned_len > 4)
854 err = eeprom_rd_phys(adapter,
855 aligned_offset + aligned_len - 4,
856 (u32 *)&buf[aligned_len - 4]);
859 memcpy(buf + (eeprom->offset & 3), data, eeprom->len);
864 err = t4_seeprom_wp(adapter, false);
868 for (p = (u32 *)buf; !err && aligned_len; aligned_len -= 4, p++) {
869 err = eeprom_wr_phys(adapter, aligned_offset, *p);
874 err = t4_seeprom_wp(adapter, true);
881 static int set_flash(struct net_device *netdev, struct ethtool_flash *ef)
884 const struct firmware *fw;
885 struct adapter *adap = netdev2adap(netdev);
886 unsigned int mbox = PCIE_FW_MASTER_M + 1;
888 ef->data[sizeof(ef->data) - 1] = '\0';
889 ret = request_firmware(&fw, ef->data, adap->pdev_dev);
893 /* If the adapter has been fully initialized then we'll go ahead and
894 * try to get the firmware's cooperation in upgrading to the new
895 * firmware image otherwise we'll try to do the entire job from the
896 * host ... and we always "force" the operation in this path.
898 if (adap->flags & FULL_INIT_DONE)
901 ret = t4_fw_upgrade(adap, mbox, fw->data, fw->size, 1);
902 release_firmware(fw);
904 dev_info(adap->pdev_dev,
905 "loaded firmware %s, reload cxgb4 driver\n", ef->data);
909 #define WOL_SUPPORTED (WAKE_BCAST | WAKE_MAGIC)
910 #define BCAST_CRC 0xa0ccc1a6
912 static void get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
914 wol->supported = WAKE_BCAST | WAKE_MAGIC;
915 wol->wolopts = netdev2adap(dev)->wol;
916 memset(&wol->sopass, 0, sizeof(wol->sopass));
919 static int set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
922 struct port_info *pi = netdev_priv(dev);
924 if (wol->wolopts & ~WOL_SUPPORTED)
926 t4_wol_magic_enable(pi->adapter, pi->tx_chan,
927 (wol->wolopts & WAKE_MAGIC) ? dev->dev_addr : NULL);
928 if (wol->wolopts & WAKE_BCAST) {
929 err = t4_wol_pat_enable(pi->adapter, pi->tx_chan, 0xfe, ~0ULL,
932 err = t4_wol_pat_enable(pi->adapter, pi->tx_chan, 1,
933 ~6ULL, ~0ULL, BCAST_CRC, true);
935 t4_wol_pat_enable(pi->adapter, pi->tx_chan, 0, 0, 0, 0, false);
940 static u32 get_rss_table_size(struct net_device *dev)
942 const struct port_info *pi = netdev_priv(dev);
947 static int get_rss_table(struct net_device *dev, u32 *p, u8 *key, u8 *hfunc)
949 const struct port_info *pi = netdev_priv(dev);
950 unsigned int n = pi->rss_size;
953 *hfunc = ETH_RSS_HASH_TOP;
961 static int set_rss_table(struct net_device *dev, const u32 *p, const u8 *key,
965 struct port_info *pi = netdev_priv(dev);
967 /* We require at least one supported parameter to be changed and no
968 * change in any of the unsupported parameters
971 (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
976 for (i = 0; i < pi->rss_size; i++)
978 if (pi->adapter->flags & FULL_INIT_DONE)
979 return cxgb4_write_rss(pi, pi->rss);
983 static int get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
986 const struct port_info *pi = netdev_priv(dev);
989 case ETHTOOL_GRXFH: {
990 unsigned int v = pi->rss_mode;
993 switch (info->flow_type) {
995 if (v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F)
996 info->data = RXH_IP_SRC | RXH_IP_DST |
997 RXH_L4_B_0_1 | RXH_L4_B_2_3;
998 else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
999 info->data = RXH_IP_SRC | RXH_IP_DST;
1002 if ((v & FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F) &&
1003 (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
1004 info->data = RXH_IP_SRC | RXH_IP_DST |
1005 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1006 else if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
1007 info->data = RXH_IP_SRC | RXH_IP_DST;
1010 case AH_ESP_V4_FLOW:
1012 if (v & FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F)
1013 info->data = RXH_IP_SRC | RXH_IP_DST;
1016 if (v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F)
1017 info->data = RXH_IP_SRC | RXH_IP_DST |
1018 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1019 else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
1020 info->data = RXH_IP_SRC | RXH_IP_DST;
1023 if ((v & FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F) &&
1024 (v & FW_RSS_VI_CONFIG_CMD_UDPEN_F))
1025 info->data = RXH_IP_SRC | RXH_IP_DST |
1026 RXH_L4_B_0_1 | RXH_L4_B_2_3;
1027 else if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
1028 info->data = RXH_IP_SRC | RXH_IP_DST;
1031 case AH_ESP_V6_FLOW:
1033 if (v & FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F)
1034 info->data = RXH_IP_SRC | RXH_IP_DST;
1039 case ETHTOOL_GRXRINGS:
1040 info->data = pi->nqsets;
1046 static const struct ethtool_ops cxgb_ethtool_ops = {
1047 .get_settings = get_settings,
1048 .set_settings = set_settings,
1049 .get_drvinfo = get_drvinfo,
1050 .get_msglevel = get_msglevel,
1051 .set_msglevel = set_msglevel,
1052 .get_ringparam = get_sge_param,
1053 .set_ringparam = set_sge_param,
1054 .get_coalesce = get_coalesce,
1055 .set_coalesce = set_coalesce,
1056 .get_eeprom_len = get_eeprom_len,
1057 .get_eeprom = get_eeprom,
1058 .set_eeprom = set_eeprom,
1059 .get_pauseparam = get_pauseparam,
1060 .set_pauseparam = set_pauseparam,
1061 .get_link = ethtool_op_get_link,
1062 .get_strings = get_strings,
1063 .set_phys_id = identify_port,
1064 .nway_reset = restart_autoneg,
1065 .get_sset_count = get_sset_count,
1066 .get_ethtool_stats = get_stats,
1067 .get_regs_len = get_regs_len,
1068 .get_regs = get_regs,
1071 .get_rxnfc = get_rxnfc,
1072 .get_rxfh_indir_size = get_rss_table_size,
1073 .get_rxfh = get_rss_table,
1074 .set_rxfh = set_rss_table,
1075 .flash_device = set_flash,
1078 void cxgb4_set_ethtool_ops(struct net_device *netdev)
1080 netdev->ethtool_ops = &cxgb_ethtool_ops;