2 * Copyright (C) 2003 - 2009 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:
27 * Cupertino, CA 95014-0701
31 #include <linux/types.h>
32 #include <linux/delay.h>
33 #include <asm/uaccess.h>
34 #include <linux/pci.h>
36 #include <linux/netdevice.h>
37 #include <linux/ethtool.h>
39 #include "netxen_nic.h"
40 #include "netxen_nic_hw.h"
41 #include "netxen_nic_phan_reg.h"
43 struct netxen_nic_stats
{
44 char stat_string
[ETH_GSTRING_LEN
];
49 #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
50 offsetof(struct netxen_adapter, m)
52 #define NETXEN_NIC_PORT_WINDOW 0x10000
53 #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
55 static const struct netxen_nic_stats netxen_nic_gstrings_stats
[] = {
56 {"rcvd_bad_skb", NETXEN_NIC_STAT(stats
.rcvdbadskb
)},
57 {"xmit_called", NETXEN_NIC_STAT(stats
.xmitcalled
)},
58 {"xmited_frames", NETXEN_NIC_STAT(stats
.xmitedframes
)},
59 {"xmit_finished", NETXEN_NIC_STAT(stats
.xmitfinished
)},
60 {"bad_skb_len", NETXEN_NIC_STAT(stats
.badskblen
)},
61 {"no_cmd_desc", NETXEN_NIC_STAT(stats
.nocmddescriptor
)},
62 {"polled", NETXEN_NIC_STAT(stats
.polled
)},
63 {"tx_dropped", NETXEN_NIC_STAT(stats
.txdropped
)},
64 {"csummed", NETXEN_NIC_STAT(stats
.csummed
)},
65 {"no_rcv", NETXEN_NIC_STAT(stats
.no_rcv
)},
66 {"rx_bytes", NETXEN_NIC_STAT(stats
.rxbytes
)},
67 {"tx_bytes", NETXEN_NIC_STAT(stats
.txbytes
)},
70 #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
72 static const char netxen_nic_gstrings_test
[][ETH_GSTRING_LEN
] = {
73 "Register_Test_on_offline",
74 "Link_Test_on_offline"
77 #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
79 #define NETXEN_NIC_REGS_COUNT 42
80 #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
81 #define NETXEN_MAX_EEPROM_LEN 1024
83 static int netxen_nic_get_eeprom_len(struct net_device
*dev
)
85 return NETXEN_FLASH_TOTAL_SIZE
;
89 netxen_nic_get_drvinfo(struct net_device
*dev
, struct ethtool_drvinfo
*drvinfo
)
91 struct netxen_adapter
*adapter
= netdev_priv(dev
);
97 strncpy(drvinfo
->driver
, netxen_nic_driver_name
, 32);
98 strncpy(drvinfo
->version
, NETXEN_NIC_LINUX_VERSIONID
, 32);
99 write_lock_irqsave(&adapter
->adapter_lock
, flags
);
100 fw_major
= adapter
->pci_read_normalize(adapter
,
101 NETXEN_FW_VERSION_MAJOR
);
102 fw_minor
= adapter
->pci_read_normalize(adapter
,
103 NETXEN_FW_VERSION_MINOR
);
104 fw_build
= adapter
->pci_read_normalize(adapter
,
105 NETXEN_FW_VERSION_SUB
);
106 write_unlock_irqrestore(&adapter
->adapter_lock
, flags
);
107 sprintf(drvinfo
->fw_version
, "%d.%d.%d", fw_major
, fw_minor
, fw_build
);
109 strncpy(drvinfo
->bus_info
, pci_name(adapter
->pdev
), 32);
110 drvinfo
->regdump_len
= NETXEN_NIC_REGS_LEN
;
111 drvinfo
->eedump_len
= netxen_nic_get_eeprom_len(dev
);
115 netxen_nic_get_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
117 struct netxen_adapter
*adapter
= netdev_priv(dev
);
119 /* read which mode */
120 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
121 ecmd
->supported
= (SUPPORTED_10baseT_Half
|
122 SUPPORTED_10baseT_Full
|
123 SUPPORTED_100baseT_Half
|
124 SUPPORTED_100baseT_Full
|
125 SUPPORTED_1000baseT_Half
|
126 SUPPORTED_1000baseT_Full
);
128 ecmd
->advertising
= (ADVERTISED_100baseT_Half
|
129 ADVERTISED_100baseT_Full
|
130 ADVERTISED_1000baseT_Half
|
131 ADVERTISED_1000baseT_Full
);
133 ecmd
->port
= PORT_TP
;
135 ecmd
->speed
= adapter
->link_speed
;
136 ecmd
->duplex
= adapter
->link_duplex
;
137 ecmd
->autoneg
= adapter
->link_autoneg
;
139 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
142 adapter
->hw_read_wx(adapter
, NETXEN_PORT_MODE_ADDR
, &val
, 4);
143 if (val
== NETXEN_PORT_MODE_802_3_AP
) {
144 ecmd
->supported
= SUPPORTED_1000baseT_Full
;
145 ecmd
->advertising
= ADVERTISED_1000baseT_Full
;
147 ecmd
->supported
= SUPPORTED_10000baseT_Full
;
148 ecmd
->advertising
= ADVERTISED_10000baseT_Full
;
151 ecmd
->port
= PORT_TP
;
153 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
)) {
154 u16 pcifn
= adapter
->ahw
.pci_func
;
156 adapter
->hw_read_wx(adapter
,
157 P3_LINK_SPEED_REG(pcifn
), &val
, 4);
158 ecmd
->speed
= P3_LINK_SPEED_MHZ
*
159 P3_LINK_SPEED_VAL(pcifn
, val
);
161 ecmd
->speed
= SPEED_10000
;
163 ecmd
->duplex
= DUPLEX_FULL
;
164 ecmd
->autoneg
= AUTONEG_DISABLE
;
168 ecmd
->phy_address
= adapter
->physical_port
;
169 ecmd
->transceiver
= XCVR_EXTERNAL
;
171 switch ((netxen_brdtype_t
)adapter
->ahw
.board_type
) {
172 case NETXEN_BRDTYPE_P2_SB35_4G
:
173 case NETXEN_BRDTYPE_P2_SB31_2G
:
174 case NETXEN_BRDTYPE_P3_REF_QG
:
175 case NETXEN_BRDTYPE_P3_4_GB
:
176 case NETXEN_BRDTYPE_P3_4_GB_MM
:
178 ecmd
->supported
|= SUPPORTED_Autoneg
;
179 ecmd
->advertising
|= ADVERTISED_Autoneg
;
180 case NETXEN_BRDTYPE_P2_SB31_10G_CX4
:
181 case NETXEN_BRDTYPE_P3_10G_CX4
:
182 case NETXEN_BRDTYPE_P3_10G_CX4_LP
:
183 case NETXEN_BRDTYPE_P3_10000_BASE_T
:
184 ecmd
->supported
|= SUPPORTED_TP
;
185 ecmd
->advertising
|= ADVERTISED_TP
;
186 ecmd
->port
= PORT_TP
;
187 ecmd
->autoneg
= (adapter
->ahw
.board_type
==
188 NETXEN_BRDTYPE_P2_SB31_10G_CX4
) ?
189 (AUTONEG_DISABLE
) : (adapter
->link_autoneg
);
191 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ
:
192 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ
:
193 case NETXEN_BRDTYPE_P3_IMEZ
:
194 case NETXEN_BRDTYPE_P3_XG_LOM
:
195 case NETXEN_BRDTYPE_P3_HMEZ
:
196 ecmd
->supported
|= SUPPORTED_MII
;
197 ecmd
->advertising
|= ADVERTISED_MII
;
198 ecmd
->port
= PORT_FIBRE
;
199 ecmd
->autoneg
= AUTONEG_DISABLE
;
201 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS
:
202 case NETXEN_BRDTYPE_P3_10G_SFP_CT
:
203 case NETXEN_BRDTYPE_P3_10G_SFP_QT
:
204 ecmd
->advertising
|= ADVERTISED_TP
;
205 ecmd
->supported
|= SUPPORTED_TP
;
206 case NETXEN_BRDTYPE_P2_SB31_10G
:
207 case NETXEN_BRDTYPE_P3_10G_XFP
:
208 ecmd
->supported
|= SUPPORTED_FIBRE
;
209 ecmd
->advertising
|= ADVERTISED_FIBRE
;
210 ecmd
->port
= PORT_FIBRE
;
211 ecmd
->autoneg
= AUTONEG_DISABLE
;
213 case NETXEN_BRDTYPE_P3_10G_TP
:
214 if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
215 ecmd
->autoneg
= AUTONEG_DISABLE
;
216 ecmd
->supported
|= (SUPPORTED_FIBRE
| SUPPORTED_TP
);
218 (ADVERTISED_FIBRE
| ADVERTISED_TP
);
219 ecmd
->port
= PORT_FIBRE
;
221 ecmd
->autoneg
= AUTONEG_ENABLE
;
222 ecmd
->supported
|= (SUPPORTED_TP
|SUPPORTED_Autoneg
);
224 (ADVERTISED_TP
| ADVERTISED_Autoneg
);
225 ecmd
->port
= PORT_TP
;
229 printk(KERN_ERR
"netxen-nic: Unsupported board model %d\n",
230 (netxen_brdtype_t
)adapter
->ahw
.board_type
);
238 netxen_nic_set_settings(struct net_device
*dev
, struct ethtool_cmd
*ecmd
)
240 struct netxen_adapter
*adapter
= netdev_priv(dev
);
243 /* read which mode */
244 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
245 /* autonegotiation */
246 if (adapter
->phy_write
247 && adapter
->phy_write(adapter
,
248 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG
,
252 adapter
->link_autoneg
= ecmd
->autoneg
;
254 if (adapter
->phy_read
255 && adapter
->phy_read(adapter
,
256 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
261 switch (ecmd
->speed
) {
263 netxen_set_phy_speed(status
, 0);
266 netxen_set_phy_speed(status
, 1);
269 netxen_set_phy_speed(status
, 2);
272 /* set duplex mode */
273 if (ecmd
->duplex
== DUPLEX_HALF
)
274 netxen_clear_phy_duplex(status
);
275 if (ecmd
->duplex
== DUPLEX_FULL
)
276 netxen_set_phy_duplex(status
);
277 if (adapter
->phy_write
278 && adapter
->phy_write(adapter
,
279 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
280 *((int *)&status
)) != 0)
283 adapter
->link_speed
= ecmd
->speed
;
284 adapter
->link_duplex
= ecmd
->duplex
;
289 if (!netif_running(dev
))
292 dev
->netdev_ops
->ndo_stop(dev
);
293 return dev
->netdev_ops
->ndo_open(dev
);
296 static int netxen_nic_get_regs_len(struct net_device
*dev
)
298 return NETXEN_NIC_REGS_LEN
;
301 struct netxen_niu_regs
{
302 __u32 reg
[NETXEN_NIC_REGS_COUNT
];
305 static struct netxen_niu_regs niu_registers
[] = {
309 NETXEN_NIU_GB_SERDES_RESET
,
310 NETXEN_NIU_GB0_MII_MODE
,
311 NETXEN_NIU_GB1_MII_MODE
,
312 NETXEN_NIU_GB2_MII_MODE
,
313 NETXEN_NIU_GB3_MII_MODE
,
314 NETXEN_NIU_GB0_GMII_MODE
,
315 NETXEN_NIU_GB1_GMII_MODE
,
316 NETXEN_NIU_GB2_GMII_MODE
,
317 NETXEN_NIU_GB3_GMII_MODE
,
318 NETXEN_NIU_REMOTE_LOOPBACK
,
319 NETXEN_NIU_GB0_HALF_DUPLEX
,
320 NETXEN_NIU_GB1_HALF_DUPLEX
,
321 NETXEN_NIU_RESET_SYS_FIFOS
,
322 NETXEN_NIU_GB_CRC_DROP
,
323 NETXEN_NIU_GB_DROP_WRONGADDR
,
324 NETXEN_NIU_TEST_MUX_CTL
,
326 NETXEN_NIU_GB_MAC_CONFIG_0(0),
327 NETXEN_NIU_GB_MAC_CONFIG_1(0),
328 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
329 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
330 NETXEN_NIU_GB_TEST_REG(0),
331 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
332 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
333 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
334 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
335 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
336 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
337 NETXEN_NIU_GB_INTERFACE_CTRL(0),
338 NETXEN_NIU_GB_INTERFACE_STATUS(0),
339 NETXEN_NIU_GB_STATION_ADDR_0(0),
340 NETXEN_NIU_GB_STATION_ADDR_1(0),
347 NETXEN_NIU_XG_SINGLE_TERM
,
348 NETXEN_NIU_XG_DRIVE_HI
,
349 NETXEN_NIU_XG_DRIVE_LO
,
352 NETXEN_NIU_XG_WORD_ALIGN
,
354 NETXEN_NIU_XG_POWER_DOWN
,
355 NETXEN_NIU_XG_RESET_PLL
,
356 NETXEN_NIU_XG_SERDES_LOOPBACK
,
357 NETXEN_NIU_XG_DO_BYTE_ALIGN
,
358 NETXEN_NIU_XG_TX_ENABLE
,
359 NETXEN_NIU_XG_RX_ENABLE
,
360 NETXEN_NIU_XG_STATUS
,
361 NETXEN_NIU_XG_PAUSE_THRESHOLD
,
362 NETXEN_NIU_XGE_CONFIG_0
,
363 NETXEN_NIU_XGE_CONFIG_1
,
365 NETXEN_NIU_XGE_STATION_ADDR_0_HI
,
366 NETXEN_NIU_XGE_STATION_ADDR_0_1
,
367 NETXEN_NIU_XGE_STATION_ADDR_1_LO
,
368 NETXEN_NIU_XGE_STATUS
,
369 NETXEN_NIU_XGE_MAX_FRAME_SIZE
,
370 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE
,
371 NETXEN_NIU_XGE_TX_BYTE_CNT
,
372 NETXEN_NIU_XGE_TX_FRAME_CNT
,
373 NETXEN_NIU_XGE_RX_BYTE_CNT
,
374 NETXEN_NIU_XGE_RX_FRAME_CNT
,
375 NETXEN_NIU_XGE_AGGR_ERROR_CNT
,
376 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT
,
377 NETXEN_NIU_XGE_UNICAST_FRAME_CNT
,
378 NETXEN_NIU_XGE_CRC_ERROR_CNT
,
379 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR
,
380 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR
,
381 NETXEN_NIU_XGE_LOCAL_ERROR_CNT
,
382 NETXEN_NIU_XGE_REMOTE_ERROR_CNT
,
383 NETXEN_NIU_XGE_CONTROL_CHAR_CNT
,
384 NETXEN_NIU_XGE_PAUSE_FRAME_CNT
,
391 netxen_nic_get_regs(struct net_device
*dev
, struct ethtool_regs
*regs
, void *p
)
393 struct netxen_adapter
*adapter
= netdev_priv(dev
);
394 __u32 mode
, *regs_buff
= p
;
397 memset(p
, 0, NETXEN_NIC_REGS_LEN
);
398 regs
->version
= (1 << 24) | (adapter
->ahw
.revision_id
<< 16) |
399 (adapter
->pdev
)->device
;
401 adapter
->hw_read_wx(adapter
, NETXEN_NIU_MODE
, ®s_buff
[0], 4);
404 /* Common registers to all the modes */
405 adapter
->hw_read_wx(adapter
,
406 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER
, ®s_buff
[2], 4);
408 mode
= (mode
/ 2) - 1;
411 for (i
= 3; niu_registers
[mode
].reg
[i
- 3] != -1; i
++) {
412 /* GB: port specific registers */
413 if (mode
== 0 && i
>= 19)
414 window
= adapter
->physical_port
*
415 NETXEN_NIC_PORT_WINDOW
;
417 adapter
->hw_read_wx(adapter
,
418 niu_registers
[mode
].reg
[i
- 3] + window
,
425 static u32
netxen_nic_test_link(struct net_device
*dev
)
427 struct netxen_adapter
*adapter
= netdev_priv(dev
);
431 /* read which mode */
432 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
433 if (adapter
->phy_read
434 && adapter
->phy_read(adapter
,
435 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS
,
439 val
= netxen_get_phy_link(status
);
442 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
443 val
= adapter
->pci_read_normalize(adapter
, CRB_XG_STATE
);
444 return (val
== XG_LINK_UP
) ? 0 : 1;
450 netxen_nic_get_eeprom(struct net_device
*dev
, struct ethtool_eeprom
*eeprom
,
453 struct netxen_adapter
*adapter
= netdev_priv(dev
);
457 if (eeprom
->len
== 0)
460 eeprom
->magic
= (adapter
->pdev
)->vendor
|
461 ((adapter
->pdev
)->device
<< 16);
462 offset
= eeprom
->offset
;
464 ret
= netxen_rom_fast_read_words(adapter
, offset
, bytes
,
473 netxen_nic_get_ringparam(struct net_device
*dev
, struct ethtool_ringparam
*ring
)
475 struct netxen_adapter
*adapter
= netdev_priv(dev
);
477 ring
->rx_pending
= 0;
478 ring
->rx_jumbo_pending
= 0;
479 ring
->rx_pending
+= adapter
->recv_ctx
.
480 rds_rings
[RCV_RING_NORMAL
].num_desc
;
481 ring
->rx_jumbo_pending
+= adapter
->recv_ctx
.
482 rds_rings
[RCV_RING_JUMBO
].num_desc
;
483 ring
->tx_pending
= adapter
->num_txd
;
485 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
)
486 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_1G
;
488 ring
->rx_max_pending
= MAX_RCV_DESCRIPTORS_10G
;
489 ring
->tx_max_pending
= MAX_CMD_DESCRIPTORS_HOST
;
490 ring
->rx_jumbo_max_pending
= MAX_JUMBO_RCV_DESCRIPTORS
;
491 ring
->rx_mini_max_pending
= 0;
492 ring
->rx_mini_pending
= 0;
496 netxen_nic_get_pauseparam(struct net_device
*dev
,
497 struct ethtool_pauseparam
*pause
)
499 struct netxen_adapter
*adapter
= netdev_priv(dev
);
501 int port
= adapter
->physical_port
;
503 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
504 if ((port
< 0) || (port
> NETXEN_NIU_MAX_GBE_PORTS
))
506 /* get flow control settings */
507 netxen_nic_read_w0(adapter
,NETXEN_NIU_GB_MAC_CONFIG_0(port
),
509 pause
->rx_pause
= netxen_gb_get_rx_flowctl(val
);
510 netxen_nic_read_w0(adapter
, NETXEN_NIU_GB_PAUSE_CTL
, &val
);
513 pause
->tx_pause
= !(netxen_gb_get_gb0_mask(val
));
516 pause
->tx_pause
= !(netxen_gb_get_gb1_mask(val
));
519 pause
->tx_pause
= !(netxen_gb_get_gb2_mask(val
));
523 pause
->tx_pause
= !(netxen_gb_get_gb3_mask(val
));
526 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
527 if ((port
< 0) || (port
> NETXEN_NIU_MAX_XG_PORTS
))
530 netxen_nic_read_w0(adapter
, NETXEN_NIU_XG_PAUSE_CTL
, &val
);
532 pause
->tx_pause
= !(netxen_xg_get_xg0_mask(val
));
534 pause
->tx_pause
= !(netxen_xg_get_xg1_mask(val
));
536 printk(KERN_ERR
"%s: Unknown board type: %x\n",
537 netxen_nic_driver_name
, adapter
->ahw
.port_type
);
542 netxen_nic_set_pauseparam(struct net_device
*dev
,
543 struct ethtool_pauseparam
*pause
)
545 struct netxen_adapter
*adapter
= netdev_priv(dev
);
547 int port
= adapter
->physical_port
;
549 if (adapter
->ahw
.port_type
== NETXEN_NIC_GBE
) {
550 if ((port
< 0) || (port
> NETXEN_NIU_MAX_GBE_PORTS
))
552 /* set flow control */
553 netxen_nic_read_w0(adapter
,
554 NETXEN_NIU_GB_MAC_CONFIG_0(port
), &val
);
557 netxen_gb_rx_flowctl(val
);
559 netxen_gb_unset_rx_flowctl(val
);
561 netxen_nic_write_w0(adapter
, NETXEN_NIU_GB_MAC_CONFIG_0(port
),
564 netxen_nic_read_w0(adapter
, NETXEN_NIU_GB_PAUSE_CTL
, &val
);
568 netxen_gb_unset_gb0_mask(val
);
570 netxen_gb_set_gb0_mask(val
);
574 netxen_gb_unset_gb1_mask(val
);
576 netxen_gb_set_gb1_mask(val
);
580 netxen_gb_unset_gb2_mask(val
);
582 netxen_gb_set_gb2_mask(val
);
587 netxen_gb_unset_gb3_mask(val
);
589 netxen_gb_set_gb3_mask(val
);
592 netxen_nic_write_w0(adapter
, NETXEN_NIU_GB_PAUSE_CTL
, val
);
593 } else if (adapter
->ahw
.port_type
== NETXEN_NIC_XGBE
) {
594 if ((port
< 0) || (port
> NETXEN_NIU_MAX_XG_PORTS
))
596 netxen_nic_read_w0(adapter
, NETXEN_NIU_XG_PAUSE_CTL
, &val
);
599 netxen_xg_unset_xg0_mask(val
);
601 netxen_xg_set_xg0_mask(val
);
604 netxen_xg_unset_xg1_mask(val
);
606 netxen_xg_set_xg1_mask(val
);
608 netxen_nic_write_w0(adapter
, NETXEN_NIU_XG_PAUSE_CTL
, val
);
610 printk(KERN_ERR
"%s: Unknown board type: %x\n",
611 netxen_nic_driver_name
,
612 adapter
->ahw
.port_type
);
617 static int netxen_nic_reg_test(struct net_device
*dev
)
619 struct netxen_adapter
*adapter
= netdev_priv(dev
);
620 u32 data_read
, data_written
;
622 netxen_nic_read_w0(adapter
, NETXEN_PCIX_PH_REG(0), &data_read
);
623 if ((data_read
& 0xffff) != PHAN_VENDOR_ID
)
626 data_written
= (u32
)0xa5a5a5a5;
628 netxen_nic_reg_write(adapter
, CRB_SCRATCHPAD_TEST
, data_written
);
629 data_read
= adapter
->pci_read_normalize(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
;
697 static u32
netxen_nic_get_rx_csum(struct net_device
*dev
)
699 struct netxen_adapter
*adapter
= netdev_priv(dev
);
700 return adapter
->rx_csum
;
703 static int netxen_nic_set_rx_csum(struct net_device
*dev
, u32 data
)
705 struct netxen_adapter
*adapter
= netdev_priv(dev
);
706 adapter
->rx_csum
= !!data
;
710 static u32
netxen_nic_get_tso(struct net_device
*dev
)
712 struct netxen_adapter
*adapter
= netdev_priv(dev
);
714 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
715 return (dev
->features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) != 0;
717 return (dev
->features
& NETIF_F_TSO
) != 0;
720 static int netxen_nic_set_tso(struct net_device
*dev
, u32 data
)
723 struct netxen_adapter
*adapter
= netdev_priv(dev
);
725 dev
->features
|= NETIF_F_TSO
;
726 if (NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
727 dev
->features
|= NETIF_F_TSO6
;
729 dev
->features
&= ~(NETIF_F_TSO
| NETIF_F_TSO6
);
735 netxen_nic_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
737 struct netxen_adapter
*adapter
= netdev_priv(dev
);
743 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
746 wol_cfg
= netxen_nic_reg_read(adapter
, NETXEN_WOL_CONFIG_NV
);
747 if (wol_cfg
& (1UL << adapter
->portnum
))
748 wol
->supported
|= WAKE_MAGIC
;
750 wol_cfg
= netxen_nic_reg_read(adapter
, NETXEN_WOL_CONFIG
);
751 if (wol_cfg
& (1UL << adapter
->portnum
))
752 wol
->wolopts
|= WAKE_MAGIC
;
756 netxen_nic_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
758 struct netxen_adapter
*adapter
= netdev_priv(dev
);
761 if (NX_IS_REVISION_P2(adapter
->ahw
.revision_id
))
764 if (wol
->wolopts
& ~WAKE_MAGIC
)
767 wol_cfg
= netxen_nic_reg_read(adapter
, NETXEN_WOL_CONFIG_NV
);
768 if (!(wol_cfg
& (1 << adapter
->portnum
)))
771 wol_cfg
= netxen_nic_reg_read(adapter
, NETXEN_WOL_CONFIG
);
772 if (wol
->wolopts
& WAKE_MAGIC
)
773 wol_cfg
|= 1UL << adapter
->portnum
;
775 wol_cfg
&= ~(1UL << adapter
->portnum
);
776 netxen_nic_reg_write(adapter
, NETXEN_WOL_CONFIG
, wol_cfg
);
782 * Set the coalescing parameters. Currently only normal is supported.
783 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
784 * firmware coalescing to default.
786 static int netxen_set_intr_coalesce(struct net_device
*netdev
,
787 struct ethtool_coalesce
*ethcoal
)
789 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
791 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
794 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
798 * Return Error if unsupported values or
799 * unsupported parameters are set.
801 if (ethcoal
->rx_coalesce_usecs
> 0xffff ||
802 ethcoal
->rx_max_coalesced_frames
> 0xffff ||
803 ethcoal
->tx_coalesce_usecs
> 0xffff ||
804 ethcoal
->tx_max_coalesced_frames
> 0xffff ||
805 ethcoal
->rx_coalesce_usecs_irq
||
806 ethcoal
->rx_max_coalesced_frames_irq
||
807 ethcoal
->tx_coalesce_usecs_irq
||
808 ethcoal
->tx_max_coalesced_frames_irq
||
809 ethcoal
->stats_block_coalesce_usecs
||
810 ethcoal
->use_adaptive_rx_coalesce
||
811 ethcoal
->use_adaptive_tx_coalesce
||
812 ethcoal
->pkt_rate_low
||
813 ethcoal
->rx_coalesce_usecs_low
||
814 ethcoal
->rx_max_coalesced_frames_low
||
815 ethcoal
->tx_coalesce_usecs_low
||
816 ethcoal
->tx_max_coalesced_frames_low
||
817 ethcoal
->pkt_rate_high
||
818 ethcoal
->rx_coalesce_usecs_high
||
819 ethcoal
->rx_max_coalesced_frames_high
||
820 ethcoal
->tx_coalesce_usecs_high
||
821 ethcoal
->tx_max_coalesced_frames_high
)
824 if (!ethcoal
->rx_coalesce_usecs
||
825 !ethcoal
->rx_max_coalesced_frames
) {
826 adapter
->coal
.flags
= NETXEN_NIC_INTR_DEFAULT
;
827 adapter
->coal
.normal
.data
.rx_time_us
=
828 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US
;
829 adapter
->coal
.normal
.data
.rx_packets
=
830 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS
;
832 adapter
->coal
.flags
= 0;
833 adapter
->coal
.normal
.data
.rx_time_us
=
834 ethcoal
->rx_coalesce_usecs
;
835 adapter
->coal
.normal
.data
.rx_packets
=
836 ethcoal
->rx_max_coalesced_frames
;
838 adapter
->coal
.normal
.data
.tx_time_us
= ethcoal
->tx_coalesce_usecs
;
839 adapter
->coal
.normal
.data
.tx_packets
=
840 ethcoal
->tx_max_coalesced_frames
;
842 netxen_config_intr_coalesce(adapter
);
847 static int netxen_get_intr_coalesce(struct net_device
*netdev
,
848 struct ethtool_coalesce
*ethcoal
)
850 struct netxen_adapter
*adapter
= netdev_priv(netdev
);
852 if (!NX_IS_REVISION_P3(adapter
->ahw
.revision_id
))
855 if (adapter
->is_up
!= NETXEN_ADAPTER_UP_MAGIC
)
858 ethcoal
->rx_coalesce_usecs
= adapter
->coal
.normal
.data
.rx_time_us
;
859 ethcoal
->tx_coalesce_usecs
= adapter
->coal
.normal
.data
.tx_time_us
;
860 ethcoal
->rx_max_coalesced_frames
=
861 adapter
->coal
.normal
.data
.rx_packets
;
862 ethcoal
->tx_max_coalesced_frames
=
863 adapter
->coal
.normal
.data
.tx_packets
;
868 struct ethtool_ops netxen_nic_ethtool_ops
= {
869 .get_settings
= netxen_nic_get_settings
,
870 .set_settings
= netxen_nic_set_settings
,
871 .get_drvinfo
= netxen_nic_get_drvinfo
,
872 .get_regs_len
= netxen_nic_get_regs_len
,
873 .get_regs
= netxen_nic_get_regs
,
874 .get_link
= ethtool_op_get_link
,
875 .get_eeprom_len
= netxen_nic_get_eeprom_len
,
876 .get_eeprom
= netxen_nic_get_eeprom
,
877 .get_ringparam
= netxen_nic_get_ringparam
,
878 .get_pauseparam
= netxen_nic_get_pauseparam
,
879 .set_pauseparam
= netxen_nic_set_pauseparam
,
880 .set_tx_csum
= ethtool_op_set_tx_csum
,
881 .set_sg
= ethtool_op_set_sg
,
882 .get_tso
= netxen_nic_get_tso
,
883 .set_tso
= netxen_nic_set_tso
,
884 .get_wol
= netxen_nic_get_wol
,
885 .set_wol
= netxen_nic_set_wol
,
886 .self_test
= netxen_nic_diag_test
,
887 .get_strings
= netxen_nic_get_strings
,
888 .get_ethtool_stats
= netxen_nic_get_ethtool_stats
,
889 .get_sset_count
= netxen_get_sset_count
,
890 .get_rx_csum
= netxen_nic_get_rx_csum
,
891 .set_rx_csum
= netxen_nic_set_rx_csum
,
892 .get_coalesce
= netxen_get_intr_coalesce
,
893 .set_coalesce
= netxen_set_intr_coalesce
,