blob: 4ad3e0844b9938de000c4bd966e02f8913976635 [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;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700143 ecmd->autoneg = adapter->link_autoneg;
144 }
145
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800146 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700147 u32 val;
148
149 adapter->hw_read_wx(adapter, NETXEN_PORT_MODE_ADDR, &val, 4);
150 if (val == NETXEN_PORT_MODE_802_3_AP) {
151 ecmd->supported = SUPPORTED_1000baseT_Full;
152 ecmd->advertising = ADVERTISED_1000baseT_Full;
153 } else {
154 ecmd->supported = SUPPORTED_10000baseT_Full;
155 ecmd->advertising = ADVERTISED_10000baseT_Full;
156 }
157
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400158 ecmd->port = PORT_TP;
159
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700160 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
161 u16 pcifn = adapter->ahw.pci_func;
162
163 adapter->hw_read_wx(adapter,
164 P3_LINK_SPEED_REG(pcifn), &val, 4);
165 ecmd->speed = P3_LINK_SPEED_MHZ *
166 P3_LINK_SPEED_VAL(pcifn, val);
167 } else
168 ecmd->speed = SPEED_10000;
169
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400170 ecmd->duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400171 ecmd->autoneg = AUTONEG_DISABLE;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800172 } else
173 return -EIO;
174
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700175 ecmd->phy_address = adapter->portnum;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800176 ecmd->transceiver = XCVR_EXTERNAL;
177
178 switch ((netxen_brdtype_t) boardinfo->board_type) {
179 case NETXEN_BRDTYPE_P2_SB35_4G:
180 case NETXEN_BRDTYPE_P2_SB31_2G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700181 case NETXEN_BRDTYPE_P3_REF_QG:
182 case NETXEN_BRDTYPE_P3_4_GB:
183 case NETXEN_BRDTYPE_P3_4_GB_MM:
184 case NETXEN_BRDTYPE_P3_10000_BASE_T:
185
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800186 ecmd->supported |= SUPPORTED_Autoneg;
187 ecmd->advertising |= ADVERTISED_Autoneg;
188 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700189 case NETXEN_BRDTYPE_P3_10G_CX4:
190 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800191 ecmd->supported |= SUPPORTED_TP;
192 ecmd->advertising |= ADVERTISED_TP;
193 ecmd->port = PORT_TP;
194 ecmd->autoneg = (boardinfo->board_type ==
195 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700196 (AUTONEG_DISABLE) : (adapter->link_autoneg);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800197 break;
198 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
199 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700200 case NETXEN_BRDTYPE_P3_IMEZ:
201 case NETXEN_BRDTYPE_P3_XG_LOM:
202 case NETXEN_BRDTYPE_P3_HMEZ:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800203 ecmd->supported |= SUPPORTED_MII;
204 ecmd->advertising |= ADVERTISED_MII;
205 ecmd->port = PORT_FIBRE;
206 ecmd->autoneg = AUTONEG_DISABLE;
207 break;
208 case NETXEN_BRDTYPE_P2_SB31_10G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700209 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700210 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
211 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700212 case NETXEN_BRDTYPE_P3_10G_XFP:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800213 ecmd->supported |= SUPPORTED_FIBRE;
214 ecmd->advertising |= ADVERTISED_FIBRE;
215 ecmd->port = PORT_FIBRE;
216 ecmd->autoneg = AUTONEG_DISABLE;
217 break;
218 default:
Amit S. Kale71bd7872006-12-01 05:36:22 -0800219 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800220 (netxen_brdtype_t) boardinfo->board_type);
221 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400222 }
223
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800224 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400225}
226
227static int
228netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
229{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700230 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000231 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400232
233 /* read which mode */
234 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
235 /* autonegotiation */
Amit S. Kale80922fb2006-12-04 09:18:00 -0800236 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700237 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800238 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab9c2007-01-02 10:39:10 +0000239 ecmd->autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400240 return -EIO;
241 else
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700242 adapter->link_autoneg = ecmd->autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400243
Amit S. Kale80922fb2006-12-04 09:18:00 -0800244 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700245 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800246 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
247 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400248 return -EIO;
249
250 /* speed */
251 switch (ecmd->speed) {
252 case SPEED_10:
253 netxen_set_phy_speed(status, 0);
254 break;
255 case SPEED_100:
256 netxen_set_phy_speed(status, 1);
257 break;
258 case SPEED_1000:
259 netxen_set_phy_speed(status, 2);
260 break;
261 }
262 /* set duplex mode */
263 if (ecmd->duplex == DUPLEX_HALF)
264 netxen_clear_phy_duplex(status);
265 if (ecmd->duplex == DUPLEX_FULL)
266 netxen_set_phy_duplex(status);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800267 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700268 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800269 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
270 *((int *)&status)) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400271 return -EIO;
272 else {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700273 adapter->link_speed = ecmd->speed;
274 adapter->link_duplex = ecmd->duplex;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400275 }
276 } else
277 return -EOPNOTSUPP;
278
279 if (netif_running(dev)) {
280 dev->stop(dev);
281 dev->open(dev);
282 }
283 return 0;
284}
285
286static int netxen_nic_get_regs_len(struct net_device *dev)
287{
288 return NETXEN_NIC_REGS_LEN;
289}
290
291struct netxen_niu_regs {
Al Viroa608ab9c2007-01-02 10:39:10 +0000292 __u32 reg[NETXEN_NIC_REGS_COUNT];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400293};
294
295static struct netxen_niu_regs niu_registers[] = {
296 {
297 /* GB Mode */
298 {
299 NETXEN_NIU_GB_SERDES_RESET,
300 NETXEN_NIU_GB0_MII_MODE,
301 NETXEN_NIU_GB1_MII_MODE,
302 NETXEN_NIU_GB2_MII_MODE,
303 NETXEN_NIU_GB3_MII_MODE,
304 NETXEN_NIU_GB0_GMII_MODE,
305 NETXEN_NIU_GB1_GMII_MODE,
306 NETXEN_NIU_GB2_GMII_MODE,
307 NETXEN_NIU_GB3_GMII_MODE,
308 NETXEN_NIU_REMOTE_LOOPBACK,
309 NETXEN_NIU_GB0_HALF_DUPLEX,
310 NETXEN_NIU_GB1_HALF_DUPLEX,
311 NETXEN_NIU_RESET_SYS_FIFOS,
312 NETXEN_NIU_GB_CRC_DROP,
313 NETXEN_NIU_GB_DROP_WRONGADDR,
314 NETXEN_NIU_TEST_MUX_CTL,
315
316 NETXEN_NIU_GB_MAC_CONFIG_0(0),
317 NETXEN_NIU_GB_MAC_CONFIG_1(0),
318 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
319 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
320 NETXEN_NIU_GB_TEST_REG(0),
321 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
322 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
323 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
324 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
325 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
326 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
327 NETXEN_NIU_GB_INTERFACE_CTRL(0),
328 NETXEN_NIU_GB_INTERFACE_STATUS(0),
329 NETXEN_NIU_GB_STATION_ADDR_0(0),
330 NETXEN_NIU_GB_STATION_ADDR_1(0),
331 -1,
332 }
333 },
334 {
335 /* XG Mode */
336 {
337 NETXEN_NIU_XG_SINGLE_TERM,
338 NETXEN_NIU_XG_DRIVE_HI,
339 NETXEN_NIU_XG_DRIVE_LO,
340 NETXEN_NIU_XG_DTX,
341 NETXEN_NIU_XG_DEQ,
342 NETXEN_NIU_XG_WORD_ALIGN,
343 NETXEN_NIU_XG_RESET,
344 NETXEN_NIU_XG_POWER_DOWN,
345 NETXEN_NIU_XG_RESET_PLL,
346 NETXEN_NIU_XG_SERDES_LOOPBACK,
347 NETXEN_NIU_XG_DO_BYTE_ALIGN,
348 NETXEN_NIU_XG_TX_ENABLE,
349 NETXEN_NIU_XG_RX_ENABLE,
350 NETXEN_NIU_XG_STATUS,
351 NETXEN_NIU_XG_PAUSE_THRESHOLD,
352 NETXEN_NIU_XGE_CONFIG_0,
353 NETXEN_NIU_XGE_CONFIG_1,
354 NETXEN_NIU_XGE_IPG,
355 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
356 NETXEN_NIU_XGE_STATION_ADDR_0_1,
357 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
358 NETXEN_NIU_XGE_STATUS,
359 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
360 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
361 NETXEN_NIU_XGE_TX_BYTE_CNT,
362 NETXEN_NIU_XGE_TX_FRAME_CNT,
363 NETXEN_NIU_XGE_RX_BYTE_CNT,
364 NETXEN_NIU_XGE_RX_FRAME_CNT,
365 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
366 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
367 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
368 NETXEN_NIU_XGE_CRC_ERROR_CNT,
369 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
370 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
371 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
372 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
373 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
374 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
375 -1,
376 }
377 }
378};
379
380static void
381netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
382{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700383 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000384 __u32 mode, *regs_buff = p;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400385 int i, window;
386
387 memset(p, 0, NETXEN_NIC_REGS_LEN);
388 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700389 (adapter->pdev)->device;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400390 /* which mode */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700391 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, &regs_buff[0], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400392 mode = regs_buff[0];
393
394 /* Common registers to all the modes */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700395 adapter->hw_read_wx(adapter,
396 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, &regs_buff[2], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400397 /* GB/XGB Mode */
398 mode = (mode / 2) - 1;
399 window = 0;
400 if (mode <= 1) {
401 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
402 /* GB: port specific registers */
403 if (mode == 0 && i >= 19)
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700404 window = adapter->physical_port *
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700405 NETXEN_NIC_PORT_WINDOW;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400406
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700407 adapter->hw_read_wx(adapter,
408 niu_registers[mode].reg[i - 3] + window,
409 &regs_buff[i], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400410 }
411
412 }
413}
414
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800415static u32 netxen_nic_test_link(struct net_device *dev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400416{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700417 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000418 __u32 status;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800419 int val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400420
421 /* read which mode */
422 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Amit S. Kale80922fb2006-12-04 09:18:00 -0800423 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700424 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800425 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
426 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400427 return -EIO;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800428 else {
429 val = netxen_get_phy_link(status);
430 return !val;
431 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400432 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700433 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800434 return (val == XG_LINK_UP) ? 0 : 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400435 }
436 return -EIO;
437}
438
439static int
440netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
441 u8 * bytes)
442{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700443 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400444 int offset;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800445 int ret;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400446
447 if (eeprom->len == 0)
448 return -EINVAL;
449
Jeff Garzik47906542007-11-23 21:23:36 -0500450 eeprom->magic = (adapter->pdev)->vendor |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700451 ((adapter->pdev)->device << 16);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800452 offset = eeprom->offset;
453
Jeff Garzik47906542007-11-23 21:23:36 -0500454 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800455 eeprom->len);
456 if (ret < 0)
457 return ret;
458
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400459 return 0;
460}
461
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700462#if 0
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800463static int
464netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
465 u8 * bytes)
466{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700467 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800468 int offset = eeprom->offset;
469 static int flash_start;
470 static int ready_to_flash;
471 int ret;
472
473 if (flash_start == 0) {
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800474 netxen_halt_pegs(adapter);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800475 ret = netxen_flash_unlock(adapter);
476 if (ret < 0) {
477 printk(KERN_ERR "%s: Flash unlock failed.\n",
478 netxen_nic_driver_name);
479 return ret;
480 }
Jeff Garzik47906542007-11-23 21:23:36 -0500481 printk(KERN_INFO "%s: flash unlocked. \n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800482 netxen_nic_driver_name);
483 ret = netxen_flash_erase_secondary(adapter);
484 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500485 printk(KERN_ERR "%s: Flash erase failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800486 netxen_nic_driver_name);
487 return ret;
488 }
Jeff Garzik47906542007-11-23 21:23:36 -0500489 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800490 netxen_nic_driver_name);
491 flash_start = 1;
492 return 0;
493 }
494
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700495 if (offset == NETXEN_BOOTLD_START) {
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800496 ret = netxen_flash_erase_primary(adapter);
497 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500498 printk(KERN_ERR "%s: Flash erase failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800499 netxen_nic_driver_name);
500 return ret;
501 }
502
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700503 ret = netxen_rom_se(adapter, NETXEN_USER_START);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800504 if (ret != FLASH_SUCCESS)
505 return ret;
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700506 ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800507 if (ret != FLASH_SUCCESS)
508 return ret;
509
Jeff Garzik47906542007-11-23 21:23:36 -0500510 printk(KERN_INFO "%s: primary flash erased successfully\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800511 netxen_nic_driver_name);
512
513 ret = netxen_backup_crbinit(adapter);
514 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500515 printk(KERN_ERR "%s: CRBinit backup failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800516 netxen_nic_driver_name);
517 return ret;
518 }
Jeff Garzik47906542007-11-23 21:23:36 -0500519 printk(KERN_INFO "%s: CRBinit backup done.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800520 netxen_nic_driver_name);
521 ready_to_flash = 1;
522 }
523
524 if (!ready_to_flash) {
525 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
526 netxen_nic_driver_name);
527 return -EINVAL;
528 }
529
530 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
531}
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700532#endif /* 0 */
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800533
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400534static void
535netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
536{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700537 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800538 int i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400539
540 ring->rx_pending = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800541 ring->rx_jumbo_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400542 for (i = 0; i < MAX_RCV_CTX; ++i) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800543 ring->rx_pending += adapter->recv_ctx[i].
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700544 rds_rings[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800545 ring->rx_jumbo_pending += adapter->recv_ctx[i].
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700546 rds_rings[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400547 }
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530548 ring->tx_pending = adapter->max_tx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400549
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530550 ring->rx_max_pending = MAX_RCV_DESCRIPTORS;
551 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
552 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400553 ring->rx_mini_max_pending = 0;
554 ring->rx_mini_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400555}
556
557static void
558netxen_nic_get_pauseparam(struct net_device *dev,
559 struct ethtool_pauseparam *pause)
560{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700561 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000562 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700563 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400564
565 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700566 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
567 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400568 /* get flow control settings */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700569 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
570 &val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400571 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700572 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
573 switch (port) {
574 case 0:
575 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
576 break;
577 case 1:
578 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
579 break;
580 case 2:
581 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
582 break;
583 case 3:
584 default:
585 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
586 break;
587 }
588 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
589 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
590 return;
591 pause->rx_pause = 1;
592 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
593 if (port == 0)
594 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
595 else
596 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
597 } else {
Jeff Garzik47906542007-11-23 21:23:36 -0500598 printk(KERN_ERR"%s: Unknown board type: %x\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700599 netxen_nic_driver_name, adapter->ahw.board_type);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400600 }
601}
602
603static int
604netxen_nic_set_pauseparam(struct net_device *dev,
605 struct ethtool_pauseparam *pause)
606{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700607 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000608 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700609 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400610 /* read mode */
611 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700612 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
613 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400614 /* set flow control */
615 netxen_nic_read_w0(adapter,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700616 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
Jeff Garzik47906542007-11-23 21:23:36 -0500617
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400618 if (pause->rx_pause)
619 netxen_gb_rx_flowctl(val);
620 else
621 netxen_gb_unset_rx_flowctl(val);
622
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700623 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
624 val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400625 /* set autoneg */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700626 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
627 switch (port) {
628 case 0:
629 if (pause->tx_pause)
630 netxen_gb_unset_gb0_mask(val);
631 else
632 netxen_gb_set_gb0_mask(val);
633 break;
634 case 1:
635 if (pause->tx_pause)
636 netxen_gb_unset_gb1_mask(val);
637 else
638 netxen_gb_set_gb1_mask(val);
639 break;
640 case 2:
641 if (pause->tx_pause)
642 netxen_gb_unset_gb2_mask(val);
643 else
644 netxen_gb_set_gb2_mask(val);
645 break;
646 case 3:
647 default:
648 if (pause->tx_pause)
649 netxen_gb_unset_gb3_mask(val);
650 else
651 netxen_gb_set_gb3_mask(val);
652 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400653 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700654 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
655 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
656 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
657 return -EIO;
658 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
659 if (port == 0) {
660 if (pause->tx_pause)
661 netxen_xg_unset_xg0_mask(val);
662 else
663 netxen_xg_set_xg0_mask(val);
664 } else {
665 if (pause->tx_pause)
666 netxen_xg_unset_xg1_mask(val);
667 else
668 netxen_xg_set_xg1_mask(val);
669 }
Jeff Garzik47906542007-11-23 21:23:36 -0500670 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700671 } else {
672 printk(KERN_ERR "%s: Unknown board type: %x\n",
Jeff Garzik47906542007-11-23 21:23:36 -0500673 netxen_nic_driver_name,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700674 adapter->ahw.board_type);
675 }
676 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400677}
678
679static int netxen_nic_reg_test(struct net_device *dev)
680{
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800681 struct netxen_adapter *adapter = netdev_priv(dev);
682 u32 data_read, data_written;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400683
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800684 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
685 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400686 return 1;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800687
688 data_written = (u32)0xa5a5a5a5;
689
690 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700691 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800692 if (data_written != data_read)
693 return 1;
694
695 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400696}
697
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700698static int netxen_get_sset_count(struct net_device *dev, int sset)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400699{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700700 switch (sset) {
701 case ETH_SS_TEST:
702 return NETXEN_NIC_TEST_LEN;
703 case ETH_SS_STATS:
704 return NETXEN_NIC_STATS_LEN;
705 default:
706 return -EOPNOTSUPP;
707 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400708}
709
710static void
711netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
712 u64 * data)
713{
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700714 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
715 if ((data[0] = netxen_nic_reg_test(dev)))
716 eth_test->flags |= ETH_TEST_FL_FAILED;
717 /* link test */
718 if ((data[1] = (u64) netxen_nic_test_link(dev)))
719 eth_test->flags |= ETH_TEST_FL_FAILED;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400720}
721
722static void
723netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
724{
725 int index;
726
727 switch (stringset) {
728 case ETH_SS_TEST:
729 memcpy(data, *netxen_nic_gstrings_test,
730 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
731 break;
732 case ETH_SS_STATS:
733 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
734 memcpy(data + index * ETH_GSTRING_LEN,
735 netxen_nic_gstrings_stats[index].stat_string,
736 ETH_GSTRING_LEN);
737 }
738 break;
739 }
740}
741
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400742static void
743netxen_nic_get_ethtool_stats(struct net_device *dev,
744 struct ethtool_stats *stats, u64 * data)
745{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700746 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400747 int index;
748
749 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
750 char *p =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700751 (char *)adapter +
752 netxen_nic_gstrings_stats[index].stat_offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400753 data[index] =
754 (netxen_nic_gstrings_stats[index].sizeof_stat ==
755 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
756 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400757}
758
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530759static u32 netxen_nic_get_rx_csum(struct net_device *dev)
760{
761 struct netxen_adapter *adapter = netdev_priv(dev);
762 return adapter->rx_csum;
763}
764
765static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
766{
767 struct netxen_adapter *adapter = netdev_priv(dev);
768 adapter->rx_csum = !!data;
769 return 0;
770}
771
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700772static u32 netxen_nic_get_tso(struct net_device *dev)
773{
774 struct netxen_adapter *adapter = netdev_priv(dev);
775
776 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
777 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
778
779 return (dev->features & NETIF_F_TSO) != 0;
780}
781
782static int netxen_nic_set_tso(struct net_device *dev, u32 data)
783{
784 if (data) {
785 struct netxen_adapter *adapter = netdev_priv(dev);
786
787 dev->features |= NETIF_F_TSO;
788 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
789 dev->features |= NETIF_F_TSO6;
790 } else
791 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
792
793 return 0;
794}
795
796/*
797 * Set the coalescing parameters. Currently only normal is supported.
798 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
799 * firmware coalescing to default.
800 */
801static int netxen_set_intr_coalesce(struct net_device *netdev,
802 struct ethtool_coalesce *ethcoal)
803{
804 struct netxen_adapter *adapter = netdev_priv(netdev);
805
806 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
807 return -EINVAL;
808
809 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
810 return -EINVAL;
811
812 /*
813 * Return Error if unsupported values or
814 * unsupported parameters are set.
815 */
816 if (ethcoal->rx_coalesce_usecs > 0xffff ||
817 ethcoal->rx_max_coalesced_frames > 0xffff ||
818 ethcoal->tx_coalesce_usecs > 0xffff ||
819 ethcoal->tx_max_coalesced_frames > 0xffff ||
820 ethcoal->rx_coalesce_usecs_irq ||
821 ethcoal->rx_max_coalesced_frames_irq ||
822 ethcoal->tx_coalesce_usecs_irq ||
823 ethcoal->tx_max_coalesced_frames_irq ||
824 ethcoal->stats_block_coalesce_usecs ||
825 ethcoal->use_adaptive_rx_coalesce ||
826 ethcoal->use_adaptive_tx_coalesce ||
827 ethcoal->pkt_rate_low ||
828 ethcoal->rx_coalesce_usecs_low ||
829 ethcoal->rx_max_coalesced_frames_low ||
830 ethcoal->tx_coalesce_usecs_low ||
831 ethcoal->tx_max_coalesced_frames_low ||
832 ethcoal->pkt_rate_high ||
833 ethcoal->rx_coalesce_usecs_high ||
834 ethcoal->rx_max_coalesced_frames_high ||
835 ethcoal->tx_coalesce_usecs_high ||
836 ethcoal->tx_max_coalesced_frames_high)
837 return -EINVAL;
838
839 if (!ethcoal->rx_coalesce_usecs ||
840 !ethcoal->rx_max_coalesced_frames) {
841 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
842 adapter->coal.normal.data.rx_time_us =
843 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
844 adapter->coal.normal.data.rx_packets =
845 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
846 } else {
847 adapter->coal.flags = 0;
848 adapter->coal.normal.data.rx_time_us =
849 ethcoal->rx_coalesce_usecs;
850 adapter->coal.normal.data.rx_packets =
851 ethcoal->rx_max_coalesced_frames;
852 }
853 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
854 adapter->coal.normal.data.tx_packets =
855 ethcoal->tx_max_coalesced_frames;
856
857 netxen_config_intr_coalesce(adapter);
858
859 return 0;
860}
861
862static int netxen_get_intr_coalesce(struct net_device *netdev,
863 struct ethtool_coalesce *ethcoal)
864{
865 struct netxen_adapter *adapter = netdev_priv(netdev);
866
867 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
868 return -EINVAL;
869
870 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
871 return -EINVAL;
872
873 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
874 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
875 ethcoal->rx_max_coalesced_frames =
876 adapter->coal.normal.data.rx_packets;
877 ethcoal->tx_max_coalesced_frames =
878 adapter->coal.normal.data.tx_packets;
879
880 return 0;
881}
882
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400883struct ethtool_ops netxen_nic_ethtool_ops = {
884 .get_settings = netxen_nic_get_settings,
885 .set_settings = netxen_nic_set_settings,
886 .get_drvinfo = netxen_nic_get_drvinfo,
887 .get_regs_len = netxen_nic_get_regs_len,
888 .get_regs = netxen_nic_get_regs,
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800889 .get_link = ethtool_op_get_link,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400890 .get_eeprom_len = netxen_nic_get_eeprom_len,
891 .get_eeprom = netxen_nic_get_eeprom,
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700892#if 0
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800893 .set_eeprom = netxen_nic_set_eeprom,
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700894#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400895 .get_ringparam = netxen_nic_get_ringparam,
896 .get_pauseparam = netxen_nic_get_pauseparam,
897 .set_pauseparam = netxen_nic_set_pauseparam,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400898 .set_tx_csum = ethtool_op_set_tx_csum,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400899 .set_sg = ethtool_op_set_sg,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700900 .get_tso = netxen_nic_get_tso,
901 .set_tso = netxen_nic_set_tso,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400902 .self_test = netxen_nic_diag_test,
903 .get_strings = netxen_nic_get_strings,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400904 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700905 .get_sset_count = netxen_get_sset_count,
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530906 .get_rx_csum = netxen_nic_get_rx_csum,
907 .set_rx_csum = netxen_nic_set_rx_csum,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700908 .get_coalesce = netxen_get_intr_coalesce,
909 .set_coalesce = netxen_set_intr_coalesce,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400910};