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
:
170 supported
|= SUPPORTED_Autoneg
;
171 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
;
202 case NETXEN_BRDTYPE_P2_SB31_10G
:
203 case NETXEN_BRDTYPE_P3_10G_XFP
:
204 supported
|= SUPPORTED_FIBRE
;
205 advertising
|= ADVERTISED_FIBRE
;
206 cmd
->base
.port
= PORT_FIBRE
;
207 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
209 case NETXEN_BRDTYPE_P3_10G_TP
:
210 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
211 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
212 supported
|= (SUPPORTED_FIBRE
| SUPPORTED_TP
);
214 (ADVERTISED_FIBRE
| ADVERTISED_TP
);
215 cmd
->base
.port
= PORT_FIBRE
;
216 check_sfp_module
= netif_running(dev
) &&
217 adapter
->has_link_events
;
219 supported
|= (SUPPORTED_TP
| SUPPORTED_Autoneg
);
221 (ADVERTISED_TP
| ADVERTISED_Autoneg
);
222 cmd
->base
.port
= PORT_TP
;
226 printk(KERN_ERR
"netxen-nic: Unsupported board model %d\n",
227 adapter
->ahw
.board_type
);
231 if (check_sfp_module
) {
232 switch (adapter
->module_type
) {
233 case LINKEVENT_MODULE_OPTICAL_UNKNOWN
:
234 case LINKEVENT_MODULE_OPTICAL_SRLR
:
235 case LINKEVENT_MODULE_OPTICAL_LRM
:
236 case LINKEVENT_MODULE_OPTICAL_SFP_1G
:
237 cmd
->base
.port
= PORT_FIBRE
;
239 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
:
240 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
:
241 case LINKEVENT_MODULE_TWINAX
:
242 cmd
->base
.port
= PORT_TP
;
249 if (!netif_running(dev
) || !adapter
->ahw
.linkup
) {
250 cmd
->base
.duplex
= DUPLEX_UNKNOWN
;
251 cmd
->base
.speed
= SPEED_UNKNOWN
;
254 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
256 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
263 netxen_nic_set_link_ksettings(struct net_device
*dev
,
264 const struct ethtool_link_ksettings
*cmd
)
266 struct netxen_adapter
*adapter
= netdev_priv(dev
);
267 u32 speed
= cmd
->base
.speed
;
270 if (adapter
->ahw
.port_type
!= NETXEN_NIC_GBE
)
273 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_GBE_LINK_CFG
))
276 ret
= nx_fw_cmd_set_gbe_port(adapter
, speed
, cmd
->base
.duplex
,
278 if (ret
== NX_RCODE_NOT_SUPPORTED
)
283 adapter
->link_speed
= speed
;
284 adapter
->link_duplex
= cmd
->base
.duplex
;
285 adapter
->link_autoneg
= cmd
->base
.autoneg
;
287 if (!netif_running(dev
))
290 dev
->netdev_ops
->ndo_stop(dev
);
291 return dev
->netdev_ops
->ndo_open(dev
);
294 static int netxen_nic_get_regs_len(struct net_device
*dev
)
296 return NETXEN_NIC_REGS_LEN
;
300 netxen_nic_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *p
)
302 struct netxen_adapter
*adapter
= netdev_priv(dev
);
303 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
304 struct nx_host_sds_ring
*sds_ring
;
307 int port
= adapter
->physical_port
;
309 memset(p
, 0, NETXEN_NIC_REGS_LEN
);
311 regs
->version
= (1 << 24) | (adapter
->ahw
.revision_id
<< 16) |
312 (adapter
->pdev
)->device
;
314 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
317 regs_buff
[i
++] = NXRD32(adapter
, CRB_CMDPEG_STATE
);
318 regs_buff
[i
++] = NXRD32(adapter
, CRB_RCVPEG_STATE
);
319 regs_buff
[i
++] = NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
320 regs_buff
[i
++] = NXRDIO(adapter
, adapter
->crb_int_state_reg
);
321 regs_buff
[i
++] = NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
322 regs_buff
[i
++] = NXRD32(adapter
, NX_CRB_DEV_STATE
);
323 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
324 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
325 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_PEG_HALT_STATUS2
);
327 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_0
+0x3c);
328 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_1
+0x3c);
329 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_2
+0x3c);
330 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_3
+0x3c);
332 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
334 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_4
+0x3c);
337 regs_buff
[i
++] = NXRD32(adapter
, CRB_XG_STATE_P3
);
338 regs_buff
[i
++] = le32_to_cpu(*(adapter
->tx_ring
->hw_consumer
));
343 regs_buff
[i
++] = NXRD32(adapter
,
344 NETXEN_NIU_XGE_CONFIG_0
+(0x10000*port
));
345 regs_buff
[i
++] = NXRD32(adapter
,
346 NETXEN_NIU_XGE_CONFIG_1
+(0x10000*port
));
348 regs_buff
[i
++] = NXRD32(adapter
, CRB_XG_STATE
);
349 regs_buff
[i
++] = NXRDIO(adapter
,
350 adapter
->tx_ring
->crb_cmd_consumer
);
353 regs_buff
[i
++] = NXRDIO(adapter
, adapter
->tx_ring
->crb_cmd_producer
);
355 regs_buff
[i
++] = NXRDIO(adapter
,
356 recv_ctx
->rds_rings
[0].crb_rcv_producer
);
357 regs_buff
[i
++] = NXRDIO(adapter
,
358 recv_ctx
->rds_rings
[1].crb_rcv_producer
);
360 regs_buff
[i
++] = adapter
->max_sds_rings
;
362 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
363 sds_ring
= &(recv_ctx
->sds_rings
[ring
]);
364 regs_buff
[i
++] = NXRDIO(adapter
,
365 sds_ring
->crb_sts_consumer
);
369 static u32
netxen_nic_test_link(struct net_device
*dev
)
371 struct netxen_adapter
*adapter
= netdev_priv(dev
);
374 port
= adapter
->physical_port
;
375 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
376 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
377 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
378 return (val
== XG_LINK_UP_P3
) ? 0 : 1;
380 val
= NXRD32(adapter
, CRB_XG_STATE
);
381 val
= (val
>> port
*8) & 0xff;
382 return (val
== XG_LINK_UP
) ? 0 : 1;
387 netxen_nic_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
390 struct netxen_adapter
*adapter
= netdev_priv(dev
);
394 if (eeprom
->len
== 0)
397 eeprom
->magic
= (adapter
->pdev
)->vendor
|
398 ((adapter
->pdev
)->device
<< 16);
399 offset
= eeprom
->offset
;
401 ret
= netxen_rom_fast_read_words(adapter
, offset
, bytes
,
410 netxen_nic_get_ringparam(struct net_device
*dev
,
411 struct ethtool_ringparam
*ring
)
413 struct netxen_adapter
*adapter
= netdev_priv(dev
);
415 ring
->rx_pending
= adapter
->num_rxd
;
416 ring
->rx_jumbo_pending
= adapter
->num_jumbo_rxd
;
417 ring
->rx_jumbo_pending
+= adapter
->num_lro_rxd
;
418 ring
->tx_pending
= adapter
->num_txd
;
420 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
421 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_1G
;
422 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
424 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_10G
;
425 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
428 ring
->tx_max_pending
= MAX_CMD_DESCRIPTORS
;
432 netxen_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 netxen_nic_driver_name
, r_name
, num_desc
, val
);
448 netxen_nic_set_ringparam(struct net_device
*dev
,
449 struct ethtool_ringparam
*ring
)
451 struct netxen_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
;
456 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
459 if (ring
->rx_mini_pending
)
462 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
463 max_rcv_desc
= MAX_RCV_DESCRIPTORS_1G
;
464 max_jumbo_desc
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
467 num_rxd
= netxen_validate_ringparam(ring
->rx_pending
,
468 MIN_RCV_DESCRIPTORS
, max_rcv_desc
, "rx");
470 num_jumbo_rxd
= netxen_validate_ringparam(ring
->rx_jumbo_pending
,
471 MIN_JUMBO_DESCRIPTORS
, max_jumbo_desc
, "rx jumbo");
473 num_txd
= netxen_validate_ringparam(ring
->tx_pending
,
474 MIN_CMD_DESCRIPTORS
, MAX_CMD_DESCRIPTORS
, "tx");
476 if (num_rxd
== adapter
->num_rxd
&& num_txd
== adapter
->num_txd
&&
477 num_jumbo_rxd
== adapter
->num_jumbo_rxd
)
480 adapter
->num_rxd
= num_rxd
;
481 adapter
->num_jumbo_rxd
= num_jumbo_rxd
;
482 adapter
->num_txd
= num_txd
;
484 return netxen_nic_reset_context(adapter
);
488 netxen_nic_get_pauseparam(struct net_device
*dev
,
489 struct ethtool_pauseparam
*pause
)
491 struct netxen_adapter
*adapter
= netdev_priv(dev
);
493 int port
= adapter
->physical_port
;
497 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
498 if ((port
< 0) || (port
>= NETXEN_NIU_MAX_GBE_PORTS
))
500 /* get flow control settings */
501 val
= NXRD32(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
));
502 pause
->rx_pause
= netxen_gb_get_rx_flowctl(val
);
503 val
= NXRD32(adapter
, NETXEN_NIU_GB_PAUSE_CTL
);
506 pause
->tx_pause
= !(netxen_gb_get_gb0_mask(val
));
509 pause
->tx_pause
= !(netxen_gb_get_gb1_mask(val
));
512 pause
->tx_pause
= !(netxen_gb_get_gb2_mask(val
));
516 pause
->tx_pause
= !(netxen_gb_get_gb3_mask(val
));
519 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
520 if ((port
< 0) || (port
>= NETXEN_NIU_MAX_XG_PORTS
))
523 val
= NXRD32(adapter
, NETXEN_NIU_XG_PAUSE_CTL
);
525 pause
->tx_pause
= !(netxen_xg_get_xg0_mask(val
));
527 pause
->tx_pause
= !(netxen_xg_get_xg1_mask(val
));
529 printk(KERN_ERR
"%s: Unknown board type: %x\n",
530 netxen_nic_driver_name
, adapter
->ahw
.port_type
);
535 netxen_nic_set_pauseparam(struct net_device
*dev
,
536 struct ethtool_pauseparam
*pause
)
538 struct netxen_adapter
*adapter
= netdev_priv(dev
);
540 int port
= adapter
->physical_port
;
547 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
548 if ((port
< 0) || (port
>= NETXEN_NIU_MAX_GBE_PORTS
))
550 /* set flow control */
551 val
= NXRD32(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
));
554 netxen_gb_rx_flowctl(val
);
556 netxen_gb_unset_rx_flowctl(val
);
558 NXWR32(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
),
561 val
= NXRD32(adapter
, NETXEN_NIU_GB_PAUSE_CTL
);
565 netxen_gb_unset_gb0_mask(val
);
567 netxen_gb_set_gb0_mask(val
);
571 netxen_gb_unset_gb1_mask(val
);
573 netxen_gb_set_gb1_mask(val
);
577 netxen_gb_unset_gb2_mask(val
);
579 netxen_gb_set_gb2_mask(val
);
584 netxen_gb_unset_gb3_mask(val
);
586 netxen_gb_set_gb3_mask(val
);
589 NXWR32(adapter
, NETXEN_NIU_GB_PAUSE_CTL
, val
);
590 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
591 if ((port
< 0) || (port
>= NETXEN_NIU_MAX_XG_PORTS
))
593 val
= NXRD32(adapter
, NETXEN_NIU_XG_PAUSE_CTL
);
596 netxen_xg_unset_xg0_mask(val
);
598 netxen_xg_set_xg0_mask(val
);
601 netxen_xg_unset_xg1_mask(val
);
603 netxen_xg_set_xg1_mask(val
);
605 NXWR32(adapter
, NETXEN_NIU_XG_PAUSE_CTL
, val
);
607 printk(KERN_ERR
"%s: Unknown board type: %x\n",
608 netxen_nic_driver_name
,
609 adapter
->ahw
.port_type
);
614 static int netxen_nic_reg_test(struct net_device
*dev
)
616 struct netxen_adapter
*adapter
= netdev_priv(dev
);
617 u32 data_read
, data_written
;
619 data_read
= NXRD32(adapter
, NETXEN_PCIX_PH_REG(0));
620 if ((data_read
& 0xffff) != adapter
->pdev
->vendor
)
623 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
626 data_written
= (u32
)0xa5a5a5a5;
628 NXWR32(adapter
, CRB_SCRATCHPAD_TEST
, data_written
);
629 data_read
= NXRD32(adapter
, CRB_SCRATCHPAD_TEST
);
630 if (data_written
!= data_read
)
636 static int netxen_get_sset_count(struct net_device
*dev
, int sset
)
640 return NETXEN_NIC_TEST_LEN
;
642 return NETXEN_NIC_STATS_LEN
;
649 netxen_nic_diag_test(struct net_device
*dev
, struct ethtool_test
*eth_test
,
652 memset(data
, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN
);
653 if ((data
[0] = netxen_nic_reg_test(dev
)))
654 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
656 if ((data
[1] = (u64
) netxen_nic_test_link(dev
)))
657 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
661 netxen_nic_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
667 memcpy(data
, *netxen_nic_gstrings_test
,
668 NETXEN_NIC_TEST_LEN
* ETH_GSTRING_LEN
);
671 for (index
= 0; index
< NETXEN_NIC_STATS_LEN
; index
++) {
672 memcpy(data
+ index
* ETH_GSTRING_LEN
,
673 netxen_nic_gstrings_stats
[index
].stat_string
,
681 netxen_nic_get_ethtool_stats(struct net_device
*dev
,
682 struct ethtool_stats
*stats
, u64
*data
)
684 struct netxen_adapter
*adapter
= netdev_priv(dev
);
687 for (index
= 0; index
< NETXEN_NIC_STATS_LEN
; index
++) {
690 netxen_nic_gstrings_stats
[index
].stat_offset
;
692 (netxen_nic_gstrings_stats
[index
].sizeof_stat
==
693 sizeof(u64
)) ? *(u64
*) p
: *(u32
*) p
;
698 netxen_nic_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
700 struct netxen_adapter
*adapter
= netdev_priv(dev
);
706 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
709 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG_NV
);
710 if (wol_cfg
& (1UL << adapter
->portnum
))
711 wol
->supported
|= WAKE_MAGIC
;
713 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG
);
714 if (wol_cfg
& (1UL << adapter
->portnum
))
715 wol
->wolopts
|= WAKE_MAGIC
;
719 netxen_nic_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
721 struct netxen_adapter
*adapter
= netdev_priv(dev
);
724 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
727 if (wol
->wolopts
& ~WAKE_MAGIC
)
730 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG_NV
);
731 if (!(wol_cfg
& (1 << adapter
->portnum
)))
734 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG
);
735 if (wol
->wolopts
& WAKE_MAGIC
)
736 wol_cfg
|= 1UL << adapter
->portnum
;
738 wol_cfg
&= ~(1UL << adapter
->portnum
);
739 NXWR32(adapter
, NETXEN_WOL_CONFIG
, wol_cfg
);
745 * Set the coalescing parameters. Currently only normal is supported.
746 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
747 * firmware coalescing to default.
749 static int netxen_set_intr_coalesce(struct net_device
*netdev
,
750 struct ethtool_coalesce
*ethcoal
)
752 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
754 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
757 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
761 * Return Error if unsupported values or
762 * unsupported parameters are set.
764 if (ethcoal
->rx_coalesce_usecs
> 0xffff ||
765 ethcoal
->rx_max_coalesced_frames
> 0xffff ||
766 ethcoal
->tx_coalesce_usecs
> 0xffff ||
767 ethcoal
->tx_max_coalesced_frames
> 0xffff ||
768 ethcoal
->rx_coalesce_usecs_irq
||
769 ethcoal
->rx_max_coalesced_frames_irq
||
770 ethcoal
->tx_coalesce_usecs_irq
||
771 ethcoal
->tx_max_coalesced_frames_irq
||
772 ethcoal
->stats_block_coalesce_usecs
||
773 ethcoal
->use_adaptive_rx_coalesce
||
774 ethcoal
->use_adaptive_tx_coalesce
||
775 ethcoal
->pkt_rate_low
||
776 ethcoal
->rx_coalesce_usecs_low
||
777 ethcoal
->rx_max_coalesced_frames_low
||
778 ethcoal
->tx_coalesce_usecs_low
||
779 ethcoal
->tx_max_coalesced_frames_low
||
780 ethcoal
->pkt_rate_high
||
781 ethcoal
->rx_coalesce_usecs_high
||
782 ethcoal
->rx_max_coalesced_frames_high
||
783 ethcoal
->tx_coalesce_usecs_high
||
784 ethcoal
->tx_max_coalesced_frames_high
)
787 if (!ethcoal
->rx_coalesce_usecs
||
788 !ethcoal
->rx_max_coalesced_frames
) {
789 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
790 adapter
->coal
.normal
.data
.rx_time_us
=
791 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
792 adapter
->coal
.normal
.data
.rx_packets
=
793 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
795 adapter
->coal
.flags
= 0;
796 adapter
->coal
.normal
.data
.rx_time_us
=
797 ethcoal
->rx_coalesce_usecs
;
798 adapter
->coal
.normal
.data
.rx_packets
=
799 ethcoal
->rx_max_coalesced_frames
;
801 adapter
->coal
.normal
.data
.tx_time_us
= ethcoal
->tx_coalesce_usecs
;
802 adapter
->coal
.normal
.data
.tx_packets
=
803 ethcoal
->tx_max_coalesced_frames
;
805 netxen_config_intr_coalesce(adapter
);
810 static int netxen_get_intr_coalesce(struct net_device
*netdev
,
811 struct ethtool_coalesce
*ethcoal
)
813 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
815 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
818 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
821 ethcoal
->rx_coalesce_usecs
= adapter
->coal
.normal
.data
.rx_time_us
;
822 ethcoal
->tx_coalesce_usecs
= adapter
->coal
.normal
.data
.tx_time_us
;
823 ethcoal
->rx_max_coalesced_frames
=
824 adapter
->coal
.normal
.data
.rx_packets
;
825 ethcoal
->tx_max_coalesced_frames
=
826 adapter
->coal
.normal
.data
.tx_packets
;
832 netxen_get_dump_flag(struct net_device
*netdev
, struct ethtool_dump
*dump
)
834 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
835 struct netxen_minidump
*mdump
= &adapter
->mdump
;
836 if (adapter
->fw_mdump_rdy
)
837 dump
->len
= mdump
->md_dump_size
;
841 if (!mdump
->md_enabled
)
842 dump
->flag
= ETH_FW_DUMP_DISABLE
;
844 dump
->flag
= mdump
->md_capture_mask
;
846 dump
->version
= adapter
->fw_version
;
851 netxen_set_dump(struct net_device
*netdev
, struct ethtool_dump
*val
)
854 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
855 struct netxen_minidump
*mdump
= &adapter
->mdump
;
858 case NX_FORCE_FW_DUMP_KEY
:
859 if (!mdump
->md_enabled
) {
860 netdev_info(netdev
, "FW dump not enabled\n");
863 if (adapter
->fw_mdump_rdy
) {
864 netdev_info(netdev
, "Previous dump not cleared, not forcing dump\n");
867 netdev_info(netdev
, "Forcing a fw dump\n");
868 nx_dev_request_reset(adapter
);
870 case NX_DISABLE_FW_DUMP
:
871 if (mdump
->md_enabled
) {
872 netdev_info(netdev
, "Disabling FW Dump\n");
873 mdump
->md_enabled
= 0;
876 case NX_ENABLE_FW_DUMP
:
877 if (!mdump
->md_enabled
) {
878 netdev_info(netdev
, "Enabling FW dump\n");
879 mdump
->md_enabled
= 1;
882 case NX_FORCE_FW_RESET
:
883 netdev_info(netdev
, "Forcing FW reset\n");
884 nx_dev_request_reset(adapter
);
885 adapter
->flags
&= ~NETXEN_FW_RESET_OWNER
;
888 for (i
= 0; i
< ARRAY_SIZE(FW_DUMP_LEVELS
); i
++) {
889 if (val
->flag
== FW_DUMP_LEVELS
[i
]) {
890 mdump
->md_capture_mask
= val
->flag
;
892 "Driver mask changed to: 0x%x\n",
893 mdump
->md_capture_mask
);
898 "Invalid dump level: 0x%x\n", val
->flag
);
906 netxen_get_dump_data(struct net_device
*netdev
, struct ethtool_dump
*dump
,
911 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
912 struct netxen_minidump
*mdump
= &adapter
->mdump
;
915 if (!adapter
->fw_mdump_rdy
) {
916 netdev_info(netdev
, "Dump not available\n");
919 /* Copy template header first */
920 copy_sz
= mdump
->md_template_size
;
921 hdr_ptr
= (u32
*) mdump
->md_template
;
923 for (i
= 0; i
< copy_sz
/sizeof(u32
); i
++)
924 *data
++ = cpu_to_le32(*hdr_ptr
++);
926 /* Copy captured dump data */
927 memcpy(buffer
+ copy_sz
,
928 mdump
->md_capture_buff
+ mdump
->md_template_size
,
929 mdump
->md_capture_size
);
930 dump
->len
= copy_sz
+ mdump
->md_capture_size
;
931 dump
->flag
= mdump
->md_capture_mask
;
933 /* Free dump area once data has been captured */
934 vfree(mdump
->md_capture_buff
);
935 mdump
->md_capture_buff
= NULL
;
936 adapter
->fw_mdump_rdy
= 0;
937 netdev_info(netdev
, "extracted the fw dump Successfully\n");
941 const struct ethtool_ops netxen_nic_ethtool_ops
= {
942 .get_drvinfo
= netxen_nic_get_drvinfo
,
943 .get_regs_len
= netxen_nic_get_regs_len
,
944 .get_regs
= netxen_nic_get_regs
,
945 .get_link
= ethtool_op_get_link
,
946 .get_eeprom_len
= netxen_nic_get_eeprom_len
,
947 .get_eeprom
= netxen_nic_get_eeprom
,
948 .get_ringparam
= netxen_nic_get_ringparam
,
949 .set_ringparam
= netxen_nic_set_ringparam
,
950 .get_pauseparam
= netxen_nic_get_pauseparam
,
951 .set_pauseparam
= netxen_nic_set_pauseparam
,
952 .get_wol
= netxen_nic_get_wol
,
953 .set_wol
= netxen_nic_set_wol
,
954 .self_test
= netxen_nic_diag_test
,
955 .get_strings
= netxen_nic_get_strings
,
956 .get_ethtool_stats
= netxen_nic_get_ethtool_stats
,
957 .get_sset_count
= netxen_get_sset_count
,
958 .get_coalesce
= netxen_get_intr_coalesce
,
959 .set_coalesce
= netxen_set_intr_coalesce
,
960 .get_dump_flag
= netxen_get_dump_flag
,
961 .get_dump_data
= netxen_get_dump_data
,
962 .set_dump
= netxen_set_dump
,
963 .get_link_ksettings
= netxen_nic_get_link_ksettings
,
964 .set_link_ksettings
= netxen_nic_set_link_ksettings
,