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 <linux/pci.h>
35 #include <linux/netdevice.h>
36 #include <linux/ethtool.h>
38 #include "netxen_nic.h"
39 #include "netxen_nic_hw.h"
40 #include "netxen_nic_phan_reg.h"
42 struct netxen_nic_stats {
43 char stat_string[ETH_GSTRING_LEN];
48 #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
49 offsetof(struct netxen_adapter, m)
51 #define NETXEN_NIC_PORT_WINDOW 0x10000
52 #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
54 static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
55 {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
56 {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
57 {"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)},
58 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
59 {"csummed", NETXEN_NIC_STAT(stats.csummed)},
60 {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
61 {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
62 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
65 #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
67 static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
68 "Register_Test_on_offline",
69 "Link_Test_on_offline"
72 #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
74 #define NETXEN_NIC_REGS_COUNT 42
75 #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
76 #define NETXEN_MAX_EEPROM_LEN 1024
78 static int netxen_nic_get_eeprom_len(struct net_device *dev)
80 return NETXEN_FLASH_TOTAL_SIZE;
84 netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
86 struct netxen_adapter *adapter = netdev_priv(dev);
92 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
93 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
94 write_lock_irqsave(&adapter->adapter_lock, flags);
95 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
96 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
97 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
98 write_unlock_irqrestore(&adapter->adapter_lock, flags);
99 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
101 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
102 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
103 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
107 netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
109 struct netxen_adapter *adapter = netdev_priv(dev);
110 int check_sfp_module = 0;
112 /* read which mode */
113 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
114 ecmd->supported = (SUPPORTED_10baseT_Half |
115 SUPPORTED_10baseT_Full |
116 SUPPORTED_100baseT_Half |
117 SUPPORTED_100baseT_Full |
118 SUPPORTED_1000baseT_Half |
119 SUPPORTED_1000baseT_Full);
121 ecmd->advertising = (ADVERTISED_100baseT_Half |
122 ADVERTISED_100baseT_Full |
123 ADVERTISED_1000baseT_Half |
124 ADVERTISED_1000baseT_Full);
126 ecmd->port = PORT_TP;
128 ecmd->speed = adapter->link_speed;
129 ecmd->duplex = adapter->link_duplex;
130 ecmd->autoneg = adapter->link_autoneg;
132 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
135 val = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
136 if (val == NETXEN_PORT_MODE_802_3_AP) {
137 ecmd->supported = SUPPORTED_1000baseT_Full;
138 ecmd->advertising = ADVERTISED_1000baseT_Full;
140 ecmd->supported = SUPPORTED_10000baseT_Full;
141 ecmd->advertising = ADVERTISED_10000baseT_Full;
144 if (netif_running(dev) && adapter->has_link_events) {
145 ecmd->speed = adapter->link_speed;
146 ecmd->autoneg = adapter->link_autoneg;
147 ecmd->duplex = adapter->link_duplex;
151 ecmd->port = PORT_TP;
153 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
154 u16 pcifn = adapter->ahw.pci_func;
156 val = NXRD32(adapter, P3_LINK_SPEED_REG(pcifn));
157 ecmd->speed = P3_LINK_SPEED_MHZ *
158 P3_LINK_SPEED_VAL(pcifn, val);
160 ecmd->speed = SPEED_10000;
162 ecmd->duplex = DUPLEX_FULL;
163 ecmd->autoneg = AUTONEG_DISABLE;
168 ecmd->phy_address = adapter->physical_port;
169 ecmd->transceiver = XCVR_EXTERNAL;
171 switch (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_MII;
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 check_sfp_module = netif_running(dev) &&
207 adapter->has_link_events;
208 case NETXEN_BRDTYPE_P2_SB31_10G:
209 case NETXEN_BRDTYPE_P3_10G_XFP:
210 ecmd->supported |= SUPPORTED_FIBRE;
211 ecmd->advertising |= ADVERTISED_FIBRE;
212 ecmd->port = PORT_FIBRE;
213 ecmd->autoneg = AUTONEG_DISABLE;
215 case NETXEN_BRDTYPE_P3_10G_TP:
216 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
217 ecmd->autoneg = AUTONEG_DISABLE;
218 ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
220 (ADVERTISED_FIBRE | ADVERTISED_TP);
221 ecmd->port = PORT_FIBRE;
222 check_sfp_module = netif_running(dev) &&
223 adapter->has_link_events;
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 adapter->ahw.board_type);
238 if (check_sfp_module) {
239 switch (adapter->module_type) {
240 case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
241 case LINKEVENT_MODULE_OPTICAL_SRLR:
242 case LINKEVENT_MODULE_OPTICAL_LRM:
243 case LINKEVENT_MODULE_OPTICAL_SFP_1G:
244 ecmd->port = PORT_FIBRE;
246 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
247 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
248 case LINKEVENT_MODULE_TWINAX:
249 ecmd->port = PORT_TP;
259 netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
261 struct netxen_adapter *adapter = netdev_priv(dev);
264 /* read which mode */
265 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
266 /* autonegotiation */
267 if (adapter->phy_write
268 && adapter->phy_write(adapter,
269 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
273 adapter->link_autoneg = ecmd->autoneg;
275 if (adapter->phy_read
276 && adapter->phy_read(adapter,
277 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
282 switch (ecmd->speed) {
284 netxen_set_phy_speed(status, 0);
287 netxen_set_phy_speed(status, 1);
290 netxen_set_phy_speed(status, 2);
293 /* set duplex mode */
294 if (ecmd->duplex == DUPLEX_HALF)
295 netxen_clear_phy_duplex(status);
296 if (ecmd->duplex == DUPLEX_FULL)
297 netxen_set_phy_duplex(status);
298 if (adapter->phy_write
299 && adapter->phy_write(adapter,
300 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
301 *((int *)&status)) != 0)
304 adapter->link_speed = ecmd->speed;
305 adapter->link_duplex = ecmd->duplex;
310 if (!netif_running(dev))
313 dev->netdev_ops->ndo_stop(dev);
314 return dev->netdev_ops->ndo_open(dev);
317 static int netxen_nic_get_regs_len(struct net_device *dev)
319 return NETXEN_NIC_REGS_LEN;
322 struct netxen_niu_regs {
323 __u32 reg[NETXEN_NIC_REGS_COUNT];
326 static struct netxen_niu_regs niu_registers[] = {
330 NETXEN_NIU_GB_SERDES_RESET,
331 NETXEN_NIU_GB0_MII_MODE,
332 NETXEN_NIU_GB1_MII_MODE,
333 NETXEN_NIU_GB2_MII_MODE,
334 NETXEN_NIU_GB3_MII_MODE,
335 NETXEN_NIU_GB0_GMII_MODE,
336 NETXEN_NIU_GB1_GMII_MODE,
337 NETXEN_NIU_GB2_GMII_MODE,
338 NETXEN_NIU_GB3_GMII_MODE,
339 NETXEN_NIU_REMOTE_LOOPBACK,
340 NETXEN_NIU_GB0_HALF_DUPLEX,
341 NETXEN_NIU_GB1_HALF_DUPLEX,
342 NETXEN_NIU_RESET_SYS_FIFOS,
343 NETXEN_NIU_GB_CRC_DROP,
344 NETXEN_NIU_GB_DROP_WRONGADDR,
345 NETXEN_NIU_TEST_MUX_CTL,
347 NETXEN_NIU_GB_MAC_CONFIG_0(0),
348 NETXEN_NIU_GB_MAC_CONFIG_1(0),
349 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
350 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
351 NETXEN_NIU_GB_TEST_REG(0),
352 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
353 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
354 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
355 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
356 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
357 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
358 NETXEN_NIU_GB_INTERFACE_CTRL(0),
359 NETXEN_NIU_GB_INTERFACE_STATUS(0),
360 NETXEN_NIU_GB_STATION_ADDR_0(0),
361 NETXEN_NIU_GB_STATION_ADDR_1(0),
368 NETXEN_NIU_XG_SINGLE_TERM,
369 NETXEN_NIU_XG_DRIVE_HI,
370 NETXEN_NIU_XG_DRIVE_LO,
373 NETXEN_NIU_XG_WORD_ALIGN,
375 NETXEN_NIU_XG_POWER_DOWN,
376 NETXEN_NIU_XG_RESET_PLL,
377 NETXEN_NIU_XG_SERDES_LOOPBACK,
378 NETXEN_NIU_XG_DO_BYTE_ALIGN,
379 NETXEN_NIU_XG_TX_ENABLE,
380 NETXEN_NIU_XG_RX_ENABLE,
381 NETXEN_NIU_XG_STATUS,
382 NETXEN_NIU_XG_PAUSE_THRESHOLD,
383 NETXEN_NIU_XGE_CONFIG_0,
384 NETXEN_NIU_XGE_CONFIG_1,
386 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
387 NETXEN_NIU_XGE_STATION_ADDR_0_1,
388 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
389 NETXEN_NIU_XGE_STATUS,
390 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
391 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
392 NETXEN_NIU_XGE_TX_BYTE_CNT,
393 NETXEN_NIU_XGE_TX_FRAME_CNT,
394 NETXEN_NIU_XGE_RX_BYTE_CNT,
395 NETXEN_NIU_XGE_RX_FRAME_CNT,
396 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
397 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
398 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
399 NETXEN_NIU_XGE_CRC_ERROR_CNT,
400 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
401 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
402 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
403 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
404 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
405 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
412 netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
414 struct netxen_adapter *adapter = netdev_priv(dev);
415 __u32 mode, *regs_buff = p;
418 memset(p, 0, NETXEN_NIC_REGS_LEN);
419 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
420 (adapter->pdev)->device;
422 regs_buff[0] = NXRD32(adapter, NETXEN_NIU_MODE);
425 /* Common registers to all the modes */
426 regs_buff[2] = NXRD32(adapter, NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER);
428 mode = (mode / 2) - 1;
431 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
432 /* GB: port specific registers */
433 if (mode == 0 && i >= 19)
434 window = adapter->physical_port *
435 NETXEN_NIC_PORT_WINDOW;
437 regs_buff[i] = NXRD32(adapter,
438 niu_registers[mode].reg[i - 3] + window);
444 static u32 netxen_nic_test_link(struct net_device *dev)
446 struct netxen_adapter *adapter = netdev_priv(dev);
450 /* read which mode */
451 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
452 if (adapter->phy_read
453 && adapter->phy_read(adapter,
454 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
458 val = netxen_get_phy_link(status);
461 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
462 val = NXRD32(adapter, CRB_XG_STATE);
463 return (val == XG_LINK_UP) ? 0 : 1;
469 netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
472 struct netxen_adapter *adapter = netdev_priv(dev);
476 if (eeprom->len == 0)
479 eeprom->magic = (adapter->pdev)->vendor |
480 ((adapter->pdev)->device << 16);
481 offset = eeprom->offset;
483 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
492 netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
494 struct netxen_adapter *adapter = netdev_priv(dev);
496 ring->rx_pending = 0;
497 ring->rx_jumbo_pending = 0;
498 ring->rx_pending += adapter->recv_ctx.
499 rds_rings[RCV_RING_NORMAL].num_desc;
500 ring->rx_jumbo_pending += adapter->recv_ctx.
501 rds_rings[RCV_RING_JUMBO].num_desc;
502 ring->tx_pending = adapter->num_txd;
504 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
505 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
507 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
508 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
509 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
510 ring->rx_mini_max_pending = 0;
511 ring->rx_mini_pending = 0;
515 netxen_nic_get_pauseparam(struct net_device *dev,
516 struct ethtool_pauseparam *pause)
518 struct netxen_adapter *adapter = netdev_priv(dev);
520 int port = adapter->physical_port;
522 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
523 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
525 /* get flow control settings */
526 val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
527 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
528 val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
531 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
534 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
537 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
541 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
544 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
545 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
548 val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
550 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
552 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
554 printk(KERN_ERR"%s: Unknown board type: %x\n",
555 netxen_nic_driver_name, adapter->ahw.port_type);
560 netxen_nic_set_pauseparam(struct net_device *dev,
561 struct ethtool_pauseparam *pause)
563 struct netxen_adapter *adapter = netdev_priv(dev);
565 int port = adapter->physical_port;
567 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
568 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
570 /* set flow control */
571 val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
574 netxen_gb_rx_flowctl(val);
576 netxen_gb_unset_rx_flowctl(val);
578 NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
581 val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
585 netxen_gb_unset_gb0_mask(val);
587 netxen_gb_set_gb0_mask(val);
591 netxen_gb_unset_gb1_mask(val);
593 netxen_gb_set_gb1_mask(val);
597 netxen_gb_unset_gb2_mask(val);
599 netxen_gb_set_gb2_mask(val);
604 netxen_gb_unset_gb3_mask(val);
606 netxen_gb_set_gb3_mask(val);
609 NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
610 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
611 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
613 val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
616 netxen_xg_unset_xg0_mask(val);
618 netxen_xg_set_xg0_mask(val);
621 netxen_xg_unset_xg1_mask(val);
623 netxen_xg_set_xg1_mask(val);
625 NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
627 printk(KERN_ERR "%s: Unknown board type: %x\n",
628 netxen_nic_driver_name,
629 adapter->ahw.port_type);
634 static int netxen_nic_reg_test(struct net_device *dev)
636 struct netxen_adapter *adapter = netdev_priv(dev);
637 u32 data_read, data_written;
639 data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0));
640 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
643 data_written = (u32)0xa5a5a5a5;
645 NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written);
646 data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST);
647 if (data_written != data_read)
653 static int netxen_get_sset_count(struct net_device *dev, int sset)
657 return NETXEN_NIC_TEST_LEN;
659 return NETXEN_NIC_STATS_LEN;
666 netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
669 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
670 if ((data[0] = netxen_nic_reg_test(dev)))
671 eth_test->flags |= ETH_TEST_FL_FAILED;
673 if ((data[1] = (u64) netxen_nic_test_link(dev)))
674 eth_test->flags |= ETH_TEST_FL_FAILED;
678 netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
684 memcpy(data, *netxen_nic_gstrings_test,
685 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
688 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
689 memcpy(data + index * ETH_GSTRING_LEN,
690 netxen_nic_gstrings_stats[index].stat_string,
698 netxen_nic_get_ethtool_stats(struct net_device *dev,
699 struct ethtool_stats *stats, u64 * data)
701 struct netxen_adapter *adapter = netdev_priv(dev);
704 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
707 netxen_nic_gstrings_stats[index].stat_offset;
709 (netxen_nic_gstrings_stats[index].sizeof_stat ==
710 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
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);
723 adapter->rx_csum = !!data;
727 static u32 netxen_nic_get_tso(struct net_device *dev)
729 struct netxen_adapter *adapter = netdev_priv(dev);
731 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
732 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
734 return (dev->features & NETIF_F_TSO) != 0;
737 static int netxen_nic_set_tso(struct net_device *dev, u32 data)
740 struct netxen_adapter *adapter = netdev_priv(dev);
742 dev->features |= NETIF_F_TSO;
743 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
744 dev->features |= NETIF_F_TSO6;
746 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
752 netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
754 struct netxen_adapter *adapter = netdev_priv(dev);
760 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
763 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
764 if (wol_cfg & (1UL << adapter->portnum))
765 wol->supported |= WAKE_MAGIC;
767 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
768 if (wol_cfg & (1UL << adapter->portnum))
769 wol->wolopts |= WAKE_MAGIC;
773 netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
775 struct netxen_adapter *adapter = netdev_priv(dev);
778 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
781 if (wol->wolopts & ~WAKE_MAGIC)
784 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
785 if (!(wol_cfg & (1 << adapter->portnum)))
788 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
789 if (wol->wolopts & WAKE_MAGIC)
790 wol_cfg |= 1UL << adapter->portnum;
792 wol_cfg &= ~(1UL << adapter->portnum);
793 NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg);
799 * Set the coalescing parameters. Currently only normal is supported.
800 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
801 * firmware coalescing to default.
803 static int netxen_set_intr_coalesce(struct net_device *netdev,
804 struct ethtool_coalesce *ethcoal)
806 struct netxen_adapter *adapter = netdev_priv(netdev);
808 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
811 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
815 * Return Error if unsupported values or
816 * unsupported parameters are set.
818 if (ethcoal->rx_coalesce_usecs > 0xffff ||
819 ethcoal->rx_max_coalesced_frames > 0xffff ||
820 ethcoal->tx_coalesce_usecs > 0xffff ||
821 ethcoal->tx_max_coalesced_frames > 0xffff ||
822 ethcoal->rx_coalesce_usecs_irq ||
823 ethcoal->rx_max_coalesced_frames_irq ||
824 ethcoal->tx_coalesce_usecs_irq ||
825 ethcoal->tx_max_coalesced_frames_irq ||
826 ethcoal->stats_block_coalesce_usecs ||
827 ethcoal->use_adaptive_rx_coalesce ||
828 ethcoal->use_adaptive_tx_coalesce ||
829 ethcoal->pkt_rate_low ||
830 ethcoal->rx_coalesce_usecs_low ||
831 ethcoal->rx_max_coalesced_frames_low ||
832 ethcoal->tx_coalesce_usecs_low ||
833 ethcoal->tx_max_coalesced_frames_low ||
834 ethcoal->pkt_rate_high ||
835 ethcoal->rx_coalesce_usecs_high ||
836 ethcoal->rx_max_coalesced_frames_high ||
837 ethcoal->tx_coalesce_usecs_high ||
838 ethcoal->tx_max_coalesced_frames_high)
841 if (!ethcoal->rx_coalesce_usecs ||
842 !ethcoal->rx_max_coalesced_frames) {
843 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
844 adapter->coal.normal.data.rx_time_us =
845 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
846 adapter->coal.normal.data.rx_packets =
847 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
849 adapter->coal.flags = 0;
850 adapter->coal.normal.data.rx_time_us =
851 ethcoal->rx_coalesce_usecs;
852 adapter->coal.normal.data.rx_packets =
853 ethcoal->rx_max_coalesced_frames;
855 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
856 adapter->coal.normal.data.tx_packets =
857 ethcoal->tx_max_coalesced_frames;
859 netxen_config_intr_coalesce(adapter);
864 static int netxen_get_intr_coalesce(struct net_device *netdev,
865 struct ethtool_coalesce *ethcoal)
867 struct netxen_adapter *adapter = netdev_priv(netdev);
869 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
872 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
875 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
876 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
877 ethcoal->rx_max_coalesced_frames =
878 adapter->coal.normal.data.rx_packets;
879 ethcoal->tx_max_coalesced_frames =
880 adapter->coal.normal.data.tx_packets;
885 struct ethtool_ops netxen_nic_ethtool_ops = {
886 .get_settings = netxen_nic_get_settings,
887 .set_settings = netxen_nic_set_settings,
888 .get_drvinfo = netxen_nic_get_drvinfo,
889 .get_regs_len = netxen_nic_get_regs_len,
890 .get_regs = netxen_nic_get_regs,
891 .get_link = ethtool_op_get_link,
892 .get_eeprom_len = netxen_nic_get_eeprom_len,
893 .get_eeprom = netxen_nic_get_eeprom,
894 .get_ringparam = netxen_nic_get_ringparam,
895 .get_pauseparam = netxen_nic_get_pauseparam,
896 .set_pauseparam = netxen_nic_set_pauseparam,
897 .set_tx_csum = ethtool_op_set_tx_csum,
898 .set_sg = ethtool_op_set_sg,
899 .get_tso = netxen_nic_get_tso,
900 .set_tso = netxen_nic_set_tso,
901 .get_wol = netxen_nic_get_wol,
902 .set_wol = netxen_nic_set_wol,
903 .self_test = netxen_nic_diag_test,
904 .get_strings = netxen_nic_get_strings,
905 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
906 .get_sset_count = netxen_get_sset_count,
907 .get_rx_csum = netxen_nic_get_rx_csum,
908 .set_rx_csum = netxen_nic_set_rx_csum,
909 .get_coalesce = netxen_get_intr_coalesce,
910 .set_coalesce = netxen_set_intr_coalesce,