2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2013 QLogic Corporation
5 * See LICENSE.qlcnic for copyright and licensing details.
8 #include <linux/types.h>
9 #include <linux/delay.h>
10 #include <linux/pci.h>
12 #include <linux/netdevice.h>
13 #include <linux/ethtool.h>
18 char stat_string[ETH_GSTRING_LEN];
23 #define QLC_SIZEOF(m) FIELD_SIZEOF(struct qlcnic_adapter, m)
24 #define QLC_OFF(m) offsetof(struct qlcnic_adapter, m)
25 static const u32 qlcnic_fw_dump_level[] = {
26 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff
29 static const struct qlcnic_stats qlcnic_gstrings_stats[] = {
30 {"xmit_on", QLC_SIZEOF(stats.xmit_on), QLC_OFF(stats.xmit_on)},
31 {"xmit_off", QLC_SIZEOF(stats.xmit_off), QLC_OFF(stats.xmit_off)},
32 {"xmit_called", QLC_SIZEOF(stats.xmitcalled),
33 QLC_OFF(stats.xmitcalled)},
34 {"xmit_finished", QLC_SIZEOF(stats.xmitfinished),
35 QLC_OFF(stats.xmitfinished)},
36 {"tx dma map error", QLC_SIZEOF(stats.tx_dma_map_error),
37 QLC_OFF(stats.tx_dma_map_error)},
38 {"tx_bytes", QLC_SIZEOF(stats.txbytes), QLC_OFF(stats.txbytes)},
39 {"tx_dropped", QLC_SIZEOF(stats.txdropped), QLC_OFF(stats.txdropped)},
40 {"rx dma map error", QLC_SIZEOF(stats.rx_dma_map_error),
41 QLC_OFF(stats.rx_dma_map_error)},
42 {"rx_pkts", QLC_SIZEOF(stats.rx_pkts), QLC_OFF(stats.rx_pkts)},
43 {"rx_bytes", QLC_SIZEOF(stats.rxbytes), QLC_OFF(stats.rxbytes)},
44 {"rx_dropped", QLC_SIZEOF(stats.rxdropped), QLC_OFF(stats.rxdropped)},
45 {"null rxbuf", QLC_SIZEOF(stats.null_rxbuf), QLC_OFF(stats.null_rxbuf)},
46 {"csummed", QLC_SIZEOF(stats.csummed), QLC_OFF(stats.csummed)},
47 {"lro_pkts", QLC_SIZEOF(stats.lro_pkts), QLC_OFF(stats.lro_pkts)},
48 {"lrobytes", QLC_SIZEOF(stats.lrobytes), QLC_OFF(stats.lrobytes)},
49 {"lso_frames", QLC_SIZEOF(stats.lso_frames), QLC_OFF(stats.lso_frames)},
50 {"encap_lso_frames", QLC_SIZEOF(stats.encap_lso_frames),
51 QLC_OFF(stats.encap_lso_frames)},
52 {"encap_tx_csummed", QLC_SIZEOF(stats.encap_tx_csummed),
53 QLC_OFF(stats.encap_tx_csummed)},
54 {"encap_rx_csummed", QLC_SIZEOF(stats.encap_rx_csummed),
55 QLC_OFF(stats.encap_rx_csummed)},
56 {"skb_alloc_failure", QLC_SIZEOF(stats.skb_alloc_failure),
57 QLC_OFF(stats.skb_alloc_failure)},
58 {"mac_filter_limit_overrun", QLC_SIZEOF(stats.mac_filter_limit_overrun),
59 QLC_OFF(stats.mac_filter_limit_overrun)},
60 {"spurious intr", QLC_SIZEOF(stats.spurious_intr),
61 QLC_OFF(stats.spurious_intr)},
62 {"mbx spurious intr", QLC_SIZEOF(stats.mbx_spurious_intr),
63 QLC_OFF(stats.mbx_spurious_intr)},
66 static const char qlcnic_device_gstrings_stats[][ETH_GSTRING_LEN] = {
68 "tx multicast frames",
69 "tx broadcast frames",
75 "rx multicast frames",
76 "rx broadcast frames",
83 static const char qlcnic_83xx_tx_stats_strings[][ETH_GSTRING_LEN] = {
87 "ctx_tx_dropped_pkts",
91 static const char qlcnic_83xx_mac_stats_strings[][ETH_GSTRING_LEN] = {
99 "mac_tx_lt_127b_pkts",
100 "mac_tx_lt_255b_pkts",
101 "mac_tx_lt_511b_pkts",
102 "mac_tx_lt_1023b_pkts",
103 "mac_tx_lt_1518b_pkts",
104 "mac_tx_gt_1518b_pkts",
111 "mac_rx_lt_64b_pkts",
112 "mac_rx_lt_127b_pkts",
113 "mac_rx_lt_255b_pkts",
114 "mac_rx_lt_511b_pkts",
115 "mac_rx_lt_1023b_pkts",
116 "mac_rx_lt_1518b_pkts",
117 "mac_rx_gt_1518b_pkts",
118 "mac_rx_length_error",
119 "mac_rx_length_small",
120 "mac_rx_length_large",
127 "eswitch_multicast_frames",
128 "eswitch_broadcast_frames",
129 "eswitch_unicast_frames",
130 "eswitch_error_free_frames",
131 "eswitch_error_free_bytes",
134 #define QLCNIC_STATS_LEN ARRAY_SIZE(qlcnic_gstrings_stats)
136 static const char qlcnic_tx_queue_stats_strings[][ETH_GSTRING_LEN] = {
144 #define QLCNIC_TX_STATS_LEN ARRAY_SIZE(qlcnic_tx_queue_stats_strings)
146 static const char qlcnic_83xx_rx_stats_strings[][ETH_GSTRING_LEN] = {
151 "ctx_rx_pkts_wo_ctx",
152 "ctx_rx_pkts_drop_wo_sds_on_card",
153 "ctx_rx_pkts_drop_wo_sds_on_host",
154 "ctx_rx_osized_pkts",
155 "ctx_rx_pkts_dropped_wo_rds",
156 "ctx_rx_unexpected_mcast_pkts",
157 "ctx_invalid_mac_address",
158 "ctx_rx_rds_ring_prim_attempted",
159 "ctx_rx_rds_ring_prim_success",
160 "ctx_num_lro_flows_added",
161 "ctx_num_lro_flows_removed",
162 "ctx_num_lro_flows_active",
163 "ctx_pkts_dropped_unknown",
166 static const char qlcnic_gstrings_test[][ETH_GSTRING_LEN] = {
167 "Register_Test_on_offline",
168 "Link_Test_on_offline",
169 "Interrupt_Test_offline",
170 "Internal_Loopback_offline",
171 "External_Loopback_offline",
172 "EEPROM_Test_offline"
175 #define QLCNIC_TEST_LEN ARRAY_SIZE(qlcnic_gstrings_test)
177 static inline int qlcnic_82xx_statistics(struct qlcnic_adapter *adapter)
179 return ARRAY_SIZE(qlcnic_gstrings_stats) +
180 ARRAY_SIZE(qlcnic_83xx_mac_stats_strings) +
181 QLCNIC_TX_STATS_LEN * adapter->drv_tx_rings;
184 static inline int qlcnic_83xx_statistics(struct qlcnic_adapter *adapter)
186 return ARRAY_SIZE(qlcnic_gstrings_stats) +
187 ARRAY_SIZE(qlcnic_83xx_tx_stats_strings) +
188 ARRAY_SIZE(qlcnic_83xx_mac_stats_strings) +
189 ARRAY_SIZE(qlcnic_83xx_rx_stats_strings) +
190 QLCNIC_TX_STATS_LEN * adapter->drv_tx_rings;
193 static int qlcnic_dev_statistics_len(struct qlcnic_adapter *adapter)
197 if (qlcnic_82xx_check(adapter)) {
198 len = qlcnic_82xx_statistics(adapter);
199 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
200 len += ARRAY_SIZE(qlcnic_device_gstrings_stats);
201 } else if (qlcnic_83xx_check(adapter)) {
202 len = qlcnic_83xx_statistics(adapter);
208 #define QLCNIC_TX_INTR_NOT_CONFIGURED 0X78563412
210 #define QLCNIC_MAX_EEPROM_LEN 1024
212 static const u32 diag_registers[] = {
215 QLCNIC_FW_CAPABILITIES,
216 QLCNIC_CRB_DRV_ACTIVE,
217 QLCNIC_CRB_DEV_STATE,
218 QLCNIC_CRB_DRV_STATE,
219 QLCNIC_CRB_DRV_SCRATCH,
220 QLCNIC_CRB_DEV_PARTITION_INFO,
221 QLCNIC_CRB_DRV_IDC_VER,
222 QLCNIC_PEG_ALIVE_COUNTER,
223 QLCNIC_PEG_HALT_STATUS1,
224 QLCNIC_PEG_HALT_STATUS2,
229 static const u32 ext_diag_registers[] = {
232 QLCNIC_CRB_PEG_NET_0+0x3c,
233 QLCNIC_CRB_PEG_NET_1+0x3c,
234 QLCNIC_CRB_PEG_NET_2+0x3c,
235 QLCNIC_CRB_PEG_NET_4+0x3c,
239 #define QLCNIC_MGMT_API_VERSION 3
240 #define QLCNIC_ETHTOOL_REGS_VER 4
242 static inline int qlcnic_get_ring_regs_len(struct qlcnic_adapter *adapter)
244 int ring_regs_cnt = (adapter->drv_tx_rings * 5) +
245 (adapter->max_rds_rings * 2) +
246 (adapter->drv_sds_rings * 3) + 5;
247 return ring_regs_cnt * sizeof(u32);
250 static int qlcnic_get_regs_len(struct net_device *dev)
252 struct qlcnic_adapter *adapter = netdev_priv(dev);
255 if (qlcnic_83xx_check(adapter))
256 len = qlcnic_83xx_get_regs_len(adapter);
258 len = sizeof(ext_diag_registers) + sizeof(diag_registers);
260 len += ((QLCNIC_DEV_INFO_SIZE + 2) * sizeof(u32));
261 len += qlcnic_get_ring_regs_len(adapter);
265 static int qlcnic_get_eeprom_len(struct net_device *dev)
267 return QLCNIC_FLASH_TOTAL_SIZE;
271 qlcnic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
273 struct qlcnic_adapter *adapter = netdev_priv(dev);
274 u32 fw_major, fw_minor, fw_build;
275 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
276 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
277 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
278 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
279 "%d.%d.%d", fw_major, fw_minor, fw_build);
281 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
282 sizeof(drvinfo->bus_info));
283 strlcpy(drvinfo->driver, qlcnic_driver_name, sizeof(drvinfo->driver));
284 strlcpy(drvinfo->version, QLCNIC_LINUX_VERSIONID,
285 sizeof(drvinfo->version));
288 static int qlcnic_82xx_get_link_ksettings(struct qlcnic_adapter *adapter,
289 struct ethtool_link_ksettings *ecmd)
291 struct qlcnic_hardware_context *ahw = adapter->ahw;
293 int check_sfp_module = 0, err = 0;
294 u16 pcifn = ahw->pci_func;
295 u32 supported, advertising;
297 /* read which mode */
298 if (adapter->ahw->port_type == QLCNIC_GBE) {
299 supported = (SUPPORTED_10baseT_Half |
300 SUPPORTED_10baseT_Full |
301 SUPPORTED_100baseT_Half |
302 SUPPORTED_100baseT_Full |
303 SUPPORTED_1000baseT_Half |
304 SUPPORTED_1000baseT_Full);
306 advertising = (ADVERTISED_100baseT_Half |
307 ADVERTISED_100baseT_Full |
308 ADVERTISED_1000baseT_Half |
309 ADVERTISED_1000baseT_Full);
311 ecmd->base.speed = adapter->ahw->link_speed;
312 ecmd->base.duplex = adapter->ahw->link_duplex;
313 ecmd->base.autoneg = adapter->ahw->link_autoneg;
315 } else if (adapter->ahw->port_type == QLCNIC_XGBE) {
317 val = QLCRD32(adapter, QLCNIC_PORT_MODE_ADDR, &err);
319 if (val == QLCNIC_PORT_MODE_802_3_AP) {
320 supported = SUPPORTED_1000baseT_Full;
321 advertising = ADVERTISED_1000baseT_Full;
323 supported = SUPPORTED_10000baseT_Full;
324 advertising = ADVERTISED_10000baseT_Full;
327 if (netif_running(adapter->netdev) && ahw->has_link_events) {
329 reg = QLCRD32(adapter,
330 P3P_LINK_SPEED_REG(pcifn), &err);
331 speed = P3P_LINK_SPEED_VAL(pcifn, reg);
332 ahw->link_speed = speed * P3P_LINK_SPEED_MHZ;
335 ecmd->base.speed = ahw->link_speed;
336 ecmd->base.autoneg = ahw->link_autoneg;
337 ecmd->base.duplex = ahw->link_duplex;
341 ecmd->base.speed = SPEED_UNKNOWN;
342 ecmd->base.duplex = DUPLEX_UNKNOWN;
343 ecmd->base.autoneg = AUTONEG_DISABLE;
348 ecmd->base.phy_address = adapter->ahw->physical_port;
350 switch (adapter->ahw->board_type) {
351 case QLCNIC_BRDTYPE_P3P_REF_QG:
352 case QLCNIC_BRDTYPE_P3P_4_GB:
353 case QLCNIC_BRDTYPE_P3P_4_GB_MM:
355 supported |= SUPPORTED_Autoneg;
356 advertising |= ADVERTISED_Autoneg;
357 case QLCNIC_BRDTYPE_P3P_10G_CX4:
358 case QLCNIC_BRDTYPE_P3P_10G_CX4_LP:
359 case QLCNIC_BRDTYPE_P3P_10000_BASE_T:
360 supported |= SUPPORTED_TP;
361 advertising |= ADVERTISED_TP;
362 ecmd->base.port = PORT_TP;
363 ecmd->base.autoneg = adapter->ahw->link_autoneg;
365 case QLCNIC_BRDTYPE_P3P_IMEZ:
366 case QLCNIC_BRDTYPE_P3P_XG_LOM:
367 case QLCNIC_BRDTYPE_P3P_HMEZ:
368 supported |= SUPPORTED_MII;
369 advertising |= ADVERTISED_MII;
370 ecmd->base.port = PORT_MII;
371 ecmd->base.autoneg = AUTONEG_DISABLE;
373 case QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS:
374 case QLCNIC_BRDTYPE_P3P_10G_SFP_CT:
375 case QLCNIC_BRDTYPE_P3P_10G_SFP_QT:
376 advertising |= ADVERTISED_TP;
377 supported |= SUPPORTED_TP;
378 check_sfp_module = netif_running(adapter->netdev) &&
379 ahw->has_link_events;
380 case QLCNIC_BRDTYPE_P3P_10G_XFP:
381 supported |= SUPPORTED_FIBRE;
382 advertising |= ADVERTISED_FIBRE;
383 ecmd->base.port = PORT_FIBRE;
384 ecmd->base.autoneg = AUTONEG_DISABLE;
386 case QLCNIC_BRDTYPE_P3P_10G_TP:
387 if (adapter->ahw->port_type == QLCNIC_XGBE) {
388 ecmd->base.autoneg = AUTONEG_DISABLE;
389 supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
391 (ADVERTISED_FIBRE | ADVERTISED_TP);
392 ecmd->base.port = PORT_FIBRE;
393 check_sfp_module = netif_running(adapter->netdev) &&
394 ahw->has_link_events;
396 ecmd->base.autoneg = AUTONEG_ENABLE;
397 supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
399 (ADVERTISED_TP | ADVERTISED_Autoneg);
400 ecmd->base.port = PORT_TP;
404 dev_err(&adapter->pdev->dev, "Unsupported board model %d\n",
405 adapter->ahw->board_type);
409 if (check_sfp_module) {
410 switch (adapter->ahw->module_type) {
411 case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
412 case LINKEVENT_MODULE_OPTICAL_SRLR:
413 case LINKEVENT_MODULE_OPTICAL_LRM:
414 case LINKEVENT_MODULE_OPTICAL_SFP_1G:
415 ecmd->base.port = PORT_FIBRE;
417 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
418 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
419 case LINKEVENT_MODULE_TWINAX:
420 ecmd->base.port = PORT_TP;
423 ecmd->base.port = PORT_OTHER;
427 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.supported,
429 ethtool_convert_legacy_u32_to_link_mode(ecmd->link_modes.advertising,
435 static int qlcnic_get_link_ksettings(struct net_device *dev,
436 struct ethtool_link_ksettings *ecmd)
438 struct qlcnic_adapter *adapter = netdev_priv(dev);
440 if (qlcnic_82xx_check(adapter))
441 return qlcnic_82xx_get_link_ksettings(adapter, ecmd);
442 else if (qlcnic_83xx_check(adapter))
443 return qlcnic_83xx_get_link_ksettings(adapter, ecmd);
449 static int qlcnic_set_port_config(struct qlcnic_adapter *adapter,
450 const struct ethtool_link_ksettings *ecmd)
452 u32 ret = 0, config = 0;
453 /* read which mode */
454 if (ecmd->base.duplex)
457 if (ecmd->base.autoneg)
460 switch (ecmd->base.speed) {
474 ret = qlcnic_fw_cmd_set_port(adapter, config);
476 if (ret == QLCNIC_RCODE_NOT_SUPPORTED)
483 static int qlcnic_set_link_ksettings(struct net_device *dev,
484 const struct ethtool_link_ksettings *ecmd)
487 struct qlcnic_adapter *adapter = netdev_priv(dev);
489 if (adapter->ahw->port_type != QLCNIC_GBE)
492 if (qlcnic_83xx_check(adapter))
493 ret = qlcnic_83xx_set_link_ksettings(adapter, ecmd);
495 ret = qlcnic_set_port_config(adapter, ecmd);
500 adapter->ahw->link_speed = ecmd->base.speed;
501 adapter->ahw->link_duplex = ecmd->base.duplex;
502 adapter->ahw->link_autoneg = ecmd->base.autoneg;
504 if (!netif_running(dev))
507 dev->netdev_ops->ndo_stop(dev);
508 return dev->netdev_ops->ndo_open(dev);
511 static int qlcnic_82xx_get_registers(struct qlcnic_adapter *adapter,
514 int i, j = 0, err = 0;
516 for (i = QLCNIC_DEV_INFO_SIZE + 1; diag_registers[j] != -1; j++, i++)
517 regs_buff[i] = QLC_SHARED_REG_RD32(adapter, diag_registers[j]);
519 while (ext_diag_registers[j] != -1)
520 regs_buff[i++] = QLCRD32(adapter, ext_diag_registers[j++],
526 qlcnic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
528 struct qlcnic_adapter *adapter = netdev_priv(dev);
529 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
530 struct qlcnic_host_sds_ring *sds_ring;
531 struct qlcnic_host_rds_ring *rds_rings;
532 struct qlcnic_host_tx_ring *tx_ring;
536 memset(p, 0, qlcnic_get_regs_len(dev));
538 regs->version = (QLCNIC_ETHTOOL_REGS_VER << 24) |
539 (adapter->ahw->revision_id << 16) | (adapter->pdev)->device;
541 regs_buff[0] = (0xcafe0000 | (QLCNIC_DEV_INFO_SIZE & 0xffff));
542 regs_buff[1] = QLCNIC_MGMT_API_VERSION;
544 if (adapter->ahw->capabilities & QLC_83XX_ESWITCH_CAPABILITY)
545 regs_buff[2] = adapter->ahw->max_vnic_func;
547 if (qlcnic_82xx_check(adapter))
548 i = qlcnic_82xx_get_registers(adapter, regs_buff);
550 i = qlcnic_83xx_get_registers(adapter, regs_buff);
552 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
555 /* Marker btw regs and TX ring count */
556 regs_buff[i++] = 0xFFEFCDAB;
558 regs_buff[i++] = adapter->drv_tx_rings; /* No. of TX ring */
559 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
560 tx_ring = &adapter->tx_ring[ring];
561 regs_buff[i++] = le32_to_cpu(*(tx_ring->hw_consumer));
562 regs_buff[i++] = tx_ring->sw_consumer;
563 regs_buff[i++] = readl(tx_ring->crb_cmd_producer);
564 regs_buff[i++] = tx_ring->producer;
565 if (tx_ring->crb_intr_mask)
566 regs_buff[i++] = readl(tx_ring->crb_intr_mask);
568 regs_buff[i++] = QLCNIC_TX_INTR_NOT_CONFIGURED;
571 regs_buff[i++] = adapter->max_rds_rings; /* No. of RX ring */
572 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
573 rds_rings = &recv_ctx->rds_rings[ring];
574 regs_buff[i++] = readl(rds_rings->crb_rcv_producer);
575 regs_buff[i++] = rds_rings->producer;
578 regs_buff[i++] = adapter->drv_sds_rings; /* No. of SDS ring */
579 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
580 sds_ring = &(recv_ctx->sds_rings[ring]);
581 regs_buff[i++] = readl(sds_ring->crb_sts_consumer);
582 regs_buff[i++] = sds_ring->consumer;
583 regs_buff[i++] = readl(sds_ring->crb_intr_mask);
587 static u32 qlcnic_test_link(struct net_device *dev)
589 struct qlcnic_adapter *adapter = netdev_priv(dev);
593 if (qlcnic_83xx_check(adapter)) {
594 val = qlcnic_83xx_test_link(adapter);
595 return (val & 1) ? 0 : 1;
597 val = QLCRD32(adapter, CRB_XG_STATE_P3P, &err);
600 val = XG_LINK_STATE_P3P(adapter->ahw->pci_func, val);
601 return (val == XG_LINK_UP_P3P) ? 0 : 1;
605 qlcnic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
608 struct qlcnic_adapter *adapter = netdev_priv(dev);
612 if (qlcnic_83xx_check(adapter))
614 if (eeprom->len == 0)
617 eeprom->magic = (adapter->pdev)->vendor |
618 ((adapter->pdev)->device << 16);
619 offset = eeprom->offset;
621 if (qlcnic_82xx_check(adapter))
622 ret = qlcnic_rom_fast_read_words(adapter, offset, bytes,
631 qlcnic_get_ringparam(struct net_device *dev,
632 struct ethtool_ringparam *ring)
634 struct qlcnic_adapter *adapter = netdev_priv(dev);
636 ring->rx_pending = adapter->num_rxd;
637 ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
638 ring->tx_pending = adapter->num_txd;
640 ring->rx_max_pending = adapter->max_rxd;
641 ring->rx_jumbo_max_pending = adapter->max_jumbo_rxd;
642 ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
646 qlcnic_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
649 num_desc = max(val, min);
650 num_desc = min(num_desc, max);
651 num_desc = roundup_pow_of_two(num_desc);
653 if (val != num_desc) {
654 printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
655 qlcnic_driver_name, r_name, num_desc, val);
662 qlcnic_set_ringparam(struct net_device *dev,
663 struct ethtool_ringparam *ring)
665 struct qlcnic_adapter *adapter = netdev_priv(dev);
666 u16 num_rxd, num_jumbo_rxd, num_txd;
668 if (ring->rx_mini_pending)
671 num_rxd = qlcnic_validate_ringparam(ring->rx_pending,
672 MIN_RCV_DESCRIPTORS, adapter->max_rxd, "rx");
674 num_jumbo_rxd = qlcnic_validate_ringparam(ring->rx_jumbo_pending,
675 MIN_JUMBO_DESCRIPTORS, adapter->max_jumbo_rxd,
678 num_txd = qlcnic_validate_ringparam(ring->tx_pending,
679 MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
681 if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
682 num_jumbo_rxd == adapter->num_jumbo_rxd)
685 adapter->num_rxd = num_rxd;
686 adapter->num_jumbo_rxd = num_jumbo_rxd;
687 adapter->num_txd = num_txd;
689 return qlcnic_reset_context(adapter);
692 static int qlcnic_validate_ring_count(struct qlcnic_adapter *adapter,
693 u8 rx_ring, u8 tx_ring)
695 if (rx_ring == 0 || tx_ring == 0)
699 if (rx_ring > adapter->max_sds_rings) {
700 netdev_err(adapter->netdev,
701 "Invalid ring count, SDS ring count %d should not be greater than max %d driver sds rings.\n",
702 rx_ring, adapter->max_sds_rings);
708 if (tx_ring > adapter->max_tx_rings) {
709 netdev_err(adapter->netdev,
710 "Invalid ring count, Tx ring count %d should not be greater than max %d driver Tx rings.\n",
711 tx_ring, adapter->max_tx_rings);
719 static void qlcnic_get_channels(struct net_device *dev,
720 struct ethtool_channels *channel)
722 struct qlcnic_adapter *adapter = netdev_priv(dev);
724 channel->max_rx = adapter->max_sds_rings;
725 channel->max_tx = adapter->max_tx_rings;
726 channel->rx_count = adapter->drv_sds_rings;
727 channel->tx_count = adapter->drv_tx_rings;
730 static int qlcnic_set_channels(struct net_device *dev,
731 struct ethtool_channels *channel)
733 struct qlcnic_adapter *adapter = netdev_priv(dev);
736 if (!(adapter->flags & QLCNIC_MSIX_ENABLED)) {
737 netdev_err(dev, "No RSS/TSS support in non MSI-X mode\n");
741 if (channel->other_count || channel->combined_count)
744 err = qlcnic_validate_ring_count(adapter, channel->rx_count,
749 if (adapter->drv_sds_rings != channel->rx_count) {
750 err = qlcnic_validate_rings(adapter, channel->rx_count,
753 netdev_err(dev, "Unable to configure %u SDS rings\n",
757 adapter->drv_rss_rings = channel->rx_count;
760 if (adapter->drv_tx_rings != channel->tx_count) {
761 err = qlcnic_validate_rings(adapter, channel->tx_count,
764 netdev_err(dev, "Unable to configure %u Tx rings\n",
768 adapter->drv_tss_rings = channel->tx_count;
771 adapter->flags |= QLCNIC_TSS_RSS;
773 err = qlcnic_setup_rings(adapter);
774 netdev_info(dev, "Allocated %d SDS rings and %d Tx rings\n",
775 adapter->drv_sds_rings, adapter->drv_tx_rings);
781 qlcnic_get_pauseparam(struct net_device *netdev,
782 struct ethtool_pauseparam *pause)
784 struct qlcnic_adapter *adapter = netdev_priv(netdev);
785 int port = adapter->ahw->physical_port;
789 if (qlcnic_83xx_check(adapter)) {
790 qlcnic_83xx_get_pauseparam(adapter, pause);
793 if (adapter->ahw->port_type == QLCNIC_GBE) {
794 if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
796 /* get flow control settings */
797 val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), &err);
800 pause->rx_pause = qlcnic_gb_get_rx_flowctl(val);
801 val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, &err);
806 pause->tx_pause = !(qlcnic_gb_get_gb0_mask(val));
809 pause->tx_pause = !(qlcnic_gb_get_gb1_mask(val));
812 pause->tx_pause = !(qlcnic_gb_get_gb2_mask(val));
816 pause->tx_pause = !(qlcnic_gb_get_gb3_mask(val));
819 } else if (adapter->ahw->port_type == QLCNIC_XGBE) {
820 if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
823 val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, &err);
827 pause->tx_pause = !(qlcnic_xg_get_xg0_mask(val));
829 pause->tx_pause = !(qlcnic_xg_get_xg1_mask(val));
831 dev_err(&netdev->dev, "Unknown board type: %x\n",
832 adapter->ahw->port_type);
837 qlcnic_set_pauseparam(struct net_device *netdev,
838 struct ethtool_pauseparam *pause)
840 struct qlcnic_adapter *adapter = netdev_priv(netdev);
841 int port = adapter->ahw->physical_port;
845 if (qlcnic_83xx_check(adapter))
846 return qlcnic_83xx_set_pauseparam(adapter, pause);
849 if (adapter->ahw->port_type == QLCNIC_GBE) {
850 if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
852 /* set flow control */
853 val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), &err);
858 qlcnic_gb_rx_flowctl(val);
860 qlcnic_gb_unset_rx_flowctl(val);
862 QLCWR32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port),
864 QLCWR32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), val);
866 val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, &err);
872 qlcnic_gb_unset_gb0_mask(val);
874 qlcnic_gb_set_gb0_mask(val);
878 qlcnic_gb_unset_gb1_mask(val);
880 qlcnic_gb_set_gb1_mask(val);
884 qlcnic_gb_unset_gb2_mask(val);
886 qlcnic_gb_set_gb2_mask(val);
891 qlcnic_gb_unset_gb3_mask(val);
893 qlcnic_gb_set_gb3_mask(val);
896 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, val);
897 } else if (adapter->ahw->port_type == QLCNIC_XGBE) {
898 if (!pause->rx_pause || pause->autoneg)
901 if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
904 val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, &err);
909 qlcnic_xg_unset_xg0_mask(val);
911 qlcnic_xg_set_xg0_mask(val);
914 qlcnic_xg_unset_xg1_mask(val);
916 qlcnic_xg_set_xg1_mask(val);
918 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, val);
920 dev_err(&netdev->dev, "Unknown board type: %x\n",
921 adapter->ahw->port_type);
926 static int qlcnic_reg_test(struct net_device *dev)
928 struct qlcnic_adapter *adapter = netdev_priv(dev);
932 if (qlcnic_83xx_check(adapter))
933 return qlcnic_83xx_reg_test(adapter);
935 data_read = QLCRD32(adapter, QLCNIC_PCIX_PH_REG(0), &err);
938 if ((data_read & 0xffff) != adapter->pdev->vendor)
944 static int qlcnic_eeprom_test(struct net_device *dev)
946 struct qlcnic_adapter *adapter = netdev_priv(dev);
948 if (qlcnic_82xx_check(adapter))
951 return qlcnic_83xx_flash_test(adapter);
954 static int qlcnic_get_sset_count(struct net_device *dev, int sset)
957 struct qlcnic_adapter *adapter = netdev_priv(dev);
960 return QLCNIC_TEST_LEN;
962 return qlcnic_dev_statistics_len(adapter);
968 static int qlcnic_irq_test(struct net_device *netdev)
970 struct qlcnic_adapter *adapter = netdev_priv(netdev);
971 struct qlcnic_hardware_context *ahw = adapter->ahw;
972 struct qlcnic_cmd_args cmd;
973 int ret, drv_sds_rings = adapter->drv_sds_rings;
974 int drv_tx_rings = adapter->drv_tx_rings;
976 if (qlcnic_83xx_check(adapter))
977 return qlcnic_83xx_interrupt_test(netdev);
979 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
982 ret = qlcnic_diag_alloc_res(netdev, QLCNIC_INTERRUPT_TEST);
987 ret = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_INTRPT_TEST);
991 cmd.req.arg[1] = ahw->pci_func;
992 ret = qlcnic_issue_cmd(adapter, &cmd);
996 usleep_range(1000, 12000);
997 ret = !ahw->diag_cnt;
1000 qlcnic_free_mbx_args(&cmd);
1003 qlcnic_diag_free_res(netdev, drv_sds_rings);
1006 adapter->drv_sds_rings = drv_sds_rings;
1007 adapter->drv_tx_rings = drv_tx_rings;
1008 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1013 #define QLCNIC_ILB_PKT_SIZE 64
1014 #define QLCNIC_NUM_ILB_PKT 16
1015 #define QLCNIC_ILB_MAX_RCV_LOOP 10
1016 #define QLCNIC_LB_PKT_POLL_DELAY_MSEC 1
1017 #define QLCNIC_LB_PKT_POLL_COUNT 20
1019 static void qlcnic_create_loopback_buff(unsigned char *data, u8 mac[])
1021 unsigned char random_data[] = {0xa8, 0x06, 0x45, 0x00};
1023 memset(data, 0x4e, QLCNIC_ILB_PKT_SIZE);
1025 memcpy(data, mac, ETH_ALEN);
1026 memcpy(data + ETH_ALEN, mac, ETH_ALEN);
1028 memcpy(data + 2 * ETH_ALEN, random_data, sizeof(random_data));
1031 int qlcnic_check_loopback_buff(unsigned char *data, u8 mac[])
1033 unsigned char buff[QLCNIC_ILB_PKT_SIZE];
1034 qlcnic_create_loopback_buff(buff, mac);
1035 return memcmp(data, buff, QLCNIC_ILB_PKT_SIZE);
1038 int qlcnic_do_lb_test(struct qlcnic_adapter *adapter, u8 mode)
1040 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1041 struct qlcnic_host_sds_ring *sds_ring = &recv_ctx->sds_rings[0];
1042 struct sk_buff *skb;
1043 int i, loop, cnt = 0;
1045 for (i = 0; i < QLCNIC_NUM_ILB_PKT; i++) {
1046 skb = netdev_alloc_skb(adapter->netdev, QLCNIC_ILB_PKT_SIZE);
1047 qlcnic_create_loopback_buff(skb->data, adapter->mac_addr);
1048 skb_put(skb, QLCNIC_ILB_PKT_SIZE);
1049 adapter->ahw->diag_cnt = 0;
1050 qlcnic_xmit_frame(skb, adapter->netdev);
1054 msleep(QLCNIC_LB_PKT_POLL_DELAY_MSEC);
1055 qlcnic_process_rcv_ring_diag(sds_ring);
1056 if (loop++ > QLCNIC_LB_PKT_POLL_COUNT)
1058 } while (!adapter->ahw->diag_cnt);
1060 dev_kfree_skb_any(skb);
1062 if (!adapter->ahw->diag_cnt)
1063 dev_warn(&adapter->pdev->dev,
1064 "LB Test: packet #%d was not received\n",
1070 dev_err(&adapter->pdev->dev,
1071 "LB Test: failed, TX[%d], RX[%d]\n", i, cnt);
1072 if (mode != QLCNIC_ILB_MODE)
1073 dev_warn(&adapter->pdev->dev,
1074 "WARNING: Please check loopback cable\n");
1080 static int qlcnic_loopback_test(struct net_device *netdev, u8 mode)
1082 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1083 int drv_tx_rings = adapter->drv_tx_rings;
1084 int drv_sds_rings = adapter->drv_sds_rings;
1085 struct qlcnic_host_sds_ring *sds_ring;
1086 struct qlcnic_hardware_context *ahw = adapter->ahw;
1090 if (qlcnic_83xx_check(adapter))
1091 return qlcnic_83xx_loopback_test(netdev, mode);
1093 if (!(ahw->capabilities & QLCNIC_FW_CAPABILITY_MULTI_LOOPBACK)) {
1094 dev_info(&adapter->pdev->dev,
1095 "Firmware do not support loopback test\n");
1099 dev_warn(&adapter->pdev->dev, "%s loopback test in progress\n",
1100 mode == QLCNIC_ILB_MODE ? "internal" : "external");
1101 if (ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
1102 dev_warn(&adapter->pdev->dev,
1103 "Loopback test not supported in nonprivileged mode\n");
1107 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1110 ret = qlcnic_diag_alloc_res(netdev, QLCNIC_LOOPBACK_TEST);
1114 sds_ring = &adapter->recv_ctx->sds_rings[0];
1115 ret = qlcnic_set_lb_mode(adapter, mode);
1122 qlcnic_process_rcv_ring_diag(sds_ring);
1123 if (loop++ > QLCNIC_ILB_MAX_RCV_LOOP) {
1125 "Firmware didn't sent link up event to loopback request\n");
1128 } else if (adapter->ahw->diag_cnt) {
1129 ret = adapter->ahw->diag_cnt;
1132 } while (!QLCNIC_IS_LB_CONFIGURED(ahw->loopback_state));
1134 ret = qlcnic_do_lb_test(adapter, mode);
1136 qlcnic_clear_lb_mode(adapter, mode);
1139 qlcnic_diag_free_res(netdev, drv_sds_rings);
1142 adapter->drv_sds_rings = drv_sds_rings;
1143 adapter->drv_tx_rings = drv_tx_rings;
1144 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1149 qlcnic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
1152 memset(data, 0, sizeof(u64) * QLCNIC_TEST_LEN);
1154 data[0] = qlcnic_reg_test(dev);
1156 eth_test->flags |= ETH_TEST_FL_FAILED;
1158 data[1] = (u64) qlcnic_test_link(dev);
1160 eth_test->flags |= ETH_TEST_FL_FAILED;
1162 if (eth_test->flags & ETH_TEST_FL_OFFLINE) {
1163 data[2] = qlcnic_irq_test(dev);
1165 eth_test->flags |= ETH_TEST_FL_FAILED;
1167 data[3] = qlcnic_loopback_test(dev, QLCNIC_ILB_MODE);
1169 eth_test->flags |= ETH_TEST_FL_FAILED;
1171 if (eth_test->flags & ETH_TEST_FL_EXTERNAL_LB) {
1172 data[4] = qlcnic_loopback_test(dev, QLCNIC_ELB_MODE);
1174 eth_test->flags |= ETH_TEST_FL_FAILED;
1175 eth_test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
1178 data[5] = qlcnic_eeprom_test(dev);
1180 eth_test->flags |= ETH_TEST_FL_FAILED;
1185 qlcnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1187 struct qlcnic_adapter *adapter = netdev_priv(dev);
1188 int index, i, num_stats;
1190 switch (stringset) {
1192 memcpy(data, *qlcnic_gstrings_test,
1193 QLCNIC_TEST_LEN * ETH_GSTRING_LEN);
1196 num_stats = ARRAY_SIZE(qlcnic_tx_queue_stats_strings);
1197 for (i = 0; i < adapter->drv_tx_rings; i++) {
1198 for (index = 0; index < num_stats; index++) {
1199 sprintf(data, "tx_queue_%d %s", i,
1200 qlcnic_tx_queue_stats_strings[index]);
1201 data += ETH_GSTRING_LEN;
1205 for (index = 0; index < QLCNIC_STATS_LEN; index++) {
1206 memcpy(data + index * ETH_GSTRING_LEN,
1207 qlcnic_gstrings_stats[index].stat_string,
1211 if (qlcnic_83xx_check(adapter)) {
1212 num_stats = ARRAY_SIZE(qlcnic_83xx_tx_stats_strings);
1213 for (i = 0; i < num_stats; i++, index++)
1214 memcpy(data + index * ETH_GSTRING_LEN,
1215 qlcnic_83xx_tx_stats_strings[i],
1217 num_stats = ARRAY_SIZE(qlcnic_83xx_mac_stats_strings);
1218 for (i = 0; i < num_stats; i++, index++)
1219 memcpy(data + index * ETH_GSTRING_LEN,
1220 qlcnic_83xx_mac_stats_strings[i],
1222 num_stats = ARRAY_SIZE(qlcnic_83xx_rx_stats_strings);
1223 for (i = 0; i < num_stats; i++, index++)
1224 memcpy(data + index * ETH_GSTRING_LEN,
1225 qlcnic_83xx_rx_stats_strings[i],
1229 num_stats = ARRAY_SIZE(qlcnic_83xx_mac_stats_strings);
1230 for (i = 0; i < num_stats; i++, index++)
1231 memcpy(data + index * ETH_GSTRING_LEN,
1232 qlcnic_83xx_mac_stats_strings[i],
1235 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1237 num_stats = ARRAY_SIZE(qlcnic_device_gstrings_stats);
1238 for (i = 0; i < num_stats; index++, i++) {
1239 memcpy(data + index * ETH_GSTRING_LEN,
1240 qlcnic_device_gstrings_stats[i],
1246 static u64 *qlcnic_fill_stats(u64 *data, void *stats, int type)
1248 if (type == QLCNIC_MAC_STATS) {
1249 struct qlcnic_mac_statistics *mac_stats =
1250 (struct qlcnic_mac_statistics *)stats;
1251 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_frames);
1252 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_bytes);
1253 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_mcast_pkts);
1254 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_bcast_pkts);
1255 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_pause_cnt);
1256 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_ctrl_pkt);
1257 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_64b_pkts);
1258 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_127b_pkts);
1259 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_255b_pkts);
1260 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_511b_pkts);
1261 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_1023b_pkts);
1262 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_1518b_pkts);
1263 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_gt_1518b_pkts);
1264 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_frames);
1265 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_bytes);
1266 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_mcast_pkts);
1267 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_bcast_pkts);
1268 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_pause_cnt);
1269 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_ctrl_pkt);
1270 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_64b_pkts);
1271 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_127b_pkts);
1272 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_255b_pkts);
1273 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_511b_pkts);
1274 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_1023b_pkts);
1275 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_1518b_pkts);
1276 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_gt_1518b_pkts);
1277 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_error);
1278 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_small);
1279 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_large);
1280 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_jabber);
1281 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_dropped);
1282 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_crc_error);
1283 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_align_error);
1284 } else if (type == QLCNIC_ESW_STATS) {
1285 struct __qlcnic_esw_statistics *esw_stats =
1286 (struct __qlcnic_esw_statistics *)stats;
1287 *data++ = QLCNIC_FILL_STATS(esw_stats->unicast_frames);
1288 *data++ = QLCNIC_FILL_STATS(esw_stats->multicast_frames);
1289 *data++ = QLCNIC_FILL_STATS(esw_stats->broadcast_frames);
1290 *data++ = QLCNIC_FILL_STATS(esw_stats->dropped_frames);
1291 *data++ = QLCNIC_FILL_STATS(esw_stats->errors);
1292 *data++ = QLCNIC_FILL_STATS(esw_stats->local_frames);
1293 *data++ = QLCNIC_FILL_STATS(esw_stats->numbytes);
1298 void qlcnic_update_stats(struct qlcnic_adapter *adapter)
1300 struct qlcnic_tx_queue_stats tx_stats;
1301 struct qlcnic_host_tx_ring *tx_ring;
1304 memset(&tx_stats, 0, sizeof(tx_stats));
1305 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
1306 tx_ring = &adapter->tx_ring[ring];
1307 tx_stats.xmit_on += tx_ring->tx_stats.xmit_on;
1308 tx_stats.xmit_off += tx_ring->tx_stats.xmit_off;
1309 tx_stats.xmit_called += tx_ring->tx_stats.xmit_called;
1310 tx_stats.xmit_finished += tx_ring->tx_stats.xmit_finished;
1311 tx_stats.tx_bytes += tx_ring->tx_stats.tx_bytes;
1314 adapter->stats.xmit_on = tx_stats.xmit_on;
1315 adapter->stats.xmit_off = tx_stats.xmit_off;
1316 adapter->stats.xmitcalled = tx_stats.xmit_called;
1317 adapter->stats.xmitfinished = tx_stats.xmit_finished;
1318 adapter->stats.txbytes = tx_stats.tx_bytes;
1321 static u64 *qlcnic_fill_tx_queue_stats(u64 *data, void *stats)
1323 struct qlcnic_host_tx_ring *tx_ring;
1325 tx_ring = (struct qlcnic_host_tx_ring *)stats;
1327 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_on);
1328 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_off);
1329 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_called);
1330 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_finished);
1331 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.tx_bytes);
1336 static void qlcnic_get_ethtool_stats(struct net_device *dev,
1337 struct ethtool_stats *stats, u64 *data)
1339 struct qlcnic_adapter *adapter = netdev_priv(dev);
1340 struct qlcnic_host_tx_ring *tx_ring;
1341 struct qlcnic_esw_statistics port_stats;
1342 struct qlcnic_mac_statistics mac_stats;
1343 int index, ret, length, size, ring;
1346 memset(data, 0, stats->n_stats * sizeof(u64));
1348 for (ring = 0, index = 0; ring < adapter->drv_tx_rings; ring++) {
1349 if (adapter->is_up == QLCNIC_ADAPTER_UP_MAGIC) {
1350 tx_ring = &adapter->tx_ring[ring];
1351 data = qlcnic_fill_tx_queue_stats(data, tx_ring);
1352 qlcnic_update_stats(adapter);
1354 data += QLCNIC_TX_STATS_LEN;
1358 length = QLCNIC_STATS_LEN;
1359 for (index = 0; index < length; index++) {
1360 p = (char *)adapter + qlcnic_gstrings_stats[index].stat_offset;
1361 size = qlcnic_gstrings_stats[index].sizeof_stat;
1362 *data++ = (size == sizeof(u64)) ? (*(u64 *)p) : ((*(u32 *)p));
1365 if (qlcnic_83xx_check(adapter)) {
1366 if (adapter->ahw->linkup)
1367 qlcnic_83xx_get_stats(adapter, data);
1370 /* Retrieve MAC statistics from firmware */
1371 memset(&mac_stats, 0, sizeof(struct qlcnic_mac_statistics));
1372 qlcnic_get_mac_stats(adapter, &mac_stats);
1373 data = qlcnic_fill_stats(data, &mac_stats, QLCNIC_MAC_STATS);
1376 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1379 memset(&port_stats, 0, sizeof(struct qlcnic_esw_statistics));
1380 ret = qlcnic_get_port_stats(adapter, adapter->ahw->pci_func,
1381 QLCNIC_QUERY_RX_COUNTER, &port_stats.rx);
1385 data = qlcnic_fill_stats(data, &port_stats.rx, QLCNIC_ESW_STATS);
1386 ret = qlcnic_get_port_stats(adapter, adapter->ahw->pci_func,
1387 QLCNIC_QUERY_TX_COUNTER, &port_stats.tx);
1391 qlcnic_fill_stats(data, &port_stats.tx, QLCNIC_ESW_STATS);
1394 static int qlcnic_set_led(struct net_device *dev,
1395 enum ethtool_phys_id_state state)
1397 struct qlcnic_adapter *adapter = netdev_priv(dev);
1398 int drv_sds_rings = adapter->drv_sds_rings;
1399 int err = -EIO, active = 1;
1401 if (qlcnic_83xx_check(adapter))
1402 return qlcnic_83xx_set_led(dev, state);
1404 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
1405 netdev_warn(dev, "LED test not supported for non "
1406 "privilege function\n");
1411 case ETHTOOL_ID_ACTIVE:
1412 if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state))
1415 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
1418 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
1419 if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
1421 set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
1424 if (adapter->nic_ops->config_led(adapter, 1, 0xf) == 0) {
1429 dev_err(&adapter->pdev->dev,
1430 "Failed to set LED blink state.\n");
1433 case ETHTOOL_ID_INACTIVE:
1436 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
1439 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
1440 if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
1442 set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
1445 if (adapter->nic_ops->config_led(adapter, 0, 0xf))
1446 dev_err(&adapter->pdev->dev,
1447 "Failed to reset LED blink state.\n");
1455 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state))
1456 qlcnic_diag_free_res(dev, drv_sds_rings);
1459 clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
1465 qlcnic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1467 struct qlcnic_adapter *adapter = netdev_priv(dev);
1471 if (qlcnic_83xx_check(adapter))
1476 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV, &err);
1479 if (wol_cfg & (1UL << adapter->portnum))
1480 wol->supported |= WAKE_MAGIC;
1482 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG, &err);
1483 if (wol_cfg & (1UL << adapter->portnum))
1484 wol->wolopts |= WAKE_MAGIC;
1488 qlcnic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1490 struct qlcnic_adapter *adapter = netdev_priv(dev);
1494 if (qlcnic_83xx_check(adapter))
1496 if (wol->wolopts & ~WAKE_MAGIC)
1499 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV, &err);
1502 if (!(wol_cfg & (1 << adapter->portnum)))
1505 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG, &err);
1508 if (wol->wolopts & WAKE_MAGIC)
1509 wol_cfg |= 1UL << adapter->portnum;
1511 wol_cfg &= ~(1UL << adapter->portnum);
1513 QLCWR32(adapter, QLCNIC_WOL_CONFIG, wol_cfg);
1519 * Set the coalescing parameters. Currently only normal is supported.
1520 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
1521 * firmware coalescing to default.
1523 static int qlcnic_set_intr_coalesce(struct net_device *netdev,
1524 struct ethtool_coalesce *ethcoal)
1526 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1529 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
1533 * Return Error if unsupported values or
1534 * unsupported parameters are set.
1536 if (ethcoal->rx_coalesce_usecs > 0xffff ||
1537 ethcoal->rx_max_coalesced_frames > 0xffff ||
1538 ethcoal->tx_coalesce_usecs > 0xffff ||
1539 ethcoal->tx_max_coalesced_frames > 0xffff ||
1540 ethcoal->rx_coalesce_usecs_irq ||
1541 ethcoal->rx_max_coalesced_frames_irq ||
1542 ethcoal->tx_coalesce_usecs_irq ||
1543 ethcoal->tx_max_coalesced_frames_irq ||
1544 ethcoal->stats_block_coalesce_usecs ||
1545 ethcoal->use_adaptive_rx_coalesce ||
1546 ethcoal->use_adaptive_tx_coalesce ||
1547 ethcoal->pkt_rate_low ||
1548 ethcoal->rx_coalesce_usecs_low ||
1549 ethcoal->rx_max_coalesced_frames_low ||
1550 ethcoal->tx_coalesce_usecs_low ||
1551 ethcoal->tx_max_coalesced_frames_low ||
1552 ethcoal->pkt_rate_high ||
1553 ethcoal->rx_coalesce_usecs_high ||
1554 ethcoal->rx_max_coalesced_frames_high ||
1555 ethcoal->tx_coalesce_usecs_high ||
1556 ethcoal->tx_max_coalesced_frames_high)
1559 err = qlcnic_config_intr_coalesce(adapter, ethcoal);
1564 static int qlcnic_get_intr_coalesce(struct net_device *netdev,
1565 struct ethtool_coalesce *ethcoal)
1567 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1569 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1572 ethcoal->rx_coalesce_usecs = adapter->ahw->coal.rx_time_us;
1573 ethcoal->rx_max_coalesced_frames = adapter->ahw->coal.rx_packets;
1574 ethcoal->tx_coalesce_usecs = adapter->ahw->coal.tx_time_us;
1575 ethcoal->tx_max_coalesced_frames = adapter->ahw->coal.tx_packets;
1580 static u32 qlcnic_get_msglevel(struct net_device *netdev)
1582 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1584 return adapter->ahw->msg_enable;
1587 static void qlcnic_set_msglevel(struct net_device *netdev, u32 msglvl)
1589 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1591 adapter->ahw->msg_enable = msglvl;
1594 int qlcnic_enable_fw_dump_state(struct qlcnic_adapter *adapter)
1596 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1599 if (qlcnic_84xx_check(adapter)) {
1600 if (qlcnic_83xx_lock_driver(adapter))
1603 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1604 val &= ~QLC_83XX_IDC_DISABLE_FW_DUMP;
1605 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1607 qlcnic_83xx_unlock_driver(adapter);
1609 fw_dump->enable = true;
1612 dev_info(&adapter->pdev->dev, "FW dump enabled\n");
1617 static int qlcnic_disable_fw_dump_state(struct qlcnic_adapter *adapter)
1619 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1622 if (qlcnic_84xx_check(adapter)) {
1623 if (qlcnic_83xx_lock_driver(adapter))
1626 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1627 val |= QLC_83XX_IDC_DISABLE_FW_DUMP;
1628 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1630 qlcnic_83xx_unlock_driver(adapter);
1632 fw_dump->enable = false;
1635 dev_info(&adapter->pdev->dev, "FW dump disabled\n");
1640 bool qlcnic_check_fw_dump_state(struct qlcnic_adapter *adapter)
1642 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1646 if (qlcnic_84xx_check(adapter)) {
1647 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1648 state = (val & QLC_83XX_IDC_DISABLE_FW_DUMP) ? false : true;
1650 state = fw_dump->enable;
1657 qlcnic_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
1659 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1660 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1662 if (!fw_dump->tmpl_hdr) {
1663 netdev_err(adapter->netdev, "FW Dump not supported\n");
1668 dump->len = fw_dump->tmpl_hdr_size + fw_dump->size;
1672 if (!qlcnic_check_fw_dump_state(adapter))
1673 dump->flag = ETH_FW_DUMP_DISABLE;
1675 dump->flag = fw_dump->cap_mask;
1677 dump->version = adapter->fw_version;
1682 qlcnic_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
1688 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1689 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1691 if (!fw_dump->tmpl_hdr) {
1692 netdev_err(netdev, "FW Dump not supported\n");
1696 if (!fw_dump->clr) {
1697 netdev_info(netdev, "Dump not available\n");
1701 /* Copy template header first */
1702 copy_sz = fw_dump->tmpl_hdr_size;
1703 hdr_ptr = (u32 *)fw_dump->tmpl_hdr;
1705 for (i = 0; i < copy_sz/sizeof(u32); i++)
1706 *data++ = cpu_to_le32(*hdr_ptr++);
1708 /* Copy captured dump data */
1709 memcpy(buffer + copy_sz, fw_dump->data, fw_dump->size);
1710 dump->len = copy_sz + fw_dump->size;
1711 dump->flag = fw_dump->cap_mask;
1713 /* Free dump area once data has been captured */
1714 vfree(fw_dump->data);
1715 fw_dump->data = NULL;
1717 netdev_info(netdev, "extracted the FW dump Successfully\n");
1721 static int qlcnic_set_dump_mask(struct qlcnic_adapter *adapter, u32 mask)
1723 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1724 struct net_device *netdev = adapter->netdev;
1726 if (!qlcnic_check_fw_dump_state(adapter)) {
1728 "Can not change driver mask to 0x%x. FW dump not enabled\n",
1733 fw_dump->cap_mask = mask;
1735 /* Store new capture mask in template header as well*/
1736 qlcnic_store_cap_mask(adapter, fw_dump->tmpl_hdr, mask);
1738 netdev_info(netdev, "Driver mask changed to: 0x%x\n", mask);
1743 qlcnic_set_dump(struct net_device *netdev, struct ethtool_dump *val)
1745 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1746 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1747 bool valid_mask = false;
1750 switch (val->flag) {
1751 case QLCNIC_FORCE_FW_DUMP_KEY:
1752 if (!fw_dump->tmpl_hdr) {
1753 netdev_err(netdev, "FW dump not supported\n");
1758 if (!qlcnic_check_fw_dump_state(adapter)) {
1759 netdev_info(netdev, "FW dump not enabled\n");
1766 "Previous dump not cleared, not forcing dump\n");
1770 netdev_info(netdev, "Forcing a FW dump\n");
1771 qlcnic_dev_request_reset(adapter, val->flag);
1773 case QLCNIC_DISABLE_FW_DUMP:
1774 if (!fw_dump->tmpl_hdr) {
1775 netdev_err(netdev, "FW dump not supported\n");
1780 ret = qlcnic_disable_fw_dump_state(adapter);
1783 case QLCNIC_ENABLE_FW_DUMP:
1784 if (!fw_dump->tmpl_hdr) {
1785 netdev_err(netdev, "FW dump not supported\n");
1790 ret = qlcnic_enable_fw_dump_state(adapter);
1793 case QLCNIC_FORCE_FW_RESET:
1794 netdev_info(netdev, "Forcing a FW reset\n");
1795 qlcnic_dev_request_reset(adapter, val->flag);
1796 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
1799 case QLCNIC_SET_QUIESCENT:
1800 case QLCNIC_RESET_QUIESCENT:
1801 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state))
1802 netdev_info(netdev, "Device is in non-operational state\n");
1806 if (!fw_dump->tmpl_hdr) {
1807 netdev_err(netdev, "FW dump not supported\n");
1812 for (i = 0; i < ARRAY_SIZE(qlcnic_fw_dump_level); i++) {
1813 if (val->flag == qlcnic_fw_dump_level[i]) {
1820 ret = qlcnic_set_dump_mask(adapter, val->flag);
1822 netdev_info(netdev, "Invalid dump level: 0x%x\n",
1830 const struct ethtool_ops qlcnic_ethtool_ops = {
1831 .get_drvinfo = qlcnic_get_drvinfo,
1832 .get_regs_len = qlcnic_get_regs_len,
1833 .get_regs = qlcnic_get_regs,
1834 .get_link = ethtool_op_get_link,
1835 .get_eeprom_len = qlcnic_get_eeprom_len,
1836 .get_eeprom = qlcnic_get_eeprom,
1837 .get_ringparam = qlcnic_get_ringparam,
1838 .set_ringparam = qlcnic_set_ringparam,
1839 .get_channels = qlcnic_get_channels,
1840 .set_channels = qlcnic_set_channels,
1841 .get_pauseparam = qlcnic_get_pauseparam,
1842 .set_pauseparam = qlcnic_set_pauseparam,
1843 .get_wol = qlcnic_get_wol,
1844 .set_wol = qlcnic_set_wol,
1845 .self_test = qlcnic_diag_test,
1846 .get_strings = qlcnic_get_strings,
1847 .get_ethtool_stats = qlcnic_get_ethtool_stats,
1848 .get_sset_count = qlcnic_get_sset_count,
1849 .get_coalesce = qlcnic_get_intr_coalesce,
1850 .set_coalesce = qlcnic_set_intr_coalesce,
1851 .set_phys_id = qlcnic_set_led,
1852 .set_msglevel = qlcnic_set_msglevel,
1853 .get_msglevel = qlcnic_get_msglevel,
1854 .get_dump_flag = qlcnic_get_dump_flag,
1855 .get_dump_data = qlcnic_get_dump_data,
1856 .set_dump = qlcnic_set_dump,
1857 .get_link_ksettings = qlcnic_get_link_ksettings,
1858 .set_link_ksettings = qlcnic_set_link_ksettings,
1861 const struct ethtool_ops qlcnic_sriov_vf_ethtool_ops = {
1862 .get_drvinfo = qlcnic_get_drvinfo,
1863 .get_regs_len = qlcnic_get_regs_len,
1864 .get_regs = qlcnic_get_regs,
1865 .get_link = ethtool_op_get_link,
1866 .get_eeprom_len = qlcnic_get_eeprom_len,
1867 .get_eeprom = qlcnic_get_eeprom,
1868 .get_ringparam = qlcnic_get_ringparam,
1869 .set_ringparam = qlcnic_set_ringparam,
1870 .get_channels = qlcnic_get_channels,
1871 .get_pauseparam = qlcnic_get_pauseparam,
1872 .get_wol = qlcnic_get_wol,
1873 .get_strings = qlcnic_get_strings,
1874 .get_ethtool_stats = qlcnic_get_ethtool_stats,
1875 .get_sset_count = qlcnic_get_sset_count,
1876 .get_coalesce = qlcnic_get_intr_coalesce,
1877 .set_coalesce = qlcnic_set_intr_coalesce,
1878 .set_msglevel = qlcnic_set_msglevel,
1879 .get_msglevel = qlcnic_get_msglevel,
1880 .get_link_ksettings = qlcnic_get_link_ksettings,
1883 const struct ethtool_ops qlcnic_ethtool_failed_ops = {
1884 .get_drvinfo = qlcnic_get_drvinfo,
1885 .set_msglevel = qlcnic_set_msglevel,
1886 .get_msglevel = qlcnic_get_msglevel,
1887 .set_dump = qlcnic_set_dump,
1888 .get_link_ksettings = qlcnic_get_link_ksettings,