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 if (netif_running(dev)) {
140 ecmd->speed = adapter->link_speed;
141 ecmd->duplex = adapter->link_duplex;
142 ecmd->autoneg = adapter->link_autoneg;
145 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
148 adapter->hw_read_wx(adapter, NETXEN_PORT_MODE_ADDR, &val, 4);
149 if (val == NETXEN_PORT_MODE_802_3_AP) {
150 ecmd->supported = SUPPORTED_1000baseT_Full;
151 ecmd->advertising = ADVERTISED_1000baseT_Full;
153 ecmd->supported = SUPPORTED_10000baseT_Full;
154 ecmd->advertising = ADVERTISED_10000baseT_Full;
157 ecmd->port = PORT_TP;
159 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
160 u16 pcifn = adapter->ahw.pci_func;
162 adapter->hw_read_wx(adapter,
163 P3_LINK_SPEED_REG(pcifn), &val, 4);
164 ecmd->speed = P3_LINK_SPEED_MHZ *
165 P3_LINK_SPEED_VAL(pcifn, val);
167 ecmd->speed = SPEED_10000;
169 ecmd->duplex = DUPLEX_FULL;
170 ecmd->autoneg = AUTONEG_DISABLE;
174 ecmd->phy_address = adapter->portnum;
175 ecmd->transceiver = XCVR_EXTERNAL;
177 switch ((netxen_brdtype_t) boardinfo->board_type) {
178 case NETXEN_BRDTYPE_P2_SB35_4G:
179 case NETXEN_BRDTYPE_P2_SB31_2G:
180 case NETXEN_BRDTYPE_P3_REF_QG:
181 case NETXEN_BRDTYPE_P3_4_GB:
182 case NETXEN_BRDTYPE_P3_4_GB_MM:
183 case NETXEN_BRDTYPE_P3_10000_BASE_T:
185 ecmd->supported |= SUPPORTED_Autoneg;
186 ecmd->advertising |= ADVERTISED_Autoneg;
187 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
188 case NETXEN_BRDTYPE_P3_10G_CX4:
189 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
190 ecmd->supported |= SUPPORTED_TP;
191 ecmd->advertising |= ADVERTISED_TP;
192 ecmd->port = PORT_TP;
193 ecmd->autoneg = (boardinfo->board_type ==
194 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
195 (AUTONEG_DISABLE) : (adapter->link_autoneg);
197 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
198 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
199 case NETXEN_BRDTYPE_P3_IMEZ:
200 case NETXEN_BRDTYPE_P3_XG_LOM:
201 case NETXEN_BRDTYPE_P3_HMEZ:
202 ecmd->supported |= SUPPORTED_MII;
203 ecmd->advertising |= ADVERTISED_MII;
204 ecmd->port = PORT_FIBRE;
205 ecmd->autoneg = AUTONEG_DISABLE;
207 case NETXEN_BRDTYPE_P2_SB31_10G:
208 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
209 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
210 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
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;
218 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
219 (netxen_brdtype_t) boardinfo->board_type);
227 netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
229 struct netxen_adapter *adapter = netdev_priv(dev);
232 /* read which mode */
233 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
234 /* autonegotiation */
235 if (adapter->phy_write
236 && adapter->phy_write(adapter,
237 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
241 adapter->link_autoneg = ecmd->autoneg;
243 if (adapter->phy_read
244 && adapter->phy_read(adapter,
245 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
250 switch (ecmd->speed) {
252 netxen_set_phy_speed(status, 0);
255 netxen_set_phy_speed(status, 1);
258 netxen_set_phy_speed(status, 2);
261 /* set duplex mode */
262 if (ecmd->duplex == DUPLEX_HALF)
263 netxen_clear_phy_duplex(status);
264 if (ecmd->duplex == DUPLEX_FULL)
265 netxen_set_phy_duplex(status);
266 if (adapter->phy_write
267 && adapter->phy_write(adapter,
268 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
269 *((int *)&status)) != 0)
272 adapter->link_speed = ecmd->speed;
273 adapter->link_duplex = ecmd->duplex;
278 if (netif_running(dev)) {
285 static int netxen_nic_get_regs_len(struct net_device *dev)
287 return NETXEN_NIC_REGS_LEN;
290 struct netxen_niu_regs {
291 __u32 reg[NETXEN_NIC_REGS_COUNT];
294 static struct netxen_niu_regs niu_registers[] = {
298 NETXEN_NIU_GB_SERDES_RESET,
299 NETXEN_NIU_GB0_MII_MODE,
300 NETXEN_NIU_GB1_MII_MODE,
301 NETXEN_NIU_GB2_MII_MODE,
302 NETXEN_NIU_GB3_MII_MODE,
303 NETXEN_NIU_GB0_GMII_MODE,
304 NETXEN_NIU_GB1_GMII_MODE,
305 NETXEN_NIU_GB2_GMII_MODE,
306 NETXEN_NIU_GB3_GMII_MODE,
307 NETXEN_NIU_REMOTE_LOOPBACK,
308 NETXEN_NIU_GB0_HALF_DUPLEX,
309 NETXEN_NIU_GB1_HALF_DUPLEX,
310 NETXEN_NIU_RESET_SYS_FIFOS,
311 NETXEN_NIU_GB_CRC_DROP,
312 NETXEN_NIU_GB_DROP_WRONGADDR,
313 NETXEN_NIU_TEST_MUX_CTL,
315 NETXEN_NIU_GB_MAC_CONFIG_0(0),
316 NETXEN_NIU_GB_MAC_CONFIG_1(0),
317 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
318 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
319 NETXEN_NIU_GB_TEST_REG(0),
320 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
321 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
322 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
323 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
324 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
325 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
326 NETXEN_NIU_GB_INTERFACE_CTRL(0),
327 NETXEN_NIU_GB_INTERFACE_STATUS(0),
328 NETXEN_NIU_GB_STATION_ADDR_0(0),
329 NETXEN_NIU_GB_STATION_ADDR_1(0),
336 NETXEN_NIU_XG_SINGLE_TERM,
337 NETXEN_NIU_XG_DRIVE_HI,
338 NETXEN_NIU_XG_DRIVE_LO,
341 NETXEN_NIU_XG_WORD_ALIGN,
343 NETXEN_NIU_XG_POWER_DOWN,
344 NETXEN_NIU_XG_RESET_PLL,
345 NETXEN_NIU_XG_SERDES_LOOPBACK,
346 NETXEN_NIU_XG_DO_BYTE_ALIGN,
347 NETXEN_NIU_XG_TX_ENABLE,
348 NETXEN_NIU_XG_RX_ENABLE,
349 NETXEN_NIU_XG_STATUS,
350 NETXEN_NIU_XG_PAUSE_THRESHOLD,
351 NETXEN_NIU_XGE_CONFIG_0,
352 NETXEN_NIU_XGE_CONFIG_1,
354 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
355 NETXEN_NIU_XGE_STATION_ADDR_0_1,
356 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
357 NETXEN_NIU_XGE_STATUS,
358 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
359 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
360 NETXEN_NIU_XGE_TX_BYTE_CNT,
361 NETXEN_NIU_XGE_TX_FRAME_CNT,
362 NETXEN_NIU_XGE_RX_BYTE_CNT,
363 NETXEN_NIU_XGE_RX_FRAME_CNT,
364 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
365 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
366 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
367 NETXEN_NIU_XGE_CRC_ERROR_CNT,
368 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
369 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
370 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
371 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
372 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
373 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
380 netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
382 struct netxen_adapter *adapter = netdev_priv(dev);
383 __u32 mode, *regs_buff = p;
386 memset(p, 0, NETXEN_NIC_REGS_LEN);
387 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
388 (adapter->pdev)->device;
390 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, ®s_buff[0], 4);
393 /* Common registers to all the modes */
394 adapter->hw_read_wx(adapter,
395 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, ®s_buff[2], 4);
397 mode = (mode / 2) - 1;
400 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
401 /* GB: port specific registers */
402 if (mode == 0 && i >= 19)
403 window = adapter->physical_port *
404 NETXEN_NIC_PORT_WINDOW;
406 adapter->hw_read_wx(adapter,
407 niu_registers[mode].reg[i - 3] + window,
414 static u32 netxen_nic_test_link(struct net_device *dev)
416 struct netxen_adapter *adapter = netdev_priv(dev);
420 /* read which mode */
421 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
422 if (adapter->phy_read
423 && adapter->phy_read(adapter,
424 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
428 val = netxen_get_phy_link(status);
431 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
432 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
433 return (val == XG_LINK_UP) ? 0 : 1;
439 netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
442 struct netxen_adapter *adapter = netdev_priv(dev);
446 if (eeprom->len == 0)
449 eeprom->magic = (adapter->pdev)->vendor |
450 ((adapter->pdev)->device << 16);
451 offset = eeprom->offset;
453 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
463 netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
466 struct netxen_adapter *adapter = netdev_priv(dev);
467 int offset = eeprom->offset;
468 static int flash_start;
469 static int ready_to_flash;
472 if (flash_start == 0) {
473 netxen_halt_pegs(adapter);
474 ret = netxen_flash_unlock(adapter);
476 printk(KERN_ERR "%s: Flash unlock failed.\n",
477 netxen_nic_driver_name);
480 printk(KERN_INFO "%s: flash unlocked. \n",
481 netxen_nic_driver_name);
482 ret = netxen_flash_erase_secondary(adapter);
483 if (ret != FLASH_SUCCESS) {
484 printk(KERN_ERR "%s: Flash erase failed.\n",
485 netxen_nic_driver_name);
488 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
489 netxen_nic_driver_name);
494 if (offset == NETXEN_BOOTLD_START) {
495 ret = netxen_flash_erase_primary(adapter);
496 if (ret != FLASH_SUCCESS) {
497 printk(KERN_ERR "%s: Flash erase failed.\n",
498 netxen_nic_driver_name);
502 ret = netxen_rom_se(adapter, NETXEN_USER_START);
503 if (ret != FLASH_SUCCESS)
505 ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
506 if (ret != FLASH_SUCCESS)
509 printk(KERN_INFO "%s: primary flash erased successfully\n",
510 netxen_nic_driver_name);
512 ret = netxen_backup_crbinit(adapter);
513 if (ret != FLASH_SUCCESS) {
514 printk(KERN_ERR "%s: CRBinit backup failed.\n",
515 netxen_nic_driver_name);
518 printk(KERN_INFO "%s: CRBinit backup done.\n",
519 netxen_nic_driver_name);
523 if (!ready_to_flash) {
524 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
525 netxen_nic_driver_name);
529 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
534 netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
536 struct netxen_adapter *adapter = netdev_priv(dev);
539 ring->rx_pending = 0;
540 ring->rx_jumbo_pending = 0;
541 for (i = 0; i < MAX_RCV_CTX; ++i) {
542 ring->rx_pending += adapter->recv_ctx[i].
543 rds_rings[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
544 ring->rx_jumbo_pending += adapter->recv_ctx[i].
545 rds_rings[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
547 ring->tx_pending = adapter->max_tx_desc_count;
549 ring->rx_max_pending = MAX_RCV_DESCRIPTORS;
550 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
551 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
552 ring->rx_mini_max_pending = 0;
553 ring->rx_mini_pending = 0;
557 netxen_nic_get_pauseparam(struct net_device *dev,
558 struct ethtool_pauseparam *pause)
560 struct netxen_adapter *adapter = netdev_priv(dev);
562 int port = adapter->physical_port;
564 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
565 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
567 /* get flow control settings */
568 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
570 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
571 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
574 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
577 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
580 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
584 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
587 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
588 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
591 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
593 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
595 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
597 printk(KERN_ERR"%s: Unknown board type: %x\n",
598 netxen_nic_driver_name, adapter->ahw.board_type);
603 netxen_nic_set_pauseparam(struct net_device *dev,
604 struct ethtool_pauseparam *pause)
606 struct netxen_adapter *adapter = netdev_priv(dev);
608 int port = adapter->physical_port;
610 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
611 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
613 /* set flow control */
614 netxen_nic_read_w0(adapter,
615 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
618 netxen_gb_rx_flowctl(val);
620 netxen_gb_unset_rx_flowctl(val);
622 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
625 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
629 netxen_gb_unset_gb0_mask(val);
631 netxen_gb_set_gb0_mask(val);
635 netxen_gb_unset_gb1_mask(val);
637 netxen_gb_set_gb1_mask(val);
641 netxen_gb_unset_gb2_mask(val);
643 netxen_gb_set_gb2_mask(val);
648 netxen_gb_unset_gb3_mask(val);
650 netxen_gb_set_gb3_mask(val);
653 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
654 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
655 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
657 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
660 netxen_xg_unset_xg0_mask(val);
662 netxen_xg_set_xg0_mask(val);
665 netxen_xg_unset_xg1_mask(val);
667 netxen_xg_set_xg1_mask(val);
669 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
671 printk(KERN_ERR "%s: Unknown board type: %x\n",
672 netxen_nic_driver_name,
673 adapter->ahw.board_type);
678 static int netxen_nic_reg_test(struct net_device *dev)
680 struct netxen_adapter *adapter = netdev_priv(dev);
681 u32 data_read, data_written;
683 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
684 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
687 data_written = (u32)0xa5a5a5a5;
689 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
690 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
691 if (data_written != data_read)
697 static int netxen_get_sset_count(struct net_device *dev, int sset)
701 return NETXEN_NIC_TEST_LEN;
703 return NETXEN_NIC_STATS_LEN;
710 netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
713 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
714 if ((data[0] = netxen_nic_reg_test(dev)))
715 eth_test->flags |= ETH_TEST_FL_FAILED;
717 if ((data[1] = (u64) netxen_nic_test_link(dev)))
718 eth_test->flags |= ETH_TEST_FL_FAILED;
722 netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
728 memcpy(data, *netxen_nic_gstrings_test,
729 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
732 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
733 memcpy(data + index * ETH_GSTRING_LEN,
734 netxen_nic_gstrings_stats[index].stat_string,
742 netxen_nic_get_ethtool_stats(struct net_device *dev,
743 struct ethtool_stats *stats, u64 * data)
745 struct netxen_adapter *adapter = netdev_priv(dev);
748 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
751 netxen_nic_gstrings_stats[index].stat_offset;
753 (netxen_nic_gstrings_stats[index].sizeof_stat ==
754 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
758 static u32 netxen_nic_get_rx_csum(struct net_device *dev)
760 struct netxen_adapter *adapter = netdev_priv(dev);
761 return adapter->rx_csum;
764 static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
766 struct netxen_adapter *adapter = netdev_priv(dev);
767 adapter->rx_csum = !!data;
771 static u32 netxen_nic_get_tso(struct net_device *dev)
773 struct netxen_adapter *adapter = netdev_priv(dev);
775 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
776 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
778 return (dev->features & NETIF_F_TSO) != 0;
781 static int netxen_nic_set_tso(struct net_device *dev, u32 data)
784 struct netxen_adapter *adapter = netdev_priv(dev);
786 dev->features |= NETIF_F_TSO;
787 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
788 dev->features |= NETIF_F_TSO6;
790 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
796 * Set the coalescing parameters. Currently only normal is supported.
797 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
798 * firmware coalescing to default.
800 static int netxen_set_intr_coalesce(struct net_device *netdev,
801 struct ethtool_coalesce *ethcoal)
803 struct netxen_adapter *adapter = netdev_priv(netdev);
805 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
808 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
812 * Return Error if unsupported values or
813 * unsupported parameters are set.
815 if (ethcoal->rx_coalesce_usecs > 0xffff ||
816 ethcoal->rx_max_coalesced_frames > 0xffff ||
817 ethcoal->tx_coalesce_usecs > 0xffff ||
818 ethcoal->tx_max_coalesced_frames > 0xffff ||
819 ethcoal->rx_coalesce_usecs_irq ||
820 ethcoal->rx_max_coalesced_frames_irq ||
821 ethcoal->tx_coalesce_usecs_irq ||
822 ethcoal->tx_max_coalesced_frames_irq ||
823 ethcoal->stats_block_coalesce_usecs ||
824 ethcoal->use_adaptive_rx_coalesce ||
825 ethcoal->use_adaptive_tx_coalesce ||
826 ethcoal->pkt_rate_low ||
827 ethcoal->rx_coalesce_usecs_low ||
828 ethcoal->rx_max_coalesced_frames_low ||
829 ethcoal->tx_coalesce_usecs_low ||
830 ethcoal->tx_max_coalesced_frames_low ||
831 ethcoal->pkt_rate_high ||
832 ethcoal->rx_coalesce_usecs_high ||
833 ethcoal->rx_max_coalesced_frames_high ||
834 ethcoal->tx_coalesce_usecs_high ||
835 ethcoal->tx_max_coalesced_frames_high)
838 if (!ethcoal->rx_coalesce_usecs ||
839 !ethcoal->rx_max_coalesced_frames) {
840 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
841 adapter->coal.normal.data.rx_time_us =
842 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
843 adapter->coal.normal.data.rx_packets =
844 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
846 adapter->coal.flags = 0;
847 adapter->coal.normal.data.rx_time_us =
848 ethcoal->rx_coalesce_usecs;
849 adapter->coal.normal.data.rx_packets =
850 ethcoal->rx_max_coalesced_frames;
852 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
853 adapter->coal.normal.data.tx_packets =
854 ethcoal->tx_max_coalesced_frames;
856 netxen_config_intr_coalesce(adapter);
861 static int netxen_get_intr_coalesce(struct net_device *netdev,
862 struct ethtool_coalesce *ethcoal)
864 struct netxen_adapter *adapter = netdev_priv(netdev);
866 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
869 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
872 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
873 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
874 ethcoal->rx_max_coalesced_frames =
875 adapter->coal.normal.data.rx_packets;
876 ethcoal->tx_max_coalesced_frames =
877 adapter->coal.normal.data.tx_packets;
882 struct ethtool_ops netxen_nic_ethtool_ops = {
883 .get_settings = netxen_nic_get_settings,
884 .set_settings = netxen_nic_set_settings,
885 .get_drvinfo = netxen_nic_get_drvinfo,
886 .get_regs_len = netxen_nic_get_regs_len,
887 .get_regs = netxen_nic_get_regs,
888 .get_link = ethtool_op_get_link,
889 .get_eeprom_len = netxen_nic_get_eeprom_len,
890 .get_eeprom = netxen_nic_get_eeprom,
892 .set_eeprom = netxen_nic_set_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 .self_test = netxen_nic_diag_test,
902 .get_strings = netxen_nic_get_strings,
903 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
904 .get_sset_count = netxen_get_sset_count,
905 .get_rx_csum = netxen_nic_get_rx_csum,
906 .set_rx_csum = netxen_nic_set_rx_csum,
907 .get_coalesce = netxen_get_intr_coalesce,
908 .set_coalesce = netxen_set_intr_coalesce,