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 {"skb_alloc_failure", QLC_SIZEOF(stats.skb_alloc_failure),
51 QLC_OFF(stats.skb_alloc_failure)},
52 {"mac_filter_limit_overrun", QLC_SIZEOF(stats.mac_filter_limit_overrun),
53 QLC_OFF(stats.mac_filter_limit_overrun)},
54 {"spurious intr", QLC_SIZEOF(stats.spurious_intr),
55 QLC_OFF(stats.spurious_intr)},
59 static const char qlcnic_device_gstrings_stats[][ETH_GSTRING_LEN] = {
61 "tx multicast frames",
62 "tx broadcast frames",
68 "rx multicast frames",
69 "rx broadcast frames",
76 static const char qlcnic_83xx_tx_stats_strings[][ETH_GSTRING_LEN] = {
80 "ctx_tx_dropped_pkts",
84 static const char qlcnic_83xx_mac_stats_strings[][ETH_GSTRING_LEN] = {
92 "mac_tx_lt_127b_pkts",
93 "mac_tx_lt_255b_pkts",
94 "mac_tx_lt_511b_pkts",
95 "mac_tx_lt_1023b_pkts",
96 "mac_tx_lt_1518b_pkts",
97 "mac_tx_gt_1518b_pkts",
104 "mac_rx_lt_64b_pkts",
105 "mac_rx_lt_127b_pkts",
106 "mac_rx_lt_255b_pkts",
107 "mac_rx_lt_511b_pkts",
108 "mac_rx_lt_1023b_pkts",
109 "mac_rx_lt_1518b_pkts",
110 "mac_rx_gt_1518b_pkts",
111 "mac_rx_length_error",
112 "mac_rx_length_small",
113 "mac_rx_length_large",
120 "eswitch_multicast_frames",
121 "eswitch_broadcast_frames",
122 "eswitch_unicast_frames",
123 "eswitch_error_free_frames",
124 "eswitch_error_free_bytes",
127 #define QLCNIC_STATS_LEN ARRAY_SIZE(qlcnic_gstrings_stats)
129 static const char qlcnic_tx_queue_stats_strings[][ETH_GSTRING_LEN] = {
137 #define QLCNIC_TX_STATS_LEN ARRAY_SIZE(qlcnic_tx_queue_stats_strings)
139 static const char qlcnic_83xx_rx_stats_strings[][ETH_GSTRING_LEN] = {
144 "ctx_rx_pkts_wo_ctx",
145 "ctx_rx_pkts_drop_wo_sds_on_card",
146 "ctx_rx_pkts_drop_wo_sds_on_host",
147 "ctx_rx_osized_pkts",
148 "ctx_rx_pkts_dropped_wo_rds",
149 "ctx_rx_unexpected_mcast_pkts",
150 "ctx_invalid_mac_address",
151 "ctx_rx_rds_ring_prim_attempted",
152 "ctx_rx_rds_ring_prim_success",
153 "ctx_num_lro_flows_added",
154 "ctx_num_lro_flows_removed",
155 "ctx_num_lro_flows_active",
156 "ctx_pkts_dropped_unknown",
159 static const char qlcnic_gstrings_test[][ETH_GSTRING_LEN] = {
160 "Register_Test_on_offline",
161 "Link_Test_on_offline",
162 "Interrupt_Test_offline",
163 "Internal_Loopback_offline",
164 "External_Loopback_offline",
165 "EEPROM_Test_offline"
168 #define QLCNIC_TEST_LEN ARRAY_SIZE(qlcnic_gstrings_test)
170 static inline int qlcnic_82xx_statistics(struct qlcnic_adapter *adapter)
172 return ARRAY_SIZE(qlcnic_gstrings_stats) +
173 ARRAY_SIZE(qlcnic_83xx_mac_stats_strings) +
174 QLCNIC_TX_STATS_LEN * adapter->drv_tx_rings;
177 static inline int qlcnic_83xx_statistics(struct qlcnic_adapter *adapter)
179 return ARRAY_SIZE(qlcnic_gstrings_stats) +
180 ARRAY_SIZE(qlcnic_83xx_tx_stats_strings) +
181 ARRAY_SIZE(qlcnic_83xx_mac_stats_strings) +
182 ARRAY_SIZE(qlcnic_83xx_rx_stats_strings) +
183 QLCNIC_TX_STATS_LEN * adapter->drv_tx_rings;
186 static int qlcnic_dev_statistics_len(struct qlcnic_adapter *adapter)
190 if (qlcnic_82xx_check(adapter)) {
191 len = qlcnic_82xx_statistics(adapter);
192 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
193 len += ARRAY_SIZE(qlcnic_device_gstrings_stats);
194 } else if (qlcnic_83xx_check(adapter)) {
195 len = qlcnic_83xx_statistics(adapter);
201 #define QLCNIC_TX_INTR_NOT_CONFIGURED 0X78563412
203 #define QLCNIC_MAX_EEPROM_LEN 1024
205 static const u32 diag_registers[] = {
208 QLCNIC_FW_CAPABILITIES,
209 QLCNIC_CRB_DRV_ACTIVE,
210 QLCNIC_CRB_DEV_STATE,
211 QLCNIC_CRB_DRV_STATE,
212 QLCNIC_CRB_DRV_SCRATCH,
213 QLCNIC_CRB_DEV_PARTITION_INFO,
214 QLCNIC_CRB_DRV_IDC_VER,
215 QLCNIC_PEG_ALIVE_COUNTER,
216 QLCNIC_PEG_HALT_STATUS1,
217 QLCNIC_PEG_HALT_STATUS2,
222 static const u32 ext_diag_registers[] = {
225 QLCNIC_CRB_PEG_NET_0+0x3c,
226 QLCNIC_CRB_PEG_NET_1+0x3c,
227 QLCNIC_CRB_PEG_NET_2+0x3c,
228 QLCNIC_CRB_PEG_NET_4+0x3c,
232 #define QLCNIC_MGMT_API_VERSION 3
233 #define QLCNIC_ETHTOOL_REGS_VER 4
235 static inline int qlcnic_get_ring_regs_len(struct qlcnic_adapter *adapter)
237 int ring_regs_cnt = (adapter->drv_tx_rings * 5) +
238 (adapter->max_rds_rings * 2) +
239 (adapter->drv_sds_rings * 3) + 5;
240 return ring_regs_cnt * sizeof(u32);
243 static int qlcnic_get_regs_len(struct net_device *dev)
245 struct qlcnic_adapter *adapter = netdev_priv(dev);
248 if (qlcnic_83xx_check(adapter))
249 len = qlcnic_83xx_get_regs_len(adapter);
251 len = sizeof(ext_diag_registers) + sizeof(diag_registers);
253 len += ((QLCNIC_DEV_INFO_SIZE + 2) * sizeof(u32));
254 len += qlcnic_get_ring_regs_len(adapter);
258 static int qlcnic_get_eeprom_len(struct net_device *dev)
260 return QLCNIC_FLASH_TOTAL_SIZE;
264 qlcnic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
266 struct qlcnic_adapter *adapter = netdev_priv(dev);
267 u32 fw_major, fw_minor, fw_build;
268 fw_major = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MAJOR);
269 fw_minor = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_MINOR);
270 fw_build = QLC_SHARED_REG_RD32(adapter, QLCNIC_FW_VERSION_SUB);
271 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
272 "%d.%d.%d", fw_major, fw_minor, fw_build);
274 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
275 sizeof(drvinfo->bus_info));
276 strlcpy(drvinfo->driver, qlcnic_driver_name, sizeof(drvinfo->driver));
277 strlcpy(drvinfo->version, QLCNIC_LINUX_VERSIONID,
278 sizeof(drvinfo->version));
282 qlcnic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
284 struct qlcnic_adapter *adapter = netdev_priv(dev);
286 if (qlcnic_82xx_check(adapter))
287 return qlcnic_82xx_get_settings(adapter, ecmd);
288 else if (qlcnic_83xx_check(adapter))
289 return qlcnic_83xx_get_settings(adapter, ecmd);
294 int qlcnic_82xx_get_settings(struct qlcnic_adapter *adapter,
295 struct ethtool_cmd *ecmd)
297 struct qlcnic_hardware_context *ahw = adapter->ahw;
299 int check_sfp_module = 0, err = 0;
300 u16 pcifn = ahw->pci_func;
302 /* read which mode */
303 if (adapter->ahw->port_type == QLCNIC_GBE) {
304 ecmd->supported = (SUPPORTED_10baseT_Half |
305 SUPPORTED_10baseT_Full |
306 SUPPORTED_100baseT_Half |
307 SUPPORTED_100baseT_Full |
308 SUPPORTED_1000baseT_Half |
309 SUPPORTED_1000baseT_Full);
311 ecmd->advertising = (ADVERTISED_100baseT_Half |
312 ADVERTISED_100baseT_Full |
313 ADVERTISED_1000baseT_Half |
314 ADVERTISED_1000baseT_Full);
316 ethtool_cmd_speed_set(ecmd, adapter->ahw->link_speed);
317 ecmd->duplex = adapter->ahw->link_duplex;
318 ecmd->autoneg = adapter->ahw->link_autoneg;
320 } else if (adapter->ahw->port_type == QLCNIC_XGBE) {
322 val = QLCRD32(adapter, QLCNIC_PORT_MODE_ADDR, &err);
324 if (val == QLCNIC_PORT_MODE_802_3_AP) {
325 ecmd->supported = SUPPORTED_1000baseT_Full;
326 ecmd->advertising = ADVERTISED_1000baseT_Full;
328 ecmd->supported = SUPPORTED_10000baseT_Full;
329 ecmd->advertising = ADVERTISED_10000baseT_Full;
332 if (netif_running(adapter->netdev) && ahw->has_link_events) {
334 reg = QLCRD32(adapter,
335 P3P_LINK_SPEED_REG(pcifn), &err);
336 speed = P3P_LINK_SPEED_VAL(pcifn, reg);
337 ahw->link_speed = speed * P3P_LINK_SPEED_MHZ;
340 ethtool_cmd_speed_set(ecmd, ahw->link_speed);
341 ecmd->autoneg = ahw->link_autoneg;
342 ecmd->duplex = ahw->link_duplex;
346 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
347 ecmd->duplex = DUPLEX_UNKNOWN;
348 ecmd->autoneg = AUTONEG_DISABLE;
353 ecmd->phy_address = adapter->ahw->physical_port;
354 ecmd->transceiver = XCVR_EXTERNAL;
356 switch (adapter->ahw->board_type) {
357 case QLCNIC_BRDTYPE_P3P_REF_QG:
358 case QLCNIC_BRDTYPE_P3P_4_GB:
359 case QLCNIC_BRDTYPE_P3P_4_GB_MM:
361 ecmd->supported |= SUPPORTED_Autoneg;
362 ecmd->advertising |= ADVERTISED_Autoneg;
363 case QLCNIC_BRDTYPE_P3P_10G_CX4:
364 case QLCNIC_BRDTYPE_P3P_10G_CX4_LP:
365 case QLCNIC_BRDTYPE_P3P_10000_BASE_T:
366 ecmd->supported |= SUPPORTED_TP;
367 ecmd->advertising |= ADVERTISED_TP;
368 ecmd->port = PORT_TP;
369 ecmd->autoneg = adapter->ahw->link_autoneg;
371 case QLCNIC_BRDTYPE_P3P_IMEZ:
372 case QLCNIC_BRDTYPE_P3P_XG_LOM:
373 case QLCNIC_BRDTYPE_P3P_HMEZ:
374 ecmd->supported |= SUPPORTED_MII;
375 ecmd->advertising |= ADVERTISED_MII;
376 ecmd->port = PORT_MII;
377 ecmd->autoneg = AUTONEG_DISABLE;
379 case QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS:
380 case QLCNIC_BRDTYPE_P3P_10G_SFP_CT:
381 case QLCNIC_BRDTYPE_P3P_10G_SFP_QT:
382 ecmd->advertising |= ADVERTISED_TP;
383 ecmd->supported |= SUPPORTED_TP;
384 check_sfp_module = netif_running(adapter->netdev) &&
385 ahw->has_link_events;
386 case QLCNIC_BRDTYPE_P3P_10G_XFP:
387 ecmd->supported |= SUPPORTED_FIBRE;
388 ecmd->advertising |= ADVERTISED_FIBRE;
389 ecmd->port = PORT_FIBRE;
390 ecmd->autoneg = AUTONEG_DISABLE;
392 case QLCNIC_BRDTYPE_P3P_10G_TP:
393 if (adapter->ahw->port_type == QLCNIC_XGBE) {
394 ecmd->autoneg = AUTONEG_DISABLE;
395 ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
397 (ADVERTISED_FIBRE | ADVERTISED_TP);
398 ecmd->port = PORT_FIBRE;
399 check_sfp_module = netif_running(adapter->netdev) &&
400 ahw->has_link_events;
402 ecmd->autoneg = AUTONEG_ENABLE;
403 ecmd->supported |= (SUPPORTED_TP | SUPPORTED_Autoneg);
405 (ADVERTISED_TP | ADVERTISED_Autoneg);
406 ecmd->port = PORT_TP;
410 dev_err(&adapter->pdev->dev, "Unsupported board model %d\n",
411 adapter->ahw->board_type);
415 if (check_sfp_module) {
416 switch (adapter->ahw->module_type) {
417 case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
418 case LINKEVENT_MODULE_OPTICAL_SRLR:
419 case LINKEVENT_MODULE_OPTICAL_LRM:
420 case LINKEVENT_MODULE_OPTICAL_SFP_1G:
421 ecmd->port = PORT_FIBRE;
423 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
424 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
425 case LINKEVENT_MODULE_TWINAX:
426 ecmd->port = PORT_TP;
429 ecmd->port = PORT_OTHER;
436 static int qlcnic_set_port_config(struct qlcnic_adapter *adapter,
437 struct ethtool_cmd *ecmd)
439 u32 ret = 0, config = 0;
440 /* read which mode */
447 switch (ethtool_cmd_speed(ecmd)) {
461 ret = qlcnic_fw_cmd_set_port(adapter, config);
463 if (ret == QLCNIC_RCODE_NOT_SUPPORTED)
470 static int qlcnic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
473 struct qlcnic_adapter *adapter = netdev_priv(dev);
475 if (adapter->ahw->port_type != QLCNIC_GBE)
478 if (qlcnic_83xx_check(adapter))
479 ret = qlcnic_83xx_set_settings(adapter, ecmd);
481 ret = qlcnic_set_port_config(adapter, ecmd);
486 adapter->ahw->link_speed = ethtool_cmd_speed(ecmd);
487 adapter->ahw->link_duplex = ecmd->duplex;
488 adapter->ahw->link_autoneg = ecmd->autoneg;
490 if (!netif_running(dev))
493 dev->netdev_ops->ndo_stop(dev);
494 return dev->netdev_ops->ndo_open(dev);
497 static int qlcnic_82xx_get_registers(struct qlcnic_adapter *adapter,
500 int i, j = 0, err = 0;
502 for (i = QLCNIC_DEV_INFO_SIZE + 1; diag_registers[j] != -1; j++, i++)
503 regs_buff[i] = QLC_SHARED_REG_RD32(adapter, diag_registers[j]);
505 while (ext_diag_registers[j] != -1)
506 regs_buff[i++] = QLCRD32(adapter, ext_diag_registers[j++],
512 qlcnic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
514 struct qlcnic_adapter *adapter = netdev_priv(dev);
515 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
516 struct qlcnic_host_sds_ring *sds_ring;
517 struct qlcnic_host_rds_ring *rds_rings;
518 struct qlcnic_host_tx_ring *tx_ring;
522 memset(p, 0, qlcnic_get_regs_len(dev));
524 regs->version = (QLCNIC_ETHTOOL_REGS_VER << 24) |
525 (adapter->ahw->revision_id << 16) | (adapter->pdev)->device;
527 regs_buff[0] = (0xcafe0000 | (QLCNIC_DEV_INFO_SIZE & 0xffff));
528 regs_buff[1] = QLCNIC_MGMT_API_VERSION;
530 if (adapter->ahw->capabilities & QLC_83XX_ESWITCH_CAPABILITY)
531 regs_buff[2] = adapter->ahw->max_vnic_func;
533 if (qlcnic_82xx_check(adapter))
534 i = qlcnic_82xx_get_registers(adapter, regs_buff);
536 i = qlcnic_83xx_get_registers(adapter, regs_buff);
538 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
541 /* Marker btw regs and TX ring count */
542 regs_buff[i++] = 0xFFEFCDAB;
544 regs_buff[i++] = adapter->drv_tx_rings; /* No. of TX ring */
545 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
546 tx_ring = &adapter->tx_ring[ring];
547 regs_buff[i++] = le32_to_cpu(*(tx_ring->hw_consumer));
548 regs_buff[i++] = tx_ring->sw_consumer;
549 regs_buff[i++] = readl(tx_ring->crb_cmd_producer);
550 regs_buff[i++] = tx_ring->producer;
551 if (tx_ring->crb_intr_mask)
552 regs_buff[i++] = readl(tx_ring->crb_intr_mask);
554 regs_buff[i++] = QLCNIC_TX_INTR_NOT_CONFIGURED;
557 regs_buff[i++] = adapter->max_rds_rings; /* No. of RX ring */
558 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
559 rds_rings = &recv_ctx->rds_rings[ring];
560 regs_buff[i++] = readl(rds_rings->crb_rcv_producer);
561 regs_buff[i++] = rds_rings->producer;
564 regs_buff[i++] = adapter->drv_sds_rings; /* No. of SDS ring */
565 for (ring = 0; ring < adapter->drv_sds_rings; ring++) {
566 sds_ring = &(recv_ctx->sds_rings[ring]);
567 regs_buff[i++] = readl(sds_ring->crb_sts_consumer);
568 regs_buff[i++] = sds_ring->consumer;
569 regs_buff[i++] = readl(sds_ring->crb_intr_mask);
573 static u32 qlcnic_test_link(struct net_device *dev)
575 struct qlcnic_adapter *adapter = netdev_priv(dev);
579 if (qlcnic_83xx_check(adapter)) {
580 val = qlcnic_83xx_test_link(adapter);
581 return (val & 1) ? 0 : 1;
583 val = QLCRD32(adapter, CRB_XG_STATE_P3P, &err);
586 val = XG_LINK_STATE_P3P(adapter->ahw->pci_func, val);
587 return (val == XG_LINK_UP_P3P) ? 0 : 1;
591 qlcnic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
594 struct qlcnic_adapter *adapter = netdev_priv(dev);
598 if (qlcnic_83xx_check(adapter))
600 if (eeprom->len == 0)
603 eeprom->magic = (adapter->pdev)->vendor |
604 ((adapter->pdev)->device << 16);
605 offset = eeprom->offset;
607 if (qlcnic_82xx_check(adapter))
608 ret = qlcnic_rom_fast_read_words(adapter, offset, bytes,
617 qlcnic_get_ringparam(struct net_device *dev,
618 struct ethtool_ringparam *ring)
620 struct qlcnic_adapter *adapter = netdev_priv(dev);
622 ring->rx_pending = adapter->num_rxd;
623 ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
624 ring->tx_pending = adapter->num_txd;
626 ring->rx_max_pending = adapter->max_rxd;
627 ring->rx_jumbo_max_pending = adapter->max_jumbo_rxd;
628 ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
632 qlcnic_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
635 num_desc = max(val, min);
636 num_desc = min(num_desc, max);
637 num_desc = roundup_pow_of_two(num_desc);
639 if (val != num_desc) {
640 printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
641 qlcnic_driver_name, r_name, num_desc, val);
648 qlcnic_set_ringparam(struct net_device *dev,
649 struct ethtool_ringparam *ring)
651 struct qlcnic_adapter *adapter = netdev_priv(dev);
652 u16 num_rxd, num_jumbo_rxd, num_txd;
654 if (ring->rx_mini_pending)
657 num_rxd = qlcnic_validate_ringparam(ring->rx_pending,
658 MIN_RCV_DESCRIPTORS, adapter->max_rxd, "rx");
660 num_jumbo_rxd = qlcnic_validate_ringparam(ring->rx_jumbo_pending,
661 MIN_JUMBO_DESCRIPTORS, adapter->max_jumbo_rxd,
664 num_txd = qlcnic_validate_ringparam(ring->tx_pending,
665 MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
667 if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
668 num_jumbo_rxd == adapter->num_jumbo_rxd)
671 adapter->num_rxd = num_rxd;
672 adapter->num_jumbo_rxd = num_jumbo_rxd;
673 adapter->num_txd = num_txd;
675 return qlcnic_reset_context(adapter);
678 static int qlcnic_validate_ring_count(struct qlcnic_adapter *adapter,
679 u8 rx_ring, u8 tx_ring)
681 if (rx_ring == 0 || tx_ring == 0)
685 if (rx_ring > adapter->max_sds_rings) {
686 netdev_err(adapter->netdev,
687 "Invalid ring count, SDS ring count %d should not be greater than max %d driver sds rings.\n",
688 rx_ring, adapter->max_sds_rings);
694 if (tx_ring > adapter->max_tx_rings) {
695 netdev_err(adapter->netdev,
696 "Invalid ring count, Tx ring count %d should not be greater than max %d driver Tx rings.\n",
697 tx_ring, adapter->max_tx_rings);
705 static void qlcnic_get_channels(struct net_device *dev,
706 struct ethtool_channels *channel)
708 struct qlcnic_adapter *adapter = netdev_priv(dev);
710 channel->max_rx = adapter->max_sds_rings;
711 channel->max_tx = adapter->max_tx_rings;
712 channel->rx_count = adapter->drv_sds_rings;
713 channel->tx_count = adapter->drv_tx_rings;
716 static int qlcnic_set_channels(struct net_device *dev,
717 struct ethtool_channels *channel)
719 struct qlcnic_adapter *adapter = netdev_priv(dev);
722 if (channel->other_count || channel->combined_count)
725 err = qlcnic_validate_ring_count(adapter, channel->rx_count,
730 if (channel->rx_count) {
731 err = qlcnic_validate_rings(adapter, channel->rx_count,
734 netdev_err(dev, "Unable to configure %u SDS rings\n",
740 if (channel->tx_count) {
741 err = qlcnic_validate_rings(adapter, channel->tx_count,
744 netdev_err(dev, "Unable to configure %u Tx rings\n",
750 err = qlcnic_setup_rings(adapter, channel->rx_count,
752 netdev_info(dev, "Allocated %d SDS rings and %d Tx rings\n",
753 adapter->drv_sds_rings, adapter->drv_tx_rings);
759 qlcnic_get_pauseparam(struct net_device *netdev,
760 struct ethtool_pauseparam *pause)
762 struct qlcnic_adapter *adapter = netdev_priv(netdev);
763 int port = adapter->ahw->physical_port;
767 if (qlcnic_83xx_check(adapter)) {
768 qlcnic_83xx_get_pauseparam(adapter, pause);
771 if (adapter->ahw->port_type == QLCNIC_GBE) {
772 if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
774 /* get flow control settings */
775 val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), &err);
778 pause->rx_pause = qlcnic_gb_get_rx_flowctl(val);
779 val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, &err);
784 pause->tx_pause = !(qlcnic_gb_get_gb0_mask(val));
787 pause->tx_pause = !(qlcnic_gb_get_gb1_mask(val));
790 pause->tx_pause = !(qlcnic_gb_get_gb2_mask(val));
794 pause->tx_pause = !(qlcnic_gb_get_gb3_mask(val));
797 } else if (adapter->ahw->port_type == QLCNIC_XGBE) {
798 if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
801 val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, &err);
805 pause->tx_pause = !(qlcnic_xg_get_xg0_mask(val));
807 pause->tx_pause = !(qlcnic_xg_get_xg1_mask(val));
809 dev_err(&netdev->dev, "Unknown board type: %x\n",
810 adapter->ahw->port_type);
815 qlcnic_set_pauseparam(struct net_device *netdev,
816 struct ethtool_pauseparam *pause)
818 struct qlcnic_adapter *adapter = netdev_priv(netdev);
819 int port = adapter->ahw->physical_port;
823 if (qlcnic_83xx_check(adapter))
824 return qlcnic_83xx_set_pauseparam(adapter, pause);
827 if (adapter->ahw->port_type == QLCNIC_GBE) {
828 if ((port < 0) || (port > QLCNIC_NIU_MAX_GBE_PORTS))
830 /* set flow control */
831 val = QLCRD32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), &err);
836 qlcnic_gb_rx_flowctl(val);
838 qlcnic_gb_unset_rx_flowctl(val);
840 QLCWR32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port),
842 QLCWR32(adapter, QLCNIC_NIU_GB_MAC_CONFIG_0(port), val);
844 val = QLCRD32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, &err);
850 qlcnic_gb_unset_gb0_mask(val);
852 qlcnic_gb_set_gb0_mask(val);
856 qlcnic_gb_unset_gb1_mask(val);
858 qlcnic_gb_set_gb1_mask(val);
862 qlcnic_gb_unset_gb2_mask(val);
864 qlcnic_gb_set_gb2_mask(val);
869 qlcnic_gb_unset_gb3_mask(val);
871 qlcnic_gb_set_gb3_mask(val);
874 QLCWR32(adapter, QLCNIC_NIU_GB_PAUSE_CTL, val);
875 } else if (adapter->ahw->port_type == QLCNIC_XGBE) {
876 if (!pause->rx_pause || pause->autoneg)
879 if ((port < 0) || (port > QLCNIC_NIU_MAX_XG_PORTS))
882 val = QLCRD32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, &err);
887 qlcnic_xg_unset_xg0_mask(val);
889 qlcnic_xg_set_xg0_mask(val);
892 qlcnic_xg_unset_xg1_mask(val);
894 qlcnic_xg_set_xg1_mask(val);
896 QLCWR32(adapter, QLCNIC_NIU_XG_PAUSE_CTL, val);
898 dev_err(&netdev->dev, "Unknown board type: %x\n",
899 adapter->ahw->port_type);
904 static int qlcnic_reg_test(struct net_device *dev)
906 struct qlcnic_adapter *adapter = netdev_priv(dev);
910 if (qlcnic_83xx_check(adapter))
911 return qlcnic_83xx_reg_test(adapter);
913 data_read = QLCRD32(adapter, QLCNIC_PCIX_PH_REG(0), &err);
916 if ((data_read & 0xffff) != adapter->pdev->vendor)
922 static int qlcnic_eeprom_test(struct net_device *dev)
924 struct qlcnic_adapter *adapter = netdev_priv(dev);
926 if (qlcnic_82xx_check(adapter))
929 return qlcnic_83xx_flash_test(adapter);
932 static int qlcnic_get_sset_count(struct net_device *dev, int sset)
935 struct qlcnic_adapter *adapter = netdev_priv(dev);
938 return QLCNIC_TEST_LEN;
940 return qlcnic_dev_statistics_len(adapter);
946 static int qlcnic_irq_test(struct net_device *netdev)
948 struct qlcnic_adapter *adapter = netdev_priv(netdev);
949 struct qlcnic_hardware_context *ahw = adapter->ahw;
950 struct qlcnic_cmd_args cmd;
951 int ret, drv_sds_rings = adapter->drv_sds_rings;
952 int drv_tx_rings = adapter->drv_tx_rings;
954 if (qlcnic_83xx_check(adapter))
955 return qlcnic_83xx_interrupt_test(netdev);
957 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
960 ret = qlcnic_diag_alloc_res(netdev, QLCNIC_INTERRUPT_TEST);
965 ret = qlcnic_alloc_mbx_args(&cmd, adapter, QLCNIC_CMD_INTRPT_TEST);
969 cmd.req.arg[1] = ahw->pci_func;
970 ret = qlcnic_issue_cmd(adapter, &cmd);
974 usleep_range(1000, 12000);
975 ret = !ahw->diag_cnt;
978 qlcnic_free_mbx_args(&cmd);
981 qlcnic_diag_free_res(netdev, drv_sds_rings);
984 adapter->drv_sds_rings = drv_sds_rings;
985 adapter->drv_tx_rings = drv_tx_rings;
986 clear_bit(__QLCNIC_RESETTING, &adapter->state);
991 #define QLCNIC_ILB_PKT_SIZE 64
992 #define QLCNIC_NUM_ILB_PKT 16
993 #define QLCNIC_ILB_MAX_RCV_LOOP 10
994 #define QLCNIC_LB_PKT_POLL_DELAY_MSEC 1
995 #define QLCNIC_LB_PKT_POLL_COUNT 20
997 static void qlcnic_create_loopback_buff(unsigned char *data, u8 mac[])
999 unsigned char random_data[] = {0xa8, 0x06, 0x45, 0x00};
1001 memset(data, 0x4e, QLCNIC_ILB_PKT_SIZE);
1003 memcpy(data, mac, ETH_ALEN);
1004 memcpy(data + ETH_ALEN, mac, ETH_ALEN);
1006 memcpy(data + 2 * ETH_ALEN, random_data, sizeof(random_data));
1009 int qlcnic_check_loopback_buff(unsigned char *data, u8 mac[])
1011 unsigned char buff[QLCNIC_ILB_PKT_SIZE];
1012 qlcnic_create_loopback_buff(buff, mac);
1013 return memcmp(data, buff, QLCNIC_ILB_PKT_SIZE);
1016 int qlcnic_do_lb_test(struct qlcnic_adapter *adapter, u8 mode)
1018 struct qlcnic_recv_context *recv_ctx = adapter->recv_ctx;
1019 struct qlcnic_host_sds_ring *sds_ring = &recv_ctx->sds_rings[0];
1020 struct sk_buff *skb;
1021 int i, loop, cnt = 0;
1023 for (i = 0; i < QLCNIC_NUM_ILB_PKT; i++) {
1024 skb = netdev_alloc_skb(adapter->netdev, QLCNIC_ILB_PKT_SIZE);
1025 qlcnic_create_loopback_buff(skb->data, adapter->mac_addr);
1026 skb_put(skb, QLCNIC_ILB_PKT_SIZE);
1027 adapter->ahw->diag_cnt = 0;
1028 qlcnic_xmit_frame(skb, adapter->netdev);
1032 msleep(QLCNIC_LB_PKT_POLL_DELAY_MSEC);
1033 qlcnic_process_rcv_ring_diag(sds_ring);
1034 if (loop++ > QLCNIC_LB_PKT_POLL_COUNT)
1036 } while (!adapter->ahw->diag_cnt);
1038 dev_kfree_skb_any(skb);
1040 if (!adapter->ahw->diag_cnt)
1041 dev_warn(&adapter->pdev->dev,
1042 "LB Test: packet #%d was not received\n",
1048 dev_err(&adapter->pdev->dev,
1049 "LB Test: failed, TX[%d], RX[%d]\n", i, cnt);
1050 if (mode != QLCNIC_ILB_MODE)
1051 dev_warn(&adapter->pdev->dev,
1052 "WARNING: Please check loopback cable\n");
1058 int qlcnic_loopback_test(struct net_device *netdev, u8 mode)
1060 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1061 int drv_tx_rings = adapter->drv_tx_rings;
1062 int drv_sds_rings = adapter->drv_sds_rings;
1063 struct qlcnic_host_sds_ring *sds_ring;
1064 struct qlcnic_hardware_context *ahw = adapter->ahw;
1068 if (qlcnic_83xx_check(adapter))
1069 return qlcnic_83xx_loopback_test(netdev, mode);
1071 if (!(ahw->capabilities & QLCNIC_FW_CAPABILITY_MULTI_LOOPBACK)) {
1072 dev_info(&adapter->pdev->dev,
1073 "Firmware do not support loopback test\n");
1077 dev_warn(&adapter->pdev->dev, "%s loopback test in progress\n",
1078 mode == QLCNIC_ILB_MODE ? "internal" : "external");
1079 if (ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
1080 dev_warn(&adapter->pdev->dev,
1081 "Loopback test not supported in nonprivileged mode\n");
1085 if (test_and_set_bit(__QLCNIC_RESETTING, &adapter->state))
1088 ret = qlcnic_diag_alloc_res(netdev, QLCNIC_LOOPBACK_TEST);
1092 sds_ring = &adapter->recv_ctx->sds_rings[0];
1093 ret = qlcnic_set_lb_mode(adapter, mode);
1100 qlcnic_process_rcv_ring_diag(sds_ring);
1101 if (loop++ > QLCNIC_ILB_MAX_RCV_LOOP) {
1103 "Firmware didn't sent link up event to loopback request\n");
1106 } else if (adapter->ahw->diag_cnt) {
1107 ret = adapter->ahw->diag_cnt;
1110 } while (!QLCNIC_IS_LB_CONFIGURED(ahw->loopback_state));
1112 ret = qlcnic_do_lb_test(adapter, mode);
1114 qlcnic_clear_lb_mode(adapter, mode);
1117 qlcnic_diag_free_res(netdev, drv_sds_rings);
1120 adapter->drv_sds_rings = drv_sds_rings;
1121 adapter->drv_tx_rings = drv_tx_rings;
1122 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1127 qlcnic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
1130 memset(data, 0, sizeof(u64) * QLCNIC_TEST_LEN);
1132 data[0] = qlcnic_reg_test(dev);
1134 eth_test->flags |= ETH_TEST_FL_FAILED;
1136 data[1] = (u64) qlcnic_test_link(dev);
1138 eth_test->flags |= ETH_TEST_FL_FAILED;
1140 if (eth_test->flags & ETH_TEST_FL_OFFLINE) {
1141 data[2] = qlcnic_irq_test(dev);
1143 eth_test->flags |= ETH_TEST_FL_FAILED;
1145 data[3] = qlcnic_loopback_test(dev, QLCNIC_ILB_MODE);
1147 eth_test->flags |= ETH_TEST_FL_FAILED;
1149 if (eth_test->flags & ETH_TEST_FL_EXTERNAL_LB) {
1150 data[4] = qlcnic_loopback_test(dev, QLCNIC_ELB_MODE);
1152 eth_test->flags |= ETH_TEST_FL_FAILED;
1153 eth_test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
1156 data[5] = qlcnic_eeprom_test(dev);
1158 eth_test->flags |= ETH_TEST_FL_FAILED;
1163 qlcnic_get_strings(struct net_device *dev, u32 stringset, u8 *data)
1165 struct qlcnic_adapter *adapter = netdev_priv(dev);
1166 int index, i, num_stats;
1168 switch (stringset) {
1170 memcpy(data, *qlcnic_gstrings_test,
1171 QLCNIC_TEST_LEN * ETH_GSTRING_LEN);
1174 num_stats = ARRAY_SIZE(qlcnic_tx_queue_stats_strings);
1175 for (i = 0; i < adapter->drv_tx_rings; i++) {
1176 for (index = 0; index < num_stats; index++) {
1177 sprintf(data, "tx_queue_%d %s", i,
1178 qlcnic_tx_queue_stats_strings[index]);
1179 data += ETH_GSTRING_LEN;
1183 for (index = 0; index < QLCNIC_STATS_LEN; index++) {
1184 memcpy(data + index * ETH_GSTRING_LEN,
1185 qlcnic_gstrings_stats[index].stat_string,
1189 if (qlcnic_83xx_check(adapter)) {
1190 num_stats = ARRAY_SIZE(qlcnic_83xx_tx_stats_strings);
1191 for (i = 0; i < num_stats; i++, index++)
1192 memcpy(data + index * ETH_GSTRING_LEN,
1193 qlcnic_83xx_tx_stats_strings[i],
1195 num_stats = ARRAY_SIZE(qlcnic_83xx_mac_stats_strings);
1196 for (i = 0; i < num_stats; i++, index++)
1197 memcpy(data + index * ETH_GSTRING_LEN,
1198 qlcnic_83xx_mac_stats_strings[i],
1200 num_stats = ARRAY_SIZE(qlcnic_83xx_rx_stats_strings);
1201 for (i = 0; i < num_stats; i++, index++)
1202 memcpy(data + index * ETH_GSTRING_LEN,
1203 qlcnic_83xx_rx_stats_strings[i],
1207 num_stats = ARRAY_SIZE(qlcnic_83xx_mac_stats_strings);
1208 for (i = 0; i < num_stats; i++, index++)
1209 memcpy(data + index * ETH_GSTRING_LEN,
1210 qlcnic_83xx_mac_stats_strings[i],
1213 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1215 num_stats = ARRAY_SIZE(qlcnic_device_gstrings_stats);
1216 for (i = 0; i < num_stats; index++, i++) {
1217 memcpy(data + index * ETH_GSTRING_LEN,
1218 qlcnic_device_gstrings_stats[i],
1224 static u64 *qlcnic_fill_stats(u64 *data, void *stats, int type)
1226 if (type == QLCNIC_MAC_STATS) {
1227 struct qlcnic_mac_statistics *mac_stats =
1228 (struct qlcnic_mac_statistics *)stats;
1229 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_frames);
1230 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_bytes);
1231 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_mcast_pkts);
1232 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_bcast_pkts);
1233 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_pause_cnt);
1234 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_ctrl_pkt);
1235 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_64b_pkts);
1236 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_127b_pkts);
1237 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_255b_pkts);
1238 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_511b_pkts);
1239 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_1023b_pkts);
1240 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_lt_1518b_pkts);
1241 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_tx_gt_1518b_pkts);
1242 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_frames);
1243 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_bytes);
1244 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_mcast_pkts);
1245 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_bcast_pkts);
1246 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_pause_cnt);
1247 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_ctrl_pkt);
1248 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_64b_pkts);
1249 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_127b_pkts);
1250 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_255b_pkts);
1251 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_511b_pkts);
1252 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_1023b_pkts);
1253 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_lt_1518b_pkts);
1254 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_gt_1518b_pkts);
1255 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_error);
1256 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_small);
1257 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_length_large);
1258 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_jabber);
1259 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_dropped);
1260 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_rx_crc_error);
1261 *data++ = QLCNIC_FILL_STATS(mac_stats->mac_align_error);
1262 } else if (type == QLCNIC_ESW_STATS) {
1263 struct __qlcnic_esw_statistics *esw_stats =
1264 (struct __qlcnic_esw_statistics *)stats;
1265 *data++ = QLCNIC_FILL_STATS(esw_stats->unicast_frames);
1266 *data++ = QLCNIC_FILL_STATS(esw_stats->multicast_frames);
1267 *data++ = QLCNIC_FILL_STATS(esw_stats->broadcast_frames);
1268 *data++ = QLCNIC_FILL_STATS(esw_stats->dropped_frames);
1269 *data++ = QLCNIC_FILL_STATS(esw_stats->errors);
1270 *data++ = QLCNIC_FILL_STATS(esw_stats->local_frames);
1271 *data++ = QLCNIC_FILL_STATS(esw_stats->numbytes);
1276 void qlcnic_update_stats(struct qlcnic_adapter *adapter)
1278 struct qlcnic_host_tx_ring *tx_ring;
1281 for (ring = 0; ring < adapter->drv_tx_rings; ring++) {
1282 tx_ring = &adapter->tx_ring[ring];
1283 adapter->stats.xmit_on += tx_ring->tx_stats.xmit_on;
1284 adapter->stats.xmit_off += tx_ring->tx_stats.xmit_off;
1285 adapter->stats.xmitcalled += tx_ring->tx_stats.xmit_called;
1286 adapter->stats.xmitfinished += tx_ring->tx_stats.xmit_finished;
1287 adapter->stats.txbytes += tx_ring->tx_stats.tx_bytes;
1291 static u64 *qlcnic_fill_tx_queue_stats(u64 *data, void *stats)
1293 struct qlcnic_host_tx_ring *tx_ring;
1295 tx_ring = (struct qlcnic_host_tx_ring *)stats;
1297 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_on);
1298 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_off);
1299 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_called);
1300 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.xmit_finished);
1301 *data++ = QLCNIC_FILL_STATS(tx_ring->tx_stats.tx_bytes);
1306 static void qlcnic_get_ethtool_stats(struct net_device *dev,
1307 struct ethtool_stats *stats, u64 *data)
1309 struct qlcnic_adapter *adapter = netdev_priv(dev);
1310 struct qlcnic_host_tx_ring *tx_ring;
1311 struct qlcnic_esw_statistics port_stats;
1312 struct qlcnic_mac_statistics mac_stats;
1313 int index, ret, length, size, tx_size, ring;
1316 tx_size = adapter->drv_tx_rings * QLCNIC_TX_STATS_LEN;
1318 memset(data, 0, tx_size * sizeof(u64));
1319 for (ring = 0, index = 0; ring < adapter->drv_tx_rings; ring++) {
1320 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
1321 tx_ring = &adapter->tx_ring[ring];
1322 data = qlcnic_fill_tx_queue_stats(data, tx_ring);
1323 qlcnic_update_stats(adapter);
1327 memset(data, 0, stats->n_stats * sizeof(u64));
1328 length = QLCNIC_STATS_LEN;
1329 for (index = 0; index < length; index++) {
1330 p = (char *)adapter + qlcnic_gstrings_stats[index].stat_offset;
1331 size = qlcnic_gstrings_stats[index].sizeof_stat;
1332 *data++ = (size == sizeof(u64)) ? (*(u64 *)p) : ((*(u32 *)p));
1335 if (qlcnic_83xx_check(adapter)) {
1336 if (adapter->ahw->linkup)
1337 qlcnic_83xx_get_stats(adapter, data);
1340 /* Retrieve MAC statistics from firmware */
1341 memset(&mac_stats, 0, sizeof(struct qlcnic_mac_statistics));
1342 qlcnic_get_mac_stats(adapter, &mac_stats);
1343 data = qlcnic_fill_stats(data, &mac_stats, QLCNIC_MAC_STATS);
1346 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
1349 memset(&port_stats, 0, sizeof(struct qlcnic_esw_statistics));
1350 ret = qlcnic_get_port_stats(adapter, adapter->ahw->pci_func,
1351 QLCNIC_QUERY_RX_COUNTER, &port_stats.rx);
1355 data = qlcnic_fill_stats(data, &port_stats.rx, QLCNIC_ESW_STATS);
1356 ret = qlcnic_get_port_stats(adapter, adapter->ahw->pci_func,
1357 QLCNIC_QUERY_TX_COUNTER, &port_stats.tx);
1361 qlcnic_fill_stats(data, &port_stats.tx, QLCNIC_ESW_STATS);
1364 static int qlcnic_set_led(struct net_device *dev,
1365 enum ethtool_phys_id_state state)
1367 struct qlcnic_adapter *adapter = netdev_priv(dev);
1368 int drv_sds_rings = adapter->drv_sds_rings;
1369 int err = -EIO, active = 1;
1371 if (qlcnic_83xx_check(adapter))
1372 return qlcnic_83xx_set_led(dev, state);
1374 if (adapter->ahw->op_mode == QLCNIC_NON_PRIV_FUNC) {
1375 netdev_warn(dev, "LED test not supported for non "
1376 "privilege function\n");
1381 case ETHTOOL_ID_ACTIVE:
1382 if (test_and_set_bit(__QLCNIC_LED_ENABLE, &adapter->state))
1385 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
1388 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
1389 if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
1391 set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
1394 if (adapter->nic_ops->config_led(adapter, 1, 0xf) == 0) {
1399 dev_err(&adapter->pdev->dev,
1400 "Failed to set LED blink state.\n");
1403 case ETHTOOL_ID_INACTIVE:
1406 if (test_bit(__QLCNIC_RESETTING, &adapter->state))
1409 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) {
1410 if (qlcnic_diag_alloc_res(dev, QLCNIC_LED_TEST))
1412 set_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state);
1415 if (adapter->nic_ops->config_led(adapter, 0, 0xf))
1416 dev_err(&adapter->pdev->dev,
1417 "Failed to reset LED blink state.\n");
1425 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC, &adapter->state))
1426 qlcnic_diag_free_res(dev, drv_sds_rings);
1429 clear_bit(__QLCNIC_LED_ENABLE, &adapter->state);
1435 qlcnic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1437 struct qlcnic_adapter *adapter = netdev_priv(dev);
1441 if (qlcnic_83xx_check(adapter))
1446 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV, &err);
1449 if (wol_cfg & (1UL << adapter->portnum))
1450 wol->supported |= WAKE_MAGIC;
1452 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG, &err);
1453 if (wol_cfg & (1UL << adapter->portnum))
1454 wol->wolopts |= WAKE_MAGIC;
1458 qlcnic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
1460 struct qlcnic_adapter *adapter = netdev_priv(dev);
1464 if (qlcnic_83xx_check(adapter))
1466 if (wol->wolopts & ~WAKE_MAGIC)
1469 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG_NV, &err);
1472 if (!(wol_cfg & (1 << adapter->portnum)))
1475 wol_cfg = QLCRD32(adapter, QLCNIC_WOL_CONFIG, &err);
1478 if (wol->wolopts & WAKE_MAGIC)
1479 wol_cfg |= 1UL << adapter->portnum;
1481 wol_cfg &= ~(1UL << adapter->portnum);
1483 QLCWR32(adapter, QLCNIC_WOL_CONFIG, wol_cfg);
1489 * Set the coalescing parameters. Currently only normal is supported.
1490 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
1491 * firmware coalescing to default.
1493 static int qlcnic_set_intr_coalesce(struct net_device *netdev,
1494 struct ethtool_coalesce *ethcoal)
1496 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1497 struct qlcnic_nic_intr_coalesce *coal;
1498 u32 rx_coalesce_usecs, rx_max_frames;
1499 u32 tx_coalesce_usecs, tx_max_frames;
1501 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
1505 * Return Error if unsupported values or
1506 * unsupported parameters are set.
1508 if (ethcoal->rx_coalesce_usecs > 0xffff ||
1509 ethcoal->rx_max_coalesced_frames > 0xffff ||
1510 ethcoal->tx_coalesce_usecs > 0xffff ||
1511 ethcoal->tx_max_coalesced_frames > 0xffff ||
1512 ethcoal->rx_coalesce_usecs_irq ||
1513 ethcoal->rx_max_coalesced_frames_irq ||
1514 ethcoal->tx_coalesce_usecs_irq ||
1515 ethcoal->tx_max_coalesced_frames_irq ||
1516 ethcoal->stats_block_coalesce_usecs ||
1517 ethcoal->use_adaptive_rx_coalesce ||
1518 ethcoal->use_adaptive_tx_coalesce ||
1519 ethcoal->pkt_rate_low ||
1520 ethcoal->rx_coalesce_usecs_low ||
1521 ethcoal->rx_max_coalesced_frames_low ||
1522 ethcoal->tx_coalesce_usecs_low ||
1523 ethcoal->tx_max_coalesced_frames_low ||
1524 ethcoal->pkt_rate_high ||
1525 ethcoal->rx_coalesce_usecs_high ||
1526 ethcoal->rx_max_coalesced_frames_high ||
1527 ethcoal->tx_coalesce_usecs_high ||
1528 ethcoal->tx_max_coalesced_frames_high)
1531 coal = &adapter->ahw->coal;
1533 if (qlcnic_83xx_check(adapter)) {
1534 if (!ethcoal->tx_coalesce_usecs ||
1535 !ethcoal->tx_max_coalesced_frames ||
1536 !ethcoal->rx_coalesce_usecs ||
1537 !ethcoal->rx_max_coalesced_frames) {
1538 coal->flag = QLCNIC_INTR_DEFAULT;
1539 coal->type = QLCNIC_INTR_COAL_TYPE_RX;
1540 coal->rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1541 coal->rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1542 coal->tx_time_us = QLCNIC_DEF_INTR_COALESCE_TX_TIME_US;
1543 coal->tx_packets = QLCNIC_DEF_INTR_COALESCE_TX_PACKETS;
1545 tx_coalesce_usecs = ethcoal->tx_coalesce_usecs;
1546 tx_max_frames = ethcoal->tx_max_coalesced_frames;
1547 rx_coalesce_usecs = ethcoal->rx_coalesce_usecs;
1548 rx_max_frames = ethcoal->rx_max_coalesced_frames;
1551 if ((coal->rx_time_us == rx_coalesce_usecs) &&
1552 (coal->rx_packets == rx_max_frames)) {
1553 coal->type = QLCNIC_INTR_COAL_TYPE_TX;
1554 coal->tx_time_us = tx_coalesce_usecs;
1555 coal->tx_packets = tx_max_frames;
1556 } else if ((coal->tx_time_us == tx_coalesce_usecs) &&
1557 (coal->tx_packets == tx_max_frames)) {
1558 coal->type = QLCNIC_INTR_COAL_TYPE_RX;
1559 coal->rx_time_us = rx_coalesce_usecs;
1560 coal->rx_packets = rx_max_frames;
1562 coal->type = QLCNIC_INTR_COAL_TYPE_RX;
1563 coal->rx_time_us = rx_coalesce_usecs;
1564 coal->rx_packets = rx_max_frames;
1565 coal->tx_time_us = tx_coalesce_usecs;
1566 coal->tx_packets = tx_max_frames;
1570 if (!ethcoal->rx_coalesce_usecs ||
1571 !ethcoal->rx_max_coalesced_frames) {
1572 coal->flag = QLCNIC_INTR_DEFAULT;
1573 coal->rx_time_us = QLCNIC_DEF_INTR_COALESCE_RX_TIME_US;
1574 coal->rx_packets = QLCNIC_DEF_INTR_COALESCE_RX_PACKETS;
1577 coal->rx_time_us = ethcoal->rx_coalesce_usecs;
1578 coal->rx_packets = ethcoal->rx_max_coalesced_frames;
1582 qlcnic_config_intr_coalesce(adapter);
1587 static int qlcnic_get_intr_coalesce(struct net_device *netdev,
1588 struct ethtool_coalesce *ethcoal)
1590 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1592 if (adapter->is_up != QLCNIC_ADAPTER_UP_MAGIC)
1595 ethcoal->rx_coalesce_usecs = adapter->ahw->coal.rx_time_us;
1596 ethcoal->rx_max_coalesced_frames = adapter->ahw->coal.rx_packets;
1597 ethcoal->tx_coalesce_usecs = adapter->ahw->coal.tx_time_us;
1598 ethcoal->tx_max_coalesced_frames = adapter->ahw->coal.tx_packets;
1603 static u32 qlcnic_get_msglevel(struct net_device *netdev)
1605 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1607 return adapter->ahw->msg_enable;
1610 static void qlcnic_set_msglevel(struct net_device *netdev, u32 msglvl)
1612 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1614 adapter->ahw->msg_enable = msglvl;
1617 int qlcnic_enable_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 = true;
1635 dev_info(&adapter->pdev->dev, "FW dump enabled\n");
1640 static int qlcnic_disable_fw_dump_state(struct qlcnic_adapter *adapter)
1642 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1645 if (qlcnic_84xx_check(adapter)) {
1646 if (qlcnic_83xx_lock_driver(adapter))
1649 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1650 val |= QLC_83XX_IDC_DISABLE_FW_DUMP;
1651 QLCWRX(adapter->ahw, QLC_83XX_IDC_CTRL, val);
1653 qlcnic_83xx_unlock_driver(adapter);
1655 fw_dump->enable = false;
1658 dev_info(&adapter->pdev->dev, "FW dump disabled\n");
1663 bool qlcnic_check_fw_dump_state(struct qlcnic_adapter *adapter)
1665 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1669 if (qlcnic_84xx_check(adapter)) {
1670 val = QLCRDX(adapter->ahw, QLC_83XX_IDC_CTRL);
1671 state = (val & QLC_83XX_IDC_DISABLE_FW_DUMP) ? false : true;
1673 state = fw_dump->enable;
1680 qlcnic_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
1682 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1683 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1685 if (!fw_dump->tmpl_hdr) {
1686 netdev_err(adapter->netdev, "FW Dump not supported\n");
1691 dump->len = fw_dump->tmpl_hdr->size + fw_dump->size;
1695 if (!qlcnic_check_fw_dump_state(adapter))
1696 dump->flag = ETH_FW_DUMP_DISABLE;
1698 dump->flag = fw_dump->tmpl_hdr->drv_cap_mask;
1700 dump->version = adapter->fw_version;
1705 qlcnic_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
1711 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1712 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1714 if (!fw_dump->tmpl_hdr) {
1715 netdev_err(netdev, "FW Dump not supported\n");
1719 if (!fw_dump->clr) {
1720 netdev_info(netdev, "Dump not available\n");
1723 /* Copy template header first */
1724 copy_sz = fw_dump->tmpl_hdr->size;
1725 hdr_ptr = (u32 *) fw_dump->tmpl_hdr;
1727 for (i = 0; i < copy_sz/sizeof(u32); i++)
1728 *data++ = cpu_to_le32(*hdr_ptr++);
1730 /* Copy captured dump data */
1731 memcpy(buffer + copy_sz, fw_dump->data, fw_dump->size);
1732 dump->len = copy_sz + fw_dump->size;
1733 dump->flag = fw_dump->tmpl_hdr->drv_cap_mask;
1735 /* Free dump area once data has been captured */
1736 vfree(fw_dump->data);
1737 fw_dump->data = NULL;
1739 netdev_info(netdev, "extracted the FW dump Successfully\n");
1743 static int qlcnic_set_dump_mask(struct qlcnic_adapter *adapter, u32 mask)
1745 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1746 struct net_device *netdev = adapter->netdev;
1748 if (!qlcnic_check_fw_dump_state(adapter)) {
1750 "Can not change driver mask to 0x%x. FW dump not enabled\n",
1755 fw_dump->tmpl_hdr->drv_cap_mask = mask;
1756 netdev_info(netdev, "Driver mask changed to: 0x%x\n", mask);
1761 qlcnic_set_dump(struct net_device *netdev, struct ethtool_dump *val)
1763 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1764 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
1765 bool valid_mask = false;
1768 switch (val->flag) {
1769 case QLCNIC_FORCE_FW_DUMP_KEY:
1770 if (!fw_dump->tmpl_hdr) {
1771 netdev_err(netdev, "FW dump not supported\n");
1776 if (!qlcnic_check_fw_dump_state(adapter)) {
1777 netdev_info(netdev, "FW dump not enabled\n");
1784 "Previous dump not cleared, not forcing dump\n");
1788 netdev_info(netdev, "Forcing a FW dump\n");
1789 qlcnic_dev_request_reset(adapter, val->flag);
1791 case QLCNIC_DISABLE_FW_DUMP:
1792 if (!fw_dump->tmpl_hdr) {
1793 netdev_err(netdev, "FW dump not supported\n");
1798 ret = qlcnic_disable_fw_dump_state(adapter);
1801 case QLCNIC_ENABLE_FW_DUMP:
1802 if (!fw_dump->tmpl_hdr) {
1803 netdev_err(netdev, "FW dump not supported\n");
1808 ret = qlcnic_enable_fw_dump_state(adapter);
1811 case QLCNIC_FORCE_FW_RESET:
1812 netdev_info(netdev, "Forcing a FW reset\n");
1813 qlcnic_dev_request_reset(adapter, val->flag);
1814 adapter->flags &= ~QLCNIC_FW_RESET_OWNER;
1817 case QLCNIC_SET_QUIESCENT:
1818 case QLCNIC_RESET_QUIESCENT:
1819 if (test_bit(__QLCNIC_MAINTENANCE_MODE, &adapter->state))
1820 netdev_info(netdev, "Device is in non-operational state\n");
1824 if (!fw_dump->tmpl_hdr) {
1825 netdev_err(netdev, "FW dump not supported\n");
1830 for (i = 0; i < ARRAY_SIZE(qlcnic_fw_dump_level); i++) {
1831 if (val->flag == qlcnic_fw_dump_level[i]) {
1838 ret = qlcnic_set_dump_mask(adapter, val->flag);
1840 netdev_info(netdev, "Invalid dump level: 0x%x\n",
1848 const struct ethtool_ops qlcnic_ethtool_ops = {
1849 .get_settings = qlcnic_get_settings,
1850 .set_settings = qlcnic_set_settings,
1851 .get_drvinfo = qlcnic_get_drvinfo,
1852 .get_regs_len = qlcnic_get_regs_len,
1853 .get_regs = qlcnic_get_regs,
1854 .get_link = ethtool_op_get_link,
1855 .get_eeprom_len = qlcnic_get_eeprom_len,
1856 .get_eeprom = qlcnic_get_eeprom,
1857 .get_ringparam = qlcnic_get_ringparam,
1858 .set_ringparam = qlcnic_set_ringparam,
1859 .get_channels = qlcnic_get_channels,
1860 .set_channels = qlcnic_set_channels,
1861 .get_pauseparam = qlcnic_get_pauseparam,
1862 .set_pauseparam = qlcnic_set_pauseparam,
1863 .get_wol = qlcnic_get_wol,
1864 .set_wol = qlcnic_set_wol,
1865 .self_test = qlcnic_diag_test,
1866 .get_strings = qlcnic_get_strings,
1867 .get_ethtool_stats = qlcnic_get_ethtool_stats,
1868 .get_sset_count = qlcnic_get_sset_count,
1869 .get_coalesce = qlcnic_get_intr_coalesce,
1870 .set_coalesce = qlcnic_set_intr_coalesce,
1871 .set_phys_id = qlcnic_set_led,
1872 .set_msglevel = qlcnic_set_msglevel,
1873 .get_msglevel = qlcnic_get_msglevel,
1874 .get_dump_flag = qlcnic_get_dump_flag,
1875 .get_dump_data = qlcnic_get_dump_data,
1876 .set_dump = qlcnic_set_dump,
1879 const struct ethtool_ops qlcnic_sriov_vf_ethtool_ops = {
1880 .get_settings = qlcnic_get_settings,
1881 .get_drvinfo = qlcnic_get_drvinfo,
1882 .get_regs_len = qlcnic_get_regs_len,
1883 .get_regs = qlcnic_get_regs,
1884 .get_link = ethtool_op_get_link,
1885 .get_eeprom_len = qlcnic_get_eeprom_len,
1886 .get_eeprom = qlcnic_get_eeprom,
1887 .get_ringparam = qlcnic_get_ringparam,
1888 .set_ringparam = qlcnic_set_ringparam,
1889 .get_channels = qlcnic_get_channels,
1890 .get_pauseparam = qlcnic_get_pauseparam,
1891 .get_wol = qlcnic_get_wol,
1892 .get_strings = qlcnic_get_strings,
1893 .get_ethtool_stats = qlcnic_get_ethtool_stats,
1894 .get_sset_count = qlcnic_get_sset_count,
1895 .get_coalesce = qlcnic_get_intr_coalesce,
1896 .set_coalesce = qlcnic_set_intr_coalesce,
1897 .set_msglevel = qlcnic_set_msglevel,
1898 .get_msglevel = qlcnic_get_msglevel,
1901 const struct ethtool_ops qlcnic_ethtool_failed_ops = {
1902 .get_settings = qlcnic_get_settings,
1903 .get_drvinfo = qlcnic_get_drvinfo,
1904 .set_msglevel = qlcnic_set_msglevel,
1905 .get_msglevel = qlcnic_get_msglevel,
1906 .set_dump = qlcnic_set_dump,