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
->tx_pending
= adapter
->num_txd
;
417 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
418 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_1G
;
419 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
421 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_10G
;
422 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
425 ring
->tx_max_pending
= MAX_CMD_DESCRIPTORS
;
427 ring
->rx_mini_max_pending
= 0;
428 ring
->rx_mini_pending
= 0;
432 qlcnic_validate_ringparam(u32 val
, u32 min
, u32 max
, char *r_name
)
435 num_desc
= max(val
, min
);
436 num_desc
= min(num_desc
, max
);
437 num_desc
= roundup_pow_of_two(num_desc
);
439 if (val
!= num_desc
) {
440 printk(KERN_INFO
"%s: setting %s ring size %d instead of %d\n",
441 qlcnic_driver_name
, r_name
, num_desc
, val
);
448 qlcnic_set_ringparam(struct net_device
*dev
,
449 struct ethtool_ringparam
*ring
)
451 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
452 u16 max_rcv_desc
= MAX_RCV_DESCRIPTORS_10G
;
453 u16 max_jumbo_desc
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
454 u16 num_rxd
, num_jumbo_rxd
, num_txd
;
457 if (ring
->rx_mini_pending
)
460 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
461 max_rcv_desc
= MAX_RCV_DESCRIPTORS_1G
;
462 max_jumbo_desc
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
465 num_rxd
= qlcnic_validate_ringparam(ring
->rx_pending
,
466 MIN_RCV_DESCRIPTORS
, max_rcv_desc
, "rx");
468 num_jumbo_rxd
= qlcnic_validate_ringparam(ring
->rx_jumbo_pending
,
469 MIN_JUMBO_DESCRIPTORS
, max_jumbo_desc
, "rx jumbo");
471 num_txd
= qlcnic_validate_ringparam(ring
->tx_pending
,
472 MIN_CMD_DESCRIPTORS
, MAX_CMD_DESCRIPTORS
, "tx");
474 if (num_rxd
== adapter
->num_rxd
&& num_txd
== adapter
->num_txd
&&
475 num_jumbo_rxd
== adapter
->num_jumbo_rxd
)
478 adapter
->num_rxd
= num_rxd
;
479 adapter
->num_jumbo_rxd
= num_jumbo_rxd
;
480 adapter
->num_txd
= num_txd
;
482 return qlcnic_reset_context(adapter
);
486 qlcnic_get_pauseparam(struct net_device
*netdev
,
487 struct ethtool_pauseparam
*pause
)
489 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
490 int port
= adapter
->physical_port
;
493 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
494 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_GBE_PORTS
))
496 /* get flow control settings */
497 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
));
498 pause
->rx_pause
= qlcnic_gb_get_rx_flowctl(val
);
499 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
);
502 pause
->tx_pause
= !(qlcnic_gb_get_gb0_mask(val
));
505 pause
->tx_pause
= !(qlcnic_gb_get_gb1_mask(val
));
508 pause
->tx_pause
= !(qlcnic_gb_get_gb2_mask(val
));
512 pause
->tx_pause
= !(qlcnic_gb_get_gb3_mask(val
));
515 } else if (adapter
->ahw
.port_type
== QLCNIC_XGBE
) {
516 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_XG_PORTS
))
519 val
= QLCRD32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
);
521 pause
->tx_pause
= !(qlcnic_xg_get_xg0_mask(val
));
523 pause
->tx_pause
= !(qlcnic_xg_get_xg1_mask(val
));
525 dev_err(&netdev
->dev
, "Unknown board type: %x\n",
526 adapter
->ahw
.port_type
);
531 qlcnic_set_pauseparam(struct net_device
*netdev
,
532 struct ethtool_pauseparam
*pause
)
534 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
535 int port
= adapter
->physical_port
;
539 if (adapter
->ahw
.port_type
== QLCNIC_GBE
) {
540 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_GBE_PORTS
))
542 /* set flow control */
543 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
));
546 qlcnic_gb_rx_flowctl(val
);
548 qlcnic_gb_unset_rx_flowctl(val
);
550 QLCWR32(adapter
, QLCNIC_NIU_GB_MAC_CONFIG_0(port
),
553 val
= QLCRD32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
);
557 qlcnic_gb_unset_gb0_mask(val
);
559 qlcnic_gb_set_gb0_mask(val
);
563 qlcnic_gb_unset_gb1_mask(val
);
565 qlcnic_gb_set_gb1_mask(val
);
569 qlcnic_gb_unset_gb2_mask(val
);
571 qlcnic_gb_set_gb2_mask(val
);
576 qlcnic_gb_unset_gb3_mask(val
);
578 qlcnic_gb_set_gb3_mask(val
);
581 QLCWR32(adapter
, QLCNIC_NIU_GB_PAUSE_CTL
, val
);
582 } else if (adapter
->ahw
.port_type
== QLCNIC_XGBE
) {
583 if ((port
< 0) || (port
> QLCNIC_NIU_MAX_XG_PORTS
))
585 val
= QLCRD32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
);
588 qlcnic_xg_unset_xg0_mask(val
);
590 qlcnic_xg_set_xg0_mask(val
);
593 qlcnic_xg_unset_xg1_mask(val
);
595 qlcnic_xg_set_xg1_mask(val
);
597 QLCWR32(adapter
, QLCNIC_NIU_XG_PAUSE_CTL
, val
);
599 dev_err(&netdev
->dev
, "Unknown board type: %x\n",
600 adapter
->ahw
.port_type
);
605 static int qlcnic_reg_test(struct net_device
*dev
)
607 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
610 data_read
= QLCRD32(adapter
, QLCNIC_PCIX_PH_REG(0));
611 if ((data_read
& 0xffff) != adapter
->pdev
->vendor
)
617 static int qlcnic_get_sset_count(struct net_device
*dev
, int sset
)
621 return QLCNIC_TEST_LEN
;
623 return QLCNIC_STATS_LEN
;
629 #define QLC_ILB_PKT_SIZE 64
631 static void qlcnic_create_loopback_buff(unsigned char *data
)
633 unsigned char random_data
[] = {0xa8, 0x06, 0x45, 0x00};
634 memset(data
, 0x4e, QLC_ILB_PKT_SIZE
);
635 memset(data
, 0xff, 12);
636 memcpy(data
+ 12, random_data
, sizeof(random_data
));
639 int qlcnic_check_loopback_buff(unsigned char *data
)
641 unsigned char buff
[QLC_ILB_PKT_SIZE
];
642 qlcnic_create_loopback_buff(buff
);
643 return memcmp(data
, buff
, QLC_ILB_PKT_SIZE
);
646 static int qlcnic_do_ilb_test(struct qlcnic_adapter
*adapter
)
648 struct qlcnic_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
649 struct qlcnic_host_sds_ring
*sds_ring
= &recv_ctx
->sds_rings
[0];
653 for (i
= 0; i
< 16; i
++) {
654 skb
= dev_alloc_skb(QLC_ILB_PKT_SIZE
);
655 qlcnic_create_loopback_buff(skb
->data
);
656 skb_put(skb
, QLC_ILB_PKT_SIZE
);
658 adapter
->diag_cnt
= 0;
660 qlcnic_xmit_frame(skb
, adapter
->netdev
);
664 qlcnic_process_rcv_ring_diag(sds_ring
);
666 dev_kfree_skb_any(skb
);
667 if (!adapter
->diag_cnt
)
673 static int qlcnic_loopback_test(struct net_device
*netdev
)
675 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
676 int max_sds_rings
= adapter
->max_sds_rings
;
679 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
682 ret
= qlcnic_diag_alloc_res(netdev
, QLCNIC_LOOPBACK_TEST
);
686 ret
= qlcnic_set_ilb_mode(adapter
);
690 ret
= qlcnic_do_ilb_test(adapter
);
692 qlcnic_clear_ilb_mode(adapter
);
695 qlcnic_diag_free_res(netdev
, max_sds_rings
);
698 adapter
->max_sds_rings
= max_sds_rings
;
699 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
703 static int qlcnic_irq_test(struct net_device
*netdev
)
705 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
706 int max_sds_rings
= adapter
->max_sds_rings
;
709 if (test_and_set_bit(__QLCNIC_RESETTING
, &adapter
->state
))
712 ret
= qlcnic_diag_alloc_res(netdev
, QLCNIC_INTERRUPT_TEST
);
716 adapter
->diag_cnt
= 0;
717 ret
= qlcnic_issue_cmd(adapter
, adapter
->ahw
.pci_func
,
718 QLCHAL_VERSION
, adapter
->portnum
, 0, 0, 0x00000011);
724 ret
= !adapter
->diag_cnt
;
727 qlcnic_diag_free_res(netdev
, max_sds_rings
);
730 adapter
->max_sds_rings
= max_sds_rings
;
731 clear_bit(__QLCNIC_RESETTING
, &adapter
->state
);
736 qlcnic_diag_test(struct net_device
*dev
, struct ethtool_test
*eth_test
,
739 memset(data
, 0, sizeof(u64
) * QLCNIC_TEST_LEN
);
741 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
742 data
[2] = qlcnic_irq_test(dev
);
744 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
746 data
[3] = qlcnic_loopback_test(dev
);
748 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
752 data
[0] = qlcnic_reg_test(dev
);
754 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
757 data
[1] = (u64
) qlcnic_test_link(dev
);
759 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
763 qlcnic_get_strings(struct net_device
*dev
, u32 stringset
, u8
* data
)
769 memcpy(data
, *qlcnic_gstrings_test
,
770 QLCNIC_TEST_LEN
* ETH_GSTRING_LEN
);
773 for (index
= 0; index
< QLCNIC_STATS_LEN
; index
++) {
774 memcpy(data
+ index
* ETH_GSTRING_LEN
,
775 qlcnic_gstrings_stats
[index
].stat_string
,
783 qlcnic_get_ethtool_stats(struct net_device
*dev
,
784 struct ethtool_stats
*stats
, u64
* data
)
786 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
789 for (index
= 0; index
< QLCNIC_STATS_LEN
; index
++) {
792 qlcnic_gstrings_stats
[index
].stat_offset
;
794 (qlcnic_gstrings_stats
[index
].sizeof_stat
==
795 sizeof(u64
)) ? *(u64
*)p
:(*(u32
*)p
);
799 static u32
qlcnic_get_tx_csum(struct net_device
*dev
)
801 return dev
->features
& NETIF_F_IP_CSUM
;
804 static u32
qlcnic_get_rx_csum(struct net_device
*dev
)
806 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
807 return adapter
->rx_csum
;
810 static int qlcnic_set_rx_csum(struct net_device
*dev
, u32 data
)
812 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
813 adapter
->rx_csum
= !!data
;
817 static u32
qlcnic_get_tso(struct net_device
*dev
)
819 return (dev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) != 0;
822 static int qlcnic_set_tso(struct net_device
*dev
, u32 data
)
825 dev
->features
|= (NETIF_F_TSO
| NETIF_F_TSO6
);
827 dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_TSO6
);
832 static int qlcnic_blink_led(struct net_device
*dev
, u32 val
)
834 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
837 ret
= qlcnic_config_led(adapter
, 1, 0xf);
839 dev_err(&adapter
->pdev
->dev
,
840 "Failed to set LED blink state.\n");
844 msleep_interruptible(val
* 1000);
846 ret
= qlcnic_config_led(adapter
, 0, 0xf);
848 dev_err(&adapter
->pdev
->dev
,
849 "Failed to reset LED blink state.\n");
857 qlcnic_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
859 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
865 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG_NV
);
866 if (wol_cfg
& (1UL << adapter
->portnum
))
867 wol
->supported
|= WAKE_MAGIC
;
869 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG
);
870 if (wol_cfg
& (1UL << adapter
->portnum
))
871 wol
->wolopts
|= WAKE_MAGIC
;
875 qlcnic_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
877 struct qlcnic_adapter
*adapter
= netdev_priv(dev
);
880 if (wol
->wolopts
& ~WAKE_MAGIC
)
883 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG_NV
);
884 if (!(wol_cfg
& (1 << adapter
->portnum
)))
887 wol_cfg
= QLCRD32(adapter
, QLCNIC_WOL_CONFIG
);
888 if (wol
->wolopts
& WAKE_MAGIC
)
889 wol_cfg
|= 1UL << adapter
->portnum
;
891 wol_cfg
&= ~(1UL << adapter
->portnum
);
893 QLCWR32(adapter
, QLCNIC_WOL_CONFIG
, wol_cfg
);
899 * Set the coalescing parameters. Currently only normal is supported.
900 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
901 * firmware coalescing to default.
903 static int qlcnic_set_intr_coalesce(struct net_device
*netdev
,
904 struct ethtool_coalesce
*ethcoal
)
906 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
908 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
912 * Return Error if unsupported values or
913 * unsupported parameters are set.
915 if (ethcoal
->rx_coalesce_usecs
> 0xffff ||
916 ethcoal
->rx_max_coalesced_frames
> 0xffff ||
917 ethcoal
->tx_coalesce_usecs
> 0xffff ||
918 ethcoal
->tx_max_coalesced_frames
> 0xffff ||
919 ethcoal
->rx_coalesce_usecs_irq
||
920 ethcoal
->rx_max_coalesced_frames_irq
||
921 ethcoal
->tx_coalesce_usecs_irq
||
922 ethcoal
->tx_max_coalesced_frames_irq
||
923 ethcoal
->stats_block_coalesce_usecs
||
924 ethcoal
->use_adaptive_rx_coalesce
||
925 ethcoal
->use_adaptive_tx_coalesce
||
926 ethcoal
->pkt_rate_low
||
927 ethcoal
->rx_coalesce_usecs_low
||
928 ethcoal
->rx_max_coalesced_frames_low
||
929 ethcoal
->tx_coalesce_usecs_low
||
930 ethcoal
->tx_max_coalesced_frames_low
||
931 ethcoal
->pkt_rate_high
||
932 ethcoal
->rx_coalesce_usecs_high
||
933 ethcoal
->rx_max_coalesced_frames_high
||
934 ethcoal
->tx_coalesce_usecs_high
||
935 ethcoal
->tx_max_coalesced_frames_high
)
938 if (!ethcoal
->rx_coalesce_usecs
||
939 !ethcoal
->rx_max_coalesced_frames
) {
940 adapter
->coal
.flags
= QLCNIC_INTR_DEFAULT
;
941 adapter
->coal
.normal
.data
.rx_time_us
=
942 QLCNIC_DEFAULT_INTR_COALESCE_RX_TIME_US
;
943 adapter
->coal
.normal
.data
.rx_packets
=
944 QLCNIC_DEFAULT_INTR_COALESCE_RX_PACKETS
;
946 adapter
->coal
.flags
= 0;
947 adapter
->coal
.normal
.data
.rx_time_us
=
948 ethcoal
->rx_coalesce_usecs
;
949 adapter
->coal
.normal
.data
.rx_packets
=
950 ethcoal
->rx_max_coalesced_frames
;
952 adapter
->coal
.normal
.data
.tx_time_us
= ethcoal
->tx_coalesce_usecs
;
953 adapter
->coal
.normal
.data
.tx_packets
=
954 ethcoal
->tx_max_coalesced_frames
;
956 qlcnic_config_intr_coalesce(adapter
);
961 static int qlcnic_get_intr_coalesce(struct net_device
*netdev
,
962 struct ethtool_coalesce
*ethcoal
)
964 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
966 if (adapter
->is_up
!= QLCNIC_ADAPTER_UP_MAGIC
)
969 ethcoal
->rx_coalesce_usecs
= adapter
->coal
.normal
.data
.rx_time_us
;
970 ethcoal
->tx_coalesce_usecs
= adapter
->coal
.normal
.data
.tx_time_us
;
971 ethcoal
->rx_max_coalesced_frames
=
972 adapter
->coal
.normal
.data
.rx_packets
;
973 ethcoal
->tx_max_coalesced_frames
=
974 adapter
->coal
.normal
.data
.tx_packets
;
979 static int qlcnic_set_flags(struct net_device
*netdev
, u32 data
)
981 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
984 if (!(adapter
->capabilities
& QLCNIC_FW_CAPABILITY_HW_LRO
))
987 ethtool_op_set_flags(netdev
, data
);
989 hw_lro
= (data
& ETH_FLAG_LRO
) ? QLCNIC_LRO_ENABLED
: 0;
991 if (qlcnic_config_hw_lro(adapter
, hw_lro
))
994 if ((hw_lro
== 0) && qlcnic_send_lro_cleanup(adapter
))
1001 static u32
qlcnic_get_msglevel(struct net_device
*netdev
)
1003 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1005 return adapter
->msg_enable
;
1008 static void qlcnic_set_msglevel(struct net_device
*netdev
, u32 msglvl
)
1010 struct qlcnic_adapter
*adapter
= netdev_priv(netdev
);
1012 adapter
->msg_enable
= msglvl
;
1015 const struct ethtool_ops qlcnic_ethtool_ops
= {
1016 .get_settings
= qlcnic_get_settings
,
1017 .set_settings
= qlcnic_set_settings
,
1018 .get_drvinfo
= qlcnic_get_drvinfo
,
1019 .get_regs_len
= qlcnic_get_regs_len
,
1020 .get_regs
= qlcnic_get_regs
,
1021 .get_link
= ethtool_op_get_link
,
1022 .get_eeprom_len
= qlcnic_get_eeprom_len
,
1023 .get_eeprom
= qlcnic_get_eeprom
,
1024 .get_ringparam
= qlcnic_get_ringparam
,
1025 .set_ringparam
= qlcnic_set_ringparam
,
1026 .get_pauseparam
= qlcnic_get_pauseparam
,
1027 .set_pauseparam
= qlcnic_set_pauseparam
,
1028 .get_tx_csum
= qlcnic_get_tx_csum
,
1029 .set_tx_csum
= ethtool_op_set_tx_csum
,
1030 .set_sg
= ethtool_op_set_sg
,
1031 .get_tso
= qlcnic_get_tso
,
1032 .set_tso
= qlcnic_set_tso
,
1033 .get_wol
= qlcnic_get_wol
,
1034 .set_wol
= qlcnic_set_wol
,
1035 .self_test
= qlcnic_diag_test
,
1036 .get_strings
= qlcnic_get_strings
,
1037 .get_ethtool_stats
= qlcnic_get_ethtool_stats
,
1038 .get_sset_count
= qlcnic_get_sset_count
,
1039 .get_rx_csum
= qlcnic_get_rx_csum
,
1040 .set_rx_csum
= qlcnic_set_rx_csum
,
1041 .get_coalesce
= qlcnic_get_intr_coalesce
,
1042 .set_coalesce
= qlcnic_set_intr_coalesce
,
1043 .get_flags
= ethtool_op_get_flags
,
1044 .set_flags
= qlcnic_set_flags
,
1045 .phys_id
= qlcnic_blink_led
,
1046 .set_msglevel
= qlcnic_set_msglevel
,
1047 .get_msglevel
= qlcnic_get_msglevel
,