2 * Copyright (C) 2003 - 2009 NetXen, Inc.
3 * Copyright (C) 2009 - QLogic Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 * The full GNU General Public License is included in this distribution
20 * in the file called "COPYING".
24 #include <linux/types.h>
25 #include <linux/delay.h>
26 #include <linux/pci.h>
28 #include <linux/netdevice.h>
29 #include <linux/ethtool.h>
31 #include "netxen_nic.h"
32 #include "netxen_nic_hw.h"
34 struct netxen_nic_stats
{
35 char stat_string
[ETH_GSTRING_LEN
];
40 #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
41 offsetof(struct netxen_adapter, m)
43 #define NETXEN_NIC_PORT_WINDOW 0x10000
44 #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
46 static const struct netxen_nic_stats netxen_nic_gstrings_stats
[] = {
47 {"xmit_called", NETXEN_NIC_STAT(stats
.xmitcalled
)},
48 {"xmit_finished", NETXEN_NIC_STAT(stats
.xmitfinished
)},
49 {"rx_dropped", NETXEN_NIC_STAT(stats
.rxdropped
)},
50 {"tx_dropped", NETXEN_NIC_STAT(stats
.txdropped
)},
51 {"csummed", NETXEN_NIC_STAT(stats
.csummed
)},
52 {"rx_pkts", NETXEN_NIC_STAT(stats
.rx_pkts
)},
53 {"lro_pkts", NETXEN_NIC_STAT(stats
.lro_pkts
)},
54 {"rx_bytes", NETXEN_NIC_STAT(stats
.rxbytes
)},
55 {"tx_bytes", NETXEN_NIC_STAT(stats
.txbytes
)},
58 #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
60 static const char netxen_nic_gstrings_test
[][ETH_GSTRING_LEN
] = {
61 "Register_Test_on_offline",
62 "Link_Test_on_offline"
65 #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
67 #define NETXEN_NIC_REGS_COUNT 30
68 #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
69 #define NETXEN_MAX_EEPROM_LEN 1024
71 static int netxen_nic_get_eeprom_len(struct net_device
*dev
)
73 return NETXEN_FLASH_TOTAL_SIZE
;
77 netxen_nic_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*drvinfo
)
79 struct netxen_adapter
*adapter
= netdev_priv(dev
);
84 strlcpy(drvinfo
->driver
, netxen_nic_driver_name
,
85 sizeof(drvinfo
->driver
));
86 strlcpy(drvinfo
->version
, NETXEN_NIC_LINUX_VERSIONID
,
87 sizeof(drvinfo
->version
));
88 fw_major
= NXRD32(adapter
, NETXEN_FW_VERSION_MAJOR
);
89 fw_minor
= NXRD32(adapter
, NETXEN_FW_VERSION_MINOR
);
90 fw_build
= NXRD32(adapter
, NETXEN_FW_VERSION_SUB
);
91 snprintf(drvinfo
->fw_version
, sizeof(drvinfo
->fw_version
),
92 "%d.%d.%d", fw_major
, fw_minor
, fw_build
);
94 strlcpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
),
95 sizeof(drvinfo
->bus_info
));
99 netxen_nic_get_link_ksettings(struct net_device
*dev
,
100 struct ethtool_link_ksettings
*cmd
)
102 struct netxen_adapter
*adapter
= netdev_priv(dev
);
103 int check_sfp_module
= 0;
104 u32 supported
, advertising
;
106 /* read which mode */
107 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
108 supported
= (SUPPORTED_10baseT_Half
|
109 SUPPORTED_10baseT_Full
|
110 SUPPORTED_100baseT_Half
|
111 SUPPORTED_100baseT_Full
|
112 SUPPORTED_1000baseT_Half
|
113 SUPPORTED_1000baseT_Full
);
115 advertising
= (ADVERTISED_100baseT_Half
|
116 ADVERTISED_100baseT_Full
|
117 ADVERTISED_1000baseT_Half
|
118 ADVERTISED_1000baseT_Full
);
120 cmd
->base
.port
= PORT_TP
;
122 cmd
->base
.speed
= adapter
->link_speed
;
123 cmd
->base
.duplex
= adapter
->link_duplex
;
124 cmd
->base
.autoneg
= adapter
->link_autoneg
;
126 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
129 val
= NXRD32(adapter
, NETXEN_PORT_MODE_ADDR
);
130 if (val
== NETXEN_PORT_MODE_802_3_AP
) {
131 supported
= SUPPORTED_1000baseT_Full
;
132 advertising
= ADVERTISED_1000baseT_Full
;
134 supported
= SUPPORTED_10000baseT_Full
;
135 advertising
= ADVERTISED_10000baseT_Full
;
138 if (netif_running(dev
) && adapter
->has_link_events
) {
139 cmd
->base
.speed
= adapter
->link_speed
;
140 cmd
->base
.autoneg
= adapter
->link_autoneg
;
141 cmd
->base
.duplex
= adapter
->link_duplex
;
145 cmd
->base
.port
= PORT_TP
;
147 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
148 u16 pcifn
= adapter
->ahw
.pci_func
;
150 val
= NXRD32(adapter
, P3_LINK_SPEED_REG(pcifn
));
151 cmd
->base
.speed
= P3_LINK_SPEED_MHZ
*
152 P3_LINK_SPEED_VAL(pcifn
, val
);
154 cmd
->base
.speed
= SPEED_10000
;
156 cmd
->base
.duplex
= DUPLEX_FULL
;
157 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
162 cmd
->base
.phy_address
= adapter
->physical_port
;
164 switch (adapter
->ahw
.board_type
) {
165 case NETXEN_BRDTYPE_P2_SB35_4G
:
166 case NETXEN_BRDTYPE_P2_SB31_2G
:
167 case NETXEN_BRDTYPE_P3_REF_QG
:
168 case NETXEN_BRDTYPE_P3_4_GB
:
169 case NETXEN_BRDTYPE_P3_4_GB_MM
:
171 supported
|= SUPPORTED_Autoneg
;
172 advertising
|= ADVERTISED_Autoneg
;
173 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
174 case NETXEN_BRDTYPE_P3_10G_CX4
:
175 case NETXEN_BRDTYPE_P3_10G_CX4_LP
:
176 case NETXEN_BRDTYPE_P3_10000_BASE_T
:
177 supported
|= SUPPORTED_TP
;
178 advertising
|= ADVERTISED_TP
;
179 cmd
->base
.port
= PORT_TP
;
180 cmd
->base
.autoneg
= (adapter
->ahw
.board_type
==
181 NETXEN_BRDTYPE_P2_SB31_10G_CX4
) ?
182 (AUTONEG_DISABLE
) : (adapter
->link_autoneg
);
184 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
185 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
186 case NETXEN_BRDTYPE_P3_IMEZ
:
187 case NETXEN_BRDTYPE_P3_XG_LOM
:
188 case NETXEN_BRDTYPE_P3_HMEZ
:
189 supported
|= SUPPORTED_MII
;
190 advertising
|= ADVERTISED_MII
;
191 cmd
->base
.port
= PORT_MII
;
192 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
194 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS
:
195 case NETXEN_BRDTYPE_P3_10G_SFP_CT
:
196 case NETXEN_BRDTYPE_P3_10G_SFP_QT
:
197 advertising
|= ADVERTISED_TP
;
198 supported
|= SUPPORTED_TP
;
199 check_sfp_module
= netif_running(dev
) &&
200 adapter
->has_link_events
;
201 case NETXEN_BRDTYPE_P2_SB31_10G
:
202 case NETXEN_BRDTYPE_P3_10G_XFP
:
203 supported
|= SUPPORTED_FIBRE
;
204 advertising
|= ADVERTISED_FIBRE
;
205 cmd
->base
.port
= PORT_FIBRE
;
206 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
208 case NETXEN_BRDTYPE_P3_10G_TP
:
209 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
210 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
211 supported
|= (SUPPORTED_FIBRE
| SUPPORTED_TP
);
213 (ADVERTISED_FIBRE
| ADVERTISED_TP
);
214 cmd
->base
.port
= PORT_FIBRE
;
215 check_sfp_module
= netif_running(dev
) &&
216 adapter
->has_link_events
;
218 supported
|= (SUPPORTED_TP
| SUPPORTED_Autoneg
);
220 (ADVERTISED_TP
| ADVERTISED_Autoneg
);
221 cmd
->base
.port
= PORT_TP
;
225 printk(KERN_ERR
"netxen-nic: Unsupported board model %d\n",
226 adapter
->ahw
.board_type
);
230 if (check_sfp_module
) {
231 switch (adapter
->module_type
) {
232 case LINKEVENT_MODULE_OPTICAL_UNKNOWN
:
233 case LINKEVENT_MODULE_OPTICAL_SRLR
:
234 case LINKEVENT_MODULE_OPTICAL_LRM
:
235 case LINKEVENT_MODULE_OPTICAL_SFP_1G
:
236 cmd
->base
.port
= PORT_FIBRE
;
238 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
:
239 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
:
240 case LINKEVENT_MODULE_TWINAX
:
241 cmd
->base
.port
= PORT_TP
;
248 if (!netif_running(dev
) || !adapter
->ahw
.linkup
) {
249 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
250 cmd
->base
.speed
= SPEED_UNKNOWN
;
253 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
255 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
262 netxen_nic_set_link_ksettings(struct net_device
*dev
,
263 const struct ethtool_link_ksettings
*cmd
)
265 struct netxen_adapter
*adapter
= netdev_priv(dev
);
266 u32 speed
= cmd
->base
.speed
;
269 if (adapter
->ahw
.port_type
!= NETXEN_NIC_GBE
)
272 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_GBE_LINK_CFG
))
275 ret
= nx_fw_cmd_set_gbe_port(adapter
, speed
, cmd
->base
.duplex
,
277 if (ret
== NX_RCODE_NOT_SUPPORTED
)
282 adapter
->link_speed
= speed
;
283 adapter
->link_duplex
= cmd
->base
.duplex
;
284 adapter
->link_autoneg
= cmd
->base
.autoneg
;
286 if (!netif_running(dev
))
289 dev
->netdev_ops
->ndo_stop(dev
);
290 return dev
->netdev_ops
->ndo_open(dev
);
293 static int netxen_nic_get_regs_len(struct net_device
*dev
)
295 return NETXEN_NIC_REGS_LEN
;
299 netxen_nic_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *p
)
301 struct netxen_adapter
*adapter
= netdev_priv(dev
);
302 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
303 struct nx_host_sds_ring
*sds_ring
;
306 int port
= adapter
->physical_port
;
308 memset(p
, 0, NETXEN_NIC_REGS_LEN
);
310 regs
->version
= (1 << 24) | (adapter
->ahw
.revision_id
<< 16) |
311 (adapter
->pdev
)->device
;
313 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
316 regs_buff
[i
++] = NXRD32(adapter
, CRB_CMDPEG_STATE
);
317 regs_buff
[i
++] = NXRD32(adapter
, CRB_RCVPEG_STATE
);
318 regs_buff
[i
++] = NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
319 regs_buff
[i
++] = NXRDIO(adapter
, adapter
->crb_int_state_reg
);
320 regs_buff
[i
++] = NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
321 regs_buff
[i
++] = NXRD32(adapter
, NX_CRB_DEV_STATE
);
322 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
323 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
324 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_PEG_HALT_STATUS2
);
326 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_0
+0x3c);
327 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_1
+0x3c);
328 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_2
+0x3c);
329 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_3
+0x3c);
331 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
333 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_4
+0x3c);
336 regs_buff
[i
++] = NXRD32(adapter
, CRB_XG_STATE_P3
);
337 regs_buff
[i
++] = le32_to_cpu(*(adapter
->tx_ring
->hw_consumer
));
342 regs_buff
[i
++] = NXRD32(adapter
,
343 NETXEN_NIU_XGE_CONFIG_0
+(0x10000*port
));
344 regs_buff
[i
++] = NXRD32(adapter
,
345 NETXEN_NIU_XGE_CONFIG_1
+(0x10000*port
));
347 regs_buff
[i
++] = NXRD32(adapter
, CRB_XG_STATE
);
348 regs_buff
[i
++] = NXRDIO(adapter
,
349 adapter
->tx_ring
->crb_cmd_consumer
);
352 regs_buff
[i
++] = NXRDIO(adapter
, adapter
->tx_ring
->crb_cmd_producer
);
354 regs_buff
[i
++] = NXRDIO(adapter
,
355 recv_ctx
->rds_rings
[0].crb_rcv_producer
);
356 regs_buff
[i
++] = NXRDIO(adapter
,
357 recv_ctx
->rds_rings
[1].crb_rcv_producer
);
359 regs_buff
[i
++] = adapter
->max_sds_rings
;
361 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
362 sds_ring
= &(recv_ctx
->sds_rings
[ring
]);
363 regs_buff
[i
++] = NXRDIO(adapter
,
364 sds_ring
->crb_sts_consumer
);
368 static u32
netxen_nic_test_link(struct net_device
*dev
)
370 struct netxen_adapter
*adapter
= netdev_priv(dev
);
373 port
= adapter
->physical_port
;
374 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
375 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
376 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
377 return (val
== XG_LINK_UP_P3
) ? 0 : 1;
379 val
= NXRD32(adapter
, CRB_XG_STATE
);
380 val
= (val
>> port
*8) & 0xff;
381 return (val
== XG_LINK_UP
) ? 0 : 1;
386 netxen_nic_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
389 struct netxen_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
= netxen_rom_fast_read_words(adapter
, offset
, bytes
,
409 netxen_nic_get_ringparam(struct net_device
*dev
,
410 struct ethtool_ringparam
*ring
)
412 struct netxen_adapter
*adapter
= netdev_priv(dev
);
414 ring
->rx_pending
= adapter
->num_rxd
;
415 ring
->rx_jumbo_pending
= adapter
->num_jumbo_rxd
;
416 ring
->rx_jumbo_pending
+= adapter
->num_lro_rxd
;
417 ring
->tx_pending
= adapter
->num_txd
;
419 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
420 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_1G
;
421 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
423 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_10G
;
424 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
427 ring
->tx_max_pending
= MAX_CMD_DESCRIPTORS
;
431 netxen_validate_ringparam(u32 val
, u32 min
, u32 max
, char *r_name
)
434 num_desc
= max(val
, min
);
435 num_desc
= min(num_desc
, max
);
436 num_desc
= roundup_pow_of_two(num_desc
);
438 if (val
!= num_desc
) {
439 printk(KERN_INFO
"%s: setting %s ring size %d instead of %d\n",
440 netxen_nic_driver_name
, r_name
, num_desc
, val
);
447 netxen_nic_set_ringparam(struct net_device
*dev
,
448 struct ethtool_ringparam
*ring
)
450 struct netxen_adapter
*adapter
= netdev_priv(dev
);
451 u16 max_rcv_desc
= MAX_RCV_DESCRIPTORS_10G
;
452 u16 max_jumbo_desc
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
453 u16 num_rxd
, num_jumbo_rxd
, num_txd
;
455 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
458 if (ring
->rx_mini_pending
)
461 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
462 max_rcv_desc
= MAX_RCV_DESCRIPTORS_1G
;
463 max_jumbo_desc
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
466 num_rxd
= netxen_validate_ringparam(ring
->rx_pending
,
467 MIN_RCV_DESCRIPTORS
, max_rcv_desc
, "rx");
469 num_jumbo_rxd
= netxen_validate_ringparam(ring
->rx_jumbo_pending
,
470 MIN_JUMBO_DESCRIPTORS
, max_jumbo_desc
, "rx jumbo");
472 num_txd
= netxen_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 netxen_nic_reset_context(adapter
);
487 netxen_nic_get_pauseparam(struct net_device
*dev
,
488 struct ethtool_pauseparam
*pause
)
490 struct netxen_adapter
*adapter
= netdev_priv(dev
);
492 int port
= adapter
->physical_port
;
496 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
497 if ((port
< 0) || (port
>= NETXEN_NIU_MAX_GBE_PORTS
))
499 /* get flow control settings */
500 val
= NXRD32(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
));
501 pause
->rx_pause
= netxen_gb_get_rx_flowctl(val
);
502 val
= NXRD32(adapter
, NETXEN_NIU_GB_PAUSE_CTL
);
505 pause
->tx_pause
= !(netxen_gb_get_gb0_mask(val
));
508 pause
->tx_pause
= !(netxen_gb_get_gb1_mask(val
));
511 pause
->tx_pause
= !(netxen_gb_get_gb2_mask(val
));
515 pause
->tx_pause
= !(netxen_gb_get_gb3_mask(val
));
518 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
519 if ((port
< 0) || (port
>= NETXEN_NIU_MAX_XG_PORTS
))
522 val
= NXRD32(adapter
, NETXEN_NIU_XG_PAUSE_CTL
);
524 pause
->tx_pause
= !(netxen_xg_get_xg0_mask(val
));
526 pause
->tx_pause
= !(netxen_xg_get_xg1_mask(val
));
528 printk(KERN_ERR
"%s: Unknown board type: %x\n",
529 netxen_nic_driver_name
, adapter
->ahw
.port_type
);
534 netxen_nic_set_pauseparam(struct net_device
*dev
,
535 struct ethtool_pauseparam
*pause
)
537 struct netxen_adapter
*adapter
= netdev_priv(dev
);
539 int port
= adapter
->physical_port
;
546 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
547 if ((port
< 0) || (port
>= NETXEN_NIU_MAX_GBE_PORTS
))
549 /* set flow control */
550 val
= NXRD32(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
));
553 netxen_gb_rx_flowctl(val
);
555 netxen_gb_unset_rx_flowctl(val
);
557 NXWR32(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
),
560 val
= NXRD32(adapter
, NETXEN_NIU_GB_PAUSE_CTL
);
564 netxen_gb_unset_gb0_mask(val
);
566 netxen_gb_set_gb0_mask(val
);
570 netxen_gb_unset_gb1_mask(val
);
572 netxen_gb_set_gb1_mask(val
);
576 netxen_gb_unset_gb2_mask(val
);
578 netxen_gb_set_gb2_mask(val
);
583 netxen_gb_unset_gb3_mask(val
);
585 netxen_gb_set_gb3_mask(val
);
588 NXWR32(adapter
, NETXEN_NIU_GB_PAUSE_CTL
, val
);
589 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
590 if ((port
< 0) || (port
>= NETXEN_NIU_MAX_XG_PORTS
))
592 val
= NXRD32(adapter
, NETXEN_NIU_XG_PAUSE_CTL
);
595 netxen_xg_unset_xg0_mask(val
);
597 netxen_xg_set_xg0_mask(val
);
600 netxen_xg_unset_xg1_mask(val
);
602 netxen_xg_set_xg1_mask(val
);
604 NXWR32(adapter
, NETXEN_NIU_XG_PAUSE_CTL
, val
);
606 printk(KERN_ERR
"%s: Unknown board type: %x\n",
607 netxen_nic_driver_name
,
608 adapter
->ahw
.port_type
);
613 static int netxen_nic_reg_test(struct net_device
*dev
)
615 struct netxen_adapter
*adapter
= netdev_priv(dev
);
616 u32 data_read
, data_written
;
618 data_read
= NXRD32(adapter
, NETXEN_PCIX_PH_REG(0));
619 if ((data_read
& 0xffff) != adapter
->pdev
->vendor
)
622 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
625 data_written
= (u32
)0xa5a5a5a5;
627 NXWR32(adapter
, CRB_SCRATCHPAD_TEST
, data_written
);
628 data_read
= NXRD32(adapter
, CRB_SCRATCHPAD_TEST
);
629 if (data_written
!= data_read
)
635 static int netxen_get_sset_count(struct net_device
*dev
, int sset
)
639 return NETXEN_NIC_TEST_LEN
;
641 return NETXEN_NIC_STATS_LEN
;
648 netxen_nic_diag_test(struct net_device
*dev
, struct ethtool_test
*eth_test
,
651 memset(data
, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN
);
652 if ((data
[0] = netxen_nic_reg_test(dev
)))
653 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
655 if ((data
[1] = (u64
) netxen_nic_test_link(dev
)))
656 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
660 netxen_nic_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
666 memcpy(data
, *netxen_nic_gstrings_test
,
667 NETXEN_NIC_TEST_LEN
* ETH_GSTRING_LEN
);
670 for (index
= 0; index
< NETXEN_NIC_STATS_LEN
; index
++) {
671 memcpy(data
+ index
* ETH_GSTRING_LEN
,
672 netxen_nic_gstrings_stats
[index
].stat_string
,
680 netxen_nic_get_ethtool_stats(struct net_device
*dev
,
681 struct ethtool_stats
*stats
, u64
*data
)
683 struct netxen_adapter
*adapter
= netdev_priv(dev
);
686 for (index
= 0; index
< NETXEN_NIC_STATS_LEN
; index
++) {
689 netxen_nic_gstrings_stats
[index
].stat_offset
;
691 (netxen_nic_gstrings_stats
[index
].sizeof_stat
==
692 sizeof(u64
)) ? *(u64
*) p
: *(u32
*) p
;
697 netxen_nic_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
699 struct netxen_adapter
*adapter
= netdev_priv(dev
);
705 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
708 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG_NV
);
709 if (wol_cfg
& (1UL << adapter
->portnum
))
710 wol
->supported
|= WAKE_MAGIC
;
712 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG
);
713 if (wol_cfg
& (1UL << adapter
->portnum
))
714 wol
->wolopts
|= WAKE_MAGIC
;
718 netxen_nic_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
720 struct netxen_adapter
*adapter
= netdev_priv(dev
);
723 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
726 if (wol
->wolopts
& ~WAKE_MAGIC
)
729 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG_NV
);
730 if (!(wol_cfg
& (1 << adapter
->portnum
)))
733 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG
);
734 if (wol
->wolopts
& WAKE_MAGIC
)
735 wol_cfg
|= 1UL << adapter
->portnum
;
737 wol_cfg
&= ~(1UL << adapter
->portnum
);
738 NXWR32(adapter
, NETXEN_WOL_CONFIG
, wol_cfg
);
744 * Set the coalescing parameters. Currently only normal is supported.
745 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
746 * firmware coalescing to default.
748 static int netxen_set_intr_coalesce(struct net_device
*netdev
,
749 struct ethtool_coalesce
*ethcoal
)
751 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
753 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
756 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
760 * Return Error if unsupported values or
761 * unsupported parameters are set.
763 if (ethcoal
->rx_coalesce_usecs
> 0xffff ||
764 ethcoal
->rx_max_coalesced_frames
> 0xffff ||
765 ethcoal
->tx_coalesce_usecs
> 0xffff ||
766 ethcoal
->tx_max_coalesced_frames
> 0xffff ||
767 ethcoal
->rx_coalesce_usecs_irq
||
768 ethcoal
->rx_max_coalesced_frames_irq
||
769 ethcoal
->tx_coalesce_usecs_irq
||
770 ethcoal
->tx_max_coalesced_frames_irq
||
771 ethcoal
->stats_block_coalesce_usecs
||
772 ethcoal
->use_adaptive_rx_coalesce
||
773 ethcoal
->use_adaptive_tx_coalesce
||
774 ethcoal
->pkt_rate_low
||
775 ethcoal
->rx_coalesce_usecs_low
||
776 ethcoal
->rx_max_coalesced_frames_low
||
777 ethcoal
->tx_coalesce_usecs_low
||
778 ethcoal
->tx_max_coalesced_frames_low
||
779 ethcoal
->pkt_rate_high
||
780 ethcoal
->rx_coalesce_usecs_high
||
781 ethcoal
->rx_max_coalesced_frames_high
||
782 ethcoal
->tx_coalesce_usecs_high
||
783 ethcoal
->tx_max_coalesced_frames_high
)
786 if (!ethcoal
->rx_coalesce_usecs
||
787 !ethcoal
->rx_max_coalesced_frames
) {
788 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
789 adapter
->coal
.normal
.data
.rx_time_us
=
790 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
791 adapter
->coal
.normal
.data
.rx_packets
=
792 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
794 adapter
->coal
.flags
= 0;
795 adapter
->coal
.normal
.data
.rx_time_us
=
796 ethcoal
->rx_coalesce_usecs
;
797 adapter
->coal
.normal
.data
.rx_packets
=
798 ethcoal
->rx_max_coalesced_frames
;
800 adapter
->coal
.normal
.data
.tx_time_us
= ethcoal
->tx_coalesce_usecs
;
801 adapter
->coal
.normal
.data
.tx_packets
=
802 ethcoal
->tx_max_coalesced_frames
;
804 netxen_config_intr_coalesce(adapter
);
809 static int netxen_get_intr_coalesce(struct net_device
*netdev
,
810 struct ethtool_coalesce
*ethcoal
)
812 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
814 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
817 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
820 ethcoal
->rx_coalesce_usecs
= adapter
->coal
.normal
.data
.rx_time_us
;
821 ethcoal
->tx_coalesce_usecs
= adapter
->coal
.normal
.data
.tx_time_us
;
822 ethcoal
->rx_max_coalesced_frames
=
823 adapter
->coal
.normal
.data
.rx_packets
;
824 ethcoal
->tx_max_coalesced_frames
=
825 adapter
->coal
.normal
.data
.tx_packets
;
831 netxen_get_dump_flag(struct net_device
*netdev
, struct ethtool_dump
*dump
)
833 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
834 struct netxen_minidump
*mdump
= &adapter
->mdump
;
835 if (adapter
->fw_mdump_rdy
)
836 dump
->len
= mdump
->md_dump_size
;
840 if (!mdump
->md_enabled
)
841 dump
->flag
= ETH_FW_DUMP_DISABLE
;
843 dump
->flag
= mdump
->md_capture_mask
;
845 dump
->version
= adapter
->fw_version
;
850 netxen_set_dump(struct net_device
*netdev
, struct ethtool_dump
*val
)
853 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
854 struct netxen_minidump
*mdump
= &adapter
->mdump
;
857 case NX_FORCE_FW_DUMP_KEY
:
858 if (!mdump
->md_enabled
) {
859 netdev_info(netdev
, "FW dump not enabled\n");
862 if (adapter
->fw_mdump_rdy
) {
863 netdev_info(netdev
, "Previous dump not cleared, not forcing dump\n");
866 netdev_info(netdev
, "Forcing a fw dump\n");
867 nx_dev_request_reset(adapter
);
869 case NX_DISABLE_FW_DUMP
:
870 if (mdump
->md_enabled
) {
871 netdev_info(netdev
, "Disabling FW Dump\n");
872 mdump
->md_enabled
= 0;
875 case NX_ENABLE_FW_DUMP
:
876 if (!mdump
->md_enabled
) {
877 netdev_info(netdev
, "Enabling FW dump\n");
878 mdump
->md_enabled
= 1;
881 case NX_FORCE_FW_RESET
:
882 netdev_info(netdev
, "Forcing FW reset\n");
883 nx_dev_request_reset(adapter
);
884 adapter
->flags
&= ~NETXEN_FW_RESET_OWNER
;
887 for (i
= 0; i
< ARRAY_SIZE(FW_DUMP_LEVELS
); i
++) {
888 if (val
->flag
== FW_DUMP_LEVELS
[i
]) {
889 mdump
->md_capture_mask
= val
->flag
;
891 "Driver mask changed to: 0x%x\n",
892 mdump
->md_capture_mask
);
897 "Invalid dump level: 0x%x\n", val
->flag
);
905 netxen_get_dump_data(struct net_device
*netdev
, struct ethtool_dump
*dump
,
910 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
911 struct netxen_minidump
*mdump
= &adapter
->mdump
;
914 if (!adapter
->fw_mdump_rdy
) {
915 netdev_info(netdev
, "Dump not available\n");
918 /* Copy template header first */
919 copy_sz
= mdump
->md_template_size
;
920 hdr_ptr
= (u32
*) mdump
->md_template
;
922 for (i
= 0; i
< copy_sz
/sizeof(u32
); i
++)
923 *data
++ = cpu_to_le32(*hdr_ptr
++);
925 /* Copy captured dump data */
926 memcpy(buffer
+ copy_sz
,
927 mdump
->md_capture_buff
+ mdump
->md_template_size
,
928 mdump
->md_capture_size
);
929 dump
->len
= copy_sz
+ mdump
->md_capture_size
;
930 dump
->flag
= mdump
->md_capture_mask
;
932 /* Free dump area once data has been captured */
933 vfree(mdump
->md_capture_buff
);
934 mdump
->md_capture_buff
= NULL
;
935 adapter
->fw_mdump_rdy
= 0;
936 netdev_info(netdev
, "extracted the fw dump Successfully\n");
940 const struct ethtool_ops netxen_nic_ethtool_ops
= {
941 .get_drvinfo
= netxen_nic_get_drvinfo
,
942 .get_regs_len
= netxen_nic_get_regs_len
,
943 .get_regs
= netxen_nic_get_regs
,
944 .get_link
= ethtool_op_get_link
,
945 .get_eeprom_len
= netxen_nic_get_eeprom_len
,
946 .get_eeprom
= netxen_nic_get_eeprom
,
947 .get_ringparam
= netxen_nic_get_ringparam
,
948 .set_ringparam
= netxen_nic_set_ringparam
,
949 .get_pauseparam
= netxen_nic_get_pauseparam
,
950 .set_pauseparam
= netxen_nic_set_pauseparam
,
951 .get_wol
= netxen_nic_get_wol
,
952 .set_wol
= netxen_nic_set_wol
,
953 .self_test
= netxen_nic_diag_test
,
954 .get_strings
= netxen_nic_get_strings
,
955 .get_ethtool_stats
= netxen_nic_get_ethtool_stats
,
956 .get_sset_count
= netxen_get_sset_count
,
957 .get_coalesce
= netxen_get_intr_coalesce
,
958 .set_coalesce
= netxen_set_intr_coalesce
,
959 .get_dump_flag
= netxen_get_dump_flag
,
960 .get_dump_data
= netxen_get_dump_data
,
961 .set_dump
= netxen_set_dump
,
962 .get_link_ksettings
= netxen_nic_get_link_ksettings
,
963 .set_link_ksettings
= netxen_nic_set_link_ksettings
,