blob: c0bd40fcf708e0caa92c7c5f96a1af5c5fe7b618 [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>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040041
Amit S. Kale3d396eb2006-10-21 15:33:03 -040042#include "netxen_nic.h"
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070043#include "netxen_nic_hw.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040044#include "netxen_nic_phan_reg.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040045
46struct netxen_nic_stats {
47 char stat_string[ETH_GSTRING_LEN];
48 int sizeof_stat;
49 int stat_offset;
50};
51
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070052#define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
53 offsetof(struct netxen_adapter, m)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040054
Amit S. Kalecb8011a2006-11-29 09:00:10 -080055#define NETXEN_NIC_PORT_WINDOW 0x10000
56#define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
57
Amit S. Kale3d396eb2006-10-21 15:33:03 -040058static 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)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040066 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040067 {"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)},
71};
72
Stephen Hemminger92104e92006-12-15 07:57:08 -080073#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040074
75static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -080076 "Register_Test_on_offline",
Amit S. Kale3d396eb2006-10-21 15:33:03 -040077 "Link_Test_on_offline"
78};
79
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +020080#define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040081
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
85
86static int netxen_nic_get_eeprom_len(struct net_device *dev)
87{
Mithlesh Thukral0d047612007-06-07 04:36:36 -070088 return NETXEN_FLASH_TOTAL_SIZE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040089}
90
91static void
92netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
93{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070094 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070095 unsigned long flags;
Amit S. Kalecb8011a2006-11-29 09:00:10 -080096 u32 fw_major = 0;
97 u32 fw_minor = 0;
98 u32 fw_build = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040099
Amit S. Kale80922fb2006-12-04 09:18:00 -0800100 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400101 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700102 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);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400110 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
111
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700112 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400113 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
114 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
115}
116
117static int
118netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
119{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700120 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale71bd7872006-12-01 05:36:22 -0800121 struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400122
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 |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800130 SUPPORTED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400131
132 ecmd->advertising = (ADVERTISED_100baseT_Half |
133 ADVERTISED_100baseT_Full |
134 ADVERTISED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800135 ADVERTISED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400136
137 ecmd->port = PORT_TP;
138
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800139 ecmd->speed = adapter->link_speed;
140 ecmd->duplex = adapter->link_duplex;
141 ecmd->autoneg = adapter->link_autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700142
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800143 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700144 u32 val;
145
146 adapter->hw_read_wx(adapter, NETXEN_PORT_MODE_ADDR, &val, 4);
147 if (val == NETXEN_PORT_MODE_802_3_AP) {
148 ecmd->supported = SUPPORTED_1000baseT_Full;
149 ecmd->advertising = ADVERTISED_1000baseT_Full;
150 } else {
151 ecmd->supported = SUPPORTED_10000baseT_Full;
152 ecmd->advertising = ADVERTISED_10000baseT_Full;
153 }
154
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400155 ecmd->port = PORT_TP;
156
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700157 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
158 u16 pcifn = adapter->ahw.pci_func;
159
160 adapter->hw_read_wx(adapter,
161 P3_LINK_SPEED_REG(pcifn), &val, 4);
162 ecmd->speed = P3_LINK_SPEED_MHZ *
163 P3_LINK_SPEED_VAL(pcifn, val);
164 } else
165 ecmd->speed = SPEED_10000;
166
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400167 ecmd->duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400168 ecmd->autoneg = AUTONEG_DISABLE;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800169 } else
170 return -EIO;
171
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800172 ecmd->phy_address = adapter->physical_port;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800173 ecmd->transceiver = XCVR_EXTERNAL;
174
175 switch ((netxen_brdtype_t) boardinfo->board_type) {
176 case NETXEN_BRDTYPE_P2_SB35_4G:
177 case NETXEN_BRDTYPE_P2_SB31_2G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700178 case NETXEN_BRDTYPE_P3_REF_QG:
179 case NETXEN_BRDTYPE_P3_4_GB:
180 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700181
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800182 ecmd->supported |= SUPPORTED_Autoneg;
183 ecmd->advertising |= ADVERTISED_Autoneg;
184 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700185 case NETXEN_BRDTYPE_P3_10G_CX4:
186 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800187 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800188 ecmd->supported |= SUPPORTED_TP;
189 ecmd->advertising |= ADVERTISED_TP;
190 ecmd->port = PORT_TP;
191 ecmd->autoneg = (boardinfo->board_type ==
192 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700193 (AUTONEG_DISABLE) : (adapter->link_autoneg);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800194 break;
195 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
196 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700197 case NETXEN_BRDTYPE_P3_IMEZ:
198 case NETXEN_BRDTYPE_P3_XG_LOM:
199 case NETXEN_BRDTYPE_P3_HMEZ:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800200 ecmd->supported |= SUPPORTED_MII;
201 ecmd->advertising |= ADVERTISED_MII;
202 ecmd->port = PORT_FIBRE;
203 ecmd->autoneg = AUTONEG_DISABLE;
204 break;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700205 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700206 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
207 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800208 ecmd->advertising |= ADVERTISED_TP;
209 ecmd->supported |= SUPPORTED_TP;
210 case NETXEN_BRDTYPE_P2_SB31_10G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700211 case NETXEN_BRDTYPE_P3_10G_XFP:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800212 ecmd->supported |= SUPPORTED_FIBRE;
213 ecmd->advertising |= ADVERTISED_FIBRE;
214 ecmd->port = PORT_FIBRE;
215 ecmd->autoneg = AUTONEG_DISABLE;
216 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800217 case NETXEN_BRDTYPE_P3_10G_TP:
218 if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
219 ecmd->autoneg = AUTONEG_DISABLE;
220 ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
221 ecmd->advertising |=
222 (ADVERTISED_FIBRE | ADVERTISED_TP);
223 ecmd->port = PORT_FIBRE;
224 } else {
225 ecmd->autoneg = AUTONEG_ENABLE;
226 ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg);
227 ecmd->advertising |=
228 (ADVERTISED_TP | ADVERTISED_Autoneg);
229 ecmd->port = PORT_TP;
230 }
231 break;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800232 default:
Amit S. Kale71bd7872006-12-01 05:36:22 -0800233 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800234 (netxen_brdtype_t) boardinfo->board_type);
235 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400236 }
237
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800238 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400239}
240
241static int
242netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
243{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700244 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000245 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400246
247 /* read which mode */
248 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
249 /* autonegotiation */
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_AUTONEG,
Al Viroa608ab9c2007-01-02 10:39:10 +0000253 ecmd->autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400254 return -EIO;
255 else
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700256 adapter->link_autoneg = ecmd->autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400257
Amit S. Kale80922fb2006-12-04 09:18:00 -0800258 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700259 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800260 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
261 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400262 return -EIO;
263
264 /* speed */
265 switch (ecmd->speed) {
266 case SPEED_10:
267 netxen_set_phy_speed(status, 0);
268 break;
269 case SPEED_100:
270 netxen_set_phy_speed(status, 1);
271 break;
272 case SPEED_1000:
273 netxen_set_phy_speed(status, 2);
274 break;
275 }
276 /* set duplex mode */
277 if (ecmd->duplex == DUPLEX_HALF)
278 netxen_clear_phy_duplex(status);
279 if (ecmd->duplex == DUPLEX_FULL)
280 netxen_set_phy_duplex(status);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800281 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700282 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800283 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
284 *((int *)&status)) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400285 return -EIO;
286 else {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700287 adapter->link_speed = ecmd->speed;
288 adapter->link_duplex = ecmd->duplex;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400289 }
290 } else
291 return -EOPNOTSUPP;
292
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800293 if (!netif_running(dev))
294 return 0;
295
296 dev->netdev_ops->ndo_stop(dev);
297 return dev->netdev_ops->ndo_open(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400298}
299
300static int netxen_nic_get_regs_len(struct net_device *dev)
301{
302 return NETXEN_NIC_REGS_LEN;
303}
304
305struct netxen_niu_regs {
Al Viroa608ab9c2007-01-02 10:39:10 +0000306 __u32 reg[NETXEN_NIC_REGS_COUNT];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400307};
308
309static struct netxen_niu_regs niu_registers[] = {
310 {
311 /* GB Mode */
312 {
313 NETXEN_NIU_GB_SERDES_RESET,
314 NETXEN_NIU_GB0_MII_MODE,
315 NETXEN_NIU_GB1_MII_MODE,
316 NETXEN_NIU_GB2_MII_MODE,
317 NETXEN_NIU_GB3_MII_MODE,
318 NETXEN_NIU_GB0_GMII_MODE,
319 NETXEN_NIU_GB1_GMII_MODE,
320 NETXEN_NIU_GB2_GMII_MODE,
321 NETXEN_NIU_GB3_GMII_MODE,
322 NETXEN_NIU_REMOTE_LOOPBACK,
323 NETXEN_NIU_GB0_HALF_DUPLEX,
324 NETXEN_NIU_GB1_HALF_DUPLEX,
325 NETXEN_NIU_RESET_SYS_FIFOS,
326 NETXEN_NIU_GB_CRC_DROP,
327 NETXEN_NIU_GB_DROP_WRONGADDR,
328 NETXEN_NIU_TEST_MUX_CTL,
329
330 NETXEN_NIU_GB_MAC_CONFIG_0(0),
331 NETXEN_NIU_GB_MAC_CONFIG_1(0),
332 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
333 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
334 NETXEN_NIU_GB_TEST_REG(0),
335 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
336 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
337 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
338 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
339 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
340 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
341 NETXEN_NIU_GB_INTERFACE_CTRL(0),
342 NETXEN_NIU_GB_INTERFACE_STATUS(0),
343 NETXEN_NIU_GB_STATION_ADDR_0(0),
344 NETXEN_NIU_GB_STATION_ADDR_1(0),
345 -1,
346 }
347 },
348 {
349 /* XG Mode */
350 {
351 NETXEN_NIU_XG_SINGLE_TERM,
352 NETXEN_NIU_XG_DRIVE_HI,
353 NETXEN_NIU_XG_DRIVE_LO,
354 NETXEN_NIU_XG_DTX,
355 NETXEN_NIU_XG_DEQ,
356 NETXEN_NIU_XG_WORD_ALIGN,
357 NETXEN_NIU_XG_RESET,
358 NETXEN_NIU_XG_POWER_DOWN,
359 NETXEN_NIU_XG_RESET_PLL,
360 NETXEN_NIU_XG_SERDES_LOOPBACK,
361 NETXEN_NIU_XG_DO_BYTE_ALIGN,
362 NETXEN_NIU_XG_TX_ENABLE,
363 NETXEN_NIU_XG_RX_ENABLE,
364 NETXEN_NIU_XG_STATUS,
365 NETXEN_NIU_XG_PAUSE_THRESHOLD,
366 NETXEN_NIU_XGE_CONFIG_0,
367 NETXEN_NIU_XGE_CONFIG_1,
368 NETXEN_NIU_XGE_IPG,
369 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
370 NETXEN_NIU_XGE_STATION_ADDR_0_1,
371 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
372 NETXEN_NIU_XGE_STATUS,
373 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
374 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
375 NETXEN_NIU_XGE_TX_BYTE_CNT,
376 NETXEN_NIU_XGE_TX_FRAME_CNT,
377 NETXEN_NIU_XGE_RX_BYTE_CNT,
378 NETXEN_NIU_XGE_RX_FRAME_CNT,
379 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
380 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
381 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
382 NETXEN_NIU_XGE_CRC_ERROR_CNT,
383 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
384 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
385 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
386 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
387 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
388 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
389 -1,
390 }
391 }
392};
393
394static void
395netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
396{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700397 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000398 __u32 mode, *regs_buff = p;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400399 int i, window;
400
401 memset(p, 0, NETXEN_NIC_REGS_LEN);
402 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700403 (adapter->pdev)->device;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400404 /* which mode */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700405 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, &regs_buff[0], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400406 mode = regs_buff[0];
407
408 /* Common registers to all the modes */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700409 adapter->hw_read_wx(adapter,
410 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, &regs_buff[2], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400411 /* GB/XGB Mode */
412 mode = (mode / 2) - 1;
413 window = 0;
414 if (mode <= 1) {
415 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
416 /* GB: port specific registers */
417 if (mode == 0 && i >= 19)
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700418 window = adapter->physical_port *
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700419 NETXEN_NIC_PORT_WINDOW;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400420
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700421 adapter->hw_read_wx(adapter,
422 niu_registers[mode].reg[i - 3] + window,
423 &regs_buff[i], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400424 }
425
426 }
427}
428
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800429static u32 netxen_nic_test_link(struct net_device *dev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400430{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700431 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000432 __u32 status;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800433 int val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400434
435 /* read which mode */
436 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Amit S. Kale80922fb2006-12-04 09:18:00 -0800437 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700438 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800439 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
440 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400441 return -EIO;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800442 else {
443 val = netxen_get_phy_link(status);
444 return !val;
445 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400446 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700447 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800448 return (val == XG_LINK_UP) ? 0 : 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400449 }
450 return -EIO;
451}
452
453static int
454netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
455 u8 * bytes)
456{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700457 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400458 int offset;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800459 int ret;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400460
461 if (eeprom->len == 0)
462 return -EINVAL;
463
Jeff Garzik47906542007-11-23 21:23:36 -0500464 eeprom->magic = (adapter->pdev)->vendor |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700465 ((adapter->pdev)->device << 16);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800466 offset = eeprom->offset;
467
Jeff Garzik47906542007-11-23 21:23:36 -0500468 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800469 eeprom->len);
470 if (ret < 0)
471 return ret;
472
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400473 return 0;
474}
475
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700476#if 0
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800477static int
478netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
479 u8 * bytes)
480{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700481 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800482 int offset = eeprom->offset;
483 static int flash_start;
484 static int ready_to_flash;
485 int ret;
486
487 if (flash_start == 0) {
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800488 netxen_halt_pegs(adapter);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800489 ret = netxen_flash_unlock(adapter);
490 if (ret < 0) {
491 printk(KERN_ERR "%s: Flash unlock failed.\n",
492 netxen_nic_driver_name);
493 return ret;
494 }
Jeff Garzik47906542007-11-23 21:23:36 -0500495 printk(KERN_INFO "%s: flash unlocked. \n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800496 netxen_nic_driver_name);
497 ret = netxen_flash_erase_secondary(adapter);
498 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500499 printk(KERN_ERR "%s: Flash erase failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800500 netxen_nic_driver_name);
501 return ret;
502 }
Jeff Garzik47906542007-11-23 21:23:36 -0500503 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800504 netxen_nic_driver_name);
505 flash_start = 1;
506 return 0;
507 }
508
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700509 if (offset == NETXEN_BOOTLD_START) {
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800510 ret = netxen_flash_erase_primary(adapter);
511 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500512 printk(KERN_ERR "%s: Flash erase failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800513 netxen_nic_driver_name);
514 return ret;
515 }
516
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700517 ret = netxen_rom_se(adapter, NETXEN_USER_START);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800518 if (ret != FLASH_SUCCESS)
519 return ret;
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700520 ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800521 if (ret != FLASH_SUCCESS)
522 return ret;
523
Jeff Garzik47906542007-11-23 21:23:36 -0500524 printk(KERN_INFO "%s: primary flash erased successfully\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800525 netxen_nic_driver_name);
526
527 ret = netxen_backup_crbinit(adapter);
528 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500529 printk(KERN_ERR "%s: CRBinit backup failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800530 netxen_nic_driver_name);
531 return ret;
532 }
Jeff Garzik47906542007-11-23 21:23:36 -0500533 printk(KERN_INFO "%s: CRBinit backup done.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800534 netxen_nic_driver_name);
535 ready_to_flash = 1;
536 }
537
538 if (!ready_to_flash) {
539 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
540 netxen_nic_driver_name);
541 return -EINVAL;
542 }
543
544 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
545}
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700546#endif /* 0 */
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800547
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400548static void
549netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
550{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700551 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800552 int i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400553
554 ring->rx_pending = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800555 ring->rx_jumbo_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400556 for (i = 0; i < MAX_RCV_CTX; ++i) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800557 ring->rx_pending += adapter->recv_ctx[i].
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700558 rds_rings[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800559 ring->rx_jumbo_pending += adapter->recv_ctx[i].
Dhananjay Phadke48bfd1e2008-07-21 19:44:06 -0700560 rds_rings[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400561 }
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530562 ring->tx_pending = adapter->max_tx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400563
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530564 ring->rx_max_pending = MAX_RCV_DESCRIPTORS;
565 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
566 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400567 ring->rx_mini_max_pending = 0;
568 ring->rx_mini_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400569}
570
571static void
572netxen_nic_get_pauseparam(struct net_device *dev,
573 struct ethtool_pauseparam *pause)
574{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700575 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000576 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700577 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400578
579 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700580 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
581 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400582 /* get flow control settings */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700583 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
584 &val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400585 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700586 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
587 switch (port) {
588 case 0:
589 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
590 break;
591 case 1:
592 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
593 break;
594 case 2:
595 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
596 break;
597 case 3:
598 default:
599 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
600 break;
601 }
602 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
603 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
604 return;
605 pause->rx_pause = 1;
606 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
607 if (port == 0)
608 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
609 else
610 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
611 } else {
Jeff Garzik47906542007-11-23 21:23:36 -0500612 printk(KERN_ERR"%s: Unknown board type: %x\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700613 netxen_nic_driver_name, adapter->ahw.board_type);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400614 }
615}
616
617static int
618netxen_nic_set_pauseparam(struct net_device *dev,
619 struct ethtool_pauseparam *pause)
620{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700621 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000622 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700623 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400624 /* read mode */
625 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700626 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
627 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400628 /* set flow control */
629 netxen_nic_read_w0(adapter,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700630 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
Jeff Garzik47906542007-11-23 21:23:36 -0500631
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400632 if (pause->rx_pause)
633 netxen_gb_rx_flowctl(val);
634 else
635 netxen_gb_unset_rx_flowctl(val);
636
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700637 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
638 val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400639 /* set autoneg */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700640 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
641 switch (port) {
642 case 0:
643 if (pause->tx_pause)
644 netxen_gb_unset_gb0_mask(val);
645 else
646 netxen_gb_set_gb0_mask(val);
647 break;
648 case 1:
649 if (pause->tx_pause)
650 netxen_gb_unset_gb1_mask(val);
651 else
652 netxen_gb_set_gb1_mask(val);
653 break;
654 case 2:
655 if (pause->tx_pause)
656 netxen_gb_unset_gb2_mask(val);
657 else
658 netxen_gb_set_gb2_mask(val);
659 break;
660 case 3:
661 default:
662 if (pause->tx_pause)
663 netxen_gb_unset_gb3_mask(val);
664 else
665 netxen_gb_set_gb3_mask(val);
666 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400667 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700668 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
669 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
670 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
671 return -EIO;
672 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
673 if (port == 0) {
674 if (pause->tx_pause)
675 netxen_xg_unset_xg0_mask(val);
676 else
677 netxen_xg_set_xg0_mask(val);
678 } else {
679 if (pause->tx_pause)
680 netxen_xg_unset_xg1_mask(val);
681 else
682 netxen_xg_set_xg1_mask(val);
683 }
Jeff Garzik47906542007-11-23 21:23:36 -0500684 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700685 } else {
686 printk(KERN_ERR "%s: Unknown board type: %x\n",
Jeff Garzik47906542007-11-23 21:23:36 -0500687 netxen_nic_driver_name,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700688 adapter->ahw.board_type);
689 }
690 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400691}
692
693static int netxen_nic_reg_test(struct net_device *dev)
694{
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800695 struct netxen_adapter *adapter = netdev_priv(dev);
696 u32 data_read, data_written;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400697
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800698 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
699 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400700 return 1;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800701
702 data_written = (u32)0xa5a5a5a5;
703
704 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700705 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800706 if (data_written != data_read)
707 return 1;
708
709 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400710}
711
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700712static int netxen_get_sset_count(struct net_device *dev, int sset)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400713{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700714 switch (sset) {
715 case ETH_SS_TEST:
716 return NETXEN_NIC_TEST_LEN;
717 case ETH_SS_STATS:
718 return NETXEN_NIC_STATS_LEN;
719 default:
720 return -EOPNOTSUPP;
721 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400722}
723
724static void
725netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
726 u64 * data)
727{
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700728 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
729 if ((data[0] = netxen_nic_reg_test(dev)))
730 eth_test->flags |= ETH_TEST_FL_FAILED;
731 /* link test */
732 if ((data[1] = (u64) netxen_nic_test_link(dev)))
733 eth_test->flags |= ETH_TEST_FL_FAILED;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400734}
735
736static void
737netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
738{
739 int index;
740
741 switch (stringset) {
742 case ETH_SS_TEST:
743 memcpy(data, *netxen_nic_gstrings_test,
744 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
745 break;
746 case ETH_SS_STATS:
747 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
748 memcpy(data + index * ETH_GSTRING_LEN,
749 netxen_nic_gstrings_stats[index].stat_string,
750 ETH_GSTRING_LEN);
751 }
752 break;
753 }
754}
755
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400756static void
757netxen_nic_get_ethtool_stats(struct net_device *dev,
758 struct ethtool_stats *stats, u64 * data)
759{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700760 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400761 int index;
762
763 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
764 char *p =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700765 (char *)adapter +
766 netxen_nic_gstrings_stats[index].stat_offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400767 data[index] =
768 (netxen_nic_gstrings_stats[index].sizeof_stat ==
769 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
770 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400771}
772
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530773static u32 netxen_nic_get_rx_csum(struct net_device *dev)
774{
775 struct netxen_adapter *adapter = netdev_priv(dev);
776 return adapter->rx_csum;
777}
778
779static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
780{
781 struct netxen_adapter *adapter = netdev_priv(dev);
782 adapter->rx_csum = !!data;
783 return 0;
784}
785
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700786static u32 netxen_nic_get_tso(struct net_device *dev)
787{
788 struct netxen_adapter *adapter = netdev_priv(dev);
789
790 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
791 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
792
793 return (dev->features & NETIF_F_TSO) != 0;
794}
795
796static int netxen_nic_set_tso(struct net_device *dev, u32 data)
797{
798 if (data) {
799 struct netxen_adapter *adapter = netdev_priv(dev);
800
801 dev->features |= NETIF_F_TSO;
802 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
803 dev->features |= NETIF_F_TSO6;
804 } else
805 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
806
807 return 0;
808}
809
810/*
811 * Set the coalescing parameters. Currently only normal is supported.
812 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
813 * firmware coalescing to default.
814 */
815static int netxen_set_intr_coalesce(struct net_device *netdev,
816 struct ethtool_coalesce *ethcoal)
817{
818 struct netxen_adapter *adapter = netdev_priv(netdev);
819
820 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
821 return -EINVAL;
822
823 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
824 return -EINVAL;
825
826 /*
827 * Return Error if unsupported values or
828 * unsupported parameters are set.
829 */
830 if (ethcoal->rx_coalesce_usecs > 0xffff ||
831 ethcoal->rx_max_coalesced_frames > 0xffff ||
832 ethcoal->tx_coalesce_usecs > 0xffff ||
833 ethcoal->tx_max_coalesced_frames > 0xffff ||
834 ethcoal->rx_coalesce_usecs_irq ||
835 ethcoal->rx_max_coalesced_frames_irq ||
836 ethcoal->tx_coalesce_usecs_irq ||
837 ethcoal->tx_max_coalesced_frames_irq ||
838 ethcoal->stats_block_coalesce_usecs ||
839 ethcoal->use_adaptive_rx_coalesce ||
840 ethcoal->use_adaptive_tx_coalesce ||
841 ethcoal->pkt_rate_low ||
842 ethcoal->rx_coalesce_usecs_low ||
843 ethcoal->rx_max_coalesced_frames_low ||
844 ethcoal->tx_coalesce_usecs_low ||
845 ethcoal->tx_max_coalesced_frames_low ||
846 ethcoal->pkt_rate_high ||
847 ethcoal->rx_coalesce_usecs_high ||
848 ethcoal->rx_max_coalesced_frames_high ||
849 ethcoal->tx_coalesce_usecs_high ||
850 ethcoal->tx_max_coalesced_frames_high)
851 return -EINVAL;
852
853 if (!ethcoal->rx_coalesce_usecs ||
854 !ethcoal->rx_max_coalesced_frames) {
855 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
856 adapter->coal.normal.data.rx_time_us =
857 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
858 adapter->coal.normal.data.rx_packets =
859 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
860 } else {
861 adapter->coal.flags = 0;
862 adapter->coal.normal.data.rx_time_us =
863 ethcoal->rx_coalesce_usecs;
864 adapter->coal.normal.data.rx_packets =
865 ethcoal->rx_max_coalesced_frames;
866 }
867 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
868 adapter->coal.normal.data.tx_packets =
869 ethcoal->tx_max_coalesced_frames;
870
871 netxen_config_intr_coalesce(adapter);
872
873 return 0;
874}
875
876static int netxen_get_intr_coalesce(struct net_device *netdev,
877 struct ethtool_coalesce *ethcoal)
878{
879 struct netxen_adapter *adapter = netdev_priv(netdev);
880
881 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
882 return -EINVAL;
883
884 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
885 return -EINVAL;
886
887 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
888 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
889 ethcoal->rx_max_coalesced_frames =
890 adapter->coal.normal.data.rx_packets;
891 ethcoal->tx_max_coalesced_frames =
892 adapter->coal.normal.data.tx_packets;
893
894 return 0;
895}
896
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400897struct ethtool_ops netxen_nic_ethtool_ops = {
898 .get_settings = netxen_nic_get_settings,
899 .set_settings = netxen_nic_set_settings,
900 .get_drvinfo = netxen_nic_get_drvinfo,
901 .get_regs_len = netxen_nic_get_regs_len,
902 .get_regs = netxen_nic_get_regs,
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800903 .get_link = ethtool_op_get_link,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400904 .get_eeprom_len = netxen_nic_get_eeprom_len,
905 .get_eeprom = netxen_nic_get_eeprom,
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700906#if 0
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800907 .set_eeprom = netxen_nic_set_eeprom,
Dhananjay Phadke7830b222008-07-21 19:44:00 -0700908#endif
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400909 .get_ringparam = netxen_nic_get_ringparam,
910 .get_pauseparam = netxen_nic_get_pauseparam,
911 .set_pauseparam = netxen_nic_set_pauseparam,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400912 .set_tx_csum = ethtool_op_set_tx_csum,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400913 .set_sg = ethtool_op_set_sg,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700914 .get_tso = netxen_nic_get_tso,
915 .set_tso = netxen_nic_set_tso,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400916 .self_test = netxen_nic_diag_test,
917 .get_strings = netxen_nic_get_strings,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400918 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700919 .get_sset_count = netxen_get_sset_count,
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530920 .get_rx_csum = netxen_nic_get_rx_csum,
921 .set_rx_csum = netxen_nic_set_rx_csum,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700922 .get_coalesce = netxen_get_intr_coalesce,
923 .set_coalesce = netxen_set_intr_coalesce,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400924};