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>
41 #include <linux/version.h>
43 #include "netxen_nic.h"
44 #include "netxen_nic_hw.h"
45 #include "netxen_nic_phan_reg.h"
47 struct netxen_nic_stats {
48 char stat_string[ETH_GSTRING_LEN];
53 #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
54 offsetof(struct netxen_adapter, m)
56 #define NETXEN_NIC_PORT_WINDOW 0x10000
57 #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
59 static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
60 {"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)},
61 {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
62 {"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)},
63 {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
64 {"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)},
65 {"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)},
66 {"polled", NETXEN_NIC_STAT(stats.polled)},
67 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
68 {"csummed", NETXEN_NIC_STAT(stats.csummed)},
69 {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
70 {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
71 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
74 #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
76 static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
77 "Register_Test_on_offline",
78 "Link_Test_on_offline"
81 #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
83 #define NETXEN_NIC_REGS_COUNT 42
84 #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
85 #define NETXEN_MAX_EEPROM_LEN 1024
87 static int netxen_nic_get_eeprom_len(struct net_device *dev)
89 return NETXEN_FLASH_TOTAL_SIZE;
93 netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
95 struct netxen_adapter *adapter = netdev_priv(dev);
101 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
102 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
103 write_lock_irqsave(&adapter->adapter_lock, flags);
104 fw_major = adapter->pci_read_normalize(adapter,
105 NETXEN_FW_VERSION_MAJOR);
106 fw_minor = adapter->pci_read_normalize(adapter,
107 NETXEN_FW_VERSION_MINOR);
108 fw_build = adapter->pci_read_normalize(adapter,
109 NETXEN_FW_VERSION_SUB);
110 write_unlock_irqrestore(&adapter->adapter_lock, flags);
111 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
113 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
114 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
115 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
119 netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
121 struct netxen_adapter *adapter = netdev_priv(dev);
122 struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg;
124 /* read which mode */
125 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
126 ecmd->supported = (SUPPORTED_10baseT_Half |
127 SUPPORTED_10baseT_Full |
128 SUPPORTED_100baseT_Half |
129 SUPPORTED_100baseT_Full |
130 SUPPORTED_1000baseT_Half |
131 SUPPORTED_1000baseT_Full);
133 ecmd->advertising = (ADVERTISED_100baseT_Half |
134 ADVERTISED_100baseT_Full |
135 ADVERTISED_1000baseT_Half |
136 ADVERTISED_1000baseT_Full);
138 ecmd->port = PORT_TP;
140 if (netif_running(dev)) {
141 ecmd->speed = adapter->link_speed;
142 ecmd->duplex = adapter->link_duplex;
144 return -EIO; /* link absent */
145 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
146 ecmd->supported = (SUPPORTED_TP |
147 SUPPORTED_1000baseT_Full |
148 SUPPORTED_10000baseT_Full);
149 ecmd->advertising = (ADVERTISED_TP |
150 ADVERTISED_1000baseT_Full |
151 ADVERTISED_10000baseT_Full);
152 ecmd->port = PORT_TP;
154 ecmd->speed = SPEED_10000;
155 ecmd->duplex = DUPLEX_FULL;
156 ecmd->autoneg = AUTONEG_DISABLE;
160 ecmd->phy_address = adapter->portnum;
161 ecmd->transceiver = XCVR_EXTERNAL;
163 switch ((netxen_brdtype_t) boardinfo->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:
169 case NETXEN_BRDTYPE_P3_10000_BASE_T:
171 ecmd->supported |= SUPPORTED_Autoneg;
172 ecmd->advertising |= ADVERTISED_Autoneg;
173 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
174 case NETXEN_BRDTYPE_P3_10G_CX4:
175 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
176 ecmd->supported |= SUPPORTED_TP;
177 ecmd->advertising |= ADVERTISED_TP;
178 ecmd->port = PORT_TP;
179 ecmd->autoneg = (boardinfo->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_FIBRE;
191 ecmd->autoneg = AUTONEG_DISABLE;
193 case NETXEN_BRDTYPE_P2_SB31_10G:
194 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
195 case NETXEN_BRDTYPE_P3_10G_XFP:
196 ecmd->supported |= SUPPORTED_FIBRE;
197 ecmd->advertising |= ADVERTISED_FIBRE;
198 ecmd->port = PORT_FIBRE;
199 ecmd->autoneg = AUTONEG_DISABLE;
202 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
203 (netxen_brdtype_t) boardinfo->board_type);
211 netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
213 struct netxen_adapter *adapter = netdev_priv(dev);
216 /* read which mode */
217 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
218 /* autonegotiation */
219 if (adapter->phy_write
220 && adapter->phy_write(adapter,
221 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
225 adapter->link_autoneg = ecmd->autoneg;
227 if (adapter->phy_read
228 && adapter->phy_read(adapter,
229 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
234 switch (ecmd->speed) {
236 netxen_set_phy_speed(status, 0);
239 netxen_set_phy_speed(status, 1);
242 netxen_set_phy_speed(status, 2);
245 /* set duplex mode */
246 if (ecmd->duplex == DUPLEX_HALF)
247 netxen_clear_phy_duplex(status);
248 if (ecmd->duplex == DUPLEX_FULL)
249 netxen_set_phy_duplex(status);
250 if (adapter->phy_write
251 && adapter->phy_write(adapter,
252 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
253 *((int *)&status)) != 0)
256 adapter->link_speed = ecmd->speed;
257 adapter->link_duplex = ecmd->duplex;
262 if (netif_running(dev)) {
269 static int netxen_nic_get_regs_len(struct net_device *dev)
271 return NETXEN_NIC_REGS_LEN;
274 struct netxen_niu_regs {
275 __u32 reg[NETXEN_NIC_REGS_COUNT];
278 static struct netxen_niu_regs niu_registers[] = {
282 NETXEN_NIU_GB_SERDES_RESET,
283 NETXEN_NIU_GB0_MII_MODE,
284 NETXEN_NIU_GB1_MII_MODE,
285 NETXEN_NIU_GB2_MII_MODE,
286 NETXEN_NIU_GB3_MII_MODE,
287 NETXEN_NIU_GB0_GMII_MODE,
288 NETXEN_NIU_GB1_GMII_MODE,
289 NETXEN_NIU_GB2_GMII_MODE,
290 NETXEN_NIU_GB3_GMII_MODE,
291 NETXEN_NIU_REMOTE_LOOPBACK,
292 NETXEN_NIU_GB0_HALF_DUPLEX,
293 NETXEN_NIU_GB1_HALF_DUPLEX,
294 NETXEN_NIU_RESET_SYS_FIFOS,
295 NETXEN_NIU_GB_CRC_DROP,
296 NETXEN_NIU_GB_DROP_WRONGADDR,
297 NETXEN_NIU_TEST_MUX_CTL,
299 NETXEN_NIU_GB_MAC_CONFIG_0(0),
300 NETXEN_NIU_GB_MAC_CONFIG_1(0),
301 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
302 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
303 NETXEN_NIU_GB_TEST_REG(0),
304 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
305 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
306 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
307 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
308 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
309 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
310 NETXEN_NIU_GB_INTERFACE_CTRL(0),
311 NETXEN_NIU_GB_INTERFACE_STATUS(0),
312 NETXEN_NIU_GB_STATION_ADDR_0(0),
313 NETXEN_NIU_GB_STATION_ADDR_1(0),
320 NETXEN_NIU_XG_SINGLE_TERM,
321 NETXEN_NIU_XG_DRIVE_HI,
322 NETXEN_NIU_XG_DRIVE_LO,
325 NETXEN_NIU_XG_WORD_ALIGN,
327 NETXEN_NIU_XG_POWER_DOWN,
328 NETXEN_NIU_XG_RESET_PLL,
329 NETXEN_NIU_XG_SERDES_LOOPBACK,
330 NETXEN_NIU_XG_DO_BYTE_ALIGN,
331 NETXEN_NIU_XG_TX_ENABLE,
332 NETXEN_NIU_XG_RX_ENABLE,
333 NETXEN_NIU_XG_STATUS,
334 NETXEN_NIU_XG_PAUSE_THRESHOLD,
335 NETXEN_NIU_XGE_CONFIG_0,
336 NETXEN_NIU_XGE_CONFIG_1,
338 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
339 NETXEN_NIU_XGE_STATION_ADDR_0_1,
340 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
341 NETXEN_NIU_XGE_STATUS,
342 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
343 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
344 NETXEN_NIU_XGE_TX_BYTE_CNT,
345 NETXEN_NIU_XGE_TX_FRAME_CNT,
346 NETXEN_NIU_XGE_RX_BYTE_CNT,
347 NETXEN_NIU_XGE_RX_FRAME_CNT,
348 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
349 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
350 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
351 NETXEN_NIU_XGE_CRC_ERROR_CNT,
352 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
353 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
354 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
355 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
356 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
357 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
364 netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
366 struct netxen_adapter *adapter = netdev_priv(dev);
367 __u32 mode, *regs_buff = p;
370 memset(p, 0, NETXEN_NIC_REGS_LEN);
371 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
372 (adapter->pdev)->device;
374 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, ®s_buff[0], 4);
377 /* Common registers to all the modes */
378 adapter->hw_read_wx(adapter,
379 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, ®s_buff[2], 4);
381 mode = (mode / 2) - 1;
384 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
385 /* GB: port specific registers */
386 if (mode == 0 && i >= 19)
387 window = adapter->physical_port *
388 NETXEN_NIC_PORT_WINDOW;
390 adapter->hw_read_wx(adapter,
391 niu_registers[mode].reg[i - 3] + window,
398 static u32 netxen_nic_test_link(struct net_device *dev)
400 struct netxen_adapter *adapter = netdev_priv(dev);
404 /* read which mode */
405 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
406 if (adapter->phy_read
407 && adapter->phy_read(adapter,
408 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
412 val = netxen_get_phy_link(status);
415 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
416 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
417 return (val == XG_LINK_UP) ? 0 : 1;
423 netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
426 struct netxen_adapter *adapter = netdev_priv(dev);
430 if (eeprom->len == 0)
433 eeprom->magic = (adapter->pdev)->vendor |
434 ((adapter->pdev)->device << 16);
435 offset = eeprom->offset;
437 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
447 netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
450 struct netxen_adapter *adapter = netdev_priv(dev);
451 int offset = eeprom->offset;
452 static int flash_start;
453 static int ready_to_flash;
456 if (flash_start == 0) {
457 netxen_halt_pegs(adapter);
458 ret = netxen_flash_unlock(adapter);
460 printk(KERN_ERR "%s: Flash unlock failed.\n",
461 netxen_nic_driver_name);
464 printk(KERN_INFO "%s: flash unlocked. \n",
465 netxen_nic_driver_name);
466 ret = netxen_flash_erase_secondary(adapter);
467 if (ret != FLASH_SUCCESS) {
468 printk(KERN_ERR "%s: Flash erase failed.\n",
469 netxen_nic_driver_name);
472 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
473 netxen_nic_driver_name);
478 if (offset == NETXEN_BOOTLD_START) {
479 ret = netxen_flash_erase_primary(adapter);
480 if (ret != FLASH_SUCCESS) {
481 printk(KERN_ERR "%s: Flash erase failed.\n",
482 netxen_nic_driver_name);
486 ret = netxen_rom_se(adapter, NETXEN_USER_START);
487 if (ret != FLASH_SUCCESS)
489 ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
490 if (ret != FLASH_SUCCESS)
493 printk(KERN_INFO "%s: primary flash erased successfully\n",
494 netxen_nic_driver_name);
496 ret = netxen_backup_crbinit(adapter);
497 if (ret != FLASH_SUCCESS) {
498 printk(KERN_ERR "%s: CRBinit backup failed.\n",
499 netxen_nic_driver_name);
502 printk(KERN_INFO "%s: CRBinit backup done.\n",
503 netxen_nic_driver_name);
507 if (!ready_to_flash) {
508 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
509 netxen_nic_driver_name);
513 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
518 netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
520 struct netxen_adapter *adapter = netdev_priv(dev);
523 ring->rx_pending = 0;
524 ring->rx_jumbo_pending = 0;
525 for (i = 0; i < MAX_RCV_CTX; ++i) {
526 ring->rx_pending += adapter->recv_ctx[i].
527 rds_rings[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
528 ring->rx_jumbo_pending += adapter->recv_ctx[i].
529 rds_rings[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
531 ring->tx_pending = adapter->max_tx_desc_count;
533 ring->rx_max_pending = MAX_RCV_DESCRIPTORS;
534 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
535 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
536 ring->rx_mini_max_pending = 0;
537 ring->rx_mini_pending = 0;
541 netxen_nic_get_pauseparam(struct net_device *dev,
542 struct ethtool_pauseparam *pause)
544 struct netxen_adapter *adapter = netdev_priv(dev);
546 int port = adapter->physical_port;
548 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
549 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
551 /* get flow control settings */
552 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
554 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
555 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
558 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
561 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
564 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
568 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
571 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
572 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
575 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
577 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
579 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
581 printk(KERN_ERR"%s: Unknown board type: %x\n",
582 netxen_nic_driver_name, adapter->ahw.board_type);
587 netxen_nic_set_pauseparam(struct net_device *dev,
588 struct ethtool_pauseparam *pause)
590 struct netxen_adapter *adapter = netdev_priv(dev);
592 int port = adapter->physical_port;
594 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
595 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
597 /* set flow control */
598 netxen_nic_read_w0(adapter,
599 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
602 netxen_gb_rx_flowctl(val);
604 netxen_gb_unset_rx_flowctl(val);
606 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
609 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
613 netxen_gb_unset_gb0_mask(val);
615 netxen_gb_set_gb0_mask(val);
619 netxen_gb_unset_gb1_mask(val);
621 netxen_gb_set_gb1_mask(val);
625 netxen_gb_unset_gb2_mask(val);
627 netxen_gb_set_gb2_mask(val);
632 netxen_gb_unset_gb3_mask(val);
634 netxen_gb_set_gb3_mask(val);
637 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
638 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
639 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
641 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
644 netxen_xg_unset_xg0_mask(val);
646 netxen_xg_set_xg0_mask(val);
649 netxen_xg_unset_xg1_mask(val);
651 netxen_xg_set_xg1_mask(val);
653 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
655 printk(KERN_ERR "%s: Unknown board type: %x\n",
656 netxen_nic_driver_name,
657 adapter->ahw.board_type);
662 static int netxen_nic_reg_test(struct net_device *dev)
664 struct netxen_adapter *adapter = netdev_priv(dev);
665 u32 data_read, data_written;
667 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
668 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
671 data_written = (u32)0xa5a5a5a5;
673 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
674 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
675 if (data_written != data_read)
681 static int netxen_get_sset_count(struct net_device *dev, int sset)
685 return NETXEN_NIC_TEST_LEN;
687 return NETXEN_NIC_STATS_LEN;
694 netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
697 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
698 if ((data[0] = netxen_nic_reg_test(dev)))
699 eth_test->flags |= ETH_TEST_FL_FAILED;
701 if ((data[1] = (u64) netxen_nic_test_link(dev)))
702 eth_test->flags |= ETH_TEST_FL_FAILED;
706 netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
712 memcpy(data, *netxen_nic_gstrings_test,
713 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
716 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
717 memcpy(data + index * ETH_GSTRING_LEN,
718 netxen_nic_gstrings_stats[index].stat_string,
726 netxen_nic_get_ethtool_stats(struct net_device *dev,
727 struct ethtool_stats *stats, u64 * data)
729 struct netxen_adapter *adapter = netdev_priv(dev);
732 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
735 netxen_nic_gstrings_stats[index].stat_offset;
737 (netxen_nic_gstrings_stats[index].sizeof_stat ==
738 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
742 static u32 netxen_nic_get_rx_csum(struct net_device *dev)
744 struct netxen_adapter *adapter = netdev_priv(dev);
745 return adapter->rx_csum;
748 static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
750 struct netxen_adapter *adapter = netdev_priv(dev);
751 adapter->rx_csum = !!data;
755 static u32 netxen_nic_get_tso(struct net_device *dev)
757 struct netxen_adapter *adapter = netdev_priv(dev);
759 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
760 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
762 return (dev->features & NETIF_F_TSO) != 0;
765 static int netxen_nic_set_tso(struct net_device *dev, u32 data)
768 struct netxen_adapter *adapter = netdev_priv(dev);
770 dev->features |= NETIF_F_TSO;
771 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
772 dev->features |= NETIF_F_TSO6;
774 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
780 * Set the coalescing parameters. Currently only normal is supported.
781 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
782 * firmware coalescing to default.
784 static int netxen_set_intr_coalesce(struct net_device *netdev,
785 struct ethtool_coalesce *ethcoal)
787 struct netxen_adapter *adapter = netdev_priv(netdev);
789 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
792 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
796 * Return Error if unsupported values or
797 * unsupported parameters are set.
799 if (ethcoal->rx_coalesce_usecs > 0xffff ||
800 ethcoal->rx_max_coalesced_frames > 0xffff ||
801 ethcoal->tx_coalesce_usecs > 0xffff ||
802 ethcoal->tx_max_coalesced_frames > 0xffff ||
803 ethcoal->rx_coalesce_usecs_irq ||
804 ethcoal->rx_max_coalesced_frames_irq ||
805 ethcoal->tx_coalesce_usecs_irq ||
806 ethcoal->tx_max_coalesced_frames_irq ||
807 ethcoal->stats_block_coalesce_usecs ||
808 ethcoal->use_adaptive_rx_coalesce ||
809 ethcoal->use_adaptive_tx_coalesce ||
810 ethcoal->pkt_rate_low ||
811 ethcoal->rx_coalesce_usecs_low ||
812 ethcoal->rx_max_coalesced_frames_low ||
813 ethcoal->tx_coalesce_usecs_low ||
814 ethcoal->tx_max_coalesced_frames_low ||
815 ethcoal->pkt_rate_high ||
816 ethcoal->rx_coalesce_usecs_high ||
817 ethcoal->rx_max_coalesced_frames_high ||
818 ethcoal->tx_coalesce_usecs_high ||
819 ethcoal->tx_max_coalesced_frames_high)
822 if (!ethcoal->rx_coalesce_usecs ||
823 !ethcoal->rx_max_coalesced_frames) {
824 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
825 adapter->coal.normal.data.rx_time_us =
826 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
827 adapter->coal.normal.data.rx_packets =
828 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
830 adapter->coal.flags = 0;
831 adapter->coal.normal.data.rx_time_us =
832 ethcoal->rx_coalesce_usecs;
833 adapter->coal.normal.data.rx_packets =
834 ethcoal->rx_max_coalesced_frames;
836 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
837 adapter->coal.normal.data.tx_packets =
838 ethcoal->tx_max_coalesced_frames;
840 netxen_config_intr_coalesce(adapter);
845 static int netxen_get_intr_coalesce(struct net_device *netdev,
846 struct ethtool_coalesce *ethcoal)
848 struct netxen_adapter *adapter = netdev_priv(netdev);
850 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
853 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
856 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
857 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
858 ethcoal->rx_max_coalesced_frames =
859 adapter->coal.normal.data.rx_packets;
860 ethcoal->tx_max_coalesced_frames =
861 adapter->coal.normal.data.tx_packets;
866 struct ethtool_ops netxen_nic_ethtool_ops = {
867 .get_settings = netxen_nic_get_settings,
868 .set_settings = netxen_nic_set_settings,
869 .get_drvinfo = netxen_nic_get_drvinfo,
870 .get_regs_len = netxen_nic_get_regs_len,
871 .get_regs = netxen_nic_get_regs,
872 .get_link = ethtool_op_get_link,
873 .get_eeprom_len = netxen_nic_get_eeprom_len,
874 .get_eeprom = netxen_nic_get_eeprom,
876 .set_eeprom = netxen_nic_set_eeprom,
878 .get_ringparam = netxen_nic_get_ringparam,
879 .get_pauseparam = netxen_nic_get_pauseparam,
880 .set_pauseparam = netxen_nic_set_pauseparam,
881 .set_tx_csum = ethtool_op_set_tx_csum,
882 .set_sg = ethtool_op_set_sg,
883 .get_tso = netxen_nic_get_tso,
884 .set_tso = netxen_nic_set_tso,
885 .self_test = netxen_nic_diag_test,
886 .get_strings = netxen_nic_get_strings,
887 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
888 .get_sset_count = netxen_get_sset_count,
889 .get_rx_csum = netxen_nic_get_rx_csum,
890 .set_rx_csum = netxen_nic_set_rx_csum,
891 .get_coalesce = netxen_get_intr_coalesce,
892 .set_coalesce = netxen_set_intr_coalesce,