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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21 * The full GNU General Public License is included in this distribution
22 * in the file called "COPYING".
26 #include <linux/types.h>
27 #include <linux/delay.h>
28 #include <linux/pci.h>
30 #include <linux/netdevice.h>
31 #include <linux/ethtool.h>
33 #include "netxen_nic.h"
34 #include "netxen_nic_hw.h"
36 struct netxen_nic_stats
{
37 char stat_string
[ETH_GSTRING_LEN
];
42 #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
43 offsetof(struct netxen_adapter, m)
45 #define NETXEN_NIC_PORT_WINDOW 0x10000
46 #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
48 static const struct netxen_nic_stats netxen_nic_gstrings_stats
[] = {
49 {"xmit_called", NETXEN_NIC_STAT(stats
.xmitcalled
)},
50 {"xmit_finished", NETXEN_NIC_STAT(stats
.xmitfinished
)},
51 {"rx_dropped", NETXEN_NIC_STAT(stats
.rxdropped
)},
52 {"tx_dropped", NETXEN_NIC_STAT(stats
.txdropped
)},
53 {"csummed", NETXEN_NIC_STAT(stats
.csummed
)},
54 {"rx_pkts", NETXEN_NIC_STAT(stats
.rx_pkts
)},
55 {"lro_pkts", NETXEN_NIC_STAT(stats
.lro_pkts
)},
56 {"rx_bytes", NETXEN_NIC_STAT(stats
.rxbytes
)},
57 {"tx_bytes", NETXEN_NIC_STAT(stats
.txbytes
)},
60 #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
62 static const char netxen_nic_gstrings_test
[][ETH_GSTRING_LEN
] = {
63 "Register_Test_on_offline",
64 "Link_Test_on_offline"
67 #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
69 #define NETXEN_NIC_REGS_COUNT 30
70 #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
71 #define NETXEN_MAX_EEPROM_LEN 1024
73 static int netxen_nic_get_eeprom_len(struct net_device
*dev
)
75 return NETXEN_FLASH_TOTAL_SIZE
;
79 netxen_nic_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*drvinfo
)
81 struct netxen_adapter
*adapter
= netdev_priv(dev
);
86 strncpy(drvinfo
->driver
, netxen_nic_driver_name
, 32);
87 strncpy(drvinfo
->version
, NETXEN_NIC_LINUX_VERSIONID
, 32);
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 sprintf(drvinfo
->fw_version
, "%d.%d.%d", fw_major
, fw_minor
, fw_build
);
93 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
94 drvinfo
->regdump_len
= NETXEN_NIC_REGS_LEN
;
95 drvinfo
->eedump_len
= netxen_nic_get_eeprom_len(dev
);
99 netxen_nic_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
101 struct netxen_adapter
*adapter
= netdev_priv(dev
);
102 int check_sfp_module
= 0;
104 /* read which mode */
105 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
106 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
107 SUPPORTED_10baseT_Full
|
108 SUPPORTED_100baseT_Half
|
109 SUPPORTED_100baseT_Full
|
110 SUPPORTED_1000baseT_Half
|
111 SUPPORTED_1000baseT_Full
);
113 ecmd
->advertising
= (ADVERTISED_100baseT_Half
|
114 ADVERTISED_100baseT_Full
|
115 ADVERTISED_1000baseT_Half
|
116 ADVERTISED_1000baseT_Full
);
118 ecmd
->port
= PORT_TP
;
120 ecmd
->speed
= adapter
->link_speed
;
121 ecmd
->duplex
= adapter
->link_duplex
;
122 ecmd
->autoneg
= adapter
->link_autoneg
;
124 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
127 val
= NXRD32(adapter
, NETXEN_PORT_MODE_ADDR
);
128 if (val
== NETXEN_PORT_MODE_802_3_AP
) {
129 ecmd
->supported
= SUPPORTED_1000baseT_Full
;
130 ecmd
->advertising
= ADVERTISED_1000baseT_Full
;
132 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
133 ecmd
->advertising
= ADVERTISED_10000baseT_Full
;
136 if (netif_running(dev
) && adapter
->has_link_events
) {
137 ecmd
->speed
= adapter
->link_speed
;
138 ecmd
->autoneg
= adapter
->link_autoneg
;
139 ecmd
->duplex
= adapter
->link_duplex
;
143 ecmd
->port
= PORT_TP
;
145 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
146 u16 pcifn
= adapter
->ahw
.pci_func
;
148 val
= NXRD32(adapter
, P3_LINK_SPEED_REG(pcifn
));
149 ecmd
->speed
= P3_LINK_SPEED_MHZ
*
150 P3_LINK_SPEED_VAL(pcifn
, val
);
152 ecmd
->speed
= SPEED_10000
;
154 ecmd
->duplex
= DUPLEX_FULL
;
155 ecmd
->autoneg
= AUTONEG_DISABLE
;
160 ecmd
->phy_address
= adapter
->physical_port
;
161 ecmd
->transceiver
= XCVR_EXTERNAL
;
163 switch (adapter
->ahw
.board_type
) {
164 case NETXEN_BRDTYPE_P2_SB35_4G
:
165 case NETXEN_BRDTYPE_P2_SB31_2G
:
166 case NETXEN_BRDTYPE_P3_REF_QG
:
167 case NETXEN_BRDTYPE_P3_4_GB
:
168 case NETXEN_BRDTYPE_P3_4_GB_MM
:
170 ecmd
->supported
|= SUPPORTED_Autoneg
;
171 ecmd
->advertising
|= ADVERTISED_Autoneg
;
172 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
173 case NETXEN_BRDTYPE_P3_10G_CX4
:
174 case NETXEN_BRDTYPE_P3_10G_CX4_LP
:
175 case NETXEN_BRDTYPE_P3_10000_BASE_T
:
176 ecmd
->supported
|= SUPPORTED_TP
;
177 ecmd
->advertising
|= ADVERTISED_TP
;
178 ecmd
->port
= PORT_TP
;
179 ecmd
->autoneg
= (adapter
->ahw
.board_type
==
180 NETXEN_BRDTYPE_P2_SB31_10G_CX4
) ?
181 (AUTONEG_DISABLE
) : (adapter
->link_autoneg
);
183 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
184 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
185 case NETXEN_BRDTYPE_P3_IMEZ
:
186 case NETXEN_BRDTYPE_P3_XG_LOM
:
187 case NETXEN_BRDTYPE_P3_HMEZ
:
188 ecmd
->supported
|= SUPPORTED_MII
;
189 ecmd
->advertising
|= ADVERTISED_MII
;
190 ecmd
->port
= PORT_MII
;
191 ecmd
->autoneg
= AUTONEG_DISABLE
;
193 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS
:
194 case NETXEN_BRDTYPE_P3_10G_SFP_CT
:
195 case NETXEN_BRDTYPE_P3_10G_SFP_QT
:
196 ecmd
->advertising
|= ADVERTISED_TP
;
197 ecmd
->supported
|= SUPPORTED_TP
;
198 check_sfp_module
= netif_running(dev
) &&
199 adapter
->has_link_events
;
200 case NETXEN_BRDTYPE_P2_SB31_10G
:
201 case NETXEN_BRDTYPE_P3_10G_XFP
:
202 ecmd
->supported
|= SUPPORTED_FIBRE
;
203 ecmd
->advertising
|= ADVERTISED_FIBRE
;
204 ecmd
->port
= PORT_FIBRE
;
205 ecmd
->autoneg
= AUTONEG_DISABLE
;
207 case NETXEN_BRDTYPE_P3_10G_TP
:
208 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
209 ecmd
->autoneg
= AUTONEG_DISABLE
;
210 ecmd
->supported
|= (SUPPORTED_FIBRE
| SUPPORTED_TP
);
212 (ADVERTISED_FIBRE
| ADVERTISED_TP
);
213 ecmd
->port
= PORT_FIBRE
;
214 check_sfp_module
= netif_running(dev
) &&
215 adapter
->has_link_events
;
217 ecmd
->autoneg
= AUTONEG_ENABLE
;
218 ecmd
->supported
|= (SUPPORTED_TP
|SUPPORTED_Autoneg
);
220 (ADVERTISED_TP
| ADVERTISED_Autoneg
);
221 ecmd
->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 ecmd
->port
= PORT_FIBRE
;
238 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE
:
239 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN
:
240 case LINKEVENT_MODULE_TWINAX
:
241 ecmd
->port
= PORT_TP
;
252 netxen_nic_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
254 struct netxen_adapter
*adapter
= netdev_priv(dev
);
257 /* read which mode */
258 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
259 /* autonegotiation */
260 if (adapter
->phy_write
&&
261 adapter
->phy_write(adapter
,
262 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG
,
266 adapter
->link_autoneg
= ecmd
->autoneg
;
268 if (adapter
->phy_read
&&
269 adapter
->phy_read(adapter
,
270 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
275 switch (ecmd
->speed
) {
277 netxen_set_phy_speed(status
, 0);
280 netxen_set_phy_speed(status
, 1);
283 netxen_set_phy_speed(status
, 2);
286 /* set duplex mode */
287 if (ecmd
->duplex
== DUPLEX_HALF
)
288 netxen_clear_phy_duplex(status
);
289 if (ecmd
->duplex
== DUPLEX_FULL
)
290 netxen_set_phy_duplex(status
);
291 if (adapter
->phy_write
&&
292 adapter
->phy_write(adapter
,
293 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
294 *((int *)&status
)) != 0)
297 adapter
->link_speed
= ecmd
->speed
;
298 adapter
->link_duplex
= ecmd
->duplex
;
303 if (!netif_running(dev
))
306 dev
->netdev_ops
->ndo_stop(dev
);
307 return dev
->netdev_ops
->ndo_open(dev
);
310 static int netxen_nic_get_regs_len(struct net_device
*dev
)
312 return NETXEN_NIC_REGS_LEN
;
316 netxen_nic_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *p
)
318 struct netxen_adapter
*adapter
= netdev_priv(dev
);
319 struct netxen_recv_context
*recv_ctx
= &adapter
->recv_ctx
;
320 struct nx_host_sds_ring
*sds_ring
;
323 int port
= adapter
->physical_port
;
325 memset(p
, 0, NETXEN_NIC_REGS_LEN
);
327 regs
->version
= (1 << 24) | (adapter
->ahw
.revision_id
<< 16) |
328 (adapter
->pdev
)->device
;
330 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
333 regs_buff
[i
++] = NXRD32(adapter
, CRB_CMDPEG_STATE
);
334 regs_buff
[i
++] = NXRD32(adapter
, CRB_RCVPEG_STATE
);
335 regs_buff
[i
++] = NXRD32(adapter
, CRB_FW_CAPABILITIES_1
);
336 regs_buff
[i
++] = NXRDIO(adapter
, adapter
->crb_int_state_reg
);
337 regs_buff
[i
++] = NXRD32(adapter
, NX_CRB_DEV_REF_COUNT
);
338 regs_buff
[i
++] = NXRD32(adapter
, NX_CRB_DEV_STATE
);
339 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_PEG_ALIVE_COUNTER
);
340 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_PEG_HALT_STATUS1
);
341 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_PEG_HALT_STATUS2
);
343 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_0
+0x3c);
344 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_1
+0x3c);
345 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_2
+0x3c);
346 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_3
+0x3c);
348 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
350 regs_buff
[i
++] = NXRD32(adapter
, NETXEN_CRB_PEG_NET_4
+0x3c);
353 regs_buff
[i
++] = NXRD32(adapter
, CRB_XG_STATE_P3
);
354 regs_buff
[i
++] = le32_to_cpu(*(adapter
->tx_ring
->hw_consumer
));
359 regs_buff
[i
++] = NXRD32(adapter
,
360 NETXEN_NIU_XGE_CONFIG_0
+(0x10000*port
));
361 regs_buff
[i
++] = NXRD32(adapter
,
362 NETXEN_NIU_XGE_CONFIG_1
+(0x10000*port
));
364 regs_buff
[i
++] = NXRD32(adapter
, CRB_XG_STATE
);
365 regs_buff
[i
++] = NXRDIO(adapter
,
366 adapter
->tx_ring
->crb_cmd_consumer
);
369 regs_buff
[i
++] = NXRDIO(adapter
, adapter
->tx_ring
->crb_cmd_producer
);
371 regs_buff
[i
++] = NXRDIO(adapter
,
372 recv_ctx
->rds_rings
[0].crb_rcv_producer
);
373 regs_buff
[i
++] = NXRDIO(adapter
,
374 recv_ctx
->rds_rings
[1].crb_rcv_producer
);
376 regs_buff
[i
++] = adapter
->max_sds_rings
;
378 for (ring
= 0; ring
< adapter
->max_sds_rings
; ring
++) {
379 sds_ring
= &(recv_ctx
->sds_rings
[ring
]);
380 regs_buff
[i
++] = NXRDIO(adapter
,
381 sds_ring
->crb_sts_consumer
);
385 static u32
netxen_nic_test_link(struct net_device
*dev
)
387 struct netxen_adapter
*adapter
= netdev_priv(dev
);
390 port
= adapter
->physical_port
;
391 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
392 val
= NXRD32(adapter
, CRB_XG_STATE_P3
);
393 val
= XG_LINK_STATE_P3(adapter
->ahw
.pci_func
, val
);
394 return (val
== XG_LINK_UP_P3
) ? 0 : 1;
396 val
= NXRD32(adapter
, CRB_XG_STATE
);
397 val
= (val
>> port
*8) & 0xff;
398 return (val
== XG_LINK_UP
) ? 0 : 1;
403 netxen_nic_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
406 struct netxen_adapter
*adapter
= netdev_priv(dev
);
410 if (eeprom
->len
== 0)
413 eeprom
->magic
= (adapter
->pdev
)->vendor
|
414 ((adapter
->pdev
)->device
<< 16);
415 offset
= eeprom
->offset
;
417 ret
= netxen_rom_fast_read_words(adapter
, offset
, bytes
,
426 netxen_nic_get_ringparam(struct net_device
*dev
,
427 struct ethtool_ringparam
*ring
)
429 struct netxen_adapter
*adapter
= netdev_priv(dev
);
431 ring
->rx_pending
= adapter
->num_rxd
;
432 ring
->rx_jumbo_pending
= adapter
->num_jumbo_rxd
;
433 ring
->rx_jumbo_pending
+= adapter
->num_lro_rxd
;
434 ring
->tx_pending
= adapter
->num_txd
;
436 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
437 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_1G
;
438 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_1G
;
440 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_10G
;
441 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
444 ring
->tx_max_pending
= MAX_CMD_DESCRIPTORS
;
446 ring
->rx_mini_max_pending
= 0;
447 ring
->rx_mini_pending
= 0;
451 netxen_validate_ringparam(u32 val
, u32 min
, u32 max
, char *r_name
)
454 num_desc
= max(val
, min
);
455 num_desc
= min(num_desc
, max
);
456 num_desc
= roundup_pow_of_two(num_desc
);
458 if (val
!= num_desc
) {
459 printk(KERN_INFO
"%s: setting %s ring size %d instead of %d\n",
460 netxen_nic_driver_name
, r_name
, num_desc
, val
);
467 netxen_nic_set_ringparam(struct net_device
*dev
,
468 struct ethtool_ringparam
*ring
)
470 struct netxen_adapter
*adapter
= netdev_priv(dev
);
471 u16 max_rcv_desc
= MAX_RCV_DESCRIPTORS_10G
;
472 u16 max_jumbo_desc
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
473 u16 num_rxd
, num_jumbo_rxd
, num_txd
;
475 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
478 if (ring
->rx_mini_pending
)
481 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
482 max_rcv_desc
= MAX_RCV_DESCRIPTORS_1G
;
483 max_jumbo_desc
= MAX_JUMBO_RCV_DESCRIPTORS_10G
;
486 num_rxd
= netxen_validate_ringparam(ring
->rx_pending
,
487 MIN_RCV_DESCRIPTORS
, max_rcv_desc
, "rx");
489 num_jumbo_rxd
= netxen_validate_ringparam(ring
->rx_jumbo_pending
,
490 MIN_JUMBO_DESCRIPTORS
, max_jumbo_desc
, "rx jumbo");
492 num_txd
= netxen_validate_ringparam(ring
->tx_pending
,
493 MIN_CMD_DESCRIPTORS
, MAX_CMD_DESCRIPTORS
, "tx");
495 if (num_rxd
== adapter
->num_rxd
&& num_txd
== adapter
->num_txd
&&
496 num_jumbo_rxd
== adapter
->num_jumbo_rxd
)
499 adapter
->num_rxd
= num_rxd
;
500 adapter
->num_jumbo_rxd
= num_jumbo_rxd
;
501 adapter
->num_txd
= num_txd
;
503 return netxen_nic_reset_context(adapter
);
507 netxen_nic_get_pauseparam(struct net_device
*dev
,
508 struct ethtool_pauseparam
*pause
)
510 struct netxen_adapter
*adapter
= netdev_priv(dev
);
512 int port
= adapter
->physical_port
;
514 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
515 if ((port
< 0) || (port
> NETXEN_NIU_MAX_GBE_PORTS
))
517 /* get flow control settings */
518 val
= NXRD32(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
));
519 pause
->rx_pause
= netxen_gb_get_rx_flowctl(val
);
520 val
= NXRD32(adapter
, NETXEN_NIU_GB_PAUSE_CTL
);
523 pause
->tx_pause
= !(netxen_gb_get_gb0_mask(val
));
526 pause
->tx_pause
= !(netxen_gb_get_gb1_mask(val
));
529 pause
->tx_pause
= !(netxen_gb_get_gb2_mask(val
));
533 pause
->tx_pause
= !(netxen_gb_get_gb3_mask(val
));
536 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
537 if ((port
< 0) || (port
> NETXEN_NIU_MAX_XG_PORTS
))
540 val
= NXRD32(adapter
, NETXEN_NIU_XG_PAUSE_CTL
);
542 pause
->tx_pause
= !(netxen_xg_get_xg0_mask(val
));
544 pause
->tx_pause
= !(netxen_xg_get_xg1_mask(val
));
546 printk(KERN_ERR
"%s: Unknown board type: %x\n",
547 netxen_nic_driver_name
, adapter
->ahw
.port_type
);
552 netxen_nic_set_pauseparam(struct net_device
*dev
,
553 struct ethtool_pauseparam
*pause
)
555 struct netxen_adapter
*adapter
= netdev_priv(dev
);
557 int port
= adapter
->physical_port
;
559 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
560 if ((port
< 0) || (port
> NETXEN_NIU_MAX_GBE_PORTS
))
562 /* set flow control */
563 val
= NXRD32(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
));
566 netxen_gb_rx_flowctl(val
);
568 netxen_gb_unset_rx_flowctl(val
);
570 NXWR32(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
),
573 val
= NXRD32(adapter
, NETXEN_NIU_GB_PAUSE_CTL
);
577 netxen_gb_unset_gb0_mask(val
);
579 netxen_gb_set_gb0_mask(val
);
583 netxen_gb_unset_gb1_mask(val
);
585 netxen_gb_set_gb1_mask(val
);
589 netxen_gb_unset_gb2_mask(val
);
591 netxen_gb_set_gb2_mask(val
);
596 netxen_gb_unset_gb3_mask(val
);
598 netxen_gb_set_gb3_mask(val
);
601 NXWR32(adapter
, NETXEN_NIU_GB_PAUSE_CTL
, val
);
602 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
603 if ((port
< 0) || (port
> NETXEN_NIU_MAX_XG_PORTS
))
605 val
= NXRD32(adapter
, NETXEN_NIU_XG_PAUSE_CTL
);
608 netxen_xg_unset_xg0_mask(val
);
610 netxen_xg_set_xg0_mask(val
);
613 netxen_xg_unset_xg1_mask(val
);
615 netxen_xg_set_xg1_mask(val
);
617 NXWR32(adapter
, NETXEN_NIU_XG_PAUSE_CTL
, val
);
619 printk(KERN_ERR
"%s: Unknown board type: %x\n",
620 netxen_nic_driver_name
,
621 adapter
->ahw
.port_type
);
626 static int netxen_nic_reg_test(struct net_device
*dev
)
628 struct netxen_adapter
*adapter
= netdev_priv(dev
);
629 u32 data_read
, data_written
;
631 data_read
= NXRD32(adapter
, NETXEN_PCIX_PH_REG(0));
632 if ((data_read
& 0xffff) != adapter
->pdev
->vendor
)
635 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
638 data_written
= (u32
)0xa5a5a5a5;
640 NXWR32(adapter
, CRB_SCRATCHPAD_TEST
, data_written
);
641 data_read
= NXRD32(adapter
, CRB_SCRATCHPAD_TEST
);
642 if (data_written
!= data_read
)
648 static int netxen_get_sset_count(struct net_device
*dev
, int sset
)
652 return NETXEN_NIC_TEST_LEN
;
654 return NETXEN_NIC_STATS_LEN
;
661 netxen_nic_diag_test(struct net_device
*dev
, struct ethtool_test
*eth_test
,
664 memset(data
, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN
);
665 if ((data
[0] = netxen_nic_reg_test(dev
)))
666 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
668 if ((data
[1] = (u64
) netxen_nic_test_link(dev
)))
669 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
673 netxen_nic_get_strings(struct net_device
*dev
, u32 stringset
, u8
* data
)
679 memcpy(data
, *netxen_nic_gstrings_test
,
680 NETXEN_NIC_TEST_LEN
* ETH_GSTRING_LEN
);
683 for (index
= 0; index
< NETXEN_NIC_STATS_LEN
; index
++) {
684 memcpy(data
+ index
* ETH_GSTRING_LEN
,
685 netxen_nic_gstrings_stats
[index
].stat_string
,
693 netxen_nic_get_ethtool_stats(struct net_device
*dev
,
694 struct ethtool_stats
*stats
, u64
* data
)
696 struct netxen_adapter
*adapter
= netdev_priv(dev
);
699 for (index
= 0; index
< NETXEN_NIC_STATS_LEN
; index
++) {
702 netxen_nic_gstrings_stats
[index
].stat_offset
;
704 (netxen_nic_gstrings_stats
[index
].sizeof_stat
==
705 sizeof(u64
)) ? *(u64
*) p
: *(u32
*) p
;
709 static u32
netxen_nic_get_tx_csum(struct net_device
*dev
)
711 return dev
->features
& NETIF_F_IP_CSUM
;
714 static u32
netxen_nic_get_rx_csum(struct net_device
*dev
)
716 struct netxen_adapter
*adapter
= netdev_priv(dev
);
717 return adapter
->rx_csum
;
720 static int netxen_nic_set_rx_csum(struct net_device
*dev
, u32 data
)
722 struct netxen_adapter
*adapter
= netdev_priv(dev
);
725 adapter
->rx_csum
= data
;
729 if (dev
->features
& NETIF_F_LRO
) {
730 if (netxen_config_hw_lro(adapter
, NETXEN_NIC_LRO_DISABLED
))
733 dev
->features
&= ~NETIF_F_LRO
;
734 netxen_send_lro_cleanup(adapter
);
735 netdev_info(dev
, "disabling LRO as rx_csum is off\n");
737 adapter
->rx_csum
= data
;
741 static u32
netxen_nic_get_tso(struct net_device
*dev
)
743 struct netxen_adapter
*adapter
= netdev_priv(dev
);
745 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
746 return (dev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) != 0;
748 return (dev
->features
& NETIF_F_TSO
) != 0;
751 static int netxen_nic_set_tso(struct net_device
*dev
, u32 data
)
754 struct netxen_adapter
*adapter
= netdev_priv(dev
);
756 dev
->features
|= NETIF_F_TSO
;
757 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
758 dev
->features
|= NETIF_F_TSO6
;
760 dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_TSO6
);
766 netxen_nic_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
768 struct netxen_adapter
*adapter
= netdev_priv(dev
);
774 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
777 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG_NV
);
778 if (wol_cfg
& (1UL << adapter
->portnum
))
779 wol
->supported
|= WAKE_MAGIC
;
781 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG
);
782 if (wol_cfg
& (1UL << adapter
->portnum
))
783 wol
->wolopts
|= WAKE_MAGIC
;
787 netxen_nic_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
789 struct netxen_adapter
*adapter
= netdev_priv(dev
);
792 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
795 if (wol
->wolopts
& ~WAKE_MAGIC
)
798 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG_NV
);
799 if (!(wol_cfg
& (1 << adapter
->portnum
)))
802 wol_cfg
= NXRD32(adapter
, NETXEN_WOL_CONFIG
);
803 if (wol
->wolopts
& WAKE_MAGIC
)
804 wol_cfg
|= 1UL << adapter
->portnum
;
806 wol_cfg
&= ~(1UL << adapter
->portnum
);
807 NXWR32(adapter
, NETXEN_WOL_CONFIG
, wol_cfg
);
813 * Set the coalescing parameters. Currently only normal is supported.
814 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
815 * firmware coalescing to default.
817 static int netxen_set_intr_coalesce(struct net_device
*netdev
,
818 struct ethtool_coalesce
*ethcoal
)
820 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
822 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
825 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
829 * Return Error if unsupported values or
830 * unsupported parameters are set.
832 if (ethcoal
->rx_coalesce_usecs
> 0xffff ||
833 ethcoal
->rx_max_coalesced_frames
> 0xffff ||
834 ethcoal
->tx_coalesce_usecs
> 0xffff ||
835 ethcoal
->tx_max_coalesced_frames
> 0xffff ||
836 ethcoal
->rx_coalesce_usecs_irq
||
837 ethcoal
->rx_max_coalesced_frames_irq
||
838 ethcoal
->tx_coalesce_usecs_irq
||
839 ethcoal
->tx_max_coalesced_frames_irq
||
840 ethcoal
->stats_block_coalesce_usecs
||
841 ethcoal
->use_adaptive_rx_coalesce
||
842 ethcoal
->use_adaptive_tx_coalesce
||
843 ethcoal
->pkt_rate_low
||
844 ethcoal
->rx_coalesce_usecs_low
||
845 ethcoal
->rx_max_coalesced_frames_low
||
846 ethcoal
->tx_coalesce_usecs_low
||
847 ethcoal
->tx_max_coalesced_frames_low
||
848 ethcoal
->pkt_rate_high
||
849 ethcoal
->rx_coalesce_usecs_high
||
850 ethcoal
->rx_max_coalesced_frames_high
||
851 ethcoal
->tx_coalesce_usecs_high
||
852 ethcoal
->tx_max_coalesced_frames_high
)
855 if (!ethcoal
->rx_coalesce_usecs
||
856 !ethcoal
->rx_max_coalesced_frames
) {
857 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
858 adapter
->coal
.normal
.data
.rx_time_us
=
859 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
860 adapter
->coal
.normal
.data
.rx_packets
=
861 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
863 adapter
->coal
.flags
= 0;
864 adapter
->coal
.normal
.data
.rx_time_us
=
865 ethcoal
->rx_coalesce_usecs
;
866 adapter
->coal
.normal
.data
.rx_packets
=
867 ethcoal
->rx_max_coalesced_frames
;
869 adapter
->coal
.normal
.data
.tx_time_us
= ethcoal
->tx_coalesce_usecs
;
870 adapter
->coal
.normal
.data
.tx_packets
=
871 ethcoal
->tx_max_coalesced_frames
;
873 netxen_config_intr_coalesce(adapter
);
878 static int netxen_get_intr_coalesce(struct net_device
*netdev
,
879 struct ethtool_coalesce
*ethcoal
)
881 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
883 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
886 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
889 ethcoal
->rx_coalesce_usecs
= adapter
->coal
.normal
.data
.rx_time_us
;
890 ethcoal
->tx_coalesce_usecs
= adapter
->coal
.normal
.data
.tx_time_us
;
891 ethcoal
->rx_max_coalesced_frames
=
892 adapter
->coal
.normal
.data
.rx_packets
;
893 ethcoal
->tx_max_coalesced_frames
=
894 adapter
->coal
.normal
.data
.tx_packets
;
899 static int netxen_nic_set_flags(struct net_device
*netdev
, u32 data
)
901 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
904 if (data
& ~ETH_FLAG_LRO
)
907 if (!(adapter
->capabilities
& NX_FW_CAPABILITY_HW_LRO
))
910 if (!adapter
->rx_csum
) {
911 netdev_info(netdev
, "rx csum is off, cannot toggle LRO\n");
915 if (!!(data
& ETH_FLAG_LRO
) == !!(netdev
->features
& NETIF_F_LRO
))
918 if (data
& ETH_FLAG_LRO
) {
919 hw_lro
= NETXEN_NIC_LRO_ENABLED
;
920 netdev
->features
|= NETIF_F_LRO
;
922 hw_lro
= NETXEN_NIC_LRO_DISABLED
;
923 netdev
->features
&= ~NETIF_F_LRO
;
926 if (netxen_config_hw_lro(adapter
, hw_lro
))
929 if ((hw_lro
== 0) && netxen_send_lro_cleanup(adapter
))
936 const struct ethtool_ops netxen_nic_ethtool_ops
= {
937 .get_settings
= netxen_nic_get_settings
,
938 .set_settings
= netxen_nic_set_settings
,
939 .get_drvinfo
= netxen_nic_get_drvinfo
,
940 .get_regs_len
= netxen_nic_get_regs_len
,
941 .get_regs
= netxen_nic_get_regs
,
942 .get_link
= ethtool_op_get_link
,
943 .get_eeprom_len
= netxen_nic_get_eeprom_len
,
944 .get_eeprom
= netxen_nic_get_eeprom
,
945 .get_ringparam
= netxen_nic_get_ringparam
,
946 .set_ringparam
= netxen_nic_set_ringparam
,
947 .get_pauseparam
= netxen_nic_get_pauseparam
,
948 .set_pauseparam
= netxen_nic_set_pauseparam
,
949 .get_tx_csum
= netxen_nic_get_tx_csum
,
950 .set_tx_csum
= ethtool_op_set_tx_csum
,
951 .set_sg
= ethtool_op_set_sg
,
952 .get_tso
= netxen_nic_get_tso
,
953 .set_tso
= netxen_nic_set_tso
,
954 .get_wol
= netxen_nic_get_wol
,
955 .set_wol
= netxen_nic_set_wol
,
956 .self_test
= netxen_nic_diag_test
,
957 .get_strings
= netxen_nic_get_strings
,
958 .get_ethtool_stats
= netxen_nic_get_ethtool_stats
,
959 .get_sset_count
= netxen_get_sset_count
,
960 .get_rx_csum
= netxen_nic_get_rx_csum
,
961 .set_rx_csum
= netxen_nic_set_rx_csum
,
962 .get_coalesce
= netxen_get_intr_coalesce
,
963 .set_coalesce
= netxen_set_intr_coalesce
,
964 .get_flags
= ethtool_op_get_flags
,
965 .set_flags
= netxen_nic_set_flags
,