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 #define QLCNIC_STATS_LEN ARRAY_SIZE(qlcnic_gstrings_stats)
82 #define QLCNIC_DEVICE_STATS_LEN ARRAY_SIZE(qlcnic_device_gstrings_stats)
84 static const char qlcnic_gstrings_test
[][ETH_GSTRING_LEN
] = {
85 "Register_Test_on_offline",
86 "Link_Test_on_offline",
87 "Interrupt_Test_offline",
88 "Internal_Loopback_offline",
89 "External_Loopback_offline"
92 #define QLCNIC_TEST_LEN ARRAY_SIZE(qlcnic_gstrings_test)
94 #define QLCNIC_RING_REGS_COUNT 20
95 #define QLCNIC_RING_REGS_LEN (QLCNIC_RING_REGS_COUNT * sizeof(u32))
96 #define QLCNIC_MAX_EEPROM_LEN 1024
98 static const u32 diag_registers
[] = {
102 CRB_FW_CAPABILITIES_1
,
104 QLCNIC_CRB_DRV_ACTIVE
,
105 QLCNIC_CRB_DEV_STATE
,
106 QLCNIC_CRB_DRV_STATE
,
107 QLCNIC_CRB_DRV_SCRATCH
,
108 QLCNIC_CRB_DEV_PARTITION_INFO
,
109 QLCNIC_CRB_DRV_IDC_VER
,
110 QLCNIC_PEG_ALIVE_COUNTER
,
111 QLCNIC_PEG_HALT_STATUS1
,
112 QLCNIC_PEG_HALT_STATUS2
,
113 QLCNIC_CRB_PEG_NET_0
+0x3c,
114 QLCNIC_CRB_PEG_NET_1
+0x3c,
115 QLCNIC_CRB_PEG_NET_2
+0x3c,
116 QLCNIC_CRB_PEG_NET_4
+0x3c,
120 #define QLCNIC_MGMT_API_VERSION 2
121 #define QLCNIC_DEV_INFO_SIZE 1
122 #define QLCNIC_ETHTOOL_REGS_VER 2
123 static int qlcnic_get_regs_len(struct net_device
*dev
)
125 return sizeof(diag_registers
) + QLCNIC_RING_REGS_LEN
+
126 QLCNIC_DEV_INFO_SIZE
+ 1;
129 static int qlcnic_get_eeprom_len(struct net_device
*dev
)
131 return QLCNIC_FLASH_TOTAL_SIZE
;
135 qlcnic_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*drvinfo
)
137 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
138 u32 fw_major
, fw_minor
, fw_build
;
140 fw_major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
141 fw_minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
142 fw_build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
143 sprintf(drvinfo
->fw_version
, "%d.%d.%d", fw_major
, fw_minor
, fw_build
);
145 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
146 strlcpy(drvinfo
->driver
, qlcnic_driver_name
, 32);
147 strlcpy(drvinfo
->version
, QLCNIC_LINUX_VERSIONID
, 32);
151 qlcnic_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
153 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
154 int check_sfp_module
= 0;
155 u16 pcifn
= adapter
->ahw
->pci_func
;
157 /* read which mode */
158 if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
159 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
160 SUPPORTED_10baseT_Full
|
161 SUPPORTED_100baseT_Half
|
162 SUPPORTED_100baseT_Full
|
163 SUPPORTED_1000baseT_Half
|
164 SUPPORTED_1000baseT_Full
);
166 ecmd
->advertising
= (ADVERTISED_100baseT_Half
|
167 ADVERTISED_100baseT_Full
|
168 ADVERTISED_1000baseT_Half
|
169 ADVERTISED_1000baseT_Full
);
171 ethtool_cmd_speed_set(ecmd
, adapter
->link_speed
);
172 ecmd
->duplex
= adapter
->link_duplex
;
173 ecmd
->autoneg
= adapter
->link_autoneg
;
175 } else if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
178 val
= QLCRD32(adapter
, QLCNIC_PORT_MODE_ADDR
);
179 if (val
== QLCNIC_PORT_MODE_802_3_AP
) {
180 ecmd
->supported
= SUPPORTED_1000baseT_Full
;
181 ecmd
->advertising
= ADVERTISED_1000baseT_Full
;
183 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
184 ecmd
->advertising
= ADVERTISED_10000baseT_Full
;
187 if (netif_running(dev
) && adapter
->has_link_events
) {
188 ethtool_cmd_speed_set(ecmd
, adapter
->link_speed
);
189 ecmd
->autoneg
= adapter
->link_autoneg
;
190 ecmd
->duplex
= adapter
->link_duplex
;
194 val
= QLCRD32(adapter
, P3P_LINK_SPEED_REG(pcifn
));
195 ethtool_cmd_speed_set(ecmd
, P3P_LINK_SPEED_MHZ
*
196 P3P_LINK_SPEED_VAL(pcifn
, val
));
197 ecmd
->duplex
= DUPLEX_FULL
;
198 ecmd
->autoneg
= AUTONEG_DISABLE
;
203 ecmd
->phy_address
= adapter
->physical_port
;
204 ecmd
->transceiver
= XCVR_EXTERNAL
;
206 switch (adapter
->ahw
->board_type
) {
207 case QLCNIC_BRDTYPE_P3P_REF_QG
:
208 case QLCNIC_BRDTYPE_P3P_4_GB
:
209 case QLCNIC_BRDTYPE_P3P_4_GB_MM
:
211 ecmd
->supported
|= SUPPORTED_Autoneg
;
212 ecmd
->advertising
|= ADVERTISED_Autoneg
;
213 case QLCNIC_BRDTYPE_P3P_10G_CX4
:
214 case QLCNIC_BRDTYPE_P3P_10G_CX4_LP
:
215 case QLCNIC_BRDTYPE_P3P_10000_BASE_T
:
216 ecmd
->supported
|= SUPPORTED_TP
;
217 ecmd
->advertising
|= ADVERTISED_TP
;
218 ecmd
->port
= PORT_TP
;
219 ecmd
->autoneg
= adapter
->link_autoneg
;
221 case QLCNIC_BRDTYPE_P3P_IMEZ
:
222 case QLCNIC_BRDTYPE_P3P_XG_LOM
:
223 case QLCNIC_BRDTYPE_P3P_HMEZ
:
224 ecmd
->supported
|= SUPPORTED_MII
;
225 ecmd
->advertising
|= ADVERTISED_MII
;
226 ecmd
->port
= PORT_MII
;
227 ecmd
->autoneg
= AUTONEG_DISABLE
;
229 case QLCNIC_BRDTYPE_P3P_10G_SFP_PLUS
:
230 case QLCNIC_BRDTYPE_P3P_10G_SFP_CT
:
231 case QLCNIC_BRDTYPE_P3P_10G_SFP_QT
:
232 ecmd
->advertising
|= ADVERTISED_TP
;
233 ecmd
->supported
|= SUPPORTED_TP
;
234 check_sfp_module
= netif_running(dev
) &&
235 adapter
->has_link_events
;
236 case QLCNIC_BRDTYPE_P3P_10G_XFP
:
237 ecmd
->supported
|= SUPPORTED_FIBRE
;
238 ecmd
->advertising
|= ADVERTISED_FIBRE
;
239 ecmd
->port
= PORT_FIBRE
;
240 ecmd
->autoneg
= AUTONEG_DISABLE
;
242 case QLCNIC_BRDTYPE_P3P_10G_TP
:
243 if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
244 ecmd
->autoneg
= AUTONEG_DISABLE
;
245 ecmd
->supported
|= (SUPPORTED_FIBRE
| SUPPORTED_TP
);
247 (ADVERTISED_FIBRE
| ADVERTISED_TP
);
248 ecmd
->port
= PORT_FIBRE
;
249 check_sfp_module
= netif_running(dev
) &&
250 adapter
->has_link_events
;
252 ecmd
->autoneg
= AUTONEG_ENABLE
;
253 ecmd
->supported
|= (SUPPORTED_TP
| SUPPORTED_Autoneg
);
255 (ADVERTISED_TP
| ADVERTISED_Autoneg
);
256 ecmd
->port
= PORT_TP
;
260 dev_err(&adapter
->pdev
->dev
, "Unsupported board model %d\n",
261 adapter
->ahw
->board_type
);
265 if (check_sfp_module
) {
266 switch (adapter
->module_type
) {
267 case LINKEVENT_MODULE_OPTICAL_UNKNOWN
:
268 case LINKEVENT_MODULE_OPTICAL_SRLR
:
269 case LINKEVENT_MODULE_OPTICAL_LRM
:
270 case LINKEVENT_MODULE_OPTICAL_SFP_1G
:
271 ecmd
->port
= PORT_FIBRE
;
273 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
:
274 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
:
275 case LINKEVENT_MODULE_TWINAX
:
276 ecmd
->port
= PORT_TP
;
279 ecmd
->port
= PORT_OTHER
;
287 qlcnic_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
291 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
293 if (adapter
->ahw
->port_type
!= QLCNIC_GBE
)
296 /* read which mode */
303 switch (ethtool_cmd_speed(ecmd
)) {
317 ret
= qlcnic_fw_cmd_set_port(adapter
, config
);
319 if (ret
== QLCNIC_RCODE_NOT_SUPPORTED
)
324 adapter
->link_speed
= ethtool_cmd_speed(ecmd
);
325 adapter
->link_duplex
= ecmd
->duplex
;
326 adapter
->link_autoneg
= ecmd
->autoneg
;
328 if (!netif_running(dev
))
331 dev
->netdev_ops
->ndo_stop(dev
);
332 return dev
->netdev_ops
->ndo_open(dev
);
336 qlcnic_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *p
)
338 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
339 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
340 struct qlcnic_host_sds_ring
*sds_ring
;
342 int ring
, i
= 0, j
= 0;
344 memset(p
, 0, qlcnic_get_regs_len(dev
));
345 regs
->version
= (QLCNIC_ETHTOOL_REGS_VER
<< 24) |
346 (adapter
->ahw
->revision_id
<< 16) | (adapter
->pdev
)->device
;
348 regs_buff
[0] = (0xcafe0000 | (QLCNIC_DEV_INFO_SIZE
& 0xffff));
349 regs_buff
[1] = QLCNIC_MGMT_API_VERSION
;
351 for (i
= QLCNIC_DEV_INFO_SIZE
+ 1; diag_registers
[j
] != -1; j
++, i
++)
352 regs_buff
[i
] = QLCRD32(adapter
, diag_registers
[j
]);
354 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
357 regs_buff
[i
++] = 0xFFEFCDAB; /* Marker btw regs and ring count*/
359 regs_buff
[i
++] = 1; /* No. of tx ring */
360 regs_buff
[i
++] = le32_to_cpu(*(adapter
->tx_ring
->hw_consumer
));
361 regs_buff
[i
++] = readl(adapter
->tx_ring
->crb_cmd_producer
);
363 regs_buff
[i
++] = 2; /* No. of rx ring */
364 regs_buff
[i
++] = readl(recv_ctx
->rds_rings
[0].crb_rcv_producer
);
365 regs_buff
[i
++] = readl(recv_ctx
->rds_rings
[1].crb_rcv_producer
);
367 regs_buff
[i
++] = adapter
->max_sds_rings
;
369 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
370 sds_ring
= &(recv_ctx
->sds_rings
[ring
]);
371 regs_buff
[i
++] = readl(sds_ring
->crb_sts_consumer
);
375 static u32
qlcnic_test_link(struct net_device
*dev
)
377 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
380 val
= QLCRD32(adapter
, CRB_XG_STATE_P3P
);
381 val
= XG_LINK_STATE_P3P(adapter
->ahw
->pci_func
, val
);
382 return (val
== XG_LINK_UP_P3P
) ? 0 : 1;
386 qlcnic_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
389 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
393 if (eeprom
->len
== 0)
396 eeprom
->magic
= (adapter
->pdev
)->vendor
|
397 ((adapter
->pdev
)->device
<< 16);
398 offset
= eeprom
->offset
;
400 ret
= qlcnic_rom_fast_read_words(adapter
, offset
, bytes
,
409 qlcnic_get_ringparam(struct net_device
*dev
,
410 struct ethtool_ringparam
*ring
)
412 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
414 ring
->rx_pending
= adapter
->num_rxd
;
415 ring
->rx_jumbo_pending
= adapter
->num_jumbo_rxd
;
416 ring
->tx_pending
= adapter
->num_txd
;
418 ring
->rx_max_pending
= adapter
->max_rxd
;
419 ring
->rx_jumbo_max_pending
= adapter
->max_jumbo_rxd
;
420 ring
->tx_max_pending
= MAX_CMD_DESCRIPTORS
;
422 ring
->rx_mini_max_pending
= 0;
423 ring
->rx_mini_pending
= 0;
427 qlcnic_validate_ringparam(u32 val
, u32 min
, u32 max
, char *r_name
)
430 num_desc
= max(val
, min
);
431 num_desc
= min(num_desc
, max
);
432 num_desc
= roundup_pow_of_two(num_desc
);
434 if (val
!= num_desc
) {
435 printk(KERN_INFO
"%s: setting %s ring size %d instead of %d\n",
436 qlcnic_driver_name
, r_name
, num_desc
, val
);
443 qlcnic_set_ringparam(struct net_device
*dev
,
444 struct ethtool_ringparam
*ring
)
446 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
447 u16 num_rxd
, num_jumbo_rxd
, num_txd
;
449 if (ring
->rx_mini_pending
)
452 num_rxd
= qlcnic_validate_ringparam(ring
->rx_pending
,
453 MIN_RCV_DESCRIPTORS
, adapter
->max_rxd
, "rx");
455 num_jumbo_rxd
= qlcnic_validate_ringparam(ring
->rx_jumbo_pending
,
456 MIN_JUMBO_DESCRIPTORS
, adapter
->max_jumbo_rxd
,
459 num_txd
= qlcnic_validate_ringparam(ring
->tx_pending
,
460 MIN_CMD_DESCRIPTORS
, MAX_CMD_DESCRIPTORS
, "tx");
462 if (num_rxd
== adapter
->num_rxd
&& num_txd
== adapter
->num_txd
&&
463 num_jumbo_rxd
== adapter
->num_jumbo_rxd
)
466 adapter
->num_rxd
= num_rxd
;
467 adapter
->num_jumbo_rxd
= num_jumbo_rxd
;
468 adapter
->num_txd
= num_txd
;
470 return qlcnic_reset_context(adapter
);
473 static void qlcnic_get_channels(struct net_device
*dev
,
474 struct ethtool_channels
*channel
)
476 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
478 channel
->max_rx
= rounddown_pow_of_two(min_t(int,
479 adapter
->max_rx_ques
, num_online_cpus()));
480 channel
->max_tx
= adapter
->max_tx_ques
;
482 channel
->rx_count
= adapter
->max_sds_rings
;
483 channel
->tx_count
= adapter
->max_tx_ques
;
486 static int qlcnic_set_channels(struct net_device
*dev
,
487 struct ethtool_channels
*channel
)
489 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
492 if (channel
->other_count
|| channel
->combined_count
||
493 channel
->tx_count
!= channel
->max_tx
)
496 err
= qlcnic_validate_max_rss(dev
, channel
->max_rx
, channel
->rx_count
);
500 err
= qlcnic_set_max_rss(adapter
, channel
->rx_count
);
501 netdev_info(dev
, "allocated 0x%x sds rings\n",
502 adapter
->max_sds_rings
);
507 qlcnic_get_pauseparam(struct net_device
*netdev
,
508 struct ethtool_pauseparam
*pause
)
510 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
511 int port
= adapter
->physical_port
;
514 if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
515 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_GBE_PORTS
))
517 /* get flow control settings */
518 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
));
519 pause
->rx_pause
= qlcnic_gb_get_rx_flowctl(val
);
520 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
);
523 pause
->tx_pause
= !(qlcnic_gb_get_gb0_mask(val
));
526 pause
->tx_pause
= !(qlcnic_gb_get_gb1_mask(val
));
529 pause
->tx_pause
= !(qlcnic_gb_get_gb2_mask(val
));
533 pause
->tx_pause
= !(qlcnic_gb_get_gb3_mask(val
));
536 } else if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
537 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_XG_PORTS
))
540 val
= QLCRD32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
);
542 pause
->tx_pause
= !(qlcnic_xg_get_xg0_mask(val
));
544 pause
->tx_pause
= !(qlcnic_xg_get_xg1_mask(val
));
546 dev_err(&netdev
->dev
, "Unknown board type: %x\n",
547 adapter
->ahw
->port_type
);
552 qlcnic_set_pauseparam(struct net_device
*netdev
,
553 struct ethtool_pauseparam
*pause
)
555 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
556 int port
= adapter
->physical_port
;
560 if (adapter
->ahw
->port_type
== QLCNIC_GBE
) {
561 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_GBE_PORTS
))
563 /* set flow control */
564 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
));
567 qlcnic_gb_rx_flowctl(val
);
569 qlcnic_gb_unset_rx_flowctl(val
);
571 QLCWR32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
),
574 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
);
578 qlcnic_gb_unset_gb0_mask(val
);
580 qlcnic_gb_set_gb0_mask(val
);
584 qlcnic_gb_unset_gb1_mask(val
);
586 qlcnic_gb_set_gb1_mask(val
);
590 qlcnic_gb_unset_gb2_mask(val
);
592 qlcnic_gb_set_gb2_mask(val
);
597 qlcnic_gb_unset_gb3_mask(val
);
599 qlcnic_gb_set_gb3_mask(val
);
602 QLCWR32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
, val
);
603 } else if (adapter
->ahw
->port_type
== QLCNIC_XGBE
) {
604 if (!pause
->rx_pause
|| pause
->autoneg
)
607 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_XG_PORTS
))
610 val
= QLCRD32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
);
613 qlcnic_xg_unset_xg0_mask(val
);
615 qlcnic_xg_set_xg0_mask(val
);
618 qlcnic_xg_unset_xg1_mask(val
);
620 qlcnic_xg_set_xg1_mask(val
);
622 QLCWR32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
, val
);
624 dev_err(&netdev
->dev
, "Unknown board type: %x\n",
625 adapter
->ahw
->port_type
);
630 static int qlcnic_reg_test(struct net_device
*dev
)
632 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
635 data_read
= QLCRD32(adapter
, QLCNIC_PCIX_PH_REG(0));
636 if ((data_read
& 0xffff) != adapter
->pdev
->vendor
)
642 static int qlcnic_get_sset_count(struct net_device
*dev
, int sset
)
644 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
647 return QLCNIC_TEST_LEN
;
649 if (adapter
->flags
& QLCNIC_ESWITCH_ENABLED
)
650 return QLCNIC_STATS_LEN
+ QLCNIC_DEVICE_STATS_LEN
;
651 return QLCNIC_STATS_LEN
;
657 static int qlcnic_irq_test(struct net_device
*netdev
)
659 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
660 int max_sds_rings
= adapter
->max_sds_rings
;
663 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
666 ret
= qlcnic_diag_alloc_res(netdev
, QLCNIC_INTERRUPT_TEST
);
670 adapter
->diag_cnt
= 0;
671 ret
= qlcnic_issue_cmd(adapter
, adapter
->ahw
->pci_func
,
672 adapter
->fw_hal_version
, adapter
->ahw
->pci_func
,
679 ret
= !adapter
->diag_cnt
;
682 qlcnic_diag_free_res(netdev
, max_sds_rings
);
685 adapter
->max_sds_rings
= max_sds_rings
;
686 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
690 #define QLCNIC_ILB_PKT_SIZE 64
691 #define QLCNIC_NUM_ILB_PKT 16
692 #define QLCNIC_ILB_MAX_RCV_LOOP 10
694 static void qlcnic_create_loopback_buff(unsigned char *data
, u8 mac
[])
696 unsigned char random_data
[] = {0xa8, 0x06, 0x45, 0x00};
698 memset(data
, 0x4e, QLCNIC_ILB_PKT_SIZE
);
700 memcpy(data
, mac
, ETH_ALEN
);
701 memcpy(data
+ ETH_ALEN
, mac
, ETH_ALEN
);
703 memcpy(data
+ 2 * ETH_ALEN
, random_data
, sizeof(random_data
));
706 int qlcnic_check_loopback_buff(unsigned char *data
, u8 mac
[])
708 unsigned char buff
[QLCNIC_ILB_PKT_SIZE
];
709 qlcnic_create_loopback_buff(buff
, mac
);
710 return memcmp(data
, buff
, QLCNIC_ILB_PKT_SIZE
);
713 static int qlcnic_do_lb_test(struct qlcnic_adapter
*adapter
)
715 struct qlcnic_recv_context
*recv_ctx
= adapter
->recv_ctx
;
716 struct qlcnic_host_sds_ring
*sds_ring
= &recv_ctx
->sds_rings
[0];
718 int i
, loop
, cnt
= 0;
720 for (i
= 0; i
< QLCNIC_NUM_ILB_PKT
; i
++) {
721 skb
= dev_alloc_skb(QLCNIC_ILB_PKT_SIZE
);
722 qlcnic_create_loopback_buff(skb
->data
, adapter
->mac_addr
);
723 skb_put(skb
, QLCNIC_ILB_PKT_SIZE
);
725 adapter
->diag_cnt
= 0;
726 qlcnic_xmit_frame(skb
, adapter
->netdev
);
731 qlcnic_process_rcv_ring_diag(sds_ring
);
732 if (loop
++ > QLCNIC_ILB_MAX_RCV_LOOP
)
734 } while (!adapter
->diag_cnt
);
736 dev_kfree_skb_any(skb
);
738 if (!adapter
->diag_cnt
)
739 dev_warn(&adapter
->pdev
->dev
, "LB Test: %dth packet"
740 " not recevied\n", i
+ 1);
745 dev_warn(&adapter
->pdev
->dev
, "LB Test failed\n");
751 static int qlcnic_loopback_test(struct net_device
*netdev
, u8 mode
)
753 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
754 int max_sds_rings
= adapter
->max_sds_rings
;
755 struct qlcnic_host_sds_ring
*sds_ring
;
759 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_MULTI_LOOPBACK
)) {
760 netdev_info(netdev
, "Firmware is not loopback test capable\n");
764 netdev_info(netdev
, "%s loopback test in progress\n",
765 mode
== QLCNIC_ILB_MODE
? "internal" : "external");
766 if (adapter
->op_mode
== QLCNIC_NON_PRIV_FUNC
) {
767 netdev_warn(netdev
, "Loopback test not supported for non "
768 "privilege function\n");
772 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
775 ret
= qlcnic_diag_alloc_res(netdev
, QLCNIC_LOOPBACK_TEST
);
779 sds_ring
= &adapter
->recv_ctx
->sds_rings
[0];
781 ret
= qlcnic_set_lb_mode(adapter
, mode
);
785 adapter
->diag_cnt
= 0;
788 qlcnic_process_rcv_ring_diag(sds_ring
);
789 if (loop
++ > QLCNIC_ILB_MAX_RCV_LOOP
) {
790 netdev_info(netdev
, "firmware didnt respond to loopback"
791 " configure request\n");
792 ret
= -QLCNIC_FW_NOT_RESPOND
;
794 } else if (adapter
->diag_cnt
) {
795 ret
= adapter
->diag_cnt
;
798 } while (!QLCNIC_IS_LB_CONFIGURED(adapter
->ahw
->loopback_state
));
800 ret
= qlcnic_do_lb_test(adapter
);
802 qlcnic_clear_lb_mode(adapter
);
805 qlcnic_diag_free_res(netdev
, max_sds_rings
);
808 adapter
->max_sds_rings
= max_sds_rings
;
809 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
814 qlcnic_diag_test(struct net_device
*dev
, struct ethtool_test
*eth_test
,
817 memset(data
, 0, sizeof(u64
) * QLCNIC_TEST_LEN
);
819 data
[0] = qlcnic_reg_test(dev
);
821 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
823 data
[1] = (u64
) qlcnic_test_link(dev
);
825 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
827 if (eth_test
->flags
& ETH_TEST_FL_OFFLINE
) {
828 data
[2] = qlcnic_irq_test(dev
);
830 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
832 data
[3] = qlcnic_loopback_test(dev
, QLCNIC_ILB_MODE
);
834 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
836 if (eth_test
->flags
& ETH_TEST_FL_EXTERNAL_LB
) {
837 data
[4] = qlcnic_loopback_test(dev
, QLCNIC_ELB_MODE
);
839 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
840 eth_test
->flags
|= ETH_TEST_FL_EXTERNAL_LB_DONE
;
846 qlcnic_get_strings(struct net_device
*dev
, u32 stringset
, u8
* data
)
848 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
853 memcpy(data
, *qlcnic_gstrings_test
,
854 QLCNIC_TEST_LEN
* ETH_GSTRING_LEN
);
857 for (index
= 0; index
< QLCNIC_STATS_LEN
; index
++) {
858 memcpy(data
+ index
* ETH_GSTRING_LEN
,
859 qlcnic_gstrings_stats
[index
].stat_string
,
862 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
864 for (i
= 0; i
< QLCNIC_DEVICE_STATS_LEN
; index
++, i
++) {
865 memcpy(data
+ index
* ETH_GSTRING_LEN
,
866 qlcnic_device_gstrings_stats
[i
],
872 #define QLCNIC_FILL_ESWITCH_STATS(VAL1) \
873 (((VAL1) == QLCNIC_ESW_STATS_NOT_AVAIL) ? 0 : VAL1)
876 qlcnic_fill_device_stats(int *index
, u64
*data
,
877 struct __qlcnic_esw_statistics
*stats
)
881 data
[ind
++] = QLCNIC_FILL_ESWITCH_STATS(stats
->unicast_frames
);
882 data
[ind
++] = QLCNIC_FILL_ESWITCH_STATS(stats
->multicast_frames
);
883 data
[ind
++] = QLCNIC_FILL_ESWITCH_STATS(stats
->broadcast_frames
);
884 data
[ind
++] = QLCNIC_FILL_ESWITCH_STATS(stats
->dropped_frames
);
885 data
[ind
++] = QLCNIC_FILL_ESWITCH_STATS(stats
->errors
);
886 data
[ind
++] = QLCNIC_FILL_ESWITCH_STATS(stats
->local_frames
);
887 data
[ind
++] = QLCNIC_FILL_ESWITCH_STATS(stats
->numbytes
);
893 qlcnic_get_ethtool_stats(struct net_device
*dev
,
894 struct ethtool_stats
*stats
, u64
* data
)
896 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
897 struct qlcnic_esw_statistics port_stats
;
900 for (index
= 0; index
< QLCNIC_STATS_LEN
; index
++) {
903 qlcnic_gstrings_stats
[index
].stat_offset
;
905 (qlcnic_gstrings_stats
[index
].sizeof_stat
==
906 sizeof(u64
)) ? *(u64
*)p
:(*(u32
*)p
);
909 if (!(adapter
->flags
& QLCNIC_ESWITCH_ENABLED
))
912 memset(&port_stats
, 0, sizeof(struct qlcnic_esw_statistics
));
913 ret
= qlcnic_get_port_stats(adapter
, adapter
->ahw
->pci_func
,
914 QLCNIC_QUERY_RX_COUNTER
, &port_stats
.rx
);
918 qlcnic_fill_device_stats(&index
, data
, &port_stats
.rx
);
920 ret
= qlcnic_get_port_stats(adapter
, adapter
->ahw
->pci_func
,
921 QLCNIC_QUERY_TX_COUNTER
, &port_stats
.tx
);
925 qlcnic_fill_device_stats(&index
, data
, &port_stats
.tx
);
928 static int qlcnic_set_led(struct net_device
*dev
,
929 enum ethtool_phys_id_state state
)
931 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
932 int max_sds_rings
= adapter
->max_sds_rings
;
935 case ETHTOOL_ID_ACTIVE
:
936 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
)) {
937 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
940 if (qlcnic_diag_alloc_res(dev
, QLCNIC_LED_TEST
)) {
941 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
944 set_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
);
947 if (adapter
->nic_ops
->config_led(adapter
, 1, 0xf) == 0)
950 dev_err(&adapter
->pdev
->dev
,
951 "Failed to set LED blink state.\n");
954 case ETHTOOL_ID_INACTIVE
:
955 if (adapter
->nic_ops
->config_led(adapter
, 0, 0xf))
956 dev_err(&adapter
->pdev
->dev
,
957 "Failed to reset LED blink state.\n");
965 if (test_and_clear_bit(__QLCNIC_DIAG_RES_ALLOC
, &adapter
->state
)) {
966 qlcnic_diag_free_res(dev
, max_sds_rings
);
967 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
974 qlcnic_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
976 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
982 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG_NV
);
983 if (wol_cfg
& (1UL << adapter
->portnum
))
984 wol
->supported
|= WAKE_MAGIC
;
986 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG
);
987 if (wol_cfg
& (1UL << adapter
->portnum
))
988 wol
->wolopts
|= WAKE_MAGIC
;
992 qlcnic_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
994 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
997 if (wol
->wolopts
& ~WAKE_MAGIC
)
1000 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG_NV
);
1001 if (!(wol_cfg
& (1 << adapter
->portnum
)))
1004 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG
);
1005 if (wol
->wolopts
& WAKE_MAGIC
)
1006 wol_cfg
|= 1UL << adapter
->portnum
;
1008 wol_cfg
&= ~(1UL << adapter
->portnum
);
1010 QLCWR32(adapter
, QLCNIC_WOL_CONFIG
, wol_cfg
);
1016 * Set the coalescing parameters. Currently only normal is supported.
1017 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
1018 * firmware coalescing to default.
1020 static int qlcnic_set_intr_coalesce(struct net_device
*netdev
,
1021 struct ethtool_coalesce
*ethcoal
)
1023 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1025 if (!test_bit(__QLCNIC_DEV_UP
, &adapter
->state
))
1029 * Return Error if unsupported values or
1030 * unsupported parameters are set.
1032 if (ethcoal
->rx_coalesce_usecs
> 0xffff ||
1033 ethcoal
->rx_max_coalesced_frames
> 0xffff ||
1034 ethcoal
->tx_coalesce_usecs
||
1035 ethcoal
->tx_max_coalesced_frames
||
1036 ethcoal
->rx_coalesce_usecs_irq
||
1037 ethcoal
->rx_max_coalesced_frames_irq
||
1038 ethcoal
->tx_coalesce_usecs_irq
||
1039 ethcoal
->tx_max_coalesced_frames_irq
||
1040 ethcoal
->stats_block_coalesce_usecs
||
1041 ethcoal
->use_adaptive_rx_coalesce
||
1042 ethcoal
->use_adaptive_tx_coalesce
||
1043 ethcoal
->pkt_rate_low
||
1044 ethcoal
->rx_coalesce_usecs_low
||
1045 ethcoal
->rx_max_coalesced_frames_low
||
1046 ethcoal
->tx_coalesce_usecs_low
||
1047 ethcoal
->tx_max_coalesced_frames_low
||
1048 ethcoal
->pkt_rate_high
||
1049 ethcoal
->rx_coalesce_usecs_high
||
1050 ethcoal
->rx_max_coalesced_frames_high
||
1051 ethcoal
->tx_coalesce_usecs_high
||
1052 ethcoal
->tx_max_coalesced_frames_high
)
1055 if (!ethcoal
->rx_coalesce_usecs
||
1056 !ethcoal
->rx_max_coalesced_frames
) {
1057 adapter
->ahw
->coal
.flag
= QLCNIC_INTR_DEFAULT
;
1058 adapter
->ahw
->coal
.rx_time_us
=
1059 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
1060 adapter
->ahw
->coal
.rx_packets
=
1061 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
1063 adapter
->ahw
->coal
.flag
= 0;
1064 adapter
->ahw
->coal
.rx_time_us
= ethcoal
->rx_coalesce_usecs
;
1065 adapter
->ahw
->coal
.rx_packets
=
1066 ethcoal
->rx_max_coalesced_frames
;
1069 qlcnic_config_intr_coalesce(adapter
);
1074 static int qlcnic_get_intr_coalesce(struct net_device
*netdev
,
1075 struct ethtool_coalesce
*ethcoal
)
1077 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1079 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
1082 ethcoal
->rx_coalesce_usecs
= adapter
->ahw
->coal
.rx_time_us
;
1083 ethcoal
->rx_max_coalesced_frames
= adapter
->ahw
->coal
.rx_packets
;
1088 static u32
qlcnic_get_msglevel(struct net_device
*netdev
)
1090 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1092 return adapter
->msg_enable
;
1095 static void qlcnic_set_msglevel(struct net_device
*netdev
, u32 msglvl
)
1097 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1099 adapter
->msg_enable
= msglvl
;
1103 qlcnic_get_dump_flag(struct net_device
*netdev
, struct ethtool_dump
*dump
)
1105 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1106 struct qlcnic_fw_dump
*fw_dump
= &adapter
->ahw
->fw_dump
;
1108 dump
->len
= fw_dump
->tmpl_hdr
->size
+ fw_dump
->size
;
1109 dump
->flag
= fw_dump
->tmpl_hdr
->drv_cap_mask
;
1110 dump
->version
= adapter
->fw_version
;
1115 qlcnic_get_dump_data(struct net_device
*netdev
, struct ethtool_dump
*dump
,
1119 u32
*hdr_ptr
, *data
;
1120 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1121 struct qlcnic_fw_dump
*fw_dump
= &adapter
->ahw
->fw_dump
;
1123 if (!fw_dump
->clr
) {
1124 netdev_info(netdev
, "Dump not available\n");
1125 qlcnic_api_unlock(adapter
);
1128 /* Copy template header first */
1129 copy_sz
= fw_dump
->tmpl_hdr
->size
;
1130 hdr_ptr
= (u32
*) fw_dump
->tmpl_hdr
;
1132 for (i
= 0; i
< copy_sz
/sizeof(u32
); i
++)
1133 *data
++ = cpu_to_le32(*hdr_ptr
++);
1135 /* Copy captured dump data */
1136 memcpy(buffer
+ copy_sz
, fw_dump
->data
, fw_dump
->size
);
1137 dump
->len
= copy_sz
+ fw_dump
->size
;
1138 dump
->flag
= fw_dump
->tmpl_hdr
->drv_cap_mask
;
1140 /* Free dump area once data has been captured */
1141 vfree(fw_dump
->data
);
1142 fw_dump
->data
= NULL
;
1149 qlcnic_set_dump(struct net_device
*netdev
, struct ethtool_dump
*val
)
1152 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1153 struct qlcnic_fw_dump
*fw_dump
= &adapter
->ahw
->fw_dump
;
1155 if (val
->flag
== QLCNIC_FORCE_FW_DUMP_KEY
) {
1156 if (!fw_dump
->enable
) {
1157 netdev_info(netdev
, "FW dump not enabled\n");
1161 dev_info(&adapter
->pdev
->dev
,
1162 "Previous dump not cleared, not forcing dump\n");
1165 netdev_info(netdev
, "Forcing a FW dump\n");
1166 qlcnic_dev_request_reset(adapter
);
1167 } else if (val
->flag
== QLCNIC_DISABLE_FW_DUMP
) {
1168 if (fw_dump
->enable
) {
1169 netdev_info(netdev
, "Disabling FW dump\n");
1170 fw_dump
->enable
= 0;
1172 } else if (val
->flag
== QLCNIC_ENABLE_FW_DUMP
) {
1173 if (!fw_dump
->enable
&& fw_dump
->tmpl_hdr
) {
1174 netdev_info(netdev
, "Enabling FW dump\n");
1175 fw_dump
->enable
= 1;
1178 if (val
->flag
> QLCNIC_DUMP_MASK_MAX
||
1179 val
->flag
< QLCNIC_DUMP_MASK_MIN
) {
1181 "Invalid dump level: 0x%x\n", val
->flag
);
1185 fw_dump
->tmpl_hdr
->drv_cap_mask
= val
->flag
& 0xff;
1186 netdev_info(netdev
, "Driver mask changed to: 0x%x\n",
1187 fw_dump
->tmpl_hdr
->drv_cap_mask
);
1193 const struct ethtool_ops qlcnic_ethtool_ops
= {
1194 .get_settings
= qlcnic_get_settings
,
1195 .set_settings
= qlcnic_set_settings
,
1196 .get_drvinfo
= qlcnic_get_drvinfo
,
1197 .get_regs_len
= qlcnic_get_regs_len
,
1198 .get_regs
= qlcnic_get_regs
,
1199 .get_link
= ethtool_op_get_link
,
1200 .get_eeprom_len
= qlcnic_get_eeprom_len
,
1201 .get_eeprom
= qlcnic_get_eeprom
,
1202 .get_ringparam
= qlcnic_get_ringparam
,
1203 .set_ringparam
= qlcnic_set_ringparam
,
1204 .get_channels
= qlcnic_get_channels
,
1205 .set_channels
= qlcnic_set_channels
,
1206 .get_pauseparam
= qlcnic_get_pauseparam
,
1207 .set_pauseparam
= qlcnic_set_pauseparam
,
1208 .get_wol
= qlcnic_get_wol
,
1209 .set_wol
= qlcnic_set_wol
,
1210 .self_test
= qlcnic_diag_test
,
1211 .get_strings
= qlcnic_get_strings
,
1212 .get_ethtool_stats
= qlcnic_get_ethtool_stats
,
1213 .get_sset_count
= qlcnic_get_sset_count
,
1214 .get_coalesce
= qlcnic_get_intr_coalesce
,
1215 .set_coalesce
= qlcnic_set_intr_coalesce
,
1216 .set_phys_id
= qlcnic_set_led
,
1217 .set_msglevel
= qlcnic_set_msglevel
,
1218 .get_msglevel
= qlcnic_get_msglevel
,
1219 .get_dump_flag
= qlcnic_get_dump_flag
,
1220 .get_dump_data
= qlcnic_get_dump_data
,
1221 .set_dump
= qlcnic_set_dump
,