2 * Copyright (C) 2009 - QLogic Corporation.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * The full GNU General Public License is included in this distribution
21 * in the file called "COPYING".
25 #include <linux/types.h>
26 #include <linux/delay.h>
27 #include <linux/pci.h>
29 #include <linux/netdevice.h>
30 #include <linux/ethtool.h>
35 char stat_string
[ETH_GSTRING_LEN
];
40 #define QLC_SIZEOF(m) FIELD_SIZEOF(struct qlcnic_adapter, m)
41 #define QLC_OFF(m) offsetof(struct qlcnic_adapter, m)
43 static const struct qlcnic_stats qlcnic_gstrings_stats
[] = {
45 QLC_SIZEOF(stats
.xmitcalled
), QLC_OFF(stats
.xmitcalled
)},
47 QLC_SIZEOF(stats
.xmitfinished
), QLC_OFF(stats
.xmitfinished
)},
49 QLC_SIZEOF(stats
.rxdropped
), QLC_OFF(stats
.rxdropped
)},
51 QLC_SIZEOF(stats
.txdropped
), QLC_OFF(stats
.txdropped
)},
53 QLC_SIZEOF(stats
.csummed
), QLC_OFF(stats
.csummed
)},
55 QLC_SIZEOF(stats
.rx_pkts
), QLC_OFF(stats
.rx_pkts
)},
57 QLC_SIZEOF(stats
.lro_pkts
), QLC_OFF(stats
.lro_pkts
)},
59 QLC_SIZEOF(stats
.rxbytes
), QLC_OFF(stats
.rxbytes
)},
61 QLC_SIZEOF(stats
.txbytes
), QLC_OFF(stats
.txbytes
)},
63 QLC_SIZEOF(stats
.lrobytes
), QLC_OFF(stats
.lrobytes
)},
65 QLC_SIZEOF(stats
.lso_frames
), QLC_OFF(stats
.lso_frames
)},
67 QLC_SIZEOF(stats
.xmit_on
), QLC_OFF(stats
.xmit_on
)},
69 QLC_SIZEOF(stats
.xmit_off
), QLC_OFF(stats
.xmit_off
)},
70 {"skb_alloc_failure", QLC_SIZEOF(stats
.skb_alloc_failure
),
71 QLC_OFF(stats
.skb_alloc_failure
)},
73 QLC_SIZEOF(stats
.null_skb
), QLC_OFF(stats
.null_skb
)},
75 QLC_SIZEOF(stats
.null_rxbuf
), QLC_OFF(stats
.null_rxbuf
)},
76 {"rx dma map error", QLC_SIZEOF(stats
.rx_dma_map_error
),
77 QLC_OFF(stats
.rx_dma_map_error
)},
78 {"tx dma map error", QLC_SIZEOF(stats
.tx_dma_map_error
),
79 QLC_OFF(stats
.tx_dma_map_error
)},
83 #define QLCNIC_STATS_LEN ARRAY_SIZE(qlcnic_gstrings_stats)
85 static const char qlcnic_gstrings_test
[][ETH_GSTRING_LEN
] = {
86 "Register_Test_on_offline",
87 "Link_Test_on_offline",
88 "Interrupt_Test_offline",
89 "Loopback_Test_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_DEV_REF_COUNT
,
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 static int qlcnic_get_regs_len(struct net_device
*dev
)
122 return sizeof(diag_registers
) + QLCNIC_RING_REGS_LEN
;
125 static int qlcnic_get_eeprom_len(struct net_device
*dev
)
127 return QLCNIC_FLASH_TOTAL_SIZE
;
131 qlcnic_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*drvinfo
)
133 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
134 u32 fw_major
, fw_minor
, fw_build
;
136 fw_major
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MAJOR
);
137 fw_minor
= QLCRD32(adapter
, QLCNIC_FW_VERSION_MINOR
);
138 fw_build
= QLCRD32(adapter
, QLCNIC_FW_VERSION_SUB
);
139 sprintf(drvinfo
->fw_version
, "%d.%d.%d", fw_major
, fw_minor
, fw_build
);
141 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
142 strlcpy(drvinfo
->driver
, qlcnic_driver_name
, 32);
143 strlcpy(drvinfo
->version
, QLCNIC_LINUX_VERSIONID
, 32);
147 qlcnic_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
149 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
150 int check_sfp_module
= 0;
151 u16 pcifn
= adapter
->ahw
.pci_func
;
153 /* read which mode */
154 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
155 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
156 SUPPORTED_10baseT_Full
|
157 SUPPORTED_100baseT_Half
|
158 SUPPORTED_100baseT_Full
|
159 SUPPORTED_1000baseT_Half
|
160 SUPPORTED_1000baseT_Full
);
162 ecmd
->advertising
= (ADVERTISED_100baseT_Half
|
163 ADVERTISED_100baseT_Full
|
164 ADVERTISED_1000baseT_Half
|
165 ADVERTISED_1000baseT_Full
);
167 ecmd
->speed
= adapter
->link_speed
;
168 ecmd
->duplex
= adapter
->link_duplex
;
169 ecmd
->autoneg
= adapter
->link_autoneg
;
171 } else if (adapter
->ahw
.port_type
== QLCNIC_XGBE
) {
174 val
= QLCRD32(adapter
, QLCNIC_PORT_MODE_ADDR
);
175 if (val
== QLCNIC_PORT_MODE_802_3_AP
) {
176 ecmd
->supported
= SUPPORTED_1000baseT_Full
;
177 ecmd
->advertising
= ADVERTISED_1000baseT_Full
;
179 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
180 ecmd
->advertising
= ADVERTISED_10000baseT_Full
;
183 if (netif_running(dev
) && adapter
->has_link_events
) {
184 ecmd
->speed
= adapter
->link_speed
;
185 ecmd
->autoneg
= adapter
->link_autoneg
;
186 ecmd
->duplex
= adapter
->link_duplex
;
190 val
= QLCRD32(adapter
, P3_LINK_SPEED_REG(pcifn
));
191 ecmd
->speed
= P3_LINK_SPEED_MHZ
*
192 P3_LINK_SPEED_VAL(pcifn
, val
);
193 ecmd
->duplex
= DUPLEX_FULL
;
194 ecmd
->autoneg
= AUTONEG_DISABLE
;
199 ecmd
->phy_address
= adapter
->physical_port
;
200 ecmd
->transceiver
= XCVR_EXTERNAL
;
202 switch (adapter
->ahw
.board_type
) {
203 case QLCNIC_BRDTYPE_P3_REF_QG
:
204 case QLCNIC_BRDTYPE_P3_4_GB
:
205 case QLCNIC_BRDTYPE_P3_4_GB_MM
:
207 ecmd
->supported
|= SUPPORTED_Autoneg
;
208 ecmd
->advertising
|= ADVERTISED_Autoneg
;
209 case QLCNIC_BRDTYPE_P3_10G_CX4
:
210 case QLCNIC_BRDTYPE_P3_10G_CX4_LP
:
211 case QLCNIC_BRDTYPE_P3_10000_BASE_T
:
212 ecmd
->supported
|= SUPPORTED_TP
;
213 ecmd
->advertising
|= ADVERTISED_TP
;
214 ecmd
->port
= PORT_TP
;
215 ecmd
->autoneg
= adapter
->link_autoneg
;
217 case QLCNIC_BRDTYPE_P3_IMEZ
:
218 case QLCNIC_BRDTYPE_P3_XG_LOM
:
219 case QLCNIC_BRDTYPE_P3_HMEZ
:
220 ecmd
->supported
|= SUPPORTED_MII
;
221 ecmd
->advertising
|= ADVERTISED_MII
;
222 ecmd
->port
= PORT_MII
;
223 ecmd
->autoneg
= AUTONEG_DISABLE
;
225 case QLCNIC_BRDTYPE_P3_10G_SFP_PLUS
:
226 case QLCNIC_BRDTYPE_P3_10G_SFP_CT
:
227 case QLCNIC_BRDTYPE_P3_10G_SFP_QT
:
228 ecmd
->advertising
|= ADVERTISED_TP
;
229 ecmd
->supported
|= SUPPORTED_TP
;
230 check_sfp_module
= netif_running(dev
) &&
231 adapter
->has_link_events
;
232 case QLCNIC_BRDTYPE_P3_10G_XFP
:
233 ecmd
->supported
|= SUPPORTED_FIBRE
;
234 ecmd
->advertising
|= ADVERTISED_FIBRE
;
235 ecmd
->port
= PORT_FIBRE
;
236 ecmd
->autoneg
= AUTONEG_DISABLE
;
238 case QLCNIC_BRDTYPE_P3_10G_TP
:
239 if (adapter
->ahw
.port_type
== QLCNIC_XGBE
) {
240 ecmd
->autoneg
= AUTONEG_DISABLE
;
241 ecmd
->supported
|= (SUPPORTED_FIBRE
| SUPPORTED_TP
);
243 (ADVERTISED_FIBRE
| ADVERTISED_TP
);
244 ecmd
->port
= PORT_FIBRE
;
245 check_sfp_module
= netif_running(dev
) &&
246 adapter
->has_link_events
;
248 ecmd
->autoneg
= AUTONEG_ENABLE
;
249 ecmd
->supported
|= (SUPPORTED_TP
| SUPPORTED_Autoneg
);
251 (ADVERTISED_TP
| ADVERTISED_Autoneg
);
252 ecmd
->port
= PORT_TP
;
256 dev_err(&adapter
->pdev
->dev
, "Unsupported board model %d\n",
257 adapter
->ahw
.board_type
);
261 if (check_sfp_module
) {
262 switch (adapter
->module_type
) {
263 case LINKEVENT_MODULE_OPTICAL_UNKNOWN
:
264 case LINKEVENT_MODULE_OPTICAL_SRLR
:
265 case LINKEVENT_MODULE_OPTICAL_LRM
:
266 case LINKEVENT_MODULE_OPTICAL_SFP_1G
:
267 ecmd
->port
= PORT_FIBRE
;
269 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
:
270 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
:
271 case LINKEVENT_MODULE_TWINAX
:
272 ecmd
->port
= PORT_TP
;
275 ecmd
->port
= PORT_OTHER
;
283 qlcnic_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
285 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
288 /* read which mode */
289 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
290 /* autonegotiation */
291 if (qlcnic_fw_cmd_set_phy(adapter
,
292 QLCNIC_NIU_GB_MII_MGMT_ADDR_AUTONEG
,
296 adapter
->link_autoneg
= ecmd
->autoneg
;
298 if (qlcnic_fw_cmd_query_phy(adapter
,
299 QLCNIC_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
303 switch (ecmd
->speed
) {
305 qlcnic_set_phy_speed(status
, 0);
308 qlcnic_set_phy_speed(status
, 1);
311 qlcnic_set_phy_speed(status
, 2);
315 if (ecmd
->duplex
== DUPLEX_HALF
)
316 qlcnic_clear_phy_duplex(status
);
317 if (ecmd
->duplex
== DUPLEX_FULL
)
318 qlcnic_set_phy_duplex(status
);
319 if (qlcnic_fw_cmd_set_phy(adapter
,
320 QLCNIC_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
321 *((int *)&status
)) != 0)
324 adapter
->link_speed
= ecmd
->speed
;
325 adapter
->link_duplex
= ecmd
->duplex
;
330 if (!netif_running(dev
))
333 dev
->netdev_ops
->ndo_stop(dev
);
334 return dev
->netdev_ops
->ndo_open(dev
);
338 qlcnic_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *p
)
340 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
341 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
342 struct qlcnic_host_sds_ring
*sds_ring
;
346 memset(p
, 0, qlcnic_get_regs_len(dev
));
347 regs
->version
= (1 << 24) | (adapter
->ahw
.revision_id
<< 16) |
348 (adapter
->pdev
)->device
;
350 for (i
= 0; diag_registers
[i
] != -1; i
++)
351 regs_buff
[i
] = QLCRD32(adapter
, diag_registers
[i
]);
353 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
356 regs_buff
[i
++] = 0xFFEFCDAB; /* Marker btw regs and ring count*/
358 regs_buff
[i
++] = 1; /* No. of tx ring */
359 regs_buff
[i
++] = le32_to_cpu(*(adapter
->tx_ring
->hw_consumer
));
360 regs_buff
[i
++] = readl(adapter
->tx_ring
->crb_cmd_producer
);
362 regs_buff
[i
++] = 2; /* No. of rx ring */
363 regs_buff
[i
++] = readl(recv_ctx
->rds_rings
[0].crb_rcv_producer
);
364 regs_buff
[i
++] = readl(recv_ctx
->rds_rings
[1].crb_rcv_producer
);
366 regs_buff
[i
++] = adapter
->max_sds_rings
;
368 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
369 sds_ring
= &(recv_ctx
->sds_rings
[ring
]);
370 regs_buff
[i
++] = readl(sds_ring
->crb_sts_consumer
);
374 static u32
qlcnic_test_link(struct net_device
*dev
)
376 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
379 val
= QLCRD32(adapter
, CRB_XG_STATE_P3
);
380 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
381 return (val
== XG_LINK_UP_P3
) ? 0 : 1;
385 qlcnic_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
388 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
392 if (eeprom
->len
== 0)
395 eeprom
->magic
= (adapter
->pdev
)->vendor
|
396 ((adapter
->pdev
)->device
<< 16);
397 offset
= eeprom
->offset
;
399 ret
= qlcnic_rom_fast_read_words(adapter
, offset
, bytes
,
408 qlcnic_get_ringparam(struct net_device
*dev
,
409 struct ethtool_ringparam
*ring
)
411 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
413 ring
->rx_pending
= adapter
->num_rxd
;
414 ring
->rx_jumbo_pending
= adapter
->num_jumbo_rxd
;
415 ring
->rx_jumbo_pending
+= adapter
->num_lro_rxd
;
416 ring
->tx_pending
= adapter
->num_txd
;
418 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
419 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_1G
;
420 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
422 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_10G
;
423 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
426 ring
->tx_max_pending
= MAX_CMD_DESCRIPTORS
;
428 ring
->rx_mini_max_pending
= 0;
429 ring
->rx_mini_pending
= 0;
433 qlcnic_validate_ringparam(u32 val
, u32 min
, u32 max
, char *r_name
)
436 num_desc
= max(val
, min
);
437 num_desc
= min(num_desc
, max
);
438 num_desc
= roundup_pow_of_two(num_desc
);
440 if (val
!= num_desc
) {
441 printk(KERN_INFO
"%s: setting %s ring size %d instead of %d\n",
442 qlcnic_driver_name
, r_name
, num_desc
, val
);
449 qlcnic_set_ringparam(struct net_device
*dev
,
450 struct ethtool_ringparam
*ring
)
452 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
453 u16 max_rcv_desc
= MAX_RCV_DESCRIPTORS_10G
;
454 u16 max_jumbo_desc
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
455 u16 num_rxd
, num_jumbo_rxd
, num_txd
;
458 if (ring
->rx_mini_pending
)
461 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
462 max_rcv_desc
= MAX_RCV_DESCRIPTORS_1G
;
463 max_jumbo_desc
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
466 num_rxd
= qlcnic_validate_ringparam(ring
->rx_pending
,
467 MIN_RCV_DESCRIPTORS
, max_rcv_desc
, "rx");
469 num_jumbo_rxd
= qlcnic_validate_ringparam(ring
->rx_jumbo_pending
,
470 MIN_JUMBO_DESCRIPTORS
, max_jumbo_desc
, "rx jumbo");
472 num_txd
= qlcnic_validate_ringparam(ring
->tx_pending
,
473 MIN_CMD_DESCRIPTORS
, MAX_CMD_DESCRIPTORS
, "tx");
475 if (num_rxd
== adapter
->num_rxd
&& num_txd
== adapter
->num_txd
&&
476 num_jumbo_rxd
== adapter
->num_jumbo_rxd
)
479 adapter
->num_rxd
= num_rxd
;
480 adapter
->num_jumbo_rxd
= num_jumbo_rxd
;
481 adapter
->num_txd
= num_txd
;
483 return qlcnic_reset_context(adapter
);
487 qlcnic_get_pauseparam(struct net_device
*netdev
,
488 struct ethtool_pauseparam
*pause
)
490 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
491 int port
= adapter
->physical_port
;
494 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
495 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_GBE_PORTS
))
497 /* get flow control settings */
498 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
));
499 pause
->rx_pause
= qlcnic_gb_get_rx_flowctl(val
);
500 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
);
503 pause
->tx_pause
= !(qlcnic_gb_get_gb0_mask(val
));
506 pause
->tx_pause
= !(qlcnic_gb_get_gb1_mask(val
));
509 pause
->tx_pause
= !(qlcnic_gb_get_gb2_mask(val
));
513 pause
->tx_pause
= !(qlcnic_gb_get_gb3_mask(val
));
516 } else if (adapter
->ahw
.port_type
== QLCNIC_XGBE
) {
517 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_XG_PORTS
))
520 val
= QLCRD32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
);
522 pause
->tx_pause
= !(qlcnic_xg_get_xg0_mask(val
));
524 pause
->tx_pause
= !(qlcnic_xg_get_xg1_mask(val
));
526 dev_err(&netdev
->dev
, "Unknown board type: %x\n",
527 adapter
->ahw
.port_type
);
532 qlcnic_set_pauseparam(struct net_device
*netdev
,
533 struct ethtool_pauseparam
*pause
)
535 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
536 int port
= adapter
->physical_port
;
540 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
541 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_GBE_PORTS
))
543 /* set flow control */
544 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
));
547 qlcnic_gb_rx_flowctl(val
);
549 qlcnic_gb_unset_rx_flowctl(val
);
551 QLCWR32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
),
554 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
);
558 qlcnic_gb_unset_gb0_mask(val
);
560 qlcnic_gb_set_gb0_mask(val
);
564 qlcnic_gb_unset_gb1_mask(val
);
566 qlcnic_gb_set_gb1_mask(val
);
570 qlcnic_gb_unset_gb2_mask(val
);
572 qlcnic_gb_set_gb2_mask(val
);
577 qlcnic_gb_unset_gb3_mask(val
);
579 qlcnic_gb_set_gb3_mask(val
);
582 QLCWR32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
, val
);
583 } else if (adapter
->ahw
.port_type
== QLCNIC_XGBE
) {
584 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_XG_PORTS
))
586 val
= QLCRD32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
);
589 qlcnic_xg_unset_xg0_mask(val
);
591 qlcnic_xg_set_xg0_mask(val
);
594 qlcnic_xg_unset_xg1_mask(val
);
596 qlcnic_xg_set_xg1_mask(val
);
598 QLCWR32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
, val
);
600 dev_err(&netdev
->dev
, "Unknown board type: %x\n",
601 adapter
->ahw
.port_type
);
606 static int qlcnic_reg_test(struct net_device
*dev
)
608 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
609 u32 data_read
, data_written
;
611 data_read
= QLCRD32(adapter
, QLCNIC_PCIX_PH_REG(0));
612 if ((data_read
& 0xffff) != adapter
->pdev
->vendor
)
615 data_written
= (u32
)0xa5a5a5a5;
617 QLCWR32(adapter
, CRB_SCRATCHPAD_TEST
, data_written
);
618 data_read
= QLCRD32(adapter
, CRB_SCRATCHPAD_TEST
);
619 if (data_written
!= data_read
)
625 static int qlcnic_get_sset_count(struct net_device
*dev
, int sset
)
629 return QLCNIC_TEST_LEN
;
631 return QLCNIC_STATS_LEN
;
637 #define QLC_ILB_PKT_SIZE 64
639 static void qlcnic_create_loopback_buff(unsigned char *data
)
641 unsigned char random_data
[] = {0xa8, 0x06, 0x45, 0x00};
642 memset(data
, 0x4e, QLC_ILB_PKT_SIZE
);
643 memset(data
, 0xff, 12);
644 memcpy(data
+ 12, random_data
, sizeof(random_data
));
647 int qlcnic_check_loopback_buff(unsigned char *data
)
649 unsigned char buff
[QLC_ILB_PKT_SIZE
];
650 qlcnic_create_loopback_buff(buff
);
651 return memcmp(data
, buff
, QLC_ILB_PKT_SIZE
);
654 static int qlcnic_do_ilb_test(struct qlcnic_adapter
*adapter
)
656 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
657 struct qlcnic_host_sds_ring
*sds_ring
= &recv_ctx
->sds_rings
[0];
661 for (i
= 0; i
< 16; i
++) {
662 skb
= dev_alloc_skb(QLC_ILB_PKT_SIZE
);
663 qlcnic_create_loopback_buff(skb
->data
);
664 skb_put(skb
, QLC_ILB_PKT_SIZE
);
666 adapter
->diag_cnt
= 0;
668 qlcnic_xmit_frame(skb
, adapter
->netdev
);
672 qlcnic_process_rcv_ring_diag(sds_ring
);
674 dev_kfree_skb_any(skb
);
675 if (!adapter
->diag_cnt
)
681 static int qlcnic_loopback_test(struct net_device
*netdev
)
683 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
684 int max_sds_rings
= adapter
->max_sds_rings
;
687 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
690 ret
= qlcnic_diag_alloc_res(netdev
, QLCNIC_LOOPBACK_TEST
);
694 ret
= qlcnic_set_ilb_mode(adapter
);
698 ret
= qlcnic_do_ilb_test(adapter
);
700 qlcnic_clear_ilb_mode(adapter
);
703 qlcnic_diag_free_res(netdev
, max_sds_rings
);
706 adapter
->max_sds_rings
= max_sds_rings
;
707 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
711 static int qlcnic_irq_test(struct net_device
*netdev
)
713 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
714 int max_sds_rings
= adapter
->max_sds_rings
;
717 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
720 ret
= qlcnic_diag_alloc_res(netdev
, QLCNIC_INTERRUPT_TEST
);
724 adapter
->diag_cnt
= 0;
725 ret
= qlcnic_issue_cmd(adapter
, adapter
->ahw
.pci_func
,
726 QLCHAL_VERSION
, adapter
->portnum
, 0, 0, 0x00000011);
732 ret
= !adapter
->diag_cnt
;
735 qlcnic_diag_free_res(netdev
, max_sds_rings
);
738 adapter
->max_sds_rings
= max_sds_rings
;
739 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
744 qlcnic_diag_test(struct net_device
*dev
, struct ethtool_test
*eth_test
,
747 memset(data
, 0, sizeof(u64
) * QLCNIC_TEST_LEN
);
749 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
750 data
[2] = qlcnic_irq_test(dev
);
752 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
754 data
[3] = qlcnic_loopback_test(dev
);
756 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
760 data
[0] = qlcnic_reg_test(dev
);
762 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
765 data
[1] = (u64
) qlcnic_test_link(dev
);
767 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
771 qlcnic_get_strings(struct net_device
*dev
, u32 stringset
, u8
* data
)
777 memcpy(data
, *qlcnic_gstrings_test
,
778 QLCNIC_TEST_LEN
* ETH_GSTRING_LEN
);
781 for (index
= 0; index
< QLCNIC_STATS_LEN
; index
++) {
782 memcpy(data
+ index
* ETH_GSTRING_LEN
,
783 qlcnic_gstrings_stats
[index
].stat_string
,
791 qlcnic_get_ethtool_stats(struct net_device
*dev
,
792 struct ethtool_stats
*stats
, u64
* data
)
794 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
797 for (index
= 0; index
< QLCNIC_STATS_LEN
; index
++) {
800 qlcnic_gstrings_stats
[index
].stat_offset
;
802 (qlcnic_gstrings_stats
[index
].sizeof_stat
==
803 sizeof(u64
)) ? *(u64
*)p
:(*(u32
*)p
);
807 static u32
qlcnic_get_tx_csum(struct net_device
*dev
)
809 return dev
->features
& NETIF_F_IP_CSUM
;
812 static u32
qlcnic_get_rx_csum(struct net_device
*dev
)
814 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
815 return adapter
->rx_csum
;
818 static int qlcnic_set_rx_csum(struct net_device
*dev
, u32 data
)
820 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
821 adapter
->rx_csum
= !!data
;
825 static u32
qlcnic_get_tso(struct net_device
*dev
)
827 return (dev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) != 0;
830 static int qlcnic_set_tso(struct net_device
*dev
, u32 data
)
833 dev
->features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
835 dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_TSO6
);
840 static int qlcnic_blink_led(struct net_device
*dev
, u32 val
)
842 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
845 ret
= qlcnic_config_led(adapter
, 1, 0xf);
847 dev_err(&adapter
->pdev
->dev
,
848 "Failed to set LED blink state.\n");
852 msleep_interruptible(val
* 1000);
854 ret
= qlcnic_config_led(adapter
, 0, 0xf);
856 dev_err(&adapter
->pdev
->dev
,
857 "Failed to reset LED blink state.\n");
865 qlcnic_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
867 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
873 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG_NV
);
874 if (wol_cfg
& (1UL << adapter
->portnum
))
875 wol
->supported
|= WAKE_MAGIC
;
877 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG
);
878 if (wol_cfg
& (1UL << adapter
->portnum
))
879 wol
->wolopts
|= WAKE_MAGIC
;
883 qlcnic_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
885 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
888 if (wol
->wolopts
& ~WAKE_MAGIC
)
891 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG_NV
);
892 if (!(wol_cfg
& (1 << adapter
->portnum
)))
895 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG
);
896 if (wol
->wolopts
& WAKE_MAGIC
)
897 wol_cfg
|= 1UL << adapter
->portnum
;
899 wol_cfg
&= ~(1UL << adapter
->portnum
);
901 QLCWR32(adapter
, QLCNIC_WOL_CONFIG
, wol_cfg
);
907 * Set the coalescing parameters. Currently only normal is supported.
908 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
909 * firmware coalescing to default.
911 static int qlcnic_set_intr_coalesce(struct net_device
*netdev
,
912 struct ethtool_coalesce
*ethcoal
)
914 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
916 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
920 * Return Error if unsupported values or
921 * unsupported parameters are set.
923 if (ethcoal
->rx_coalesce_usecs
> 0xffff ||
924 ethcoal
->rx_max_coalesced_frames
> 0xffff ||
925 ethcoal
->tx_coalesce_usecs
> 0xffff ||
926 ethcoal
->tx_max_coalesced_frames
> 0xffff ||
927 ethcoal
->rx_coalesce_usecs_irq
||
928 ethcoal
->rx_max_coalesced_frames_irq
||
929 ethcoal
->tx_coalesce_usecs_irq
||
930 ethcoal
->tx_max_coalesced_frames_irq
||
931 ethcoal
->stats_block_coalesce_usecs
||
932 ethcoal
->use_adaptive_rx_coalesce
||
933 ethcoal
->use_adaptive_tx_coalesce
||
934 ethcoal
->pkt_rate_low
||
935 ethcoal
->rx_coalesce_usecs_low
||
936 ethcoal
->rx_max_coalesced_frames_low
||
937 ethcoal
->tx_coalesce_usecs_low
||
938 ethcoal
->tx_max_coalesced_frames_low
||
939 ethcoal
->pkt_rate_high
||
940 ethcoal
->rx_coalesce_usecs_high
||
941 ethcoal
->rx_max_coalesced_frames_high
||
942 ethcoal
->tx_coalesce_usecs_high
||
943 ethcoal
->tx_max_coalesced_frames_high
)
946 if (!ethcoal
->rx_coalesce_usecs
||
947 !ethcoal
->rx_max_coalesced_frames
) {
948 adapter
->coal
.flags
= QLCNIC_INTR_DEFAULT
;
949 adapter
->coal
.normal
.data
.rx_time_us
=
950 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
951 adapter
->coal
.normal
.data
.rx_packets
=
952 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
954 adapter
->coal
.flags
= 0;
955 adapter
->coal
.normal
.data
.rx_time_us
=
956 ethcoal
->rx_coalesce_usecs
;
957 adapter
->coal
.normal
.data
.rx_packets
=
958 ethcoal
->rx_max_coalesced_frames
;
960 adapter
->coal
.normal
.data
.tx_time_us
= ethcoal
->tx_coalesce_usecs
;
961 adapter
->coal
.normal
.data
.tx_packets
=
962 ethcoal
->tx_max_coalesced_frames
;
964 qlcnic_config_intr_coalesce(adapter
);
969 static int qlcnic_get_intr_coalesce(struct net_device
*netdev
,
970 struct ethtool_coalesce
*ethcoal
)
972 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
974 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
977 ethcoal
->rx_coalesce_usecs
= adapter
->coal
.normal
.data
.rx_time_us
;
978 ethcoal
->tx_coalesce_usecs
= adapter
->coal
.normal
.data
.tx_time_us
;
979 ethcoal
->rx_max_coalesced_frames
=
980 adapter
->coal
.normal
.data
.rx_packets
;
981 ethcoal
->tx_max_coalesced_frames
=
982 adapter
->coal
.normal
.data
.tx_packets
;
987 static int qlcnic_set_flags(struct net_device
*netdev
, u32 data
)
989 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
992 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
))
995 ethtool_op_set_flags(netdev
, data
);
997 hw_lro
= (data
& ETH_FLAG_LRO
) ? QLCNIC_LRO_ENABLED
: 0;
999 if (qlcnic_config_hw_lro(adapter
, hw_lro
))
1002 if ((hw_lro
== 0) && qlcnic_send_lro_cleanup(adapter
))
1009 static u32
qlcnic_get_msglevel(struct net_device
*netdev
)
1011 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1013 return adapter
->msg_enable
;
1016 static void qlcnic_set_msglevel(struct net_device
*netdev
, u32 msglvl
)
1018 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1020 adapter
->msg_enable
= msglvl
;
1023 const struct ethtool_ops qlcnic_ethtool_ops
= {
1024 .get_settings
= qlcnic_get_settings
,
1025 .set_settings
= qlcnic_set_settings
,
1026 .get_drvinfo
= qlcnic_get_drvinfo
,
1027 .get_regs_len
= qlcnic_get_regs_len
,
1028 .get_regs
= qlcnic_get_regs
,
1029 .get_link
= ethtool_op_get_link
,
1030 .get_eeprom_len
= qlcnic_get_eeprom_len
,
1031 .get_eeprom
= qlcnic_get_eeprom
,
1032 .get_ringparam
= qlcnic_get_ringparam
,
1033 .set_ringparam
= qlcnic_set_ringparam
,
1034 .get_pauseparam
= qlcnic_get_pauseparam
,
1035 .set_pauseparam
= qlcnic_set_pauseparam
,
1036 .get_tx_csum
= qlcnic_get_tx_csum
,
1037 .set_tx_csum
= ethtool_op_set_tx_csum
,
1038 .set_sg
= ethtool_op_set_sg
,
1039 .get_tso
= qlcnic_get_tso
,
1040 .set_tso
= qlcnic_set_tso
,
1041 .get_wol
= qlcnic_get_wol
,
1042 .set_wol
= qlcnic_set_wol
,
1043 .self_test
= qlcnic_diag_test
,
1044 .get_strings
= qlcnic_get_strings
,
1045 .get_ethtool_stats
= qlcnic_get_ethtool_stats
,
1046 .get_sset_count
= qlcnic_get_sset_count
,
1047 .get_rx_csum
= qlcnic_get_rx_csum
,
1048 .set_rx_csum
= qlcnic_set_rx_csum
,
1049 .get_coalesce
= qlcnic_get_intr_coalesce
,
1050 .set_coalesce
= qlcnic_set_intr_coalesce
,
1051 .get_flags
= ethtool_op_get_flags
,
1052 .set_flags
= qlcnic_set_flags
,
1053 .phys_id
= qlcnic_blink_led
,
1054 .set_msglevel
= qlcnic_set_msglevel
,
1055 .get_msglevel
= qlcnic_get_msglevel
,