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 ecmd->speed = adapter->link_speed;
140 ecmd->duplex = adapter->link_duplex;
141 ecmd->autoneg = adapter->link_autoneg;
143 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
146 adapter->hw_read_wx(adapter, NETXEN_PORT_MODE_ADDR, &val, 4);
147 if (val == NETXEN_PORT_MODE_802_3_AP) {
148 ecmd->supported = SUPPORTED_1000baseT_Full;
149 ecmd->advertising = ADVERTISED_1000baseT_Full;
151 ecmd->supported = SUPPORTED_10000baseT_Full;
152 ecmd->advertising = ADVERTISED_10000baseT_Full;
155 ecmd->port = PORT_TP;
157 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
158 u16 pcifn = adapter->ahw.pci_func;
160 adapter->hw_read_wx(adapter,
161 P3_LINK_SPEED_REG(pcifn), &val, 4);
162 ecmd->speed = P3_LINK_SPEED_MHZ *
163 P3_LINK_SPEED_VAL(pcifn, val);
165 ecmd->speed = SPEED_10000;
167 ecmd->duplex = DUPLEX_FULL;
168 ecmd->autoneg = AUTONEG_DISABLE;
172 ecmd->phy_address = adapter->physical_port;
173 ecmd->transceiver = XCVR_EXTERNAL;
175 switch ((netxen_brdtype_t) boardinfo->board_type) {
176 case NETXEN_BRDTYPE_P2_SB35_4G:
177 case NETXEN_BRDTYPE_P2_SB31_2G:
178 case NETXEN_BRDTYPE_P3_REF_QG:
179 case NETXEN_BRDTYPE_P3_4_GB:
180 case NETXEN_BRDTYPE_P3_4_GB_MM:
182 ecmd->supported |= SUPPORTED_Autoneg;
183 ecmd->advertising |= ADVERTISED_Autoneg;
184 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
185 case NETXEN_BRDTYPE_P3_10G_CX4:
186 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
187 case NETXEN_BRDTYPE_P3_10000_BASE_T:
188 ecmd->supported |= SUPPORTED_TP;
189 ecmd->advertising |= ADVERTISED_TP;
190 ecmd->port = PORT_TP;
191 ecmd->autoneg = (boardinfo->board_type ==
192 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
193 (AUTONEG_DISABLE) : (adapter->link_autoneg);
195 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
196 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
197 case NETXEN_BRDTYPE_P3_IMEZ:
198 case NETXEN_BRDTYPE_P3_XG_LOM:
199 case NETXEN_BRDTYPE_P3_HMEZ:
200 ecmd->supported |= SUPPORTED_MII;
201 ecmd->advertising |= ADVERTISED_MII;
202 ecmd->port = PORT_FIBRE;
203 ecmd->autoneg = AUTONEG_DISABLE;
205 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
206 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
207 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
208 ecmd->advertising |= ADVERTISED_TP;
209 ecmd->supported |= SUPPORTED_TP;
210 case NETXEN_BRDTYPE_P2_SB31_10G:
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;
217 case NETXEN_BRDTYPE_P3_10G_TP:
218 if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
219 ecmd->autoneg = AUTONEG_DISABLE;
220 ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
222 (ADVERTISED_FIBRE | ADVERTISED_TP);
223 ecmd->port = PORT_FIBRE;
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 (netxen_brdtype_t) boardinfo->board_type);
242 netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
244 struct netxen_adapter *adapter = netdev_priv(dev);
247 /* read which mode */
248 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
249 /* autonegotiation */
250 if (adapter->phy_write
251 && adapter->phy_write(adapter,
252 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
256 adapter->link_autoneg = ecmd->autoneg;
258 if (adapter->phy_read
259 && adapter->phy_read(adapter,
260 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
265 switch (ecmd->speed) {
267 netxen_set_phy_speed(status, 0);
270 netxen_set_phy_speed(status, 1);
273 netxen_set_phy_speed(status, 2);
276 /* set duplex mode */
277 if (ecmd->duplex == DUPLEX_HALF)
278 netxen_clear_phy_duplex(status);
279 if (ecmd->duplex == DUPLEX_FULL)
280 netxen_set_phy_duplex(status);
281 if (adapter->phy_write
282 && adapter->phy_write(adapter,
283 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
284 *((int *)&status)) != 0)
287 adapter->link_speed = ecmd->speed;
288 adapter->link_duplex = ecmd->duplex;
293 if (!netif_running(dev))
296 dev->netdev_ops->ndo_stop(dev);
297 return dev->netdev_ops->ndo_open(dev);
300 static int netxen_nic_get_regs_len(struct net_device *dev)
302 return NETXEN_NIC_REGS_LEN;
305 struct netxen_niu_regs {
306 __u32 reg[NETXEN_NIC_REGS_COUNT];
309 static struct netxen_niu_regs niu_registers[] = {
313 NETXEN_NIU_GB_SERDES_RESET,
314 NETXEN_NIU_GB0_MII_MODE,
315 NETXEN_NIU_GB1_MII_MODE,
316 NETXEN_NIU_GB2_MII_MODE,
317 NETXEN_NIU_GB3_MII_MODE,
318 NETXEN_NIU_GB0_GMII_MODE,
319 NETXEN_NIU_GB1_GMII_MODE,
320 NETXEN_NIU_GB2_GMII_MODE,
321 NETXEN_NIU_GB3_GMII_MODE,
322 NETXEN_NIU_REMOTE_LOOPBACK,
323 NETXEN_NIU_GB0_HALF_DUPLEX,
324 NETXEN_NIU_GB1_HALF_DUPLEX,
325 NETXEN_NIU_RESET_SYS_FIFOS,
326 NETXEN_NIU_GB_CRC_DROP,
327 NETXEN_NIU_GB_DROP_WRONGADDR,
328 NETXEN_NIU_TEST_MUX_CTL,
330 NETXEN_NIU_GB_MAC_CONFIG_0(0),
331 NETXEN_NIU_GB_MAC_CONFIG_1(0),
332 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
333 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
334 NETXEN_NIU_GB_TEST_REG(0),
335 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
336 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
337 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
338 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
339 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
340 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
341 NETXEN_NIU_GB_INTERFACE_CTRL(0),
342 NETXEN_NIU_GB_INTERFACE_STATUS(0),
343 NETXEN_NIU_GB_STATION_ADDR_0(0),
344 NETXEN_NIU_GB_STATION_ADDR_1(0),
351 NETXEN_NIU_XG_SINGLE_TERM,
352 NETXEN_NIU_XG_DRIVE_HI,
353 NETXEN_NIU_XG_DRIVE_LO,
356 NETXEN_NIU_XG_WORD_ALIGN,
358 NETXEN_NIU_XG_POWER_DOWN,
359 NETXEN_NIU_XG_RESET_PLL,
360 NETXEN_NIU_XG_SERDES_LOOPBACK,
361 NETXEN_NIU_XG_DO_BYTE_ALIGN,
362 NETXEN_NIU_XG_TX_ENABLE,
363 NETXEN_NIU_XG_RX_ENABLE,
364 NETXEN_NIU_XG_STATUS,
365 NETXEN_NIU_XG_PAUSE_THRESHOLD,
366 NETXEN_NIU_XGE_CONFIG_0,
367 NETXEN_NIU_XGE_CONFIG_1,
369 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
370 NETXEN_NIU_XGE_STATION_ADDR_0_1,
371 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
372 NETXEN_NIU_XGE_STATUS,
373 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
374 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
375 NETXEN_NIU_XGE_TX_BYTE_CNT,
376 NETXEN_NIU_XGE_TX_FRAME_CNT,
377 NETXEN_NIU_XGE_RX_BYTE_CNT,
378 NETXEN_NIU_XGE_RX_FRAME_CNT,
379 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
380 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
381 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
382 NETXEN_NIU_XGE_CRC_ERROR_CNT,
383 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
384 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
385 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
386 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
387 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
388 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
395 netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
397 struct netxen_adapter *adapter = netdev_priv(dev);
398 __u32 mode, *regs_buff = p;
401 memset(p, 0, NETXEN_NIC_REGS_LEN);
402 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
403 (adapter->pdev)->device;
405 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, ®s_buff[0], 4);
408 /* Common registers to all the modes */
409 adapter->hw_read_wx(adapter,
410 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, ®s_buff[2], 4);
412 mode = (mode / 2) - 1;
415 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
416 /* GB: port specific registers */
417 if (mode == 0 && i >= 19)
418 window = adapter->physical_port *
419 NETXEN_NIC_PORT_WINDOW;
421 adapter->hw_read_wx(adapter,
422 niu_registers[mode].reg[i - 3] + window,
429 static u32 netxen_nic_test_link(struct net_device *dev)
431 struct netxen_adapter *adapter = netdev_priv(dev);
435 /* read which mode */
436 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
437 if (adapter->phy_read
438 && adapter->phy_read(adapter,
439 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
443 val = netxen_get_phy_link(status);
446 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
447 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
448 return (val == XG_LINK_UP) ? 0 : 1;
454 netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
457 struct netxen_adapter *adapter = netdev_priv(dev);
461 if (eeprom->len == 0)
464 eeprom->magic = (adapter->pdev)->vendor |
465 ((adapter->pdev)->device << 16);
466 offset = eeprom->offset;
468 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
478 netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
481 struct netxen_adapter *adapter = netdev_priv(dev);
482 int offset = eeprom->offset;
483 static int flash_start;
484 static int ready_to_flash;
487 if (flash_start == 0) {
488 netxen_halt_pegs(adapter);
489 ret = netxen_flash_unlock(adapter);
491 printk(KERN_ERR "%s: Flash unlock failed.\n",
492 netxen_nic_driver_name);
495 printk(KERN_INFO "%s: flash unlocked. \n",
496 netxen_nic_driver_name);
497 ret = netxen_flash_erase_secondary(adapter);
498 if (ret != FLASH_SUCCESS) {
499 printk(KERN_ERR "%s: Flash erase failed.\n",
500 netxen_nic_driver_name);
503 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
504 netxen_nic_driver_name);
509 if (offset == NETXEN_BOOTLD_START) {
510 ret = netxen_flash_erase_primary(adapter);
511 if (ret != FLASH_SUCCESS) {
512 printk(KERN_ERR "%s: Flash erase failed.\n",
513 netxen_nic_driver_name);
517 ret = netxen_rom_se(adapter, NETXEN_USER_START);
518 if (ret != FLASH_SUCCESS)
520 ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
521 if (ret != FLASH_SUCCESS)
524 printk(KERN_INFO "%s: primary flash erased successfully\n",
525 netxen_nic_driver_name);
527 ret = netxen_backup_crbinit(adapter);
528 if (ret != FLASH_SUCCESS) {
529 printk(KERN_ERR "%s: CRBinit backup failed.\n",
530 netxen_nic_driver_name);
533 printk(KERN_INFO "%s: CRBinit backup done.\n",
534 netxen_nic_driver_name);
538 if (!ready_to_flash) {
539 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
540 netxen_nic_driver_name);
544 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
549 netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
551 struct netxen_adapter *adapter = netdev_priv(dev);
554 ring->rx_pending = 0;
555 ring->rx_jumbo_pending = 0;
556 for (i = 0; i < MAX_RCV_CTX; ++i) {
557 ring->rx_pending += adapter->recv_ctx[i].
558 rds_rings[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
559 ring->rx_jumbo_pending += adapter->recv_ctx[i].
560 rds_rings[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
562 ring->tx_pending = adapter->max_tx_desc_count;
564 if (adapter->ahw.board_type == NETXEN_NIC_GBE)
565 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
567 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
568 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
569 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
570 ring->rx_mini_max_pending = 0;
571 ring->rx_mini_pending = 0;
575 netxen_nic_get_pauseparam(struct net_device *dev,
576 struct ethtool_pauseparam *pause)
578 struct netxen_adapter *adapter = netdev_priv(dev);
580 int port = adapter->physical_port;
582 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
583 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
585 /* get flow control settings */
586 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
588 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
589 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
592 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
595 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
598 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
602 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
605 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
606 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
609 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
611 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
613 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
615 printk(KERN_ERR"%s: Unknown board type: %x\n",
616 netxen_nic_driver_name, adapter->ahw.board_type);
621 netxen_nic_set_pauseparam(struct net_device *dev,
622 struct ethtool_pauseparam *pause)
624 struct netxen_adapter *adapter = netdev_priv(dev);
626 int port = adapter->physical_port;
628 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
629 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
631 /* set flow control */
632 netxen_nic_read_w0(adapter,
633 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
636 netxen_gb_rx_flowctl(val);
638 netxen_gb_unset_rx_flowctl(val);
640 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
643 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
647 netxen_gb_unset_gb0_mask(val);
649 netxen_gb_set_gb0_mask(val);
653 netxen_gb_unset_gb1_mask(val);
655 netxen_gb_set_gb1_mask(val);
659 netxen_gb_unset_gb2_mask(val);
661 netxen_gb_set_gb2_mask(val);
666 netxen_gb_unset_gb3_mask(val);
668 netxen_gb_set_gb3_mask(val);
671 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
672 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
673 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
675 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
678 netxen_xg_unset_xg0_mask(val);
680 netxen_xg_set_xg0_mask(val);
683 netxen_xg_unset_xg1_mask(val);
685 netxen_xg_set_xg1_mask(val);
687 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
689 printk(KERN_ERR "%s: Unknown board type: %x\n",
690 netxen_nic_driver_name,
691 adapter->ahw.board_type);
696 static int netxen_nic_reg_test(struct net_device *dev)
698 struct netxen_adapter *adapter = netdev_priv(dev);
699 u32 data_read, data_written;
701 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
702 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
705 data_written = (u32)0xa5a5a5a5;
707 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
708 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
709 if (data_written != data_read)
715 static int netxen_get_sset_count(struct net_device *dev, int sset)
719 return NETXEN_NIC_TEST_LEN;
721 return NETXEN_NIC_STATS_LEN;
728 netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
731 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
732 if ((data[0] = netxen_nic_reg_test(dev)))
733 eth_test->flags |= ETH_TEST_FL_FAILED;
735 if ((data[1] = (u64) netxen_nic_test_link(dev)))
736 eth_test->flags |= ETH_TEST_FL_FAILED;
740 netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
746 memcpy(data, *netxen_nic_gstrings_test,
747 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
750 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
751 memcpy(data + index * ETH_GSTRING_LEN,
752 netxen_nic_gstrings_stats[index].stat_string,
760 netxen_nic_get_ethtool_stats(struct net_device *dev,
761 struct ethtool_stats *stats, u64 * data)
763 struct netxen_adapter *adapter = netdev_priv(dev);
766 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
769 netxen_nic_gstrings_stats[index].stat_offset;
771 (netxen_nic_gstrings_stats[index].sizeof_stat ==
772 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
776 static u32 netxen_nic_get_rx_csum(struct net_device *dev)
778 struct netxen_adapter *adapter = netdev_priv(dev);
779 return adapter->rx_csum;
782 static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
784 struct netxen_adapter *adapter = netdev_priv(dev);
785 adapter->rx_csum = !!data;
789 static u32 netxen_nic_get_tso(struct net_device *dev)
791 struct netxen_adapter *adapter = netdev_priv(dev);
793 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
794 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
796 return (dev->features & NETIF_F_TSO) != 0;
799 static int netxen_nic_set_tso(struct net_device *dev, u32 data)
802 struct netxen_adapter *adapter = netdev_priv(dev);
804 dev->features |= NETIF_F_TSO;
805 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
806 dev->features |= NETIF_F_TSO6;
808 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
814 * Set the coalescing parameters. Currently only normal is supported.
815 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
816 * firmware coalescing to default.
818 static int netxen_set_intr_coalesce(struct net_device *netdev,
819 struct ethtool_coalesce *ethcoal)
821 struct netxen_adapter *adapter = netdev_priv(netdev);
823 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
826 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
830 * Return Error if unsupported values or
831 * unsupported parameters are set.
833 if (ethcoal->rx_coalesce_usecs > 0xffff ||
834 ethcoal->rx_max_coalesced_frames > 0xffff ||
835 ethcoal->tx_coalesce_usecs > 0xffff ||
836 ethcoal->tx_max_coalesced_frames > 0xffff ||
837 ethcoal->rx_coalesce_usecs_irq ||
838 ethcoal->rx_max_coalesced_frames_irq ||
839 ethcoal->tx_coalesce_usecs_irq ||
840 ethcoal->tx_max_coalesced_frames_irq ||
841 ethcoal->stats_block_coalesce_usecs ||
842 ethcoal->use_adaptive_rx_coalesce ||
843 ethcoal->use_adaptive_tx_coalesce ||
844 ethcoal->pkt_rate_low ||
845 ethcoal->rx_coalesce_usecs_low ||
846 ethcoal->rx_max_coalesced_frames_low ||
847 ethcoal->tx_coalesce_usecs_low ||
848 ethcoal->tx_max_coalesced_frames_low ||
849 ethcoal->pkt_rate_high ||
850 ethcoal->rx_coalesce_usecs_high ||
851 ethcoal->rx_max_coalesced_frames_high ||
852 ethcoal->tx_coalesce_usecs_high ||
853 ethcoal->tx_max_coalesced_frames_high)
856 if (!ethcoal->rx_coalesce_usecs ||
857 !ethcoal->rx_max_coalesced_frames) {
858 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
859 adapter->coal.normal.data.rx_time_us =
860 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
861 adapter->coal.normal.data.rx_packets =
862 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
864 adapter->coal.flags = 0;
865 adapter->coal.normal.data.rx_time_us =
866 ethcoal->rx_coalesce_usecs;
867 adapter->coal.normal.data.rx_packets =
868 ethcoal->rx_max_coalesced_frames;
870 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
871 adapter->coal.normal.data.tx_packets =
872 ethcoal->tx_max_coalesced_frames;
874 netxen_config_intr_coalesce(adapter);
879 static int netxen_get_intr_coalesce(struct net_device *netdev,
880 struct ethtool_coalesce *ethcoal)
882 struct netxen_adapter *adapter = netdev_priv(netdev);
884 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
887 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
890 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
891 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
892 ethcoal->rx_max_coalesced_frames =
893 adapter->coal.normal.data.rx_packets;
894 ethcoal->tx_max_coalesced_frames =
895 adapter->coal.normal.data.tx_packets;
900 struct ethtool_ops netxen_nic_ethtool_ops = {
901 .get_settings = netxen_nic_get_settings,
902 .set_settings = netxen_nic_set_settings,
903 .get_drvinfo = netxen_nic_get_drvinfo,
904 .get_regs_len = netxen_nic_get_regs_len,
905 .get_regs = netxen_nic_get_regs,
906 .get_link = ethtool_op_get_link,
907 .get_eeprom_len = netxen_nic_get_eeprom_len,
908 .get_eeprom = netxen_nic_get_eeprom,
910 .set_eeprom = netxen_nic_set_eeprom,
912 .get_ringparam = netxen_nic_get_ringparam,
913 .get_pauseparam = netxen_nic_get_pauseparam,
914 .set_pauseparam = netxen_nic_set_pauseparam,
915 .set_tx_csum = ethtool_op_set_tx_csum,
916 .set_sg = ethtool_op_set_sg,
917 .get_tso = netxen_nic_get_tso,
918 .set_tso = netxen_nic_set_tso,
919 .self_test = netxen_nic_diag_test,
920 .get_strings = netxen_nic_get_strings,
921 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
922 .get_sset_count = netxen_get_sset_count,
923 .get_rx_csum = netxen_nic_get_rx_csum,
924 .set_rx_csum = netxen_nic_set_rx_csum,
925 .get_coalesce = netxen_get_intr_coalesce,
926 .set_coalesce = netxen_set_intr_coalesce,