2 * Copyright (C) 2003 - 2006 NetXen, Inc.
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 LICENSE.
23 * Contact Information:
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
30 * ethtool support for netxen nic
34 #include <linux/types.h>
35 #include <linux/delay.h>
36 #include <asm/uaccess.h>
37 #include <linux/pci.h>
39 #include <linux/netdevice.h>
40 #include <linux/ethtool.h>
42 #include "netxen_nic.h"
43 #include "netxen_nic_hw.h"
44 #include "netxen_nic_phan_reg.h"
46 struct netxen_nic_stats
{
47 char stat_string
[ETH_GSTRING_LEN
];
52 #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
53 offsetof(struct netxen_adapter, m)
55 #define NETXEN_NIC_PORT_WINDOW 0x10000
56 #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
58 static const struct netxen_nic_stats netxen_nic_gstrings_stats
[] = {
59 {"rcvd_bad_skb", NETXEN_NIC_STAT(stats
.rcvdbadskb
)},
60 {"xmit_called", NETXEN_NIC_STAT(stats
.xmitcalled
)},
61 {"xmited_frames", NETXEN_NIC_STAT(stats
.xmitedframes
)},
62 {"xmit_finished", NETXEN_NIC_STAT(stats
.xmitfinished
)},
63 {"bad_skb_len", NETXEN_NIC_STAT(stats
.badskblen
)},
64 {"no_cmd_desc", NETXEN_NIC_STAT(stats
.nocmddescriptor
)},
65 {"polled", NETXEN_NIC_STAT(stats
.polled
)},
66 {"tx_dropped", NETXEN_NIC_STAT(stats
.txdropped
)},
67 {"csummed", NETXEN_NIC_STAT(stats
.csummed
)},
68 {"no_rcv", NETXEN_NIC_STAT(stats
.no_rcv
)},
69 {"rx_bytes", NETXEN_NIC_STAT(stats
.rxbytes
)},
70 {"tx_bytes", NETXEN_NIC_STAT(stats
.txbytes
)},
73 #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
75 static const char netxen_nic_gstrings_test
[][ETH_GSTRING_LEN
] = {
76 "Register_Test_on_offline",
77 "Link_Test_on_offline"
80 #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
82 #define NETXEN_NIC_REGS_COUNT 42
83 #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
84 #define NETXEN_MAX_EEPROM_LEN 1024
86 static int netxen_nic_get_eeprom_len(struct net_device
*dev
)
88 return NETXEN_FLASH_TOTAL_SIZE
;
92 netxen_nic_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*drvinfo
)
94 struct netxen_adapter
*adapter
= netdev_priv(dev
);
100 strncpy(drvinfo
->driver
, netxen_nic_driver_name
, 32);
101 strncpy(drvinfo
->version
, NETXEN_NIC_LINUX_VERSIONID
, 32);
102 write_lock_irqsave(&adapter
->adapter_lock
, flags
);
103 fw_major
= adapter
->pci_read_normalize(adapter
,
104 NETXEN_FW_VERSION_MAJOR
);
105 fw_minor
= adapter
->pci_read_normalize(adapter
,
106 NETXEN_FW_VERSION_MINOR
);
107 fw_build
= adapter
->pci_read_normalize(adapter
,
108 NETXEN_FW_VERSION_SUB
);
109 write_unlock_irqrestore(&adapter
->adapter_lock
, flags
);
110 sprintf(drvinfo
->fw_version
, "%d.%d.%d", fw_major
, fw_minor
, fw_build
);
112 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
113 drvinfo
->regdump_len
= NETXEN_NIC_REGS_LEN
;
114 drvinfo
->eedump_len
= netxen_nic_get_eeprom_len(dev
);
118 netxen_nic_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
120 struct netxen_adapter
*adapter
= netdev_priv(dev
);
121 struct netxen_board_info
*boardinfo
= &adapter
->ahw
.boardcfg
;
123 /* read which mode */
124 if (adapter
->ahw
.board_type
== NETXEN_NIC_GBE
) {
125 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
126 SUPPORTED_10baseT_Full
|
127 SUPPORTED_100baseT_Half
|
128 SUPPORTED_100baseT_Full
|
129 SUPPORTED_1000baseT_Half
|
130 SUPPORTED_1000baseT_Full
);
132 ecmd
->advertising
= (ADVERTISED_100baseT_Half
|
133 ADVERTISED_100baseT_Full
|
134 ADVERTISED_1000baseT_Half
|
135 ADVERTISED_1000baseT_Full
);
137 ecmd
->port
= PORT_TP
;
139 ecmd
->speed
= adapter
->link_speed
;
140 ecmd
->duplex
= adapter
->link_duplex
;
141 ecmd
->autoneg
= adapter
->link_autoneg
;
143 } else if (adapter
->ahw
.board_type
== NETXEN_NIC_XGBE
) {
146 adapter
->hw_read_wx(adapter
, NETXEN_PORT_MODE_ADDR
, &val
, 4);
147 if (val
== NETXEN_PORT_MODE_802_3_AP
) {
148 ecmd
->supported
= SUPPORTED_1000baseT_Full
;
149 ecmd
->advertising
= ADVERTISED_1000baseT_Full
;
151 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
152 ecmd
->advertising
= ADVERTISED_10000baseT_Full
;
155 ecmd
->port
= PORT_TP
;
157 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
158 u16 pcifn
= adapter
->ahw
.pci_func
;
160 adapter
->hw_read_wx(adapter
,
161 P3_LINK_SPEED_REG(pcifn
), &val
, 4);
162 ecmd
->speed
= P3_LINK_SPEED_MHZ
*
163 P3_LINK_SPEED_VAL(pcifn
, val
);
165 ecmd
->speed
= SPEED_10000
;
167 ecmd
->duplex
= DUPLEX_FULL
;
168 ecmd
->autoneg
= AUTONEG_DISABLE
;
172 ecmd
->phy_address
= adapter
->physical_port
;
173 ecmd
->transceiver
= XCVR_EXTERNAL
;
175 switch ((netxen_brdtype_t
) boardinfo
->board_type
) {
176 case NETXEN_BRDTYPE_P2_SB35_4G
:
177 case NETXEN_BRDTYPE_P2_SB31_2G
:
178 case NETXEN_BRDTYPE_P3_REF_QG
:
179 case NETXEN_BRDTYPE_P3_4_GB
:
180 case NETXEN_BRDTYPE_P3_4_GB_MM
:
182 ecmd
->supported
|= SUPPORTED_Autoneg
;
183 ecmd
->advertising
|= ADVERTISED_Autoneg
;
184 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
185 case NETXEN_BRDTYPE_P3_10G_CX4
:
186 case NETXEN_BRDTYPE_P3_10G_CX4_LP
:
187 case NETXEN_BRDTYPE_P3_10000_BASE_T
:
188 ecmd
->supported
|= SUPPORTED_TP
;
189 ecmd
->advertising
|= ADVERTISED_TP
;
190 ecmd
->port
= PORT_TP
;
191 ecmd
->autoneg
= (boardinfo
->board_type
==
192 NETXEN_BRDTYPE_P2_SB31_10G_CX4
) ?
193 (AUTONEG_DISABLE
) : (adapter
->link_autoneg
);
195 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
196 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
197 case NETXEN_BRDTYPE_P3_IMEZ
:
198 case NETXEN_BRDTYPE_P3_XG_LOM
:
199 case NETXEN_BRDTYPE_P3_HMEZ
:
200 ecmd
->supported
|= SUPPORTED_MII
;
201 ecmd
->advertising
|= ADVERTISED_MII
;
202 ecmd
->port
= PORT_FIBRE
;
203 ecmd
->autoneg
= AUTONEG_DISABLE
;
205 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS
:
206 case NETXEN_BRDTYPE_P3_10G_SFP_CT
:
207 case NETXEN_BRDTYPE_P3_10G_SFP_QT
:
208 ecmd
->advertising
|= ADVERTISED_TP
;
209 ecmd
->supported
|= SUPPORTED_TP
;
210 case NETXEN_BRDTYPE_P2_SB31_10G
:
211 case NETXEN_BRDTYPE_P3_10G_XFP
:
212 ecmd
->supported
|= SUPPORTED_FIBRE
;
213 ecmd
->advertising
|= ADVERTISED_FIBRE
;
214 ecmd
->port
= PORT_FIBRE
;
215 ecmd
->autoneg
= AUTONEG_DISABLE
;
217 case NETXEN_BRDTYPE_P3_10G_TP
:
218 if (adapter
->ahw
.board_type
== NETXEN_NIC_XGBE
) {
219 ecmd
->autoneg
= AUTONEG_DISABLE
;
220 ecmd
->supported
|= (SUPPORTED_FIBRE
| SUPPORTED_TP
);
222 (ADVERTISED_FIBRE
| ADVERTISED_TP
);
223 ecmd
->port
= PORT_FIBRE
;
225 ecmd
->autoneg
= AUTONEG_ENABLE
;
226 ecmd
->supported
|= (SUPPORTED_TP
|SUPPORTED_Autoneg
);
228 (ADVERTISED_TP
| ADVERTISED_Autoneg
);
229 ecmd
->port
= PORT_TP
;
233 printk(KERN_ERR
"netxen-nic: Unsupported board model %d\n",
234 (netxen_brdtype_t
) boardinfo
->board_type
);
242 netxen_nic_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
244 struct netxen_adapter
*adapter
= netdev_priv(dev
);
247 /* read which mode */
248 if (adapter
->ahw
.board_type
== NETXEN_NIC_GBE
) {
249 /* autonegotiation */
250 if (adapter
->phy_write
251 && adapter
->phy_write(adapter
,
252 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG
,
256 adapter
->link_autoneg
= ecmd
->autoneg
;
258 if (adapter
->phy_read
259 && adapter
->phy_read(adapter
,
260 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
265 switch (ecmd
->speed
) {
267 netxen_set_phy_speed(status
, 0);
270 netxen_set_phy_speed(status
, 1);
273 netxen_set_phy_speed(status
, 2);
276 /* set duplex mode */
277 if (ecmd
->duplex
== DUPLEX_HALF
)
278 netxen_clear_phy_duplex(status
);
279 if (ecmd
->duplex
== DUPLEX_FULL
)
280 netxen_set_phy_duplex(status
);
281 if (adapter
->phy_write
282 && adapter
->phy_write(adapter
,
283 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
284 *((int *)&status
)) != 0)
287 adapter
->link_speed
= ecmd
->speed
;
288 adapter
->link_duplex
= ecmd
->duplex
;
293 if (!netif_running(dev
))
296 dev
->netdev_ops
->ndo_stop(dev
);
297 return dev
->netdev_ops
->ndo_open(dev
);
300 static int netxen_nic_get_regs_len(struct net_device
*dev
)
302 return NETXEN_NIC_REGS_LEN
;
305 struct netxen_niu_regs
{
306 __u32 reg
[NETXEN_NIC_REGS_COUNT
];
309 static struct netxen_niu_regs niu_registers
[] = {
313 NETXEN_NIU_GB_SERDES_RESET
,
314 NETXEN_NIU_GB0_MII_MODE
,
315 NETXEN_NIU_GB1_MII_MODE
,
316 NETXEN_NIU_GB2_MII_MODE
,
317 NETXEN_NIU_GB3_MII_MODE
,
318 NETXEN_NIU_GB0_GMII_MODE
,
319 NETXEN_NIU_GB1_GMII_MODE
,
320 NETXEN_NIU_GB2_GMII_MODE
,
321 NETXEN_NIU_GB3_GMII_MODE
,
322 NETXEN_NIU_REMOTE_LOOPBACK
,
323 NETXEN_NIU_GB0_HALF_DUPLEX
,
324 NETXEN_NIU_GB1_HALF_DUPLEX
,
325 NETXEN_NIU_RESET_SYS_FIFOS
,
326 NETXEN_NIU_GB_CRC_DROP
,
327 NETXEN_NIU_GB_DROP_WRONGADDR
,
328 NETXEN_NIU_TEST_MUX_CTL
,
330 NETXEN_NIU_GB_MAC_CONFIG_0(0),
331 NETXEN_NIU_GB_MAC_CONFIG_1(0),
332 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
333 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
334 NETXEN_NIU_GB_TEST_REG(0),
335 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
336 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
337 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
338 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
339 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
340 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
341 NETXEN_NIU_GB_INTERFACE_CTRL(0),
342 NETXEN_NIU_GB_INTERFACE_STATUS(0),
343 NETXEN_NIU_GB_STATION_ADDR_0(0),
344 NETXEN_NIU_GB_STATION_ADDR_1(0),
351 NETXEN_NIU_XG_SINGLE_TERM
,
352 NETXEN_NIU_XG_DRIVE_HI
,
353 NETXEN_NIU_XG_DRIVE_LO
,
356 NETXEN_NIU_XG_WORD_ALIGN
,
358 NETXEN_NIU_XG_POWER_DOWN
,
359 NETXEN_NIU_XG_RESET_PLL
,
360 NETXEN_NIU_XG_SERDES_LOOPBACK
,
361 NETXEN_NIU_XG_DO_BYTE_ALIGN
,
362 NETXEN_NIU_XG_TX_ENABLE
,
363 NETXEN_NIU_XG_RX_ENABLE
,
364 NETXEN_NIU_XG_STATUS
,
365 NETXEN_NIU_XG_PAUSE_THRESHOLD
,
366 NETXEN_NIU_XGE_CONFIG_0
,
367 NETXEN_NIU_XGE_CONFIG_1
,
369 NETXEN_NIU_XGE_STATION_ADDR_0_HI
,
370 NETXEN_NIU_XGE_STATION_ADDR_0_1
,
371 NETXEN_NIU_XGE_STATION_ADDR_1_LO
,
372 NETXEN_NIU_XGE_STATUS
,
373 NETXEN_NIU_XGE_MAX_FRAME_SIZE
,
374 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE
,
375 NETXEN_NIU_XGE_TX_BYTE_CNT
,
376 NETXEN_NIU_XGE_TX_FRAME_CNT
,
377 NETXEN_NIU_XGE_RX_BYTE_CNT
,
378 NETXEN_NIU_XGE_RX_FRAME_CNT
,
379 NETXEN_NIU_XGE_AGGR_ERROR_CNT
,
380 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT
,
381 NETXEN_NIU_XGE_UNICAST_FRAME_CNT
,
382 NETXEN_NIU_XGE_CRC_ERROR_CNT
,
383 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR
,
384 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR
,
385 NETXEN_NIU_XGE_LOCAL_ERROR_CNT
,
386 NETXEN_NIU_XGE_REMOTE_ERROR_CNT
,
387 NETXEN_NIU_XGE_CONTROL_CHAR_CNT
,
388 NETXEN_NIU_XGE_PAUSE_FRAME_CNT
,
395 netxen_nic_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *p
)
397 struct netxen_adapter
*adapter
= netdev_priv(dev
);
398 __u32 mode
, *regs_buff
= p
;
401 memset(p
, 0, NETXEN_NIC_REGS_LEN
);
402 regs
->version
= (1 << 24) | (adapter
->ahw
.revision_id
<< 16) |
403 (adapter
->pdev
)->device
;
405 adapter
->hw_read_wx(adapter
, NETXEN_NIU_MODE
, ®s_buff
[0], 4);
408 /* Common registers to all the modes */
409 adapter
->hw_read_wx(adapter
,
410 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER
, ®s_buff
[2], 4);
412 mode
= (mode
/ 2) - 1;
415 for (i
= 3; niu_registers
[mode
].reg
[i
- 3] != -1; i
++) {
416 /* GB: port specific registers */
417 if (mode
== 0 && i
>= 19)
418 window
= adapter
->physical_port
*
419 NETXEN_NIC_PORT_WINDOW
;
421 adapter
->hw_read_wx(adapter
,
422 niu_registers
[mode
].reg
[i
- 3] + window
,
429 static u32
netxen_nic_test_link(struct net_device
*dev
)
431 struct netxen_adapter
*adapter
= netdev_priv(dev
);
435 /* read which mode */
436 if (adapter
->ahw
.board_type
== NETXEN_NIC_GBE
) {
437 if (adapter
->phy_read
438 && adapter
->phy_read(adapter
,
439 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
443 val
= netxen_get_phy_link(status
);
446 } else if (adapter
->ahw
.board_type
== NETXEN_NIC_XGBE
) {
447 val
= adapter
->pci_read_normalize(adapter
, CRB_XG_STATE
);
448 return (val
== XG_LINK_UP
) ? 0 : 1;
454 netxen_nic_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
457 struct netxen_adapter
*adapter
= netdev_priv(dev
);
461 if (eeprom
->len
== 0)
464 eeprom
->magic
= (adapter
->pdev
)->vendor
|
465 ((adapter
->pdev
)->device
<< 16);
466 offset
= eeprom
->offset
;
468 ret
= netxen_rom_fast_read_words(adapter
, offset
, bytes
,
477 netxen_nic_get_ringparam(struct net_device
*dev
, struct ethtool_ringparam
*ring
)
479 struct netxen_adapter
*adapter
= netdev_priv(dev
);
482 ring
->rx_pending
= 0;
483 ring
->rx_jumbo_pending
= 0;
484 for (i
= 0; i
< MAX_RCV_CTX
; ++i
) {
485 ring
->rx_pending
+= adapter
->recv_ctx
[i
].
486 rds_rings
[RCV_DESC_NORMAL_CTXID
].max_rx_desc_count
;
487 ring
->rx_jumbo_pending
+= adapter
->recv_ctx
[i
].
488 rds_rings
[RCV_DESC_JUMBO_CTXID
].max_rx_desc_count
;
490 ring
->tx_pending
= adapter
->max_tx_desc_count
;
492 if (adapter
->ahw
.board_type
== NETXEN_NIC_GBE
)
493 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_1G
;
495 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_10G
;
496 ring
->tx_max_pending
= MAX_CMD_DESCRIPTORS_HOST
;
497 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS
;
498 ring
->rx_mini_max_pending
= 0;
499 ring
->rx_mini_pending
= 0;
503 netxen_nic_get_pauseparam(struct net_device
*dev
,
504 struct ethtool_pauseparam
*pause
)
506 struct netxen_adapter
*adapter
= netdev_priv(dev
);
508 int port
= adapter
->physical_port
;
510 if (adapter
->ahw
.board_type
== NETXEN_NIC_GBE
) {
511 if ((port
< 0) || (port
> NETXEN_NIU_MAX_GBE_PORTS
))
513 /* get flow control settings */
514 netxen_nic_read_w0(adapter
,NETXEN_NIU_GB_MAC_CONFIG_0(port
),
516 pause
->rx_pause
= netxen_gb_get_rx_flowctl(val
);
517 netxen_nic_read_w0(adapter
, NETXEN_NIU_GB_PAUSE_CTL
, &val
);
520 pause
->tx_pause
= !(netxen_gb_get_gb0_mask(val
));
523 pause
->tx_pause
= !(netxen_gb_get_gb1_mask(val
));
526 pause
->tx_pause
= !(netxen_gb_get_gb2_mask(val
));
530 pause
->tx_pause
= !(netxen_gb_get_gb3_mask(val
));
533 } else if (adapter
->ahw
.board_type
== NETXEN_NIC_XGBE
) {
534 if ((port
< 0) || (port
> NETXEN_NIU_MAX_XG_PORTS
))
537 netxen_nic_read_w0(adapter
, NETXEN_NIU_XG_PAUSE_CTL
, &val
);
539 pause
->tx_pause
= !(netxen_xg_get_xg0_mask(val
));
541 pause
->tx_pause
= !(netxen_xg_get_xg1_mask(val
));
543 printk(KERN_ERR
"%s: Unknown board type: %x\n",
544 netxen_nic_driver_name
, adapter
->ahw
.board_type
);
549 netxen_nic_set_pauseparam(struct net_device
*dev
,
550 struct ethtool_pauseparam
*pause
)
552 struct netxen_adapter
*adapter
= netdev_priv(dev
);
554 int port
= adapter
->physical_port
;
556 if (adapter
->ahw
.board_type
== NETXEN_NIC_GBE
) {
557 if ((port
< 0) || (port
> NETXEN_NIU_MAX_GBE_PORTS
))
559 /* set flow control */
560 netxen_nic_read_w0(adapter
,
561 NETXEN_NIU_GB_MAC_CONFIG_0(port
), &val
);
564 netxen_gb_rx_flowctl(val
);
566 netxen_gb_unset_rx_flowctl(val
);
568 netxen_nic_write_w0(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
),
571 netxen_nic_read_w0(adapter
, NETXEN_NIU_GB_PAUSE_CTL
, &val
);
575 netxen_gb_unset_gb0_mask(val
);
577 netxen_gb_set_gb0_mask(val
);
581 netxen_gb_unset_gb1_mask(val
);
583 netxen_gb_set_gb1_mask(val
);
587 netxen_gb_unset_gb2_mask(val
);
589 netxen_gb_set_gb2_mask(val
);
594 netxen_gb_unset_gb3_mask(val
);
596 netxen_gb_set_gb3_mask(val
);
599 netxen_nic_write_w0(adapter
, NETXEN_NIU_GB_PAUSE_CTL
, val
);
600 } else if (adapter
->ahw
.board_type
== NETXEN_NIC_XGBE
) {
601 if ((port
< 0) || (port
> NETXEN_NIU_MAX_XG_PORTS
))
603 netxen_nic_read_w0(adapter
, NETXEN_NIU_XG_PAUSE_CTL
, &val
);
606 netxen_xg_unset_xg0_mask(val
);
608 netxen_xg_set_xg0_mask(val
);
611 netxen_xg_unset_xg1_mask(val
);
613 netxen_xg_set_xg1_mask(val
);
615 netxen_nic_write_w0(adapter
, NETXEN_NIU_XG_PAUSE_CTL
, val
);
617 printk(KERN_ERR
"%s: Unknown board type: %x\n",
618 netxen_nic_driver_name
,
619 adapter
->ahw
.board_type
);
624 static int netxen_nic_reg_test(struct net_device
*dev
)
626 struct netxen_adapter
*adapter
= netdev_priv(dev
);
627 u32 data_read
, data_written
;
629 netxen_nic_read_w0(adapter
, NETXEN_PCIX_PH_REG(0), &data_read
);
630 if ((data_read
& 0xffff) != PHAN_VENDOR_ID
)
633 data_written
= (u32
)0xa5a5a5a5;
635 netxen_nic_reg_write(adapter
, CRB_SCRATCHPAD_TEST
, data_written
);
636 data_read
= adapter
->pci_read_normalize(adapter
, CRB_SCRATCHPAD_TEST
);
637 if (data_written
!= data_read
)
643 static int netxen_get_sset_count(struct net_device
*dev
, int sset
)
647 return NETXEN_NIC_TEST_LEN
;
649 return NETXEN_NIC_STATS_LEN
;
656 netxen_nic_diag_test(struct net_device
*dev
, struct ethtool_test
*eth_test
,
659 memset(data
, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN
);
660 if ((data
[0] = netxen_nic_reg_test(dev
)))
661 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
663 if ((data
[1] = (u64
) netxen_nic_test_link(dev
)))
664 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
668 netxen_nic_get_strings(struct net_device
*dev
, u32 stringset
, u8
* data
)
674 memcpy(data
, *netxen_nic_gstrings_test
,
675 NETXEN_NIC_TEST_LEN
* ETH_GSTRING_LEN
);
678 for (index
= 0; index
< NETXEN_NIC_STATS_LEN
; index
++) {
679 memcpy(data
+ index
* ETH_GSTRING_LEN
,
680 netxen_nic_gstrings_stats
[index
].stat_string
,
688 netxen_nic_get_ethtool_stats(struct net_device
*dev
,
689 struct ethtool_stats
*stats
, u64
* data
)
691 struct netxen_adapter
*adapter
= netdev_priv(dev
);
694 for (index
= 0; index
< NETXEN_NIC_STATS_LEN
; index
++) {
697 netxen_nic_gstrings_stats
[index
].stat_offset
;
699 (netxen_nic_gstrings_stats
[index
].sizeof_stat
==
700 sizeof(u64
)) ? *(u64
*) p
: *(u32
*) p
;
704 static u32
netxen_nic_get_rx_csum(struct net_device
*dev
)
706 struct netxen_adapter
*adapter
= netdev_priv(dev
);
707 return adapter
->rx_csum
;
710 static int netxen_nic_set_rx_csum(struct net_device
*dev
, u32 data
)
712 struct netxen_adapter
*adapter
= netdev_priv(dev
);
713 adapter
->rx_csum
= !!data
;
717 static u32
netxen_nic_get_tso(struct net_device
*dev
)
719 struct netxen_adapter
*adapter
= netdev_priv(dev
);
721 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
722 return (dev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) != 0;
724 return (dev
->features
& NETIF_F_TSO
) != 0;
727 static int netxen_nic_set_tso(struct net_device
*dev
, u32 data
)
730 struct netxen_adapter
*adapter
= netdev_priv(dev
);
732 dev
->features
|= NETIF_F_TSO
;
733 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
734 dev
->features
|= NETIF_F_TSO6
;
736 dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_TSO6
);
742 netxen_nic_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
744 struct netxen_adapter
*adapter
= netdev_priv(dev
);
750 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
753 wol_cfg
= netxen_nic_reg_read(adapter
, NETXEN_WOL_CONFIG_NV
);
754 if (wol_cfg
& (1UL << adapter
->portnum
))
755 wol
->supported
|= WAKE_MAGIC
;
757 wol_cfg
= netxen_nic_reg_read(adapter
, NETXEN_WOL_CONFIG
);
758 if (wol_cfg
& (1UL << adapter
->portnum
))
759 wol
->wolopts
|= WAKE_MAGIC
;
763 netxen_nic_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
765 struct netxen_adapter
*adapter
= netdev_priv(dev
);
768 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
771 if (wol
->wolopts
& ~WAKE_MAGIC
)
774 wol_cfg
= netxen_nic_reg_read(adapter
, NETXEN_WOL_CONFIG_NV
);
775 if (!(wol_cfg
& (1 << adapter
->portnum
)))
778 wol_cfg
= netxen_nic_reg_read(adapter
, NETXEN_WOL_CONFIG
);
779 if (wol
->wolopts
& WAKE_MAGIC
)
780 wol_cfg
|= 1UL << adapter
->portnum
;
782 wol_cfg
&= ~(1UL << adapter
->portnum
);
783 netxen_nic_reg_write(adapter
, NETXEN_WOL_CONFIG
, wol_cfg
);
789 * Set the coalescing parameters. Currently only normal is supported.
790 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
791 * firmware coalescing to default.
793 static int netxen_set_intr_coalesce(struct net_device
*netdev
,
794 struct ethtool_coalesce
*ethcoal
)
796 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
798 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
801 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
805 * Return Error if unsupported values or
806 * unsupported parameters are set.
808 if (ethcoal
->rx_coalesce_usecs
> 0xffff ||
809 ethcoal
->rx_max_coalesced_frames
> 0xffff ||
810 ethcoal
->tx_coalesce_usecs
> 0xffff ||
811 ethcoal
->tx_max_coalesced_frames
> 0xffff ||
812 ethcoal
->rx_coalesce_usecs_irq
||
813 ethcoal
->rx_max_coalesced_frames_irq
||
814 ethcoal
->tx_coalesce_usecs_irq
||
815 ethcoal
->tx_max_coalesced_frames_irq
||
816 ethcoal
->stats_block_coalesce_usecs
||
817 ethcoal
->use_adaptive_rx_coalesce
||
818 ethcoal
->use_adaptive_tx_coalesce
||
819 ethcoal
->pkt_rate_low
||
820 ethcoal
->rx_coalesce_usecs_low
||
821 ethcoal
->rx_max_coalesced_frames_low
||
822 ethcoal
->tx_coalesce_usecs_low
||
823 ethcoal
->tx_max_coalesced_frames_low
||
824 ethcoal
->pkt_rate_high
||
825 ethcoal
->rx_coalesce_usecs_high
||
826 ethcoal
->rx_max_coalesced_frames_high
||
827 ethcoal
->tx_coalesce_usecs_high
||
828 ethcoal
->tx_max_coalesced_frames_high
)
831 if (!ethcoal
->rx_coalesce_usecs
||
832 !ethcoal
->rx_max_coalesced_frames
) {
833 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
834 adapter
->coal
.normal
.data
.rx_time_us
=
835 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
836 adapter
->coal
.normal
.data
.rx_packets
=
837 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
839 adapter
->coal
.flags
= 0;
840 adapter
->coal
.normal
.data
.rx_time_us
=
841 ethcoal
->rx_coalesce_usecs
;
842 adapter
->coal
.normal
.data
.rx_packets
=
843 ethcoal
->rx_max_coalesced_frames
;
845 adapter
->coal
.normal
.data
.tx_time_us
= ethcoal
->tx_coalesce_usecs
;
846 adapter
->coal
.normal
.data
.tx_packets
=
847 ethcoal
->tx_max_coalesced_frames
;
849 netxen_config_intr_coalesce(adapter
);
854 static int netxen_get_intr_coalesce(struct net_device
*netdev
,
855 struct ethtool_coalesce
*ethcoal
)
857 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
859 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
862 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
865 ethcoal
->rx_coalesce_usecs
= adapter
->coal
.normal
.data
.rx_time_us
;
866 ethcoal
->tx_coalesce_usecs
= adapter
->coal
.normal
.data
.tx_time_us
;
867 ethcoal
->rx_max_coalesced_frames
=
868 adapter
->coal
.normal
.data
.rx_packets
;
869 ethcoal
->tx_max_coalesced_frames
=
870 adapter
->coal
.normal
.data
.tx_packets
;
875 struct ethtool_ops netxen_nic_ethtool_ops
= {
876 .get_settings
= netxen_nic_get_settings
,
877 .set_settings
= netxen_nic_set_settings
,
878 .get_drvinfo
= netxen_nic_get_drvinfo
,
879 .get_regs_len
= netxen_nic_get_regs_len
,
880 .get_regs
= netxen_nic_get_regs
,
881 .get_link
= ethtool_op_get_link
,
882 .get_eeprom_len
= netxen_nic_get_eeprom_len
,
883 .get_eeprom
= netxen_nic_get_eeprom
,
884 .get_ringparam
= netxen_nic_get_ringparam
,
885 .get_pauseparam
= netxen_nic_get_pauseparam
,
886 .set_pauseparam
= netxen_nic_set_pauseparam
,
887 .set_tx_csum
= ethtool_op_set_tx_csum
,
888 .set_sg
= ethtool_op_set_sg
,
889 .get_tso
= netxen_nic_get_tso
,
890 .set_tso
= netxen_nic_set_tso
,
891 .get_wol
= netxen_nic_get_wol
,
892 .set_wol
= netxen_nic_set_wol
,
893 .self_test
= netxen_nic_diag_test
,
894 .get_strings
= netxen_nic_get_strings
,
895 .get_ethtool_stats
= netxen_nic_get_ethtool_stats
,
896 .get_sset_count
= netxen_get_sset_count
,
897 .get_rx_csum
= netxen_nic_get_rx_csum
,
898 .set_rx_csum
= netxen_nic_set_rx_csum
,
899 .get_coalesce
= netxen_get_intr_coalesce
,
900 .set_coalesce
= netxen_set_intr_coalesce
,