blob: 48ee06b6f4e9c3f06cf3b2072ef75d56d9743cfb [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08004 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04005 * 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.
Amit S. Kale80922fb2006-12-04 09:18:00 -08009 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040010 * 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.
Amit S. Kale80922fb2006-12-04 09:18:00 -080014 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040015 * 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.
Amit S. Kale80922fb2006-12-04 09:18:00 -080019 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040020 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080022 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040023 * Contact Information:
24 * info@netxen.com
25 * NetXen,
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
28 *
29 *
30 * ethtool support for netxen nic
31 *
32 */
33
34#include <linux/types.h>
Amit S. Kale27d2ab52007-02-05 07:40:49 -080035#include <linux/delay.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040036#include <asm/uaccess.h>
37#include <linux/pci.h>
38#include <asm/io.h>
39#include <linux/netdevice.h>
40#include <linux/ethtool.h>
41#include <linux/version.h>
42
Amit S. Kale3d396eb2006-10-21 15:33:03 -040043#include "netxen_nic.h"
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070044#include "netxen_nic_hw.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040045#include "netxen_nic_phan_reg.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040046
47struct netxen_nic_stats {
48 char stat_string[ETH_GSTRING_LEN];
49 int sizeof_stat;
50 int stat_offset;
51};
52
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070053#define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
54 offsetof(struct netxen_adapter, m)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040055
Amit S. Kalecb8011a2006-11-29 09:00:10 -080056#define NETXEN_NIC_PORT_WINDOW 0x10000
57#define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
58
Amit S. Kale3d396eb2006-10-21 15:33:03 -040059static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
60 {"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)},
61 {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
62 {"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)},
63 {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
64 {"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)},
65 {"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)},
66 {"polled", NETXEN_NIC_STAT(stats.polled)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040067 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040068 {"csummed", NETXEN_NIC_STAT(stats.csummed)},
69 {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
70 {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
71 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
72};
73
Stephen Hemminger92104e92006-12-15 07:57:08 -080074#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040075
76static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -080077 "Register_Test_on_offline",
Amit S. Kale3d396eb2006-10-21 15:33:03 -040078 "Link_Test_on_offline"
79};
80
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +020081#define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040082
83#define NETXEN_NIC_REGS_COUNT 42
84#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
85#define NETXEN_MAX_EEPROM_LEN 1024
86
87static int netxen_nic_get_eeprom_len(struct net_device *dev)
88{
Mithlesh Thukral0d047612007-06-07 04:36:36 -070089 return NETXEN_FLASH_TOTAL_SIZE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040090}
91
92static void
93netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
94{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070095 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070096 unsigned long flags;
Amit S. Kalecb8011a2006-11-29 09:00:10 -080097 u32 fw_major = 0;
98 u32 fw_minor = 0;
99 u32 fw_build = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400100
Amit S. Kale80922fb2006-12-04 09:18:00 -0800101 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400102 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700103 write_lock_irqsave(&adapter->adapter_lock, flags);
104 fw_major = adapter->pci_read_normalize(adapter,
105 NETXEN_FW_VERSION_MAJOR);
106 fw_minor = adapter->pci_read_normalize(adapter,
107 NETXEN_FW_VERSION_MINOR);
108 fw_build = adapter->pci_read_normalize(adapter,
109 NETXEN_FW_VERSION_SUB);
110 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400111 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
112
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700113 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400114 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
115 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
116}
117
118static int
119netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
120{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700121 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale71bd7872006-12-01 05:36:22 -0800122 struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400123
124 /* read which mode */
125 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
126 ecmd->supported = (SUPPORTED_10baseT_Half |
127 SUPPORTED_10baseT_Full |
128 SUPPORTED_100baseT_Half |
129 SUPPORTED_100baseT_Full |
130 SUPPORTED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800131 SUPPORTED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400132
133 ecmd->advertising = (ADVERTISED_100baseT_Half |
134 ADVERTISED_100baseT_Full |
135 ADVERTISED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800136 ADVERTISED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400137
138 ecmd->port = PORT_TP;
139
140 if (netif_running(dev)) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700141 ecmd->speed = adapter->link_speed;
142 ecmd->duplex = adapter->link_duplex;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400143 } else
144 return -EIO; /* link absent */
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800145 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400146 ecmd->supported = (SUPPORTED_TP |
147 SUPPORTED_1000baseT_Full |
148 SUPPORTED_10000baseT_Full);
149 ecmd->advertising = (ADVERTISED_TP |
150 ADVERTISED_1000baseT_Full |
151 ADVERTISED_10000baseT_Full);
152 ecmd->port = PORT_TP;
153
154 ecmd->speed = SPEED_10000;
155 ecmd->duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400156 ecmd->autoneg = AUTONEG_DISABLE;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800157 } else
158 return -EIO;
159
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700160 ecmd->phy_address = adapter->portnum;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800161 ecmd->transceiver = XCVR_EXTERNAL;
162
163 switch ((netxen_brdtype_t) boardinfo->board_type) {
164 case NETXEN_BRDTYPE_P2_SB35_4G:
165 case NETXEN_BRDTYPE_P2_SB31_2G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700166 case NETXEN_BRDTYPE_P3_REF_QG:
167 case NETXEN_BRDTYPE_P3_4_GB:
168 case NETXEN_BRDTYPE_P3_4_GB_MM:
169 case NETXEN_BRDTYPE_P3_10000_BASE_T:
170
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800171 ecmd->supported |= SUPPORTED_Autoneg;
172 ecmd->advertising |= ADVERTISED_Autoneg;
173 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700174 case NETXEN_BRDTYPE_P3_10G_CX4:
175 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800176 ecmd->supported |= SUPPORTED_TP;
177 ecmd->advertising |= ADVERTISED_TP;
178 ecmd->port = PORT_TP;
179 ecmd->autoneg = (boardinfo->board_type ==
180 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700181 (AUTONEG_DISABLE) : (adapter->link_autoneg);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800182 break;
183 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
184 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700185 case NETXEN_BRDTYPE_P3_IMEZ:
186 case NETXEN_BRDTYPE_P3_XG_LOM:
187 case NETXEN_BRDTYPE_P3_HMEZ:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800188 ecmd->supported |= SUPPORTED_MII;
189 ecmd->advertising |= ADVERTISED_MII;
190 ecmd->port = PORT_FIBRE;
191 ecmd->autoneg = AUTONEG_DISABLE;
192 break;
193 case NETXEN_BRDTYPE_P2_SB31_10G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700194 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
195 case NETXEN_BRDTYPE_P3_10G_XFP:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800196 ecmd->supported |= SUPPORTED_FIBRE;
197 ecmd->advertising |= ADVERTISED_FIBRE;
198 ecmd->port = PORT_FIBRE;
199 ecmd->autoneg = AUTONEG_DISABLE;
200 break;
201 default:
Amit S. Kale71bd7872006-12-01 05:36:22 -0800202 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800203 (netxen_brdtype_t) boardinfo->board_type);
204 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400205 }
206
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800207 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400208}
209
210static int
211netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
212{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700213 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000214 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400215
216 /* read which mode */
217 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
218 /* autonegotiation */
Amit S. Kale80922fb2006-12-04 09:18:00 -0800219 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700220 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800221 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab9c2007-01-02 10:39:10 +0000222 ecmd->autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400223 return -EIO;
224 else
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700225 adapter->link_autoneg = ecmd->autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400226
Amit S. Kale80922fb2006-12-04 09:18:00 -0800227 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700228 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800229 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
230 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400231 return -EIO;
232
233 /* speed */
234 switch (ecmd->speed) {
235 case SPEED_10:
236 netxen_set_phy_speed(status, 0);
237 break;
238 case SPEED_100:
239 netxen_set_phy_speed(status, 1);
240 break;
241 case SPEED_1000:
242 netxen_set_phy_speed(status, 2);
243 break;
244 }
245 /* set duplex mode */
246 if (ecmd->duplex == DUPLEX_HALF)
247 netxen_clear_phy_duplex(status);
248 if (ecmd->duplex == DUPLEX_FULL)
249 netxen_set_phy_duplex(status);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800250 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700251 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800252 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
253 *((int *)&status)) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400254 return -EIO;
255 else {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700256 adapter->link_speed = ecmd->speed;
257 adapter->link_duplex = ecmd->duplex;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400258 }
259 } else
260 return -EOPNOTSUPP;
261
262 if (netif_running(dev)) {
263 dev->stop(dev);
264 dev->open(dev);
265 }
266 return 0;
267}
268
269static int netxen_nic_get_regs_len(struct net_device *dev)
270{
271 return NETXEN_NIC_REGS_LEN;
272}
273
274struct netxen_niu_regs {
Al Viroa608ab9c2007-01-02 10:39:10 +0000275 __u32 reg[NETXEN_NIC_REGS_COUNT];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400276};
277
278static struct netxen_niu_regs niu_registers[] = {
279 {
280 /* GB Mode */
281 {
282 NETXEN_NIU_GB_SERDES_RESET,
283 NETXEN_NIU_GB0_MII_MODE,
284 NETXEN_NIU_GB1_MII_MODE,
285 NETXEN_NIU_GB2_MII_MODE,
286 NETXEN_NIU_GB3_MII_MODE,
287 NETXEN_NIU_GB0_GMII_MODE,
288 NETXEN_NIU_GB1_GMII_MODE,
289 NETXEN_NIU_GB2_GMII_MODE,
290 NETXEN_NIU_GB3_GMII_MODE,
291 NETXEN_NIU_REMOTE_LOOPBACK,
292 NETXEN_NIU_GB0_HALF_DUPLEX,
293 NETXEN_NIU_GB1_HALF_DUPLEX,
294 NETXEN_NIU_RESET_SYS_FIFOS,
295 NETXEN_NIU_GB_CRC_DROP,
296 NETXEN_NIU_GB_DROP_WRONGADDR,
297 NETXEN_NIU_TEST_MUX_CTL,
298
299 NETXEN_NIU_GB_MAC_CONFIG_0(0),
300 NETXEN_NIU_GB_MAC_CONFIG_1(0),
301 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
302 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
303 NETXEN_NIU_GB_TEST_REG(0),
304 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
305 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
306 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
307 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
308 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
309 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
310 NETXEN_NIU_GB_INTERFACE_CTRL(0),
311 NETXEN_NIU_GB_INTERFACE_STATUS(0),
312 NETXEN_NIU_GB_STATION_ADDR_0(0),
313 NETXEN_NIU_GB_STATION_ADDR_1(0),
314 -1,
315 }
316 },
317 {
318 /* XG Mode */
319 {
320 NETXEN_NIU_XG_SINGLE_TERM,
321 NETXEN_NIU_XG_DRIVE_HI,
322 NETXEN_NIU_XG_DRIVE_LO,
323 NETXEN_NIU_XG_DTX,
324 NETXEN_NIU_XG_DEQ,
325 NETXEN_NIU_XG_WORD_ALIGN,
326 NETXEN_NIU_XG_RESET,
327 NETXEN_NIU_XG_POWER_DOWN,
328 NETXEN_NIU_XG_RESET_PLL,
329 NETXEN_NIU_XG_SERDES_LOOPBACK,
330 NETXEN_NIU_XG_DO_BYTE_ALIGN,
331 NETXEN_NIU_XG_TX_ENABLE,
332 NETXEN_NIU_XG_RX_ENABLE,
333 NETXEN_NIU_XG_STATUS,
334 NETXEN_NIU_XG_PAUSE_THRESHOLD,
335 NETXEN_NIU_XGE_CONFIG_0,
336 NETXEN_NIU_XGE_CONFIG_1,
337 NETXEN_NIU_XGE_IPG,
338 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
339 NETXEN_NIU_XGE_STATION_ADDR_0_1,
340 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
341 NETXEN_NIU_XGE_STATUS,
342 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
343 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
344 NETXEN_NIU_XGE_TX_BYTE_CNT,
345 NETXEN_NIU_XGE_TX_FRAME_CNT,
346 NETXEN_NIU_XGE_RX_BYTE_CNT,
347 NETXEN_NIU_XGE_RX_FRAME_CNT,
348 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
349 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
350 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
351 NETXEN_NIU_XGE_CRC_ERROR_CNT,
352 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
353 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
354 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
355 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
356 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
357 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
358 -1,
359 }
360 }
361};
362
363static void
364netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
365{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700366 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000367 __u32 mode, *regs_buff = p;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400368 int i, window;
369
370 memset(p, 0, NETXEN_NIC_REGS_LEN);
371 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700372 (adapter->pdev)->device;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400373 /* which mode */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700374 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, &regs_buff[0], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400375 mode = regs_buff[0];
376
377 /* Common registers to all the modes */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700378 adapter->hw_read_wx(adapter,
379 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, &regs_buff[2], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400380 /* GB/XGB Mode */
381 mode = (mode / 2) - 1;
382 window = 0;
383 if (mode <= 1) {
384 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
385 /* GB: port specific registers */
386 if (mode == 0 && i >= 19)
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700387 window = adapter->physical_port *
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700388 NETXEN_NIC_PORT_WINDOW;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400389
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700390 adapter->hw_read_wx(adapter,
391 niu_registers[mode].reg[i - 3] + window,
392 &regs_buff[i], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400393 }
394
395 }
396}
397
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800398static u32 netxen_nic_test_link(struct net_device *dev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400399{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700400 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000401 __u32 status;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800402 int val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400403
404 /* read which mode */
405 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Amit S. Kale80922fb2006-12-04 09:18:00 -0800406 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700407 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800408 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
409 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400410 return -EIO;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800411 else {
412 val = netxen_get_phy_link(status);
413 return !val;
414 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400415 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700416 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800417 return (val == XG_LINK_UP) ? 0 : 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400418 }
419 return -EIO;
420}
421
422static int
423netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
424 u8 * bytes)
425{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700426 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400427 int offset;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800428 int ret;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400429
430 if (eeprom->len == 0)
431 return -EINVAL;
432
Jeff Garzik47906542007-11-23 21:23:36 -0500433 eeprom->magic = (adapter->pdev)->vendor |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700434 ((adapter->pdev)->device << 16);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800435 offset = eeprom->offset;
436
Jeff Garzik47906542007-11-23 21:23:36 -0500437 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800438 eeprom->len);
439 if (ret < 0)
440 return ret;
441
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400442 return 0;
443}
444
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700445#if 0
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800446static int
447netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
448 u8 * bytes)
449{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700450 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800451 int offset = eeprom->offset;
452 static int flash_start;
453 static int ready_to_flash;
454 int ret;
455
456 if (flash_start == 0) {
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800457 netxen_halt_pegs(adapter);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800458 ret = netxen_flash_unlock(adapter);
459 if (ret < 0) {
460 printk(KERN_ERR "%s: Flash unlock failed.\n",
461 netxen_nic_driver_name);
462 return ret;
463 }
Jeff Garzik47906542007-11-23 21:23:36 -0500464 printk(KERN_INFO "%s: flash unlocked. \n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800465 netxen_nic_driver_name);
466 ret = netxen_flash_erase_secondary(adapter);
467 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500468 printk(KERN_ERR "%s: Flash erase failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800469 netxen_nic_driver_name);
470 return ret;
471 }
Jeff Garzik47906542007-11-23 21:23:36 -0500472 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800473 netxen_nic_driver_name);
474 flash_start = 1;
475 return 0;
476 }
477
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700478 if (offset == NETXEN_BOOTLD_START) {
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800479 ret = netxen_flash_erase_primary(adapter);
480 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500481 printk(KERN_ERR "%s: Flash erase failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800482 netxen_nic_driver_name);
483 return ret;
484 }
485
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700486 ret = netxen_rom_se(adapter, NETXEN_USER_START);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800487 if (ret != FLASH_SUCCESS)
488 return ret;
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700489 ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800490 if (ret != FLASH_SUCCESS)
491 return ret;
492
Jeff Garzik47906542007-11-23 21:23:36 -0500493 printk(KERN_INFO "%s: primary flash erased successfully\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800494 netxen_nic_driver_name);
495
496 ret = netxen_backup_crbinit(adapter);
497 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500498 printk(KERN_ERR "%s: CRBinit backup failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800499 netxen_nic_driver_name);
500 return ret;
501 }
Jeff Garzik47906542007-11-23 21:23:36 -0500502 printk(KERN_INFO "%s: CRBinit backup done.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800503 netxen_nic_driver_name);
504 ready_to_flash = 1;
505 }
506
507 if (!ready_to_flash) {
508 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
509 netxen_nic_driver_name);
510 return -EINVAL;
511 }
512
513 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
514}
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700515#endif /* 0 */
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800516
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400517static void
518netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
519{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700520 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800521 int i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400522
523 ring->rx_pending = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800524 ring->rx_jumbo_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400525 for (i = 0; i < MAX_RCV_CTX; ++i) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800526 ring->rx_pending += adapter->recv_ctx[i].
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700527 rds_rings[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800528 ring->rx_jumbo_pending += adapter->recv_ctx[i].
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700529 rds_rings[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400530 }
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530531 ring->tx_pending = adapter->max_tx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400532
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530533 ring->rx_max_pending = MAX_RCV_DESCRIPTORS;
534 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
535 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400536 ring->rx_mini_max_pending = 0;
537 ring->rx_mini_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400538}
539
540static void
541netxen_nic_get_pauseparam(struct net_device *dev,
542 struct ethtool_pauseparam *pause)
543{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700544 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000545 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700546 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400547
548 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700549 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
550 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400551 /* get flow control settings */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700552 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
553 &val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400554 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700555 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
556 switch (port) {
557 case 0:
558 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
559 break;
560 case 1:
561 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
562 break;
563 case 2:
564 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
565 break;
566 case 3:
567 default:
568 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
569 break;
570 }
571 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
572 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
573 return;
574 pause->rx_pause = 1;
575 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
576 if (port == 0)
577 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
578 else
579 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
580 } else {
Jeff Garzik47906542007-11-23 21:23:36 -0500581 printk(KERN_ERR"%s: Unknown board type: %x\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700582 netxen_nic_driver_name, adapter->ahw.board_type);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400583 }
584}
585
586static int
587netxen_nic_set_pauseparam(struct net_device *dev,
588 struct ethtool_pauseparam *pause)
589{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700590 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000591 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700592 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400593 /* read mode */
594 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700595 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
596 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400597 /* set flow control */
598 netxen_nic_read_w0(adapter,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700599 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
Jeff Garzik47906542007-11-23 21:23:36 -0500600
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400601 if (pause->rx_pause)
602 netxen_gb_rx_flowctl(val);
603 else
604 netxen_gb_unset_rx_flowctl(val);
605
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700606 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
607 val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400608 /* set autoneg */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700609 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
610 switch (port) {
611 case 0:
612 if (pause->tx_pause)
613 netxen_gb_unset_gb0_mask(val);
614 else
615 netxen_gb_set_gb0_mask(val);
616 break;
617 case 1:
618 if (pause->tx_pause)
619 netxen_gb_unset_gb1_mask(val);
620 else
621 netxen_gb_set_gb1_mask(val);
622 break;
623 case 2:
624 if (pause->tx_pause)
625 netxen_gb_unset_gb2_mask(val);
626 else
627 netxen_gb_set_gb2_mask(val);
628 break;
629 case 3:
630 default:
631 if (pause->tx_pause)
632 netxen_gb_unset_gb3_mask(val);
633 else
634 netxen_gb_set_gb3_mask(val);
635 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400636 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700637 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
638 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
639 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
640 return -EIO;
641 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
642 if (port == 0) {
643 if (pause->tx_pause)
644 netxen_xg_unset_xg0_mask(val);
645 else
646 netxen_xg_set_xg0_mask(val);
647 } else {
648 if (pause->tx_pause)
649 netxen_xg_unset_xg1_mask(val);
650 else
651 netxen_xg_set_xg1_mask(val);
652 }
Jeff Garzik47906542007-11-23 21:23:36 -0500653 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700654 } else {
655 printk(KERN_ERR "%s: Unknown board type: %x\n",
Jeff Garzik47906542007-11-23 21:23:36 -0500656 netxen_nic_driver_name,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700657 adapter->ahw.board_type);
658 }
659 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400660}
661
662static int netxen_nic_reg_test(struct net_device *dev)
663{
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800664 struct netxen_adapter *adapter = netdev_priv(dev);
665 u32 data_read, data_written;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400666
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800667 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
668 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400669 return 1;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800670
671 data_written = (u32)0xa5a5a5a5;
672
673 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700674 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800675 if (data_written != data_read)
676 return 1;
677
678 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400679}
680
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700681static int netxen_get_sset_count(struct net_device *dev, int sset)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400682{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700683 switch (sset) {
684 case ETH_SS_TEST:
685 return NETXEN_NIC_TEST_LEN;
686 case ETH_SS_STATS:
687 return NETXEN_NIC_STATS_LEN;
688 default:
689 return -EOPNOTSUPP;
690 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400691}
692
693static void
694netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
695 u64 * data)
696{
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700697 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
698 if ((data[0] = netxen_nic_reg_test(dev)))
699 eth_test->flags |= ETH_TEST_FL_FAILED;
700 /* link test */
701 if ((data[1] = (u64) netxen_nic_test_link(dev)))
702 eth_test->flags |= ETH_TEST_FL_FAILED;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400703}
704
705static void
706netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
707{
708 int index;
709
710 switch (stringset) {
711 case ETH_SS_TEST:
712 memcpy(data, *netxen_nic_gstrings_test,
713 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
714 break;
715 case ETH_SS_STATS:
716 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
717 memcpy(data + index * ETH_GSTRING_LEN,
718 netxen_nic_gstrings_stats[index].stat_string,
719 ETH_GSTRING_LEN);
720 }
721 break;
722 }
723}
724
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400725static void
726netxen_nic_get_ethtool_stats(struct net_device *dev,
727 struct ethtool_stats *stats, u64 * data)
728{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700729 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400730 int index;
731
732 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
733 char *p =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700734 (char *)adapter +
735 netxen_nic_gstrings_stats[index].stat_offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400736 data[index] =
737 (netxen_nic_gstrings_stats[index].sizeof_stat ==
738 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
739 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400740}
741
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530742static u32 netxen_nic_get_rx_csum(struct net_device *dev)
743{
744 struct netxen_adapter *adapter = netdev_priv(dev);
745 return adapter->rx_csum;
746}
747
748static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
749{
750 struct netxen_adapter *adapter = netdev_priv(dev);
751 adapter->rx_csum = !!data;
752 return 0;
753}
754
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700755static u32 netxen_nic_get_tso(struct net_device *dev)
756{
757 struct netxen_adapter *adapter = netdev_priv(dev);
758
759 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
760 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
761
762 return (dev->features & NETIF_F_TSO) != 0;
763}
764
765static int netxen_nic_set_tso(struct net_device *dev, u32 data)
766{
767 if (data) {
768 struct netxen_adapter *adapter = netdev_priv(dev);
769
770 dev->features |= NETIF_F_TSO;
771 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
772 dev->features |= NETIF_F_TSO6;
773 } else
774 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
775
776 return 0;
777}
778
779/*
780 * Set the coalescing parameters. Currently only normal is supported.
781 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
782 * firmware coalescing to default.
783 */
784static int netxen_set_intr_coalesce(struct net_device *netdev,
785 struct ethtool_coalesce *ethcoal)
786{
787 struct netxen_adapter *adapter = netdev_priv(netdev);
788
789 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
790 return -EINVAL;
791
792 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
793 return -EINVAL;
794
795 /*
796 * Return Error if unsupported values or
797 * unsupported parameters are set.
798 */
799 if (ethcoal->rx_coalesce_usecs > 0xffff ||
800 ethcoal->rx_max_coalesced_frames > 0xffff ||
801 ethcoal->tx_coalesce_usecs > 0xffff ||
802 ethcoal->tx_max_coalesced_frames > 0xffff ||
803 ethcoal->rx_coalesce_usecs_irq ||
804 ethcoal->rx_max_coalesced_frames_irq ||
805 ethcoal->tx_coalesce_usecs_irq ||
806 ethcoal->tx_max_coalesced_frames_irq ||
807 ethcoal->stats_block_coalesce_usecs ||
808 ethcoal->use_adaptive_rx_coalesce ||
809 ethcoal->use_adaptive_tx_coalesce ||
810 ethcoal->pkt_rate_low ||
811 ethcoal->rx_coalesce_usecs_low ||
812 ethcoal->rx_max_coalesced_frames_low ||
813 ethcoal->tx_coalesce_usecs_low ||
814 ethcoal->tx_max_coalesced_frames_low ||
815 ethcoal->pkt_rate_high ||
816 ethcoal->rx_coalesce_usecs_high ||
817 ethcoal->rx_max_coalesced_frames_high ||
818 ethcoal->tx_coalesce_usecs_high ||
819 ethcoal->tx_max_coalesced_frames_high)
820 return -EINVAL;
821
822 if (!ethcoal->rx_coalesce_usecs ||
823 !ethcoal->rx_max_coalesced_frames) {
824 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
825 adapter->coal.normal.data.rx_time_us =
826 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
827 adapter->coal.normal.data.rx_packets =
828 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
829 } else {
830 adapter->coal.flags = 0;
831 adapter->coal.normal.data.rx_time_us =
832 ethcoal->rx_coalesce_usecs;
833 adapter->coal.normal.data.rx_packets =
834 ethcoal->rx_max_coalesced_frames;
835 }
836 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
837 adapter->coal.normal.data.tx_packets =
838 ethcoal->tx_max_coalesced_frames;
839
840 netxen_config_intr_coalesce(adapter);
841
842 return 0;
843}
844
845static int netxen_get_intr_coalesce(struct net_device *netdev,
846 struct ethtool_coalesce *ethcoal)
847{
848 struct netxen_adapter *adapter = netdev_priv(netdev);
849
850 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
851 return -EINVAL;
852
853 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
854 return -EINVAL;
855
856 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
857 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
858 ethcoal->rx_max_coalesced_frames =
859 adapter->coal.normal.data.rx_packets;
860 ethcoal->tx_max_coalesced_frames =
861 adapter->coal.normal.data.tx_packets;
862
863 return 0;
864}
865
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400866struct ethtool_ops netxen_nic_ethtool_ops = {
867 .get_settings = netxen_nic_get_settings,
868 .set_settings = netxen_nic_set_settings,
869 .get_drvinfo = netxen_nic_get_drvinfo,
870 .get_regs_len = netxen_nic_get_regs_len,
871 .get_regs = netxen_nic_get_regs,
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800872 .get_link = ethtool_op_get_link,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400873 .get_eeprom_len = netxen_nic_get_eeprom_len,
874 .get_eeprom = netxen_nic_get_eeprom,
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700875#if 0
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800876 .set_eeprom = netxen_nic_set_eeprom,
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700877#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400878 .get_ringparam = netxen_nic_get_ringparam,
879 .get_pauseparam = netxen_nic_get_pauseparam,
880 .set_pauseparam = netxen_nic_set_pauseparam,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400881 .set_tx_csum = ethtool_op_set_tx_csum,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400882 .set_sg = ethtool_op_set_sg,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700883 .get_tso = netxen_nic_get_tso,
884 .set_tso = netxen_nic_set_tso,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400885 .self_test = netxen_nic_diag_test,
886 .get_strings = netxen_nic_get_strings,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400887 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700888 .get_sset_count = netxen_get_sset_count,
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530889 .get_rx_csum = netxen_nic_get_rx_csum,
890 .set_rx_csum = netxen_nic_set_rx_csum,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700891 .get_coalesce = netxen_get_intr_coalesce,
892 .set_coalesce = netxen_set_intr_coalesce,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400893};