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 <asm/uaccess.h>
34 #include <linux/pci.h>
36 #include <linux/netdevice.h>
37 #include <linux/ethtool.h>
39 #include "netxen_nic.h"
40 #include "netxen_nic_hw.h"
41 #include "netxen_nic_phan_reg.h"
43 struct netxen_nic_stats {
44 char stat_string[ETH_GSTRING_LEN];
49 #define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
50 offsetof(struct netxen_adapter, m)
52 #define NETXEN_NIC_PORT_WINDOW 0x10000
53 #define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
55 static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
56 {"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)},
57 {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
58 {"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)},
59 {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
60 {"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)},
61 {"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)},
62 {"polled", NETXEN_NIC_STAT(stats.polled)},
63 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
64 {"csummed", NETXEN_NIC_STAT(stats.csummed)},
65 {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
66 {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
67 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
70 #define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
72 static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
73 "Register_Test_on_offline",
74 "Link_Test_on_offline"
77 #define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
79 #define NETXEN_NIC_REGS_COUNT 42
80 #define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
81 #define NETXEN_MAX_EEPROM_LEN 1024
83 static int netxen_nic_get_eeprom_len(struct net_device *dev)
85 return NETXEN_FLASH_TOTAL_SIZE;
89 netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
91 struct netxen_adapter *adapter = netdev_priv(dev);
97 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
98 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
99 write_lock_irqsave(&adapter->adapter_lock, flags);
100 fw_major = adapter->pci_read_normalize(adapter,
101 NETXEN_FW_VERSION_MAJOR);
102 fw_minor = adapter->pci_read_normalize(adapter,
103 NETXEN_FW_VERSION_MINOR);
104 fw_build = adapter->pci_read_normalize(adapter,
105 NETXEN_FW_VERSION_SUB);
106 write_unlock_irqrestore(&adapter->adapter_lock, flags);
107 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
109 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
110 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
111 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
115 netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
117 struct netxen_adapter *adapter = netdev_priv(dev);
118 struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg;
120 /* read which mode */
121 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
122 ecmd->supported = (SUPPORTED_10baseT_Half |
123 SUPPORTED_10baseT_Full |
124 SUPPORTED_100baseT_Half |
125 SUPPORTED_100baseT_Full |
126 SUPPORTED_1000baseT_Half |
127 SUPPORTED_1000baseT_Full);
129 ecmd->advertising = (ADVERTISED_100baseT_Half |
130 ADVERTISED_100baseT_Full |
131 ADVERTISED_1000baseT_Half |
132 ADVERTISED_1000baseT_Full);
134 ecmd->port = PORT_TP;
136 ecmd->speed = adapter->link_speed;
137 ecmd->duplex = adapter->link_duplex;
138 ecmd->autoneg = adapter->link_autoneg;
140 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
143 adapter->hw_read_wx(adapter, NETXEN_PORT_MODE_ADDR, &val, 4);
144 if (val == NETXEN_PORT_MODE_802_3_AP) {
145 ecmd->supported = SUPPORTED_1000baseT_Full;
146 ecmd->advertising = ADVERTISED_1000baseT_Full;
148 ecmd->supported = SUPPORTED_10000baseT_Full;
149 ecmd->advertising = ADVERTISED_10000baseT_Full;
152 ecmd->port = PORT_TP;
154 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
155 u16 pcifn = adapter->ahw.pci_func;
157 adapter->hw_read_wx(adapter,
158 P3_LINK_SPEED_REG(pcifn), &val, 4);
159 ecmd->speed = P3_LINK_SPEED_MHZ *
160 P3_LINK_SPEED_VAL(pcifn, val);
162 ecmd->speed = SPEED_10000;
164 ecmd->duplex = DUPLEX_FULL;
165 ecmd->autoneg = AUTONEG_DISABLE;
169 ecmd->phy_address = adapter->physical_port;
170 ecmd->transceiver = XCVR_EXTERNAL;
172 switch ((netxen_brdtype_t) boardinfo->board_type) {
173 case NETXEN_BRDTYPE_P2_SB35_4G:
174 case NETXEN_BRDTYPE_P2_SB31_2G:
175 case NETXEN_BRDTYPE_P3_REF_QG:
176 case NETXEN_BRDTYPE_P3_4_GB:
177 case NETXEN_BRDTYPE_P3_4_GB_MM:
179 ecmd->supported |= SUPPORTED_Autoneg;
180 ecmd->advertising |= ADVERTISED_Autoneg;
181 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
182 case NETXEN_BRDTYPE_P3_10G_CX4:
183 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
184 case NETXEN_BRDTYPE_P3_10000_BASE_T:
185 ecmd->supported |= SUPPORTED_TP;
186 ecmd->advertising |= ADVERTISED_TP;
187 ecmd->port = PORT_TP;
188 ecmd->autoneg = (boardinfo->board_type ==
189 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
190 (AUTONEG_DISABLE) : (adapter->link_autoneg);
192 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
193 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
194 case NETXEN_BRDTYPE_P3_IMEZ:
195 case NETXEN_BRDTYPE_P3_XG_LOM:
196 case NETXEN_BRDTYPE_P3_HMEZ:
197 ecmd->supported |= SUPPORTED_MII;
198 ecmd->advertising |= ADVERTISED_MII;
199 ecmd->port = PORT_FIBRE;
200 ecmd->autoneg = AUTONEG_DISABLE;
202 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
203 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
204 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
205 ecmd->advertising |= ADVERTISED_TP;
206 ecmd->supported |= SUPPORTED_TP;
207 case NETXEN_BRDTYPE_P2_SB31_10G:
208 case NETXEN_BRDTYPE_P3_10G_XFP:
209 ecmd->supported |= SUPPORTED_FIBRE;
210 ecmd->advertising |= ADVERTISED_FIBRE;
211 ecmd->port = PORT_FIBRE;
212 ecmd->autoneg = AUTONEG_DISABLE;
214 case NETXEN_BRDTYPE_P3_10G_TP:
215 if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
216 ecmd->autoneg = AUTONEG_DISABLE;
217 ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
219 (ADVERTISED_FIBRE | ADVERTISED_TP);
220 ecmd->port = PORT_FIBRE;
222 ecmd->autoneg = AUTONEG_ENABLE;
223 ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg);
225 (ADVERTISED_TP | ADVERTISED_Autoneg);
226 ecmd->port = PORT_TP;
230 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
231 (netxen_brdtype_t) boardinfo->board_type);
239 netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
241 struct netxen_adapter *adapter = netdev_priv(dev);
244 /* read which mode */
245 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
246 /* autonegotiation */
247 if (adapter->phy_write
248 && adapter->phy_write(adapter,
249 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
253 adapter->link_autoneg = ecmd->autoneg;
255 if (adapter->phy_read
256 && adapter->phy_read(adapter,
257 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
262 switch (ecmd->speed) {
264 netxen_set_phy_speed(status, 0);
267 netxen_set_phy_speed(status, 1);
270 netxen_set_phy_speed(status, 2);
273 /* set duplex mode */
274 if (ecmd->duplex == DUPLEX_HALF)
275 netxen_clear_phy_duplex(status);
276 if (ecmd->duplex == DUPLEX_FULL)
277 netxen_set_phy_duplex(status);
278 if (adapter->phy_write
279 && adapter->phy_write(adapter,
280 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
281 *((int *)&status)) != 0)
284 adapter->link_speed = ecmd->speed;
285 adapter->link_duplex = ecmd->duplex;
290 if (!netif_running(dev))
293 dev->netdev_ops->ndo_stop(dev);
294 return dev->netdev_ops->ndo_open(dev);
297 static int netxen_nic_get_regs_len(struct net_device *dev)
299 return NETXEN_NIC_REGS_LEN;
302 struct netxen_niu_regs {
303 __u32 reg[NETXEN_NIC_REGS_COUNT];
306 static struct netxen_niu_regs niu_registers[] = {
310 NETXEN_NIU_GB_SERDES_RESET,
311 NETXEN_NIU_GB0_MII_MODE,
312 NETXEN_NIU_GB1_MII_MODE,
313 NETXEN_NIU_GB2_MII_MODE,
314 NETXEN_NIU_GB3_MII_MODE,
315 NETXEN_NIU_GB0_GMII_MODE,
316 NETXEN_NIU_GB1_GMII_MODE,
317 NETXEN_NIU_GB2_GMII_MODE,
318 NETXEN_NIU_GB3_GMII_MODE,
319 NETXEN_NIU_REMOTE_LOOPBACK,
320 NETXEN_NIU_GB0_HALF_DUPLEX,
321 NETXEN_NIU_GB1_HALF_DUPLEX,
322 NETXEN_NIU_RESET_SYS_FIFOS,
323 NETXEN_NIU_GB_CRC_DROP,
324 NETXEN_NIU_GB_DROP_WRONGADDR,
325 NETXEN_NIU_TEST_MUX_CTL,
327 NETXEN_NIU_GB_MAC_CONFIG_0(0),
328 NETXEN_NIU_GB_MAC_CONFIG_1(0),
329 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
330 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
331 NETXEN_NIU_GB_TEST_REG(0),
332 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
333 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
334 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
335 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
336 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
337 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
338 NETXEN_NIU_GB_INTERFACE_CTRL(0),
339 NETXEN_NIU_GB_INTERFACE_STATUS(0),
340 NETXEN_NIU_GB_STATION_ADDR_0(0),
341 NETXEN_NIU_GB_STATION_ADDR_1(0),
348 NETXEN_NIU_XG_SINGLE_TERM,
349 NETXEN_NIU_XG_DRIVE_HI,
350 NETXEN_NIU_XG_DRIVE_LO,
353 NETXEN_NIU_XG_WORD_ALIGN,
355 NETXEN_NIU_XG_POWER_DOWN,
356 NETXEN_NIU_XG_RESET_PLL,
357 NETXEN_NIU_XG_SERDES_LOOPBACK,
358 NETXEN_NIU_XG_DO_BYTE_ALIGN,
359 NETXEN_NIU_XG_TX_ENABLE,
360 NETXEN_NIU_XG_RX_ENABLE,
361 NETXEN_NIU_XG_STATUS,
362 NETXEN_NIU_XG_PAUSE_THRESHOLD,
363 NETXEN_NIU_XGE_CONFIG_0,
364 NETXEN_NIU_XGE_CONFIG_1,
366 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
367 NETXEN_NIU_XGE_STATION_ADDR_0_1,
368 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
369 NETXEN_NIU_XGE_STATUS,
370 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
371 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
372 NETXEN_NIU_XGE_TX_BYTE_CNT,
373 NETXEN_NIU_XGE_TX_FRAME_CNT,
374 NETXEN_NIU_XGE_RX_BYTE_CNT,
375 NETXEN_NIU_XGE_RX_FRAME_CNT,
376 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
377 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
378 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
379 NETXEN_NIU_XGE_CRC_ERROR_CNT,
380 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
381 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
382 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
383 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
384 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
385 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
392 netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
394 struct netxen_adapter *adapter = netdev_priv(dev);
395 __u32 mode, *regs_buff = p;
398 memset(p, 0, NETXEN_NIC_REGS_LEN);
399 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
400 (adapter->pdev)->device;
402 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, ®s_buff[0], 4);
405 /* Common registers to all the modes */
406 adapter->hw_read_wx(adapter,
407 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, ®s_buff[2], 4);
409 mode = (mode / 2) - 1;
412 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
413 /* GB: port specific registers */
414 if (mode == 0 && i >= 19)
415 window = adapter->physical_port *
416 NETXEN_NIC_PORT_WINDOW;
418 adapter->hw_read_wx(adapter,
419 niu_registers[mode].reg[i - 3] + window,
426 static u32 netxen_nic_test_link(struct net_device *dev)
428 struct netxen_adapter *adapter = netdev_priv(dev);
432 /* read which mode */
433 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
434 if (adapter->phy_read
435 && adapter->phy_read(adapter,
436 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
440 val = netxen_get_phy_link(status);
443 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
444 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
445 return (val == XG_LINK_UP) ? 0 : 1;
451 netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
454 struct netxen_adapter *adapter = netdev_priv(dev);
458 if (eeprom->len == 0)
461 eeprom->magic = (adapter->pdev)->vendor |
462 ((adapter->pdev)->device << 16);
463 offset = eeprom->offset;
465 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
474 netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
476 struct netxen_adapter *adapter = netdev_priv(dev);
479 ring->rx_pending = 0;
480 ring->rx_jumbo_pending = 0;
481 for (i = 0; i < MAX_RCV_CTX; ++i) {
482 ring->rx_pending += adapter->recv_ctx[i].
483 rds_rings[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
484 ring->rx_jumbo_pending += adapter->recv_ctx[i].
485 rds_rings[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
487 ring->tx_pending = adapter->max_tx_desc_count;
489 if (adapter->ahw.board_type == NETXEN_NIC_GBE)
490 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
492 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
493 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
494 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
495 ring->rx_mini_max_pending = 0;
496 ring->rx_mini_pending = 0;
500 netxen_nic_get_pauseparam(struct net_device *dev,
501 struct ethtool_pauseparam *pause)
503 struct netxen_adapter *adapter = netdev_priv(dev);
505 int port = adapter->physical_port;
507 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
508 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
510 /* get flow control settings */
511 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
513 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
514 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
517 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
520 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
523 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
527 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
530 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
531 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
534 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
536 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
538 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
540 printk(KERN_ERR"%s: Unknown board type: %x\n",
541 netxen_nic_driver_name, adapter->ahw.board_type);
546 netxen_nic_set_pauseparam(struct net_device *dev,
547 struct ethtool_pauseparam *pause)
549 struct netxen_adapter *adapter = netdev_priv(dev);
551 int port = adapter->physical_port;
553 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
554 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
556 /* set flow control */
557 netxen_nic_read_w0(adapter,
558 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
561 netxen_gb_rx_flowctl(val);
563 netxen_gb_unset_rx_flowctl(val);
565 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
568 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
572 netxen_gb_unset_gb0_mask(val);
574 netxen_gb_set_gb0_mask(val);
578 netxen_gb_unset_gb1_mask(val);
580 netxen_gb_set_gb1_mask(val);
584 netxen_gb_unset_gb2_mask(val);
586 netxen_gb_set_gb2_mask(val);
591 netxen_gb_unset_gb3_mask(val);
593 netxen_gb_set_gb3_mask(val);
596 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
597 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
598 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
600 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
603 netxen_xg_unset_xg0_mask(val);
605 netxen_xg_set_xg0_mask(val);
608 netxen_xg_unset_xg1_mask(val);
610 netxen_xg_set_xg1_mask(val);
612 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
614 printk(KERN_ERR "%s: Unknown board type: %x\n",
615 netxen_nic_driver_name,
616 adapter->ahw.board_type);
621 static int netxen_nic_reg_test(struct net_device *dev)
623 struct netxen_adapter *adapter = netdev_priv(dev);
624 u32 data_read, data_written;
626 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
627 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
630 data_written = (u32)0xa5a5a5a5;
632 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
633 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
634 if (data_written != data_read)
640 static int netxen_get_sset_count(struct net_device *dev, int sset)
644 return NETXEN_NIC_TEST_LEN;
646 return NETXEN_NIC_STATS_LEN;
653 netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
656 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
657 if ((data[0] = netxen_nic_reg_test(dev)))
658 eth_test->flags |= ETH_TEST_FL_FAILED;
660 if ((data[1] = (u64) netxen_nic_test_link(dev)))
661 eth_test->flags |= ETH_TEST_FL_FAILED;
665 netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
671 memcpy(data, *netxen_nic_gstrings_test,
672 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
675 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
676 memcpy(data + index * ETH_GSTRING_LEN,
677 netxen_nic_gstrings_stats[index].stat_string,
685 netxen_nic_get_ethtool_stats(struct net_device *dev,
686 struct ethtool_stats *stats, u64 * data)
688 struct netxen_adapter *adapter = netdev_priv(dev);
691 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
694 netxen_nic_gstrings_stats[index].stat_offset;
696 (netxen_nic_gstrings_stats[index].sizeof_stat ==
697 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
701 static u32 netxen_nic_get_rx_csum(struct net_device *dev)
703 struct netxen_adapter *adapter = netdev_priv(dev);
704 return adapter->rx_csum;
707 static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
709 struct netxen_adapter *adapter = netdev_priv(dev);
710 adapter->rx_csum = !!data;
714 static u32 netxen_nic_get_tso(struct net_device *dev)
716 struct netxen_adapter *adapter = netdev_priv(dev);
718 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
719 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
721 return (dev->features & NETIF_F_TSO) != 0;
724 static int netxen_nic_set_tso(struct net_device *dev, u32 data)
727 struct netxen_adapter *adapter = netdev_priv(dev);
729 dev->features |= NETIF_F_TSO;
730 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
731 dev->features |= NETIF_F_TSO6;
733 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
739 netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
741 struct netxen_adapter *adapter = netdev_priv(dev);
747 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
750 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG_NV);
751 if (wol_cfg & (1UL << adapter->portnum))
752 wol->supported |= WAKE_MAGIC;
754 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG);
755 if (wol_cfg & (1UL << adapter->portnum))
756 wol->wolopts |= WAKE_MAGIC;
760 netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
762 struct netxen_adapter *adapter = netdev_priv(dev);
765 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
768 if (wol->wolopts & ~WAKE_MAGIC)
771 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG_NV);
772 if (!(wol_cfg & (1 << adapter->portnum)))
775 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG);
776 if (wol->wolopts & WAKE_MAGIC)
777 wol_cfg |= 1UL << adapter->portnum;
779 wol_cfg &= ~(1UL << adapter->portnum);
780 netxen_nic_reg_write(adapter, NETXEN_WOL_CONFIG, wol_cfg);
786 * Set the coalescing parameters. Currently only normal is supported.
787 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
788 * firmware coalescing to default.
790 static int netxen_set_intr_coalesce(struct net_device *netdev,
791 struct ethtool_coalesce *ethcoal)
793 struct netxen_adapter *adapter = netdev_priv(netdev);
795 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
798 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
802 * Return Error if unsupported values or
803 * unsupported parameters are set.
805 if (ethcoal->rx_coalesce_usecs > 0xffff ||
806 ethcoal->rx_max_coalesced_frames > 0xffff ||
807 ethcoal->tx_coalesce_usecs > 0xffff ||
808 ethcoal->tx_max_coalesced_frames > 0xffff ||
809 ethcoal->rx_coalesce_usecs_irq ||
810 ethcoal->rx_max_coalesced_frames_irq ||
811 ethcoal->tx_coalesce_usecs_irq ||
812 ethcoal->tx_max_coalesced_frames_irq ||
813 ethcoal->stats_block_coalesce_usecs ||
814 ethcoal->use_adaptive_rx_coalesce ||
815 ethcoal->use_adaptive_tx_coalesce ||
816 ethcoal->pkt_rate_low ||
817 ethcoal->rx_coalesce_usecs_low ||
818 ethcoal->rx_max_coalesced_frames_low ||
819 ethcoal->tx_coalesce_usecs_low ||
820 ethcoal->tx_max_coalesced_frames_low ||
821 ethcoal->pkt_rate_high ||
822 ethcoal->rx_coalesce_usecs_high ||
823 ethcoal->rx_max_coalesced_frames_high ||
824 ethcoal->tx_coalesce_usecs_high ||
825 ethcoal->tx_max_coalesced_frames_high)
828 if (!ethcoal->rx_coalesce_usecs ||
829 !ethcoal->rx_max_coalesced_frames) {
830 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
831 adapter->coal.normal.data.rx_time_us =
832 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
833 adapter->coal.normal.data.rx_packets =
834 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
836 adapter->coal.flags = 0;
837 adapter->coal.normal.data.rx_time_us =
838 ethcoal->rx_coalesce_usecs;
839 adapter->coal.normal.data.rx_packets =
840 ethcoal->rx_max_coalesced_frames;
842 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
843 adapter->coal.normal.data.tx_packets =
844 ethcoal->tx_max_coalesced_frames;
846 netxen_config_intr_coalesce(adapter);
851 static int netxen_get_intr_coalesce(struct net_device *netdev,
852 struct ethtool_coalesce *ethcoal)
854 struct netxen_adapter *adapter = netdev_priv(netdev);
856 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
859 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
862 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
863 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
864 ethcoal->rx_max_coalesced_frames =
865 adapter->coal.normal.data.rx_packets;
866 ethcoal->tx_max_coalesced_frames =
867 adapter->coal.normal.data.tx_packets;
872 struct ethtool_ops netxen_nic_ethtool_ops = {
873 .get_settings = netxen_nic_get_settings,
874 .set_settings = netxen_nic_set_settings,
875 .get_drvinfo = netxen_nic_get_drvinfo,
876 .get_regs_len = netxen_nic_get_regs_len,
877 .get_regs = netxen_nic_get_regs,
878 .get_link = ethtool_op_get_link,
879 .get_eeprom_len = netxen_nic_get_eeprom_len,
880 .get_eeprom = netxen_nic_get_eeprom,
881 .get_ringparam = netxen_nic_get_ringparam,
882 .get_pauseparam = netxen_nic_get_pauseparam,
883 .set_pauseparam = netxen_nic_set_pauseparam,
884 .set_tx_csum = ethtool_op_set_tx_csum,
885 .set_sg = ethtool_op_set_sg,
886 .get_tso = netxen_nic_get_tso,
887 .set_tso = netxen_nic_set_tso,
888 .get_wol = netxen_nic_get_wol,
889 .set_wol = netxen_nic_set_wol,
890 .self_test = netxen_nic_diag_test,
891 .get_strings = netxen_nic_get_strings,
892 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
893 .get_sset_count = netxen_get_sset_count,
894 .get_rx_csum = netxen_nic_get_rx_csum,
895 .set_rx_csum = netxen_nic_set_rx_csum,
896 .get_coalesce = netxen_get_intr_coalesce,
897 .set_coalesce = netxen_set_intr_coalesce,