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;
143 ecmd->autoneg = adapter->link_autoneg;
146 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
149 adapter->hw_read_wx(adapter, NETXEN_PORT_MODE_ADDR, &val, 4);
150 if (val == NETXEN_PORT_MODE_802_3_AP) {
151 ecmd->supported = SUPPORTED_1000baseT_Full;
152 ecmd->advertising = ADVERTISED_1000baseT_Full;
154 ecmd->supported = SUPPORTED_10000baseT_Full;
155 ecmd->advertising = ADVERTISED_10000baseT_Full;
158 ecmd->port = PORT_TP;
160 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
161 u16 pcifn = adapter->ahw.pci_func;
163 adapter->hw_read_wx(adapter,
164 P3_LINK_SPEED_REG(pcifn), &val, 4);
165 ecmd->speed = P3_LINK_SPEED_MHZ *
166 P3_LINK_SPEED_VAL(pcifn, val);
168 ecmd->speed = SPEED_10000;
170 ecmd->duplex = DUPLEX_FULL;
171 ecmd->autoneg = AUTONEG_DISABLE;
175 ecmd->phy_address = adapter->portnum;
176 ecmd->transceiver = XCVR_EXTERNAL;
178 switch ((netxen_brdtype_t) boardinfo->board_type) {
179 case NETXEN_BRDTYPE_P2_SB35_4G:
180 case NETXEN_BRDTYPE_P2_SB31_2G:
181 case NETXEN_BRDTYPE_P3_REF_QG:
182 case NETXEN_BRDTYPE_P3_4_GB:
183 case NETXEN_BRDTYPE_P3_4_GB_MM:
184 case NETXEN_BRDTYPE_P3_10000_BASE_T:
186 ecmd->supported |= SUPPORTED_Autoneg;
187 ecmd->advertising |= ADVERTISED_Autoneg;
188 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
189 case NETXEN_BRDTYPE_P3_10G_CX4:
190 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
191 ecmd->supported |= SUPPORTED_TP;
192 ecmd->advertising |= ADVERTISED_TP;
193 ecmd->port = PORT_TP;
194 ecmd->autoneg = (boardinfo->board_type ==
195 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
196 (AUTONEG_DISABLE) : (adapter->link_autoneg);
198 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
199 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
200 case NETXEN_BRDTYPE_P3_IMEZ:
201 case NETXEN_BRDTYPE_P3_XG_LOM:
202 case NETXEN_BRDTYPE_P3_HMEZ:
203 ecmd->supported |= SUPPORTED_MII;
204 ecmd->advertising |= ADVERTISED_MII;
205 ecmd->port = PORT_FIBRE;
206 ecmd->autoneg = AUTONEG_DISABLE;
208 case NETXEN_BRDTYPE_P2_SB31_10G:
209 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
210 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
211 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
212 case NETXEN_BRDTYPE_P3_10G_XFP:
213 ecmd->supported |= SUPPORTED_FIBRE;
214 ecmd->advertising |= ADVERTISED_FIBRE;
215 ecmd->port = PORT_FIBRE;
216 ecmd->autoneg = AUTONEG_DISABLE;
219 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
220 (netxen_brdtype_t) boardinfo->board_type);
228 netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
230 struct netxen_adapter *adapter = netdev_priv(dev);
233 /* read which mode */
234 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
235 /* autonegotiation */
236 if (adapter->phy_write
237 && adapter->phy_write(adapter,
238 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
242 adapter->link_autoneg = ecmd->autoneg;
244 if (adapter->phy_read
245 && adapter->phy_read(adapter,
246 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
251 switch (ecmd->speed) {
253 netxen_set_phy_speed(status, 0);
256 netxen_set_phy_speed(status, 1);
259 netxen_set_phy_speed(status, 2);
262 /* set duplex mode */
263 if (ecmd->duplex == DUPLEX_HALF)
264 netxen_clear_phy_duplex(status);
265 if (ecmd->duplex == DUPLEX_FULL)
266 netxen_set_phy_duplex(status);
267 if (adapter->phy_write
268 && adapter->phy_write(adapter,
269 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
270 *((int *)&status)) != 0)
273 adapter->link_speed = ecmd->speed;
274 adapter->link_duplex = ecmd->duplex;
279 if (netif_running(dev)) {
286 static int netxen_nic_get_regs_len(struct net_device *dev)
288 return NETXEN_NIC_REGS_LEN;
291 struct netxen_niu_regs {
292 __u32 reg[NETXEN_NIC_REGS_COUNT];
295 static struct netxen_niu_regs niu_registers[] = {
299 NETXEN_NIU_GB_SERDES_RESET,
300 NETXEN_NIU_GB0_MII_MODE,
301 NETXEN_NIU_GB1_MII_MODE,
302 NETXEN_NIU_GB2_MII_MODE,
303 NETXEN_NIU_GB3_MII_MODE,
304 NETXEN_NIU_GB0_GMII_MODE,
305 NETXEN_NIU_GB1_GMII_MODE,
306 NETXEN_NIU_GB2_GMII_MODE,
307 NETXEN_NIU_GB3_GMII_MODE,
308 NETXEN_NIU_REMOTE_LOOPBACK,
309 NETXEN_NIU_GB0_HALF_DUPLEX,
310 NETXEN_NIU_GB1_HALF_DUPLEX,
311 NETXEN_NIU_RESET_SYS_FIFOS,
312 NETXEN_NIU_GB_CRC_DROP,
313 NETXEN_NIU_GB_DROP_WRONGADDR,
314 NETXEN_NIU_TEST_MUX_CTL,
316 NETXEN_NIU_GB_MAC_CONFIG_0(0),
317 NETXEN_NIU_GB_MAC_CONFIG_1(0),
318 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
319 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
320 NETXEN_NIU_GB_TEST_REG(0),
321 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
322 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
323 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
324 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
325 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
326 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
327 NETXEN_NIU_GB_INTERFACE_CTRL(0),
328 NETXEN_NIU_GB_INTERFACE_STATUS(0),
329 NETXEN_NIU_GB_STATION_ADDR_0(0),
330 NETXEN_NIU_GB_STATION_ADDR_1(0),
337 NETXEN_NIU_XG_SINGLE_TERM,
338 NETXEN_NIU_XG_DRIVE_HI,
339 NETXEN_NIU_XG_DRIVE_LO,
342 NETXEN_NIU_XG_WORD_ALIGN,
344 NETXEN_NIU_XG_POWER_DOWN,
345 NETXEN_NIU_XG_RESET_PLL,
346 NETXEN_NIU_XG_SERDES_LOOPBACK,
347 NETXEN_NIU_XG_DO_BYTE_ALIGN,
348 NETXEN_NIU_XG_TX_ENABLE,
349 NETXEN_NIU_XG_RX_ENABLE,
350 NETXEN_NIU_XG_STATUS,
351 NETXEN_NIU_XG_PAUSE_THRESHOLD,
352 NETXEN_NIU_XGE_CONFIG_0,
353 NETXEN_NIU_XGE_CONFIG_1,
355 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
356 NETXEN_NIU_XGE_STATION_ADDR_0_1,
357 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
358 NETXEN_NIU_XGE_STATUS,
359 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
360 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
361 NETXEN_NIU_XGE_TX_BYTE_CNT,
362 NETXEN_NIU_XGE_TX_FRAME_CNT,
363 NETXEN_NIU_XGE_RX_BYTE_CNT,
364 NETXEN_NIU_XGE_RX_FRAME_CNT,
365 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
366 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
367 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
368 NETXEN_NIU_XGE_CRC_ERROR_CNT,
369 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
370 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
371 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
372 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
373 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
374 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
381 netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
383 struct netxen_adapter *adapter = netdev_priv(dev);
384 __u32 mode, *regs_buff = p;
387 memset(p, 0, NETXEN_NIC_REGS_LEN);
388 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
389 (adapter->pdev)->device;
391 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, ®s_buff[0], 4);
394 /* Common registers to all the modes */
395 adapter->hw_read_wx(adapter,
396 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, ®s_buff[2], 4);
398 mode = (mode / 2) - 1;
401 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
402 /* GB: port specific registers */
403 if (mode == 0 && i >= 19)
404 window = adapter->physical_port *
405 NETXEN_NIC_PORT_WINDOW;
407 adapter->hw_read_wx(adapter,
408 niu_registers[mode].reg[i - 3] + window,
415 static u32 netxen_nic_test_link(struct net_device *dev)
417 struct netxen_adapter *adapter = netdev_priv(dev);
421 /* read which mode */
422 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
423 if (adapter->phy_read
424 && adapter->phy_read(adapter,
425 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
429 val = netxen_get_phy_link(status);
432 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
433 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
434 return (val == XG_LINK_UP) ? 0 : 1;
440 netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
443 struct netxen_adapter *adapter = netdev_priv(dev);
447 if (eeprom->len == 0)
450 eeprom->magic = (adapter->pdev)->vendor |
451 ((adapter->pdev)->device << 16);
452 offset = eeprom->offset;
454 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
464 netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
467 struct netxen_adapter *adapter = netdev_priv(dev);
468 int offset = eeprom->offset;
469 static int flash_start;
470 static int ready_to_flash;
473 if (flash_start == 0) {
474 netxen_halt_pegs(adapter);
475 ret = netxen_flash_unlock(adapter);
477 printk(KERN_ERR "%s: Flash unlock failed.\n",
478 netxen_nic_driver_name);
481 printk(KERN_INFO "%s: flash unlocked. \n",
482 netxen_nic_driver_name);
483 ret = netxen_flash_erase_secondary(adapter);
484 if (ret != FLASH_SUCCESS) {
485 printk(KERN_ERR "%s: Flash erase failed.\n",
486 netxen_nic_driver_name);
489 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
490 netxen_nic_driver_name);
495 if (offset == NETXEN_BOOTLD_START) {
496 ret = netxen_flash_erase_primary(adapter);
497 if (ret != FLASH_SUCCESS) {
498 printk(KERN_ERR "%s: Flash erase failed.\n",
499 netxen_nic_driver_name);
503 ret = netxen_rom_se(adapter, NETXEN_USER_START);
504 if (ret != FLASH_SUCCESS)
506 ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
507 if (ret != FLASH_SUCCESS)
510 printk(KERN_INFO "%s: primary flash erased successfully\n",
511 netxen_nic_driver_name);
513 ret = netxen_backup_crbinit(adapter);
514 if (ret != FLASH_SUCCESS) {
515 printk(KERN_ERR "%s: CRBinit backup failed.\n",
516 netxen_nic_driver_name);
519 printk(KERN_INFO "%s: CRBinit backup done.\n",
520 netxen_nic_driver_name);
524 if (!ready_to_flash) {
525 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
526 netxen_nic_driver_name);
530 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
535 netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
537 struct netxen_adapter *adapter = netdev_priv(dev);
540 ring->rx_pending = 0;
541 ring->rx_jumbo_pending = 0;
542 for (i = 0; i < MAX_RCV_CTX; ++i) {
543 ring->rx_pending += adapter->recv_ctx[i].
544 rds_rings[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
545 ring->rx_jumbo_pending += adapter->recv_ctx[i].
546 rds_rings[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
548 ring->tx_pending = adapter->max_tx_desc_count;
550 ring->rx_max_pending = MAX_RCV_DESCRIPTORS;
551 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
552 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
553 ring->rx_mini_max_pending = 0;
554 ring->rx_mini_pending = 0;
558 netxen_nic_get_pauseparam(struct net_device *dev,
559 struct ethtool_pauseparam *pause)
561 struct netxen_adapter *adapter = netdev_priv(dev);
563 int port = adapter->physical_port;
565 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
566 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
568 /* get flow control settings */
569 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
571 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
572 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
575 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
578 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
581 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
585 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
588 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
589 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
592 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
594 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
596 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
598 printk(KERN_ERR"%s: Unknown board type: %x\n",
599 netxen_nic_driver_name, adapter->ahw.board_type);
604 netxen_nic_set_pauseparam(struct net_device *dev,
605 struct ethtool_pauseparam *pause)
607 struct netxen_adapter *adapter = netdev_priv(dev);
609 int port = adapter->physical_port;
611 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
612 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
614 /* set flow control */
615 netxen_nic_read_w0(adapter,
616 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
619 netxen_gb_rx_flowctl(val);
621 netxen_gb_unset_rx_flowctl(val);
623 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
626 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
630 netxen_gb_unset_gb0_mask(val);
632 netxen_gb_set_gb0_mask(val);
636 netxen_gb_unset_gb1_mask(val);
638 netxen_gb_set_gb1_mask(val);
642 netxen_gb_unset_gb2_mask(val);
644 netxen_gb_set_gb2_mask(val);
649 netxen_gb_unset_gb3_mask(val);
651 netxen_gb_set_gb3_mask(val);
654 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
655 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
656 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
658 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
661 netxen_xg_unset_xg0_mask(val);
663 netxen_xg_set_xg0_mask(val);
666 netxen_xg_unset_xg1_mask(val);
668 netxen_xg_set_xg1_mask(val);
670 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
672 printk(KERN_ERR "%s: Unknown board type: %x\n",
673 netxen_nic_driver_name,
674 adapter->ahw.board_type);
679 static int netxen_nic_reg_test(struct net_device *dev)
681 struct netxen_adapter *adapter = netdev_priv(dev);
682 u32 data_read, data_written;
684 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
685 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
688 data_written = (u32)0xa5a5a5a5;
690 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
691 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
692 if (data_written != data_read)
698 static int netxen_get_sset_count(struct net_device *dev, int sset)
702 return NETXEN_NIC_TEST_LEN;
704 return NETXEN_NIC_STATS_LEN;
711 netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
714 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
715 if ((data[0] = netxen_nic_reg_test(dev)))
716 eth_test->flags |= ETH_TEST_FL_FAILED;
718 if ((data[1] = (u64) netxen_nic_test_link(dev)))
719 eth_test->flags |= ETH_TEST_FL_FAILED;
723 netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
729 memcpy(data, *netxen_nic_gstrings_test,
730 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
733 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
734 memcpy(data + index * ETH_GSTRING_LEN,
735 netxen_nic_gstrings_stats[index].stat_string,
743 netxen_nic_get_ethtool_stats(struct net_device *dev,
744 struct ethtool_stats *stats, u64 * data)
746 struct netxen_adapter *adapter = netdev_priv(dev);
749 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
752 netxen_nic_gstrings_stats[index].stat_offset;
754 (netxen_nic_gstrings_stats[index].sizeof_stat ==
755 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
759 static u32 netxen_nic_get_rx_csum(struct net_device *dev)
761 struct netxen_adapter *adapter = netdev_priv(dev);
762 return adapter->rx_csum;
765 static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
767 struct netxen_adapter *adapter = netdev_priv(dev);
768 adapter->rx_csum = !!data;
772 static u32 netxen_nic_get_tso(struct net_device *dev)
774 struct netxen_adapter *adapter = netdev_priv(dev);
776 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
777 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
779 return (dev->features & NETIF_F_TSO) != 0;
782 static int netxen_nic_set_tso(struct net_device *dev, u32 data)
785 struct netxen_adapter *adapter = netdev_priv(dev);
787 dev->features |= NETIF_F_TSO;
788 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
789 dev->features |= NETIF_F_TSO6;
791 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
797 * Set the coalescing parameters. Currently only normal is supported.
798 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
799 * firmware coalescing to default.
801 static int netxen_set_intr_coalesce(struct net_device *netdev,
802 struct ethtool_coalesce *ethcoal)
804 struct netxen_adapter *adapter = netdev_priv(netdev);
806 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
809 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
813 * Return Error if unsupported values or
814 * unsupported parameters are set.
816 if (ethcoal->rx_coalesce_usecs > 0xffff ||
817 ethcoal->rx_max_coalesced_frames > 0xffff ||
818 ethcoal->tx_coalesce_usecs > 0xffff ||
819 ethcoal->tx_max_coalesced_frames > 0xffff ||
820 ethcoal->rx_coalesce_usecs_irq ||
821 ethcoal->rx_max_coalesced_frames_irq ||
822 ethcoal->tx_coalesce_usecs_irq ||
823 ethcoal->tx_max_coalesced_frames_irq ||
824 ethcoal->stats_block_coalesce_usecs ||
825 ethcoal->use_adaptive_rx_coalesce ||
826 ethcoal->use_adaptive_tx_coalesce ||
827 ethcoal->pkt_rate_low ||
828 ethcoal->rx_coalesce_usecs_low ||
829 ethcoal->rx_max_coalesced_frames_low ||
830 ethcoal->tx_coalesce_usecs_low ||
831 ethcoal->tx_max_coalesced_frames_low ||
832 ethcoal->pkt_rate_high ||
833 ethcoal->rx_coalesce_usecs_high ||
834 ethcoal->rx_max_coalesced_frames_high ||
835 ethcoal->tx_coalesce_usecs_high ||
836 ethcoal->tx_max_coalesced_frames_high)
839 if (!ethcoal->rx_coalesce_usecs ||
840 !ethcoal->rx_max_coalesced_frames) {
841 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
842 adapter->coal.normal.data.rx_time_us =
843 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
844 adapter->coal.normal.data.rx_packets =
845 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
847 adapter->coal.flags = 0;
848 adapter->coal.normal.data.rx_time_us =
849 ethcoal->rx_coalesce_usecs;
850 adapter->coal.normal.data.rx_packets =
851 ethcoal->rx_max_coalesced_frames;
853 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
854 adapter->coal.normal.data.tx_packets =
855 ethcoal->tx_max_coalesced_frames;
857 netxen_config_intr_coalesce(adapter);
862 static int netxen_get_intr_coalesce(struct net_device *netdev,
863 struct ethtool_coalesce *ethcoal)
865 struct netxen_adapter *adapter = netdev_priv(netdev);
867 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
870 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
873 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
874 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
875 ethcoal->rx_max_coalesced_frames =
876 adapter->coal.normal.data.rx_packets;
877 ethcoal->tx_max_coalesced_frames =
878 adapter->coal.normal.data.tx_packets;
883 struct ethtool_ops netxen_nic_ethtool_ops = {
884 .get_settings = netxen_nic_get_settings,
885 .set_settings = netxen_nic_set_settings,
886 .get_drvinfo = netxen_nic_get_drvinfo,
887 .get_regs_len = netxen_nic_get_regs_len,
888 .get_regs = netxen_nic_get_regs,
889 .get_link = ethtool_op_get_link,
890 .get_eeprom_len = netxen_nic_get_eeprom_len,
891 .get_eeprom = netxen_nic_get_eeprom,
893 .set_eeprom = netxen_nic_set_eeprom,
895 .get_ringparam = netxen_nic_get_ringparam,
896 .get_pauseparam = netxen_nic_get_pauseparam,
897 .set_pauseparam = netxen_nic_set_pauseparam,
898 .set_tx_csum = ethtool_op_set_tx_csum,
899 .set_sg = ethtool_op_set_sg,
900 .get_tso = netxen_nic_get_tso,
901 .set_tso = netxen_nic_set_tso,
902 .self_test = netxen_nic_diag_test,
903 .get_strings = netxen_nic_get_strings,
904 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
905 .get_sset_count = netxen_get_sset_count,
906 .get_rx_csum = netxen_nic_get_rx_csum,
907 .set_rx_csum = netxen_nic_set_rx_csum,
908 .get_coalesce = netxen_get_intr_coalesce,
909 .set_coalesce = netxen_set_intr_coalesce,