page_cgroup should ignore empty nodes
[linux-2.6/zen-sources.git] / drivers / net / netxen / netxen_nic_ethtool.c
blobb974ca0fc530a45babd8962ec47a0f70c2820f9a
1 /*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
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,
18 * MA 02111-1307, USA.
20 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
23 * Contact Information:
24 * info@netxen.com
25 * NetXen,
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>
38 #include <asm/io.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];
48 int sizeof_stat;
49 int stat_offset;
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;
91 static void
92 netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
94 struct netxen_adapter *adapter = netdev_priv(dev);
95 unsigned long flags;
96 u32 fw_major = 0;
97 u32 fw_minor = 0;
98 u32 fw_build = 0;
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);
117 static int
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) {
146 u32 val;
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;
152 } else {
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);
166 } else
167 ecmd->speed = SPEED_10000;
169 ecmd->duplex = DUPLEX_FULL;
170 ecmd->autoneg = AUTONEG_DISABLE;
171 } else
172 return -EIO;
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);
196 break;
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;
206 break;
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;
216 break;
217 default:
218 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
219 (netxen_brdtype_t) boardinfo->board_type);
220 return -EIO;
223 return 0;
226 static int
227 netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
229 struct netxen_adapter *adapter = netdev_priv(dev);
230 __u32 status;
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,
238 ecmd->autoneg) != 0)
239 return -EIO;
240 else
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,
246 &status) != 0)
247 return -EIO;
249 /* speed */
250 switch (ecmd->speed) {
251 case SPEED_10:
252 netxen_set_phy_speed(status, 0);
253 break;
254 case SPEED_100:
255 netxen_set_phy_speed(status, 1);
256 break;
257 case SPEED_1000:
258 netxen_set_phy_speed(status, 2);
259 break;
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)
270 return -EIO;
271 else {
272 adapter->link_speed = ecmd->speed;
273 adapter->link_duplex = ecmd->duplex;
275 } else
276 return -EOPNOTSUPP;
278 if (netif_running(dev)) {
279 dev->stop(dev);
280 dev->open(dev);
282 return 0;
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[] = {
296 /* GB Mode */
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),
334 /* XG Mode */
336 NETXEN_NIU_XG_SINGLE_TERM,
337 NETXEN_NIU_XG_DRIVE_HI,
338 NETXEN_NIU_XG_DRIVE_LO,
339 NETXEN_NIU_XG_DTX,
340 NETXEN_NIU_XG_DEQ,
341 NETXEN_NIU_XG_WORD_ALIGN,
342 NETXEN_NIU_XG_RESET,
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,
353 NETXEN_NIU_XGE_IPG,
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,
379 static void
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;
384 int i, window;
386 memset(p, 0, NETXEN_NIC_REGS_LEN);
387 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
388 (adapter->pdev)->device;
389 /* which mode */
390 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, &regs_buff[0], 4);
391 mode = regs_buff[0];
393 /* Common registers to all the modes */
394 adapter->hw_read_wx(adapter,
395 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, &regs_buff[2], 4);
396 /* GB/XGB Mode */
397 mode = (mode / 2) - 1;
398 window = 0;
399 if (mode <= 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,
408 &regs_buff[i], 4);
414 static u32 netxen_nic_test_link(struct net_device *dev)
416 struct netxen_adapter *adapter = netdev_priv(dev);
417 __u32 status;
418 int val;
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,
425 &status) != 0)
426 return -EIO;
427 else {
428 val = netxen_get_phy_link(status);
429 return !val;
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;
435 return -EIO;
438 static int
439 netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
440 u8 * bytes)
442 struct netxen_adapter *adapter = netdev_priv(dev);
443 int offset;
444 int ret;
446 if (eeprom->len == 0)
447 return -EINVAL;
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,
454 eeprom->len);
455 if (ret < 0)
456 return ret;
458 return 0;
461 #if 0
462 static int
463 netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
464 u8 * bytes)
466 struct netxen_adapter *adapter = netdev_priv(dev);
467 int offset = eeprom->offset;
468 static int flash_start;
469 static int ready_to_flash;
470 int ret;
472 if (flash_start == 0) {
473 netxen_halt_pegs(adapter);
474 ret = netxen_flash_unlock(adapter);
475 if (ret < 0) {
476 printk(KERN_ERR "%s: Flash unlock failed.\n",
477 netxen_nic_driver_name);
478 return ret;
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);
486 return ret;
488 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
489 netxen_nic_driver_name);
490 flash_start = 1;
491 return 0;
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);
499 return ret;
502 ret = netxen_rom_se(adapter, NETXEN_USER_START);
503 if (ret != FLASH_SUCCESS)
504 return ret;
505 ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
506 if (ret != FLASH_SUCCESS)
507 return ret;
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);
516 return ret;
518 printk(KERN_INFO "%s: CRBinit backup done.\n",
519 netxen_nic_driver_name);
520 ready_to_flash = 1;
523 if (!ready_to_flash) {
524 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
525 netxen_nic_driver_name);
526 return -EINVAL;
529 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
531 #endif /* 0 */
533 static void
534 netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
536 struct netxen_adapter *adapter = netdev_priv(dev);
537 int i;
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;
556 static void
557 netxen_nic_get_pauseparam(struct net_device *dev,
558 struct ethtool_pauseparam *pause)
560 struct netxen_adapter *adapter = netdev_priv(dev);
561 __u32 val;
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))
566 return;
567 /* get flow control settings */
568 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
569 &val);
570 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
571 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
572 switch (port) {
573 case 0:
574 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
575 break;
576 case 1:
577 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
578 break;
579 case 2:
580 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
581 break;
582 case 3:
583 default:
584 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
585 break;
587 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
588 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
589 return;
590 pause->rx_pause = 1;
591 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
592 if (port == 0)
593 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
594 else
595 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
596 } else {
597 printk(KERN_ERR"%s: Unknown board type: %x\n",
598 netxen_nic_driver_name, adapter->ahw.board_type);
602 static int
603 netxen_nic_set_pauseparam(struct net_device *dev,
604 struct ethtool_pauseparam *pause)
606 struct netxen_adapter *adapter = netdev_priv(dev);
607 __u32 val;
608 int port = adapter->physical_port;
609 /* read mode */
610 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
611 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
612 return -EIO;
613 /* set flow control */
614 netxen_nic_read_w0(adapter,
615 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
617 if (pause->rx_pause)
618 netxen_gb_rx_flowctl(val);
619 else
620 netxen_gb_unset_rx_flowctl(val);
622 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
623 val);
624 /* set autoneg */
625 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
626 switch (port) {
627 case 0:
628 if (pause->tx_pause)
629 netxen_gb_unset_gb0_mask(val);
630 else
631 netxen_gb_set_gb0_mask(val);
632 break;
633 case 1:
634 if (pause->tx_pause)
635 netxen_gb_unset_gb1_mask(val);
636 else
637 netxen_gb_set_gb1_mask(val);
638 break;
639 case 2:
640 if (pause->tx_pause)
641 netxen_gb_unset_gb2_mask(val);
642 else
643 netxen_gb_set_gb2_mask(val);
644 break;
645 case 3:
646 default:
647 if (pause->tx_pause)
648 netxen_gb_unset_gb3_mask(val);
649 else
650 netxen_gb_set_gb3_mask(val);
651 break;
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))
656 return -EIO;
657 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
658 if (port == 0) {
659 if (pause->tx_pause)
660 netxen_xg_unset_xg0_mask(val);
661 else
662 netxen_xg_set_xg0_mask(val);
663 } else {
664 if (pause->tx_pause)
665 netxen_xg_unset_xg1_mask(val);
666 else
667 netxen_xg_set_xg1_mask(val);
669 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
670 } else {
671 printk(KERN_ERR "%s: Unknown board type: %x\n",
672 netxen_nic_driver_name,
673 adapter->ahw.board_type);
675 return 0;
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)
685 return 1;
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)
692 return 1;
694 return 0;
697 static int netxen_get_sset_count(struct net_device *dev, int sset)
699 switch (sset) {
700 case ETH_SS_TEST:
701 return NETXEN_NIC_TEST_LEN;
702 case ETH_SS_STATS:
703 return NETXEN_NIC_STATS_LEN;
704 default:
705 return -EOPNOTSUPP;
709 static void
710 netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
711 u64 * data)
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;
716 /* link test */
717 if ((data[1] = (u64) netxen_nic_test_link(dev)))
718 eth_test->flags |= ETH_TEST_FL_FAILED;
721 static void
722 netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
724 int index;
726 switch (stringset) {
727 case ETH_SS_TEST:
728 memcpy(data, *netxen_nic_gstrings_test,
729 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
730 break;
731 case ETH_SS_STATS:
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,
735 ETH_GSTRING_LEN);
737 break;
741 static void
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);
746 int index;
748 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
749 char *p =
750 (char *)adapter +
751 netxen_nic_gstrings_stats[index].stat_offset;
752 data[index] =
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;
768 return 0;
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)
783 if (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;
789 } else
790 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
792 return 0;
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))
806 return -EINVAL;
808 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
809 return -EINVAL;
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)
836 return -EINVAL;
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;
845 } else {
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);
858 return 0;
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))
867 return -EINVAL;
869 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
870 return -EINVAL;
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;
879 return 0;
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,
891 #if 0
892 .set_eeprom = netxen_nic_set_eeprom,
893 #endif
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,