2 * QLogic qlcnic NIC Driver
3 * Copyright (c) 2009-2010 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)
26 static const struct qlcnic_stats qlcnic_gstrings_stats
[] = {
28 QLC_SIZEOF(stats
.xmitcalled
), QLC_OFF(stats
.xmitcalled
)},
30 QLC_SIZEOF(stats
.xmitfinished
), QLC_OFF(stats
.xmitfinished
)},
32 QLC_SIZEOF(stats
.rxdropped
), QLC_OFF(stats
.rxdropped
)},
34 QLC_SIZEOF(stats
.txdropped
), QLC_OFF(stats
.txdropped
)},
36 QLC_SIZEOF(stats
.csummed
), QLC_OFF(stats
.csummed
)},
38 QLC_SIZEOF(stats
.rx_pkts
), QLC_OFF(stats
.rx_pkts
)},
40 QLC_SIZEOF(stats
.lro_pkts
), QLC_OFF(stats
.lro_pkts
)},
42 QLC_SIZEOF(stats
.rxbytes
), QLC_OFF(stats
.rxbytes
)},
44 QLC_SIZEOF(stats
.txbytes
), QLC_OFF(stats
.txbytes
)},
46 QLC_SIZEOF(stats
.lrobytes
), QLC_OFF(stats
.lrobytes
)},
48 QLC_SIZEOF(stats
.lso_frames
), QLC_OFF(stats
.lso_frames
)},
50 QLC_SIZEOF(stats
.xmit_on
), QLC_OFF(stats
.xmit_on
)},
52 QLC_SIZEOF(stats
.xmit_off
), QLC_OFF(stats
.xmit_off
)},
53 {"skb_alloc_failure", QLC_SIZEOF(stats
.skb_alloc_failure
),
54 QLC_OFF(stats
.skb_alloc_failure
)},
56 QLC_SIZEOF(stats
.null_rxbuf
), QLC_OFF(stats
.null_rxbuf
)},
57 {"rx dma map error", QLC_SIZEOF(stats
.rx_dma_map_error
),
58 QLC_OFF(stats
.rx_dma_map_error
)},
59 {"tx dma map error", QLC_SIZEOF(stats
.tx_dma_map_error
),
60 QLC_OFF(stats
.tx_dma_map_error
)},
64 static const char qlcnic_device_gstrings_stats
[][ETH_GSTRING_LEN
] = {
66 "rx multicast frames",
67 "rx broadcast frames",
73 "tx multicast frames",
74 "tx broadcast frames",
81 static const char qlcnic_mac_stats_strings
[][ETH_GSTRING_LEN
] = {
89 "mac_tx_lt_127b_pkts",
90 "mac_tx_lt_255b_pkts",
91 "mac_tx_lt_511b_pkts",
92 "mac_tx_lt_1023b_pkts",
93 "mac_tx_lt_1518b_pkts",
94 "mac_tx_gt_1518b_pkts",
101 "mac_rx_lt_64b_pkts",
102 "mac_rx_lt_127b_pkts",
103 "mac_rx_lt_255b_pkts",
104 "mac_rx_lt_511b_pkts",
105 "mac_rx_lt_1023b_pkts",
106 "mac_rx_lt_1518b_pkts",
107 "mac_rx_gt_1518b_pkts",
108 "mac_rx_length_error",
109 "mac_rx_length_small",
110 "mac_rx_length_large",
117 #define QLCNIC_STATS_LEN ARRAY_SIZE(qlcnic_gstrings_stats)
118 #define QLCNIC_MAC_STATS_LEN ARRAY_SIZE(qlcnic_mac_stats_strings)
119 #define QLCNIC_DEVICE_STATS_LEN ARRAY_SIZE(qlcnic_device_gstrings_stats)
120 #define QLCNIC_TOTAL_STATS_LEN QLCNIC_STATS_LEN + QLCNIC_MAC_STATS_LEN
122 static const char qlcnic_gstrings_test
[][ETH_GSTRING_LEN
] = {
123 "Register_Test_on_offline",
124 "Link_Test_on_offline",
125 "Interrupt_Test_offline",
126 "Internal_Loopback_offline",
127 "External_Loopback_offline"
130 #define QLCNIC_TEST_LEN ARRAY_SIZE(qlcnic_gstrings_test)
132 #define QLCNIC_RING_REGS_COUNT 20
133 #define QLCNIC_RING_REGS_LEN (QLCNIC_RING_REGS_COUNT * sizeof(u32))
134 #define QLCNIC_MAX_EEPROM_LEN 1024
136 static const u32 diag_registers
[] = {
140 CRB_FW_CAPABILITIES_1
,
142 QLCNIC_CRB_DRV_ACTIVE
,
143 QLCNIC_CRB_DEV_STATE
,
144 QLCNIC_CRB_DRV_STATE
,
145 QLCNIC_CRB_DRV_SCRATCH
,
146 QLCNIC_CRB_DEV_PARTITION_INFO
,
147 QLCNIC_CRB_DRV_IDC_VER
,
148 QLCNIC_PEG_ALIVE_COUNTER
,
149 QLCNIC_PEG_HALT_STATUS1
,
150 QLCNIC_PEG_HALT_STATUS2
,
151 QLCNIC_CRB_PEG_NET_0
+0x3c,
152 QLCNIC_CRB_PEG_NET_1
+0x3c,
153 QLCNIC_CRB_PEG_NET_2
+0x3c,
154 QLCNIC_CRB_PEG_NET_4
+0x3c,
158 #define QLCNIC_MGMT_API_VERSION 2
159 #define QLCNIC_DEV_INFO_SIZE 1
160 #define QLCNIC_ETHTOOL_REGS_VER 2
161 static int qlcnic_get_regs_len(struct net_device
*dev
)
163 return sizeof(diag_registers
) + QLCNIC_RING_REGS_LEN
+
164 QLCNIC_DEV_INFO_SIZE
+ 1;
167 static int qlcnic_get_eeprom_len(struct net_device
*dev
)
169 return QLCNIC_FLASH_TOTAL_SIZE
;
173 qlcnic_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*drvinfo
)
175 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
176 u32 fw_major
, fw_minor
, fw_build
;
178 fw_major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
179 fw_minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
180 fw_build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
181 snprintf(drvinfo
->fw_version
, sizeof(drvinfo
->fw_version
),
182 "%d.%d.%d", fw_major
, fw_minor
, fw_build
);
184 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
185 sizeof(drvinfo
->bus_info
));
186 strlcpy(drvinfo
->driver
, qlcnic_driver_name
, sizeof(drvinfo
->driver
));
187 strlcpy(drvinfo
->version
, QLCNIC_LINUX_VERSIONID
,
188 sizeof(drvinfo
->version
));
192 qlcnic_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
194 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
195 int check_sfp_module
= 0;
197 /* read which mode */
198 if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
199 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
200 SUPPORTED_10baseT_Full
|
201 SUPPORTED_100baseT_Half
|
202 SUPPORTED_100baseT_Full
|
203 SUPPORTED_1000baseT_Half
|
204 SUPPORTED_1000baseT_Full
);
206 ecmd
->advertising
= (ADVERTISED_100baseT_Half
|
207 ADVERTISED_100baseT_Full
|
208 ADVERTISED_1000baseT_Half
|
209 ADVERTISED_1000baseT_Full
);
211 ethtool_cmd_speed_set(ecmd
, adapter
->ahw
->link_speed
);
212 ecmd
->duplex
= adapter
->ahw
->link_duplex
;
213 ecmd
->autoneg
= adapter
->ahw
->link_autoneg
;
215 } else if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
218 val
= QLCRD32(adapter
, QLCNIC_PORT_MODE_ADDR
);
219 if (val
== QLCNIC_PORT_MODE_802_3_AP
) {
220 ecmd
->supported
= SUPPORTED_1000baseT_Full
;
221 ecmd
->advertising
= ADVERTISED_1000baseT_Full
;
223 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
224 ecmd
->advertising
= ADVERTISED_10000baseT_Full
;
227 if (netif_running(dev
) && adapter
->ahw
->has_link_events
) {
228 ethtool_cmd_speed_set(ecmd
, adapter
->ahw
->link_speed
);
229 ecmd
->autoneg
= adapter
->ahw
->link_autoneg
;
230 ecmd
->duplex
= adapter
->ahw
->link_duplex
;
234 ethtool_cmd_speed_set(ecmd
, SPEED_UNKNOWN
);
235 ecmd
->duplex
= DUPLEX_UNKNOWN
;
236 ecmd
->autoneg
= AUTONEG_DISABLE
;
241 ecmd
->phy_address
= adapter
->ahw
->physical_port
;
242 ecmd
->transceiver
= XCVR_EXTERNAL
;
244 switch (adapter
->ahw
->board_type
) {
245 case QLCNIC_BRDTYPE_P3P_REF_QG
:
246 case QLCNIC_BRDTYPE_P3P_4_GB
:
247 case QLCNIC_BRDTYPE_P3P_4_GB_MM
:
249 ecmd
->supported
|= SUPPORTED_Autoneg
;
250 ecmd
->advertising
|= ADVERTISED_Autoneg
;
251 case QLCNIC_BRDTYPE_P3P_10G_CX4
:
252 case QLCNIC_BRDTYPE_P3P_10G_CX4_LP
:
253 case QLCNIC_BRDTYPE_P3P_10000_BASE_T
:
254 ecmd
->supported
|= SUPPORTED_TP
;
255 ecmd
->advertising
|= ADVERTISED_TP
;
256 ecmd
->port
= PORT_TP
;
257 ecmd
->autoneg
= adapter
->ahw
->link_autoneg
;
259 case QLCNIC_BRDTYPE_P3P_IMEZ
:
260 case QLCNIC_BRDTYPE_P3P_XG_LOM
:
261 case QLCNIC_BRDTYPE_P3P_HMEZ
:
262 ecmd
->supported
|= SUPPORTED_MII
;
263 ecmd
->advertising
|= ADVERTISED_MII
;
264 ecmd
->port
= PORT_MII
;
265 ecmd
->autoneg
= AUTONEG_DISABLE
;
267 case QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS
:
268 case QLCNIC_BRDTYPE_P3P_10G_SFP_CT
:
269 case QLCNIC_BRDTYPE_P3P_10G_SFP_QT
:
270 ecmd
->advertising
|= ADVERTISED_TP
;
271 ecmd
->supported
|= SUPPORTED_TP
;
272 check_sfp_module
= netif_running(dev
) &&
273 adapter
->ahw
->has_link_events
;
274 case QLCNIC_BRDTYPE_P3P_10G_XFP
:
275 ecmd
->supported
|= SUPPORTED_FIBRE
;
276 ecmd
->advertising
|= ADVERTISED_FIBRE
;
277 ecmd
->port
= PORT_FIBRE
;
278 ecmd
->autoneg
= AUTONEG_DISABLE
;
280 case QLCNIC_BRDTYPE_P3P_10G_TP
:
281 if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
282 ecmd
->autoneg
= AUTONEG_DISABLE
;
283 ecmd
->supported
|= (SUPPORTED_FIBRE
| SUPPORTED_TP
);
285 (ADVERTISED_FIBRE
| ADVERTISED_TP
);
286 ecmd
->port
= PORT_FIBRE
;
287 check_sfp_module
= netif_running(dev
) &&
288 adapter
->ahw
->has_link_events
;
290 ecmd
->autoneg
= AUTONEG_ENABLE
;
291 ecmd
->supported
|= (SUPPORTED_TP
| SUPPORTED_Autoneg
);
293 (ADVERTISED_TP
| ADVERTISED_Autoneg
);
294 ecmd
->port
= PORT_TP
;
298 dev_err(&adapter
->pdev
->dev
, "Unsupported board model %d\n",
299 adapter
->ahw
->board_type
);
303 if (check_sfp_module
) {
304 switch (adapter
->ahw
->module_type
) {
305 case LINKEVENT_MODULE_OPTICAL_UNKNOWN
:
306 case LINKEVENT_MODULE_OPTICAL_SRLR
:
307 case LINKEVENT_MODULE_OPTICAL_LRM
:
308 case LINKEVENT_MODULE_OPTICAL_SFP_1G
:
309 ecmd
->port
= PORT_FIBRE
;
311 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
:
312 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
:
313 case LINKEVENT_MODULE_TWINAX
:
314 ecmd
->port
= PORT_TP
;
317 ecmd
->port
= PORT_OTHER
;
325 qlcnic_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
329 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
331 if (adapter
->ahw
->port_type
!= QLCNIC_GBE
)
334 /* read which mode */
341 switch (ethtool_cmd_speed(ecmd
)) {
355 ret
= qlcnic_fw_cmd_set_port(adapter
, config
);
357 if (ret
== QLCNIC_RCODE_NOT_SUPPORTED
)
362 adapter
->ahw
->link_speed
= ethtool_cmd_speed(ecmd
);
363 adapter
->ahw
->link_duplex
= ecmd
->duplex
;
364 adapter
->ahw
->link_autoneg
= ecmd
->autoneg
;
366 if (!netif_running(dev
))
369 dev
->netdev_ops
->ndo_stop(dev
);
370 return dev
->netdev_ops
->ndo_open(dev
);
374 qlcnic_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *p
)
376 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
377 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
378 struct qlcnic_host_sds_ring
*sds_ring
;
380 int ring
, i
= 0, j
= 0;
382 memset(p
, 0, qlcnic_get_regs_len(dev
));
383 regs
->version
= (QLCNIC_ETHTOOL_REGS_VER
<< 24) |
384 (adapter
->ahw
->revision_id
<< 16) | (adapter
->pdev
)->device
;
386 regs_buff
[0] = (0xcafe0000 | (QLCNIC_DEV_INFO_SIZE
& 0xffff));
387 regs_buff
[1] = QLCNIC_MGMT_API_VERSION
;
389 for (i
= QLCNIC_DEV_INFO_SIZE
+ 1; diag_registers
[j
] != -1; j
++, i
++)
390 regs_buff
[i
] = QLCRD32(adapter
, diag_registers
[j
]);
392 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
395 regs_buff
[i
++] = 0xFFEFCDAB; /* Marker btw regs and ring count*/
397 regs_buff
[i
++] = 1; /* No. of tx ring */
398 regs_buff
[i
++] = le32_to_cpu(*(adapter
->tx_ring
->hw_consumer
));
399 regs_buff
[i
++] = readl(adapter
->tx_ring
->crb_cmd_producer
);
401 regs_buff
[i
++] = 2; /* No. of rx ring */
402 regs_buff
[i
++] = readl(recv_ctx
->rds_rings
[0].crb_rcv_producer
);
403 regs_buff
[i
++] = readl(recv_ctx
->rds_rings
[1].crb_rcv_producer
);
405 regs_buff
[i
++] = adapter
->max_sds_rings
;
407 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
408 sds_ring
= &(recv_ctx
->sds_rings
[ring
]);
409 regs_buff
[i
++] = readl(sds_ring
->crb_sts_consumer
);
413 static u32
qlcnic_test_link(struct net_device
*dev
)
415 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
418 val
= QLCRD32(adapter
, CRB_XG_STATE_P3P
);
419 val
= XG_LINK_STATE_P3P(adapter
->ahw
->pci_func
, val
);
420 return (val
== XG_LINK_UP_P3P
) ? 0 : 1;
424 qlcnic_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
427 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
431 if (eeprom
->len
== 0)
434 eeprom
->magic
= (adapter
->pdev
)->vendor
|
435 ((adapter
->pdev
)->device
<< 16);
436 offset
= eeprom
->offset
;
438 ret
= qlcnic_rom_fast_read_words(adapter
, offset
, bytes
,
447 qlcnic_get_ringparam(struct net_device
*dev
,
448 struct ethtool_ringparam
*ring
)
450 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
452 ring
->rx_pending
= adapter
->num_rxd
;
453 ring
->rx_jumbo_pending
= adapter
->num_jumbo_rxd
;
454 ring
->tx_pending
= adapter
->num_txd
;
456 ring
->rx_max_pending
= adapter
->max_rxd
;
457 ring
->rx_jumbo_max_pending
= adapter
->max_jumbo_rxd
;
458 ring
->tx_max_pending
= MAX_CMD_DESCRIPTORS
;
462 qlcnic_validate_ringparam(u32 val
, u32 min
, u32 max
, char *r_name
)
465 num_desc
= max(val
, min
);
466 num_desc
= min(num_desc
, max
);
467 num_desc
= roundup_pow_of_two(num_desc
);
469 if (val
!= num_desc
) {
470 printk(KERN_INFO
"%s: setting %s ring size %d instead of %d\n",
471 qlcnic_driver_name
, r_name
, num_desc
, val
);
478 qlcnic_set_ringparam(struct net_device
*dev
,
479 struct ethtool_ringparam
*ring
)
481 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
482 u16 num_rxd
, num_jumbo_rxd
, num_txd
;
484 if (ring
->rx_mini_pending
)
487 num_rxd
= qlcnic_validate_ringparam(ring
->rx_pending
,
488 MIN_RCV_DESCRIPTORS
, adapter
->max_rxd
, "rx");
490 num_jumbo_rxd
= qlcnic_validate_ringparam(ring
->rx_jumbo_pending
,
491 MIN_JUMBO_DESCRIPTORS
, adapter
->max_jumbo_rxd
,
494 num_txd
= qlcnic_validate_ringparam(ring
->tx_pending
,
495 MIN_CMD_DESCRIPTORS
, MAX_CMD_DESCRIPTORS
, "tx");
497 if (num_rxd
== adapter
->num_rxd
&& num_txd
== adapter
->num_txd
&&
498 num_jumbo_rxd
== adapter
->num_jumbo_rxd
)
501 adapter
->num_rxd
= num_rxd
;
502 adapter
->num_jumbo_rxd
= num_jumbo_rxd
;
503 adapter
->num_txd
= num_txd
;
505 return qlcnic_reset_context(adapter
);
508 static void qlcnic_get_channels(struct net_device
*dev
,
509 struct ethtool_channels
*channel
)
512 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
514 min
= min_t(int, adapter
->ahw
->max_rx_ques
, num_online_cpus());
515 channel
->max_rx
= rounddown_pow_of_two(min
);
516 channel
->max_tx
= adapter
->ahw
->max_tx_ques
;
518 channel
->rx_count
= adapter
->max_sds_rings
;
519 channel
->tx_count
= adapter
->ahw
->max_tx_ques
;
522 static int qlcnic_set_channels(struct net_device
*dev
,
523 struct ethtool_channels
*channel
)
525 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
528 if (channel
->other_count
|| channel
->combined_count
||
529 channel
->tx_count
!= channel
->max_tx
)
532 err
= qlcnic_validate_max_rss(channel
->max_rx
, channel
->rx_count
);
536 err
= qlcnic_set_max_rss(adapter
, channel
->rx_count
, 0);
537 netdev_info(dev
, "allocated 0x%x sds rings\n",
538 adapter
->max_sds_rings
);
543 qlcnic_get_pauseparam(struct net_device
*netdev
,
544 struct ethtool_pauseparam
*pause
)
546 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
547 int port
= adapter
->ahw
->physical_port
;
550 if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
551 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_GBE_PORTS
))
553 /* get flow control settings */
554 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
));
555 pause
->rx_pause
= qlcnic_gb_get_rx_flowctl(val
);
556 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
);
559 pause
->tx_pause
= !(qlcnic_gb_get_gb0_mask(val
));
562 pause
->tx_pause
= !(qlcnic_gb_get_gb1_mask(val
));
565 pause
->tx_pause
= !(qlcnic_gb_get_gb2_mask(val
));
569 pause
->tx_pause
= !(qlcnic_gb_get_gb3_mask(val
));
572 } else if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
573 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_XG_PORTS
))
576 val
= QLCRD32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
);
578 pause
->tx_pause
= !(qlcnic_xg_get_xg0_mask(val
));
580 pause
->tx_pause
= !(qlcnic_xg_get_xg1_mask(val
));
582 dev_err(&netdev
->dev
, "Unknown board type: %x\n",
583 adapter
->ahw
->port_type
);
588 qlcnic_set_pauseparam(struct net_device
*netdev
,
589 struct ethtool_pauseparam
*pause
)
591 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
592 int port
= adapter
->ahw
->physical_port
;
596 if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
597 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_GBE_PORTS
))
599 /* set flow control */
600 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
));
603 qlcnic_gb_rx_flowctl(val
);
605 qlcnic_gb_unset_rx_flowctl(val
);
607 QLCWR32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
),
610 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
);
614 qlcnic_gb_unset_gb0_mask(val
);
616 qlcnic_gb_set_gb0_mask(val
);
620 qlcnic_gb_unset_gb1_mask(val
);
622 qlcnic_gb_set_gb1_mask(val
);
626 qlcnic_gb_unset_gb2_mask(val
);
628 qlcnic_gb_set_gb2_mask(val
);
633 qlcnic_gb_unset_gb3_mask(val
);
635 qlcnic_gb_set_gb3_mask(val
);
638 QLCWR32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
, val
);
639 } else if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
640 if (!pause
->rx_pause
|| pause
->autoneg
)
643 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_XG_PORTS
))
646 val
= QLCRD32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
);
649 qlcnic_xg_unset_xg0_mask(val
);
651 qlcnic_xg_set_xg0_mask(val
);
654 qlcnic_xg_unset_xg1_mask(val
);
656 qlcnic_xg_set_xg1_mask(val
);
658 QLCWR32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
, val
);
660 dev_err(&netdev
->dev
, "Unknown board type: %x\n",
661 adapter
->ahw
->port_type
);
666 static int qlcnic_reg_test(struct net_device
*dev
)
668 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
671 data_read
= QLCRD32(adapter
, QLCNIC_PCIX_PH_REG(0));
672 if ((data_read
& 0xffff) != adapter
->pdev
->vendor
)
678 static int qlcnic_get_sset_count(struct net_device
*dev
, int sset
)
680 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
683 return QLCNIC_TEST_LEN
;
685 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)
686 return QLCNIC_TOTAL_STATS_LEN
+ QLCNIC_DEVICE_STATS_LEN
;
687 return QLCNIC_TOTAL_STATS_LEN
;
693 static int qlcnic_irq_test(struct net_device
*netdev
)
695 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
696 int max_sds_rings
= adapter
->max_sds_rings
;
698 struct qlcnic_cmd_args cmd
;
700 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
703 ret
= qlcnic_diag_alloc_res(netdev
, QLCNIC_INTERRUPT_TEST
);
707 adapter
->ahw
->diag_cnt
= 0;
708 qlcnic_alloc_mbx_args(&cmd
, adapter
, QLCNIC_CMD_INTRPT_TEST
);
710 cmd
.req
.arg
[1] = adapter
->ahw
->pci_func
;
711 ret
= qlcnic_issue_cmd(adapter
, &cmd
);
716 usleep_range(1000, 12000);
717 ret
= !adapter
->ahw
->diag_cnt
;
720 qlcnic_free_mbx_args(&cmd
);
721 qlcnic_diag_free_res(netdev
, max_sds_rings
);
724 adapter
->max_sds_rings
= max_sds_rings
;
725 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
729 #define QLCNIC_ILB_PKT_SIZE 64
730 #define QLCNIC_NUM_ILB_PKT 16
731 #define QLCNIC_ILB_MAX_RCV_LOOP 10
733 static void qlcnic_create_loopback_buff(unsigned char *data
, u8 mac
[])
735 unsigned char random_data
[] = {0xa8, 0x06, 0x45, 0x00};
737 memset(data
, 0x4e, QLCNIC_ILB_PKT_SIZE
);
739 memcpy(data
, mac
, ETH_ALEN
);
740 memcpy(data
+ ETH_ALEN
, mac
, ETH_ALEN
);
742 memcpy(data
+ 2 * ETH_ALEN
, random_data
, sizeof(random_data
));
745 int qlcnic_check_loopback_buff(unsigned char *data
, u8 mac
[])
747 unsigned char buff
[QLCNIC_ILB_PKT_SIZE
];
748 qlcnic_create_loopback_buff(buff
, mac
);
749 return memcmp(data
, buff
, QLCNIC_ILB_PKT_SIZE
);
752 static int qlcnic_do_lb_test(struct qlcnic_adapter
*adapter
, u8 mode
)
754 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
755 struct qlcnic_host_sds_ring
*sds_ring
= &recv_ctx
->sds_rings
[0];
757 int i
, loop
, cnt
= 0;
759 for (i
= 0; i
< QLCNIC_NUM_ILB_PKT
; i
++) {
760 skb
= netdev_alloc_skb(adapter
->netdev
, QLCNIC_ILB_PKT_SIZE
);
761 qlcnic_create_loopback_buff(skb
->data
, adapter
->mac_addr
);
762 skb_put(skb
, QLCNIC_ILB_PKT_SIZE
);
764 adapter
->ahw
->diag_cnt
= 0;
765 qlcnic_xmit_frame(skb
, adapter
->netdev
);
770 qlcnic_process_rcv_ring_diag(sds_ring
);
771 if (loop
++ > QLCNIC_ILB_MAX_RCV_LOOP
)
773 } while (!adapter
->ahw
->diag_cnt
);
775 dev_kfree_skb_any(skb
);
777 if (!adapter
->ahw
->diag_cnt
)
779 "LB Test: packet #%d was not received\n", i
+ 1);
784 dev_warn(&adapter
->pdev
->dev
, "LB Test failed\n");
785 if (mode
!= QLCNIC_ILB_MODE
) {
786 dev_warn(&adapter
->pdev
->dev
,
787 "WARNING: Please make sure external"
788 "loopback connector is plugged in\n");
795 static int qlcnic_loopback_test(struct net_device
*netdev
, u8 mode
)
797 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
798 int max_sds_rings
= adapter
->max_sds_rings
;
799 struct qlcnic_host_sds_ring
*sds_ring
;
803 if (!(adapter
->ahw
->capabilities
&
804 QLCNIC_FW_CAPABILITY_MULTI_LOOPBACK
)) {
805 netdev_info(netdev
, "Firmware is not loopback test capable\n");
809 QLCDB(adapter
, DRV
, "%s loopback test in progress\n",
810 mode
== QLCNIC_ILB_MODE
? "internal" : "external");
811 if (adapter
->ahw
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
812 netdev_warn(netdev
, "Loopback test not supported for non "
813 "privilege function\n");
817 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
820 ret
= qlcnic_diag_alloc_res(netdev
, QLCNIC_LOOPBACK_TEST
);
824 sds_ring
= &adapter
->recv_ctx
->sds_rings
[0];
826 ret
= qlcnic_set_lb_mode(adapter
, mode
);
830 adapter
->ahw
->diag_cnt
= 0;
833 qlcnic_process_rcv_ring_diag(sds_ring
);
834 if (loop
++ > QLCNIC_ILB_MAX_RCV_LOOP
) {
835 netdev_info(netdev
, "firmware didnt respond to loopback"
836 " configure request\n");
837 ret
= -QLCNIC_FW_NOT_RESPOND
;
839 } else if (adapter
->ahw
->diag_cnt
) {
840 ret
= adapter
->ahw
->diag_cnt
;
843 } while (!QLCNIC_IS_LB_CONFIGURED(adapter
->ahw
->loopback_state
));
845 ret
= qlcnic_do_lb_test(adapter
, mode
);
847 qlcnic_clear_lb_mode(adapter
, mode
);
850 qlcnic_diag_free_res(netdev
, max_sds_rings
);
853 adapter
->max_sds_rings
= max_sds_rings
;
854 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
859 qlcnic_diag_test(struct net_device
*dev
, struct ethtool_test
*eth_test
,
862 memset(data
, 0, sizeof(u64
) * QLCNIC_TEST_LEN
);
864 data
[0] = qlcnic_reg_test(dev
);
866 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
868 data
[1] = (u64
) qlcnic_test_link(dev
);
870 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
872 if (eth_test
->flags
& ETH_TEST_FL_OFFLINE
) {
873 data
[2] = qlcnic_irq_test(dev
);
875 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
877 data
[3] = qlcnic_loopback_test(dev
, QLCNIC_ILB_MODE
);
879 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
880 if (eth_test
->flags
& ETH_TEST_FL_EXTERNAL_LB
) {
881 data
[4] = qlcnic_loopback_test(dev
, QLCNIC_ELB_MODE
);
883 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
884 eth_test
->flags
|= ETH_TEST_FL_EXTERNAL_LB_DONE
;
890 qlcnic_get_strings(struct net_device
*dev
, u32 stringset
, u8
* data
)
892 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
897 memcpy(data
, *qlcnic_gstrings_test
,
898 QLCNIC_TEST_LEN
* ETH_GSTRING_LEN
);
901 for (index
= 0; index
< QLCNIC_STATS_LEN
; index
++) {
902 memcpy(data
+ index
* ETH_GSTRING_LEN
,
903 qlcnic_gstrings_stats
[index
].stat_string
,
906 for (j
= 0; j
< QLCNIC_MAC_STATS_LEN
; index
++, j
++) {
907 memcpy(data
+ index
* ETH_GSTRING_LEN
,
908 qlcnic_mac_stats_strings
[j
],
911 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
913 for (i
= 0; i
< QLCNIC_DEVICE_STATS_LEN
; index
++, i
++) {
914 memcpy(data
+ index
* ETH_GSTRING_LEN
,
915 qlcnic_device_gstrings_stats
[i
],
922 qlcnic_fill_stats(int *index
, u64
*data
, void *stats
, int type
)
926 if (type
== QLCNIC_MAC_STATS
) {
927 struct qlcnic_mac_statistics
*mac_stats
=
928 (struct qlcnic_mac_statistics
*)stats
;
929 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_frames
);
930 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_bytes
);
931 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_mcast_pkts
);
932 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_bcast_pkts
);
933 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_pause_cnt
);
934 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_ctrl_pkt
);
935 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_lt_64b_pkts
);
936 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_lt_127b_pkts
);
937 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_lt_255b_pkts
);
938 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_tx_lt_511b_pkts
);
940 QLCNIC_FILL_STATS(mac_stats
->mac_tx_lt_1023b_pkts
);
942 QLCNIC_FILL_STATS(mac_stats
->mac_tx_lt_1518b_pkts
);
944 QLCNIC_FILL_STATS(mac_stats
->mac_tx_gt_1518b_pkts
);
945 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_frames
);
946 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_bytes
);
947 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_mcast_pkts
);
948 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_bcast_pkts
);
949 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_pause_cnt
);
950 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_ctrl_pkt
);
951 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_lt_64b_pkts
);
952 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_lt_127b_pkts
);
953 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_lt_255b_pkts
);
954 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_lt_511b_pkts
);
956 QLCNIC_FILL_STATS(mac_stats
->mac_rx_lt_1023b_pkts
);
958 QLCNIC_FILL_STATS(mac_stats
->mac_rx_lt_1518b_pkts
);
960 QLCNIC_FILL_STATS(mac_stats
->mac_rx_gt_1518b_pkts
);
961 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_length_error
);
962 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_length_small
);
963 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_length_large
);
964 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_jabber
);
965 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_dropped
);
966 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_rx_crc_error
);
967 data
[ind
++] = QLCNIC_FILL_STATS(mac_stats
->mac_align_error
);
968 } else if (type
== QLCNIC_ESW_STATS
) {
969 struct __qlcnic_esw_statistics
*esw_stats
=
970 (struct __qlcnic_esw_statistics
*)stats
;
971 data
[ind
++] = QLCNIC_FILL_STATS(esw_stats
->unicast_frames
);
972 data
[ind
++] = QLCNIC_FILL_STATS(esw_stats
->multicast_frames
);
973 data
[ind
++] = QLCNIC_FILL_STATS(esw_stats
->broadcast_frames
);
974 data
[ind
++] = QLCNIC_FILL_STATS(esw_stats
->dropped_frames
);
975 data
[ind
++] = QLCNIC_FILL_STATS(esw_stats
->errors
);
976 data
[ind
++] = QLCNIC_FILL_STATS(esw_stats
->local_frames
);
977 data
[ind
++] = QLCNIC_FILL_STATS(esw_stats
->numbytes
);
984 qlcnic_get_ethtool_stats(struct net_device
*dev
,
985 struct ethtool_stats
*stats
, u64
* data
)
987 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
988 struct qlcnic_esw_statistics port_stats
;
989 struct qlcnic_mac_statistics mac_stats
;
992 for (index
= 0; index
< QLCNIC_STATS_LEN
; index
++) {
995 qlcnic_gstrings_stats
[index
].stat_offset
;
997 (qlcnic_gstrings_stats
[index
].sizeof_stat
==
998 sizeof(u64
)) ? *(u64
*)p
:(*(u32
*)p
);
1001 /* Retrieve MAC statistics from firmware */
1002 memset(&mac_stats
, 0, sizeof(struct qlcnic_mac_statistics
));
1003 qlcnic_get_mac_stats(adapter
, &mac_stats
);
1004 qlcnic_fill_stats(&index
, data
, &mac_stats
, QLCNIC_MAC_STATS
);
1006 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
1009 memset(&port_stats
, 0, sizeof(struct qlcnic_esw_statistics
));
1010 ret
= qlcnic_get_port_stats(adapter
, adapter
->ahw
->pci_func
,
1011 QLCNIC_QUERY_RX_COUNTER
, &port_stats
.rx
);
1015 qlcnic_fill_stats(&index
, data
, &port_stats
.rx
, QLCNIC_ESW_STATS
);
1017 ret
= qlcnic_get_port_stats(adapter
, adapter
->ahw
->pci_func
,
1018 QLCNIC_QUERY_TX_COUNTER
, &port_stats
.tx
);
1022 qlcnic_fill_stats(&index
, data
, &port_stats
.tx
, QLCNIC_ESW_STATS
);
1025 static int qlcnic_set_led(struct net_device
*dev
,
1026 enum ethtool_phys_id_state state
)
1028 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
1029 int max_sds_rings
= adapter
->max_sds_rings
;
1030 int err
= -EIO
, active
= 1;
1032 if (adapter
->ahw
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
1033 netdev_warn(dev
, "LED test not supported for non "
1034 "privilege function\n");
1039 case ETHTOOL_ID_ACTIVE
:
1040 if (test_and_set_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
))
1043 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1046 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
1047 if (qlcnic_diag_alloc_res(dev
, QLCNIC_LED_TEST
))
1049 set_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
);
1052 if (adapter
->nic_ops
->config_led(adapter
, 1, 0xf) == 0) {
1057 dev_err(&adapter
->pdev
->dev
,
1058 "Failed to set LED blink state.\n");
1061 case ETHTOOL_ID_INACTIVE
:
1064 if (test_bit(__QLCNIC_RESETTING
, &adapter
->state
))
1067 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
1068 if (qlcnic_diag_alloc_res(dev
, QLCNIC_LED_TEST
))
1070 set_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
);
1073 if (adapter
->nic_ops
->config_led(adapter
, 0, 0xf))
1074 dev_err(&adapter
->pdev
->dev
,
1075 "Failed to reset LED blink state.\n");
1083 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
))
1084 qlcnic_diag_free_res(dev
, max_sds_rings
);
1087 clear_bit(__QLCNIC_LED_ENABLE
, &adapter
->state
);
1093 qlcnic_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
1095 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
1101 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG_NV
);
1102 if (wol_cfg
& (1UL << adapter
->portnum
))
1103 wol
->supported
|= WAKE_MAGIC
;
1105 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG
);
1106 if (wol_cfg
& (1UL << adapter
->portnum
))
1107 wol
->wolopts
|= WAKE_MAGIC
;
1111 qlcnic_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
1113 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
1116 if (wol
->wolopts
& ~WAKE_MAGIC
)
1119 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG_NV
);
1120 if (!(wol_cfg
& (1 << adapter
->portnum
)))
1123 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG
);
1124 if (wol
->wolopts
& WAKE_MAGIC
)
1125 wol_cfg
|= 1UL << adapter
->portnum
;
1127 wol_cfg
&= ~(1UL << adapter
->portnum
);
1129 QLCWR32(adapter
, QLCNIC_WOL_CONFIG
, wol_cfg
);
1135 * Set the coalescing parameters. Currently only normal is supported.
1136 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
1137 * firmware coalescing to default.
1139 static int qlcnic_set_intr_coalesce(struct net_device
*netdev
,
1140 struct ethtool_coalesce
*ethcoal
)
1142 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1144 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1148 * Return Error if unsupported values or
1149 * unsupported parameters are set.
1151 if (ethcoal
->rx_coalesce_usecs
> 0xffff ||
1152 ethcoal
->rx_max_coalesced_frames
> 0xffff ||
1153 ethcoal
->tx_coalesce_usecs
||
1154 ethcoal
->tx_max_coalesced_frames
||
1155 ethcoal
->rx_coalesce_usecs_irq
||
1156 ethcoal
->rx_max_coalesced_frames_irq
||
1157 ethcoal
->tx_coalesce_usecs_irq
||
1158 ethcoal
->tx_max_coalesced_frames_irq
||
1159 ethcoal
->stats_block_coalesce_usecs
||
1160 ethcoal
->use_adaptive_rx_coalesce
||
1161 ethcoal
->use_adaptive_tx_coalesce
||
1162 ethcoal
->pkt_rate_low
||
1163 ethcoal
->rx_coalesce_usecs_low
||
1164 ethcoal
->rx_max_coalesced_frames_low
||
1165 ethcoal
->tx_coalesce_usecs_low
||
1166 ethcoal
->tx_max_coalesced_frames_low
||
1167 ethcoal
->pkt_rate_high
||
1168 ethcoal
->rx_coalesce_usecs_high
||
1169 ethcoal
->rx_max_coalesced_frames_high
||
1170 ethcoal
->tx_coalesce_usecs_high
||
1171 ethcoal
->tx_max_coalesced_frames_high
)
1174 if (!ethcoal
->rx_coalesce_usecs
||
1175 !ethcoal
->rx_max_coalesced_frames
) {
1176 adapter
->ahw
->coal
.flag
= QLCNIC_INTR_DEFAULT
;
1177 adapter
->ahw
->coal
.rx_time_us
=
1178 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1179 adapter
->ahw
->coal
.rx_packets
=
1180 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1182 adapter
->ahw
->coal
.flag
= 0;
1183 adapter
->ahw
->coal
.rx_time_us
= ethcoal
->rx_coalesce_usecs
;
1184 adapter
->ahw
->coal
.rx_packets
=
1185 ethcoal
->rx_max_coalesced_frames
;
1188 qlcnic_config_intr_coalesce(adapter
);
1193 static int qlcnic_get_intr_coalesce(struct net_device
*netdev
,
1194 struct ethtool_coalesce
*ethcoal
)
1196 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1198 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1201 ethcoal
->rx_coalesce_usecs
= adapter
->ahw
->coal
.rx_time_us
;
1202 ethcoal
->rx_max_coalesced_frames
= adapter
->ahw
->coal
.rx_packets
;
1207 static u32
qlcnic_get_msglevel(struct net_device
*netdev
)
1209 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1211 return adapter
->ahw
->msg_enable
;
1214 static void qlcnic_set_msglevel(struct net_device
*netdev
, u32 msglvl
)
1216 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1218 adapter
->ahw
->msg_enable
= msglvl
;
1222 qlcnic_get_dump_flag(struct net_device
*netdev
, struct ethtool_dump
*dump
)
1224 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1225 struct qlcnic_fw_dump
*fw_dump
= &adapter
->ahw
->fw_dump
;
1227 if (!fw_dump
->tmpl_hdr
) {
1228 netdev_err(adapter
->netdev
, "FW Dump not supported\n");
1233 dump
->len
= fw_dump
->tmpl_hdr
->size
+ fw_dump
->size
;
1237 if (!fw_dump
->enable
)
1238 dump
->flag
= ETH_FW_DUMP_DISABLE
;
1240 dump
->flag
= fw_dump
->tmpl_hdr
->drv_cap_mask
;
1242 dump
->version
= adapter
->fw_version
;
1247 qlcnic_get_dump_data(struct net_device
*netdev
, struct ethtool_dump
*dump
,
1253 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1254 struct qlcnic_fw_dump
*fw_dump
= &adapter
->ahw
->fw_dump
;
1256 if (!fw_dump
->tmpl_hdr
) {
1257 netdev_err(netdev
, "FW Dump not supported\n");
1261 if (!fw_dump
->clr
) {
1262 netdev_info(netdev
, "Dump not available\n");
1265 /* Copy template header first */
1266 copy_sz
= fw_dump
->tmpl_hdr
->size
;
1267 hdr_ptr
= (u32
*) fw_dump
->tmpl_hdr
;
1269 for (i
= 0; i
< copy_sz
/sizeof(u32
); i
++)
1270 *data
++ = cpu_to_le32(*hdr_ptr
++);
1272 /* Copy captured dump data */
1273 memcpy(buffer
+ copy_sz
, fw_dump
->data
, fw_dump
->size
);
1274 dump
->len
= copy_sz
+ fw_dump
->size
;
1275 dump
->flag
= fw_dump
->tmpl_hdr
->drv_cap_mask
;
1277 /* Free dump area once data has been captured */
1278 vfree(fw_dump
->data
);
1279 fw_dump
->data
= NULL
;
1281 netdev_info(netdev
, "extracted the FW dump Successfully\n");
1286 qlcnic_set_dump(struct net_device
*netdev
, struct ethtool_dump
*val
)
1289 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1290 struct qlcnic_fw_dump
*fw_dump
= &adapter
->ahw
->fw_dump
;
1293 switch (val
->flag
) {
1294 case QLCNIC_FORCE_FW_DUMP_KEY
:
1295 if (!fw_dump
->tmpl_hdr
) {
1296 netdev_err(netdev
, "FW dump not supported\n");
1299 if (!fw_dump
->enable
) {
1300 netdev_info(netdev
, "FW dump not enabled\n");
1305 "Previous dump not cleared, not forcing dump\n");
1308 netdev_info(netdev
, "Forcing a FW dump\n");
1309 qlcnic_dev_request_reset(adapter
, 0);
1311 case QLCNIC_DISABLE_FW_DUMP
:
1312 if (fw_dump
->enable
&& fw_dump
->tmpl_hdr
) {
1313 netdev_info(netdev
, "Disabling FW dump\n");
1314 fw_dump
->enable
= 0;
1317 case QLCNIC_ENABLE_FW_DUMP
:
1318 if (!fw_dump
->tmpl_hdr
) {
1319 netdev_err(netdev
, "FW dump not supported\n");
1322 if (!fw_dump
->enable
) {
1323 netdev_info(netdev
, "Enabling FW dump\n");
1324 fw_dump
->enable
= 1;
1327 case QLCNIC_FORCE_FW_RESET
:
1328 netdev_info(netdev
, "Forcing a FW reset\n");
1329 qlcnic_dev_request_reset(adapter
, 0);
1330 adapter
->flags
&= ~QLCNIC_FW_RESET_OWNER
;
1332 case QLCNIC_SET_QUIESCENT
:
1333 case QLCNIC_RESET_QUIESCENT
:
1334 state
= QLCRD32(adapter
, QLCNIC_CRB_DEV_STATE
);
1335 if (state
== QLCNIC_DEV_FAILED
|| (state
== QLCNIC_DEV_BADBAD
))
1336 netdev_info(netdev
, "Device in FAILED state\n");
1339 if (!fw_dump
->tmpl_hdr
) {
1340 netdev_err(netdev
, "FW dump not supported\n");
1343 for (i
= 0; i
< ARRAY_SIZE(FW_DUMP_LEVELS
); i
++) {
1344 if (val
->flag
== FW_DUMP_LEVELS
[i
]) {
1345 fw_dump
->tmpl_hdr
->drv_cap_mask
=
1347 netdev_info(netdev
, "Driver mask changed to: 0x%x\n",
1348 fw_dump
->tmpl_hdr
->drv_cap_mask
);
1352 netdev_info(netdev
, "Invalid dump level: 0x%x\n", val
->flag
);
1358 const struct ethtool_ops qlcnic_ethtool_ops
= {
1359 .get_settings
= qlcnic_get_settings
,
1360 .set_settings
= qlcnic_set_settings
,
1361 .get_drvinfo
= qlcnic_get_drvinfo
,
1362 .get_regs_len
= qlcnic_get_regs_len
,
1363 .get_regs
= qlcnic_get_regs
,
1364 .get_link
= ethtool_op_get_link
,
1365 .get_eeprom_len
= qlcnic_get_eeprom_len
,
1366 .get_eeprom
= qlcnic_get_eeprom
,
1367 .get_ringparam
= qlcnic_get_ringparam
,
1368 .set_ringparam
= qlcnic_set_ringparam
,
1369 .get_channels
= qlcnic_get_channels
,
1370 .set_channels
= qlcnic_set_channels
,
1371 .get_pauseparam
= qlcnic_get_pauseparam
,
1372 .set_pauseparam
= qlcnic_set_pauseparam
,
1373 .get_wol
= qlcnic_get_wol
,
1374 .set_wol
= qlcnic_set_wol
,
1375 .self_test
= qlcnic_diag_test
,
1376 .get_strings
= qlcnic_get_strings
,
1377 .get_ethtool_stats
= qlcnic_get_ethtool_stats
,
1378 .get_sset_count
= qlcnic_get_sset_count
,
1379 .get_coalesce
= qlcnic_get_intr_coalesce
,
1380 .set_coalesce
= qlcnic_set_intr_coalesce
,
1381 .set_phys_id
= qlcnic_set_led
,
1382 .set_msglevel
= qlcnic_set_msglevel
,
1383 .get_msglevel
= qlcnic_get_msglevel
,
1384 .get_dump_flag
= qlcnic_get_dump_flag
,
1385 .get_dump_data
= qlcnic_get_dump_data
,
1386 .set_dump
= qlcnic_set_dump
,
1389 const struct ethtool_ops qlcnic_ethtool_failed_ops
= {
1390 .get_settings
= qlcnic_get_settings
,
1391 .get_drvinfo
= qlcnic_get_drvinfo
,
1392 .set_msglevel
= qlcnic_set_msglevel
,
1393 .get_msglevel
= qlcnic_get_msglevel
,