blob: fe910c1715d66b29aaad320f9ffc443bcd379158 [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
Dhananjay Phadke5d242f12009-02-25 15:57:56 +00002 * Copyright (C) 2003 - 2009 NetXen, Inc.
Amit S. Kale3d396eb2006-10-21 15:33:03 -04003 * 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
Dhananjay Phadke5d242f12009-02-25 15:57:56 +000025 * NetXen Inc,
26 * 18922 Forge Drive
27 * Cupertino, CA 95014-0701
Amit S. Kale3d396eb2006-10-21 15:33:03 -040028 *
29 */
30
31#include <linux/types.h>
Amit S. Kale27d2ab52007-02-05 07:40:49 -080032#include <linux/delay.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040033#include <linux/pci.h>
34#include <asm/io.h>
35#include <linux/netdevice.h>
36#include <linux/ethtool.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040037
Amit S. Kale3d396eb2006-10-21 15:33:03 -040038#include "netxen_nic.h"
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070039#include "netxen_nic_hw.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040040#include "netxen_nic_phan_reg.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040041
42struct netxen_nic_stats {
43 char stat_string[ETH_GSTRING_LEN];
44 int sizeof_stat;
45 int stat_offset;
46};
47
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070048#define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
49 offsetof(struct netxen_adapter, m)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040050
Amit S. Kalecb8011a2006-11-29 09:00:10 -080051#define NETXEN_NIC_PORT_WINDOW 0x10000
52#define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
53
Amit S. Kale3d396eb2006-10-21 15:33:03 -040054static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
Amit S. Kale3d396eb2006-10-21 15:33:03 -040055 {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040056 {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
Dhananjay Phadkee98e3352009-04-07 22:50:38 +000057 {"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040058 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040059 {"csummed", NETXEN_NIC_STAT(stats.csummed)},
60 {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
61 {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
62 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
63};
64
Stephen Hemminger92104e92006-12-15 07:57:08 -080065#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040066
67static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -080068 "Register_Test_on_offline",
Amit S. Kale3d396eb2006-10-21 15:33:03 -040069 "Link_Test_on_offline"
70};
71
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +020072#define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040073
74#define NETXEN_NIC_REGS_COUNT 42
75#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
76#define NETXEN_MAX_EEPROM_LEN 1024
77
78static int netxen_nic_get_eeprom_len(struct net_device *dev)
79{
Mithlesh Thukral0d047612007-06-07 04:36:36 -070080 return NETXEN_FLASH_TOTAL_SIZE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040081}
82
83static void
84netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
85{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070086 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070087 unsigned long flags;
Amit S. Kalecb8011a2006-11-29 09:00:10 -080088 u32 fw_major = 0;
89 u32 fw_minor = 0;
90 u32 fw_build = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040091
Amit S. Kale80922fb2006-12-04 09:18:00 -080092 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040093 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070094 write_lock_irqsave(&adapter->adapter_lock, flags);
95 fw_major = adapter->pci_read_normalize(adapter,
96 NETXEN_FW_VERSION_MAJOR);
97 fw_minor = adapter->pci_read_normalize(adapter,
98 NETXEN_FW_VERSION_MINOR);
99 fw_build = adapter->pci_read_normalize(adapter,
100 NETXEN_FW_VERSION_SUB);
101 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400102 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
103
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700104 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400105 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
106 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
107}
108
109static int
110netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
111{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700112 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400113
114 /* read which mode */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000115 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400116 ecmd->supported = (SUPPORTED_10baseT_Half |
117 SUPPORTED_10baseT_Full |
118 SUPPORTED_100baseT_Half |
119 SUPPORTED_100baseT_Full |
120 SUPPORTED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800121 SUPPORTED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400122
123 ecmd->advertising = (ADVERTISED_100baseT_Half |
124 ADVERTISED_100baseT_Full |
125 ADVERTISED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800126 ADVERTISED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400127
128 ecmd->port = PORT_TP;
129
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800130 ecmd->speed = adapter->link_speed;
131 ecmd->duplex = adapter->link_duplex;
132 ecmd->autoneg = adapter->link_autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700133
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000134 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700135 u32 val;
136
137 adapter->hw_read_wx(adapter, NETXEN_PORT_MODE_ADDR, &val, 4);
138 if (val == NETXEN_PORT_MODE_802_3_AP) {
139 ecmd->supported = SUPPORTED_1000baseT_Full;
140 ecmd->advertising = ADVERTISED_1000baseT_Full;
141 } else {
142 ecmd->supported = SUPPORTED_10000baseT_Full;
143 ecmd->advertising = ADVERTISED_10000baseT_Full;
144 }
145
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400146 ecmd->port = PORT_TP;
147
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700148 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
149 u16 pcifn = adapter->ahw.pci_func;
150
151 adapter->hw_read_wx(adapter,
152 P3_LINK_SPEED_REG(pcifn), &val, 4);
153 ecmd->speed = P3_LINK_SPEED_MHZ *
154 P3_LINK_SPEED_VAL(pcifn, val);
155 } else
156 ecmd->speed = SPEED_10000;
157
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400158 ecmd->duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400159 ecmd->autoneg = AUTONEG_DISABLE;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800160 } else
161 return -EIO;
162
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800163 ecmd->phy_address = adapter->physical_port;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800164 ecmd->transceiver = XCVR_EXTERNAL;
165
Dhananjay Phadkee98e3352009-04-07 22:50:38 +0000166 switch (adapter->ahw.board_type) {
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800167 case NETXEN_BRDTYPE_P2_SB35_4G:
168 case NETXEN_BRDTYPE_P2_SB31_2G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700169 case NETXEN_BRDTYPE_P3_REF_QG:
170 case NETXEN_BRDTYPE_P3_4_GB:
171 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700172
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800173 ecmd->supported |= SUPPORTED_Autoneg;
174 ecmd->advertising |= ADVERTISED_Autoneg;
175 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700176 case NETXEN_BRDTYPE_P3_10G_CX4:
177 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800178 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800179 ecmd->supported |= SUPPORTED_TP;
180 ecmd->advertising |= ADVERTISED_TP;
181 ecmd->port = PORT_TP;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000182 ecmd->autoneg = (adapter->ahw.board_type ==
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800183 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700184 (AUTONEG_DISABLE) : (adapter->link_autoneg);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800185 break;
186 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
187 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700188 case NETXEN_BRDTYPE_P3_IMEZ:
189 case NETXEN_BRDTYPE_P3_XG_LOM:
190 case NETXEN_BRDTYPE_P3_HMEZ:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800191 ecmd->supported |= SUPPORTED_MII;
192 ecmd->advertising |= ADVERTISED_MII;
193 ecmd->port = PORT_FIBRE;
194 ecmd->autoneg = AUTONEG_DISABLE;
195 break;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700196 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700197 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
198 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800199 ecmd->advertising |= ADVERTISED_TP;
200 ecmd->supported |= SUPPORTED_TP;
201 case NETXEN_BRDTYPE_P2_SB31_10G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700202 case NETXEN_BRDTYPE_P3_10G_XFP:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800203 ecmd->supported |= SUPPORTED_FIBRE;
204 ecmd->advertising |= ADVERTISED_FIBRE;
205 ecmd->port = PORT_FIBRE;
206 ecmd->autoneg = AUTONEG_DISABLE;
207 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800208 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000209 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800210 ecmd->autoneg = AUTONEG_DISABLE;
211 ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
212 ecmd->advertising |=
213 (ADVERTISED_FIBRE | ADVERTISED_TP);
214 ecmd->port = PORT_FIBRE;
215 } else {
216 ecmd->autoneg = AUTONEG_ENABLE;
217 ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg);
218 ecmd->advertising |=
219 (ADVERTISED_TP | ADVERTISED_Autoneg);
220 ecmd->port = PORT_TP;
221 }
222 break;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800223 default:
Amit S. Kale71bd7872006-12-01 05:36:22 -0800224 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
Dhananjay Phadkee98e3352009-04-07 22:50:38 +0000225 adapter->ahw.board_type);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800226 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400227 }
228
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800229 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400230}
231
232static int
233netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
234{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700235 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000236 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400237
238 /* read which mode */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000239 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400240 /* autonegotiation */
Amit S. Kale80922fb2006-12-04 09:18:00 -0800241 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700242 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800243 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab9c2007-01-02 10:39:10 +0000244 ecmd->autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400245 return -EIO;
246 else
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700247 adapter->link_autoneg = ecmd->autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400248
Amit S. Kale80922fb2006-12-04 09:18:00 -0800249 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700250 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800251 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
252 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400253 return -EIO;
254
255 /* speed */
256 switch (ecmd->speed) {
257 case SPEED_10:
258 netxen_set_phy_speed(status, 0);
259 break;
260 case SPEED_100:
261 netxen_set_phy_speed(status, 1);
262 break;
263 case SPEED_1000:
264 netxen_set_phy_speed(status, 2);
265 break;
266 }
267 /* set duplex mode */
268 if (ecmd->duplex == DUPLEX_HALF)
269 netxen_clear_phy_duplex(status);
270 if (ecmd->duplex == DUPLEX_FULL)
271 netxen_set_phy_duplex(status);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800272 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700273 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800274 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
275 *((int *)&status)) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400276 return -EIO;
277 else {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700278 adapter->link_speed = ecmd->speed;
279 adapter->link_duplex = ecmd->duplex;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400280 }
281 } else
282 return -EOPNOTSUPP;
283
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800284 if (!netif_running(dev))
285 return 0;
286
287 dev->netdev_ops->ndo_stop(dev);
288 return dev->netdev_ops->ndo_open(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400289}
290
291static int netxen_nic_get_regs_len(struct net_device *dev)
292{
293 return NETXEN_NIC_REGS_LEN;
294}
295
296struct netxen_niu_regs {
Al Viroa608ab9c2007-01-02 10:39:10 +0000297 __u32 reg[NETXEN_NIC_REGS_COUNT];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400298};
299
300static struct netxen_niu_regs niu_registers[] = {
301 {
302 /* GB Mode */
303 {
304 NETXEN_NIU_GB_SERDES_RESET,
305 NETXEN_NIU_GB0_MII_MODE,
306 NETXEN_NIU_GB1_MII_MODE,
307 NETXEN_NIU_GB2_MII_MODE,
308 NETXEN_NIU_GB3_MII_MODE,
309 NETXEN_NIU_GB0_GMII_MODE,
310 NETXEN_NIU_GB1_GMII_MODE,
311 NETXEN_NIU_GB2_GMII_MODE,
312 NETXEN_NIU_GB3_GMII_MODE,
313 NETXEN_NIU_REMOTE_LOOPBACK,
314 NETXEN_NIU_GB0_HALF_DUPLEX,
315 NETXEN_NIU_GB1_HALF_DUPLEX,
316 NETXEN_NIU_RESET_SYS_FIFOS,
317 NETXEN_NIU_GB_CRC_DROP,
318 NETXEN_NIU_GB_DROP_WRONGADDR,
319 NETXEN_NIU_TEST_MUX_CTL,
320
321 NETXEN_NIU_GB_MAC_CONFIG_0(0),
322 NETXEN_NIU_GB_MAC_CONFIG_1(0),
323 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
324 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
325 NETXEN_NIU_GB_TEST_REG(0),
326 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
327 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
328 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
329 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
330 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
331 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
332 NETXEN_NIU_GB_INTERFACE_CTRL(0),
333 NETXEN_NIU_GB_INTERFACE_STATUS(0),
334 NETXEN_NIU_GB_STATION_ADDR_0(0),
335 NETXEN_NIU_GB_STATION_ADDR_1(0),
336 -1,
337 }
338 },
339 {
340 /* XG Mode */
341 {
342 NETXEN_NIU_XG_SINGLE_TERM,
343 NETXEN_NIU_XG_DRIVE_HI,
344 NETXEN_NIU_XG_DRIVE_LO,
345 NETXEN_NIU_XG_DTX,
346 NETXEN_NIU_XG_DEQ,
347 NETXEN_NIU_XG_WORD_ALIGN,
348 NETXEN_NIU_XG_RESET,
349 NETXEN_NIU_XG_POWER_DOWN,
350 NETXEN_NIU_XG_RESET_PLL,
351 NETXEN_NIU_XG_SERDES_LOOPBACK,
352 NETXEN_NIU_XG_DO_BYTE_ALIGN,
353 NETXEN_NIU_XG_TX_ENABLE,
354 NETXEN_NIU_XG_RX_ENABLE,
355 NETXEN_NIU_XG_STATUS,
356 NETXEN_NIU_XG_PAUSE_THRESHOLD,
357 NETXEN_NIU_XGE_CONFIG_0,
358 NETXEN_NIU_XGE_CONFIG_1,
359 NETXEN_NIU_XGE_IPG,
360 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
361 NETXEN_NIU_XGE_STATION_ADDR_0_1,
362 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
363 NETXEN_NIU_XGE_STATUS,
364 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
365 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
366 NETXEN_NIU_XGE_TX_BYTE_CNT,
367 NETXEN_NIU_XGE_TX_FRAME_CNT,
368 NETXEN_NIU_XGE_RX_BYTE_CNT,
369 NETXEN_NIU_XGE_RX_FRAME_CNT,
370 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
371 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
372 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
373 NETXEN_NIU_XGE_CRC_ERROR_CNT,
374 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
375 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
376 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
377 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
378 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
379 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
380 -1,
381 }
382 }
383};
384
385static void
386netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
387{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700388 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000389 __u32 mode, *regs_buff = p;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400390 int i, window;
391
392 memset(p, 0, NETXEN_NIC_REGS_LEN);
393 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700394 (adapter->pdev)->device;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400395 /* which mode */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700396 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, &regs_buff[0], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400397 mode = regs_buff[0];
398
399 /* Common registers to all the modes */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700400 adapter->hw_read_wx(adapter,
401 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, &regs_buff[2], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400402 /* GB/XGB Mode */
403 mode = (mode / 2) - 1;
404 window = 0;
405 if (mode <= 1) {
406 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
407 /* GB: port specific registers */
408 if (mode == 0 && i >= 19)
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700409 window = adapter->physical_port *
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700410 NETXEN_NIC_PORT_WINDOW;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400411
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700412 adapter->hw_read_wx(adapter,
413 niu_registers[mode].reg[i - 3] + window,
414 &regs_buff[i], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400415 }
416
417 }
418}
419
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800420static u32 netxen_nic_test_link(struct net_device *dev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400421{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700422 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000423 __u32 status;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800424 int val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400425
426 /* read which mode */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000427 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Amit S. Kale80922fb2006-12-04 09:18:00 -0800428 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700429 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800430 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
431 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400432 return -EIO;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800433 else {
434 val = netxen_get_phy_link(status);
435 return !val;
436 }
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000437 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700438 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800439 return (val == XG_LINK_UP) ? 0 : 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400440 }
441 return -EIO;
442}
443
444static int
445netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
446 u8 * bytes)
447{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700448 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400449 int offset;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800450 int ret;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400451
452 if (eeprom->len == 0)
453 return -EINVAL;
454
Jeff Garzik47906542007-11-23 21:23:36 -0500455 eeprom->magic = (adapter->pdev)->vendor |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700456 ((adapter->pdev)->device << 16);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800457 offset = eeprom->offset;
458
Jeff Garzik47906542007-11-23 21:23:36 -0500459 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800460 eeprom->len);
461 if (ret < 0)
462 return ret;
463
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400464 return 0;
465}
466
467static void
468netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
469{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700470 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400471
472 ring->rx_pending = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800473 ring->rx_jumbo_pending = 0;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000474 ring->rx_pending += adapter->recv_ctx.
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000475 rds_rings[RCV_RING_NORMAL].num_desc;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000476 ring->rx_jumbo_pending += adapter->recv_ctx.
Dhananjay Phadke438627c2009-03-13 14:52:03 +0000477 rds_rings[RCV_RING_JUMBO].num_desc;
478 ring->tx_pending = adapter->num_txd;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400479
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000480 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke32ec8032009-01-26 12:35:19 -0800481 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
482 else
483 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530484 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
485 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400486 ring->rx_mini_max_pending = 0;
487 ring->rx_mini_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400488}
489
490static void
491netxen_nic_get_pauseparam(struct net_device *dev,
492 struct ethtool_pauseparam *pause)
493{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700494 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000495 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700496 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400497
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000498 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700499 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
500 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400501 /* get flow control settings */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700502 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
503 &val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400504 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700505 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
506 switch (port) {
507 case 0:
508 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
509 break;
510 case 1:
511 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
512 break;
513 case 2:
514 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
515 break;
516 case 3:
517 default:
518 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
519 break;
520 }
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000521 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700522 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
523 return;
524 pause->rx_pause = 1;
525 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
526 if (port == 0)
527 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
528 else
529 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
530 } else {
Jeff Garzik47906542007-11-23 21:23:36 -0500531 printk(KERN_ERR"%s: Unknown board type: %x\n",
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000532 netxen_nic_driver_name, adapter->ahw.port_type);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400533 }
534}
535
536static int
537netxen_nic_set_pauseparam(struct net_device *dev,
538 struct ethtool_pauseparam *pause)
539{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700540 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000541 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700542 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400543 /* read mode */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000544 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700545 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
546 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400547 /* set flow control */
548 netxen_nic_read_w0(adapter,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700549 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
Jeff Garzik47906542007-11-23 21:23:36 -0500550
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400551 if (pause->rx_pause)
552 netxen_gb_rx_flowctl(val);
553 else
554 netxen_gb_unset_rx_flowctl(val);
555
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700556 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
557 val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400558 /* set autoneg */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700559 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
560 switch (port) {
561 case 0:
562 if (pause->tx_pause)
563 netxen_gb_unset_gb0_mask(val);
564 else
565 netxen_gb_set_gb0_mask(val);
566 break;
567 case 1:
568 if (pause->tx_pause)
569 netxen_gb_unset_gb1_mask(val);
570 else
571 netxen_gb_set_gb1_mask(val);
572 break;
573 case 2:
574 if (pause->tx_pause)
575 netxen_gb_unset_gb2_mask(val);
576 else
577 netxen_gb_set_gb2_mask(val);
578 break;
579 case 3:
580 default:
581 if (pause->tx_pause)
582 netxen_gb_unset_gb3_mask(val);
583 else
584 netxen_gb_set_gb3_mask(val);
585 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400586 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700587 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000588 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700589 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
590 return -EIO;
591 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
592 if (port == 0) {
593 if (pause->tx_pause)
594 netxen_xg_unset_xg0_mask(val);
595 else
596 netxen_xg_set_xg0_mask(val);
597 } else {
598 if (pause->tx_pause)
599 netxen_xg_unset_xg1_mask(val);
600 else
601 netxen_xg_set_xg1_mask(val);
602 }
Jeff Garzik47906542007-11-23 21:23:36 -0500603 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700604 } else {
605 printk(KERN_ERR "%s: Unknown board type: %x\n",
Jeff Garzik47906542007-11-23 21:23:36 -0500606 netxen_nic_driver_name,
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000607 adapter->ahw.port_type);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700608 }
609 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400610}
611
612static int netxen_nic_reg_test(struct net_device *dev)
613{
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800614 struct netxen_adapter *adapter = netdev_priv(dev);
615 u32 data_read, data_written;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400616
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800617 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
618 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400619 return 1;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800620
621 data_written = (u32)0xa5a5a5a5;
622
623 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700624 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800625 if (data_written != data_read)
626 return 1;
627
628 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400629}
630
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700631static int netxen_get_sset_count(struct net_device *dev, int sset)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400632{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700633 switch (sset) {
634 case ETH_SS_TEST:
635 return NETXEN_NIC_TEST_LEN;
636 case ETH_SS_STATS:
637 return NETXEN_NIC_STATS_LEN;
638 default:
639 return -EOPNOTSUPP;
640 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400641}
642
643static void
644netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
645 u64 * data)
646{
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700647 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
648 if ((data[0] = netxen_nic_reg_test(dev)))
649 eth_test->flags |= ETH_TEST_FL_FAILED;
650 /* link test */
651 if ((data[1] = (u64) netxen_nic_test_link(dev)))
652 eth_test->flags |= ETH_TEST_FL_FAILED;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400653}
654
655static void
656netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
657{
658 int index;
659
660 switch (stringset) {
661 case ETH_SS_TEST:
662 memcpy(data, *netxen_nic_gstrings_test,
663 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
664 break;
665 case ETH_SS_STATS:
666 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
667 memcpy(data + index * ETH_GSTRING_LEN,
668 netxen_nic_gstrings_stats[index].stat_string,
669 ETH_GSTRING_LEN);
670 }
671 break;
672 }
673}
674
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400675static void
676netxen_nic_get_ethtool_stats(struct net_device *dev,
677 struct ethtool_stats *stats, u64 * data)
678{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700679 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400680 int index;
681
682 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
683 char *p =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700684 (char *)adapter +
685 netxen_nic_gstrings_stats[index].stat_offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400686 data[index] =
687 (netxen_nic_gstrings_stats[index].sizeof_stat ==
688 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
689 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400690}
691
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530692static u32 netxen_nic_get_rx_csum(struct net_device *dev)
693{
694 struct netxen_adapter *adapter = netdev_priv(dev);
695 return adapter->rx_csum;
696}
697
698static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
699{
700 struct netxen_adapter *adapter = netdev_priv(dev);
701 adapter->rx_csum = !!data;
702 return 0;
703}
704
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700705static u32 netxen_nic_get_tso(struct net_device *dev)
706{
707 struct netxen_adapter *adapter = netdev_priv(dev);
708
709 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
710 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
711
712 return (dev->features & NETIF_F_TSO) != 0;
713}
714
715static int netxen_nic_set_tso(struct net_device *dev, u32 data)
716{
717 if (data) {
718 struct netxen_adapter *adapter = netdev_priv(dev);
719
720 dev->features |= NETIF_F_TSO;
721 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
722 dev->features |= NETIF_F_TSO6;
723 } else
724 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
725
726 return 0;
727}
728
Dhananjay Phadke4da12942009-02-24 16:38:44 -0800729static void
730netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
731{
732 struct netxen_adapter *adapter = netdev_priv(dev);
733 u32 wol_cfg = 0;
734
735 wol->supported = 0;
736 wol->wolopts = 0;
737
738 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
739 return;
740
741 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG_NV);
742 if (wol_cfg & (1UL << adapter->portnum))
743 wol->supported |= WAKE_MAGIC;
744
745 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG);
746 if (wol_cfg & (1UL << adapter->portnum))
747 wol->wolopts |= WAKE_MAGIC;
748}
749
750static int
751netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
752{
753 struct netxen_adapter *adapter = netdev_priv(dev);
754 u32 wol_cfg = 0;
755
756 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
757 return -EOPNOTSUPP;
758
759 if (wol->wolopts & ~WAKE_MAGIC)
760 return -EOPNOTSUPP;
761
762 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG_NV);
763 if (!(wol_cfg & (1 << adapter->portnum)))
764 return -EOPNOTSUPP;
765
766 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG);
767 if (wol->wolopts & WAKE_MAGIC)
768 wol_cfg |= 1UL << adapter->portnum;
769 else
770 wol_cfg &= ~(1UL << adapter->portnum);
771 netxen_nic_reg_write(adapter, NETXEN_WOL_CONFIG, wol_cfg);
772
773 return 0;
774}
775
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700776/*
777 * Set the coalescing parameters. Currently only normal is supported.
778 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
779 * firmware coalescing to default.
780 */
781static int netxen_set_intr_coalesce(struct net_device *netdev,
782 struct ethtool_coalesce *ethcoal)
783{
784 struct netxen_adapter *adapter = netdev_priv(netdev);
785
786 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
787 return -EINVAL;
788
789 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
790 return -EINVAL;
791
792 /*
793 * Return Error if unsupported values or
794 * unsupported parameters are set.
795 */
796 if (ethcoal->rx_coalesce_usecs > 0xffff ||
797 ethcoal->rx_max_coalesced_frames > 0xffff ||
798 ethcoal->tx_coalesce_usecs > 0xffff ||
799 ethcoal->tx_max_coalesced_frames > 0xffff ||
800 ethcoal->rx_coalesce_usecs_irq ||
801 ethcoal->rx_max_coalesced_frames_irq ||
802 ethcoal->tx_coalesce_usecs_irq ||
803 ethcoal->tx_max_coalesced_frames_irq ||
804 ethcoal->stats_block_coalesce_usecs ||
805 ethcoal->use_adaptive_rx_coalesce ||
806 ethcoal->use_adaptive_tx_coalesce ||
807 ethcoal->pkt_rate_low ||
808 ethcoal->rx_coalesce_usecs_low ||
809 ethcoal->rx_max_coalesced_frames_low ||
810 ethcoal->tx_coalesce_usecs_low ||
811 ethcoal->tx_max_coalesced_frames_low ||
812 ethcoal->pkt_rate_high ||
813 ethcoal->rx_coalesce_usecs_high ||
814 ethcoal->rx_max_coalesced_frames_high ||
815 ethcoal->tx_coalesce_usecs_high ||
816 ethcoal->tx_max_coalesced_frames_high)
817 return -EINVAL;
818
819 if (!ethcoal->rx_coalesce_usecs ||
820 !ethcoal->rx_max_coalesced_frames) {
821 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
822 adapter->coal.normal.data.rx_time_us =
823 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
824 adapter->coal.normal.data.rx_packets =
825 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
826 } else {
827 adapter->coal.flags = 0;
828 adapter->coal.normal.data.rx_time_us =
829 ethcoal->rx_coalesce_usecs;
830 adapter->coal.normal.data.rx_packets =
831 ethcoal->rx_max_coalesced_frames;
832 }
833 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
834 adapter->coal.normal.data.tx_packets =
835 ethcoal->tx_max_coalesced_frames;
836
837 netxen_config_intr_coalesce(adapter);
838
839 return 0;
840}
841
842static int netxen_get_intr_coalesce(struct net_device *netdev,
843 struct ethtool_coalesce *ethcoal)
844{
845 struct netxen_adapter *adapter = netdev_priv(netdev);
846
847 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
848 return -EINVAL;
849
850 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
851 return -EINVAL;
852
853 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
854 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
855 ethcoal->rx_max_coalesced_frames =
856 adapter->coal.normal.data.rx_packets;
857 ethcoal->tx_max_coalesced_frames =
858 adapter->coal.normal.data.tx_packets;
859
860 return 0;
861}
862
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400863struct ethtool_ops netxen_nic_ethtool_ops = {
864 .get_settings = netxen_nic_get_settings,
865 .set_settings = netxen_nic_set_settings,
866 .get_drvinfo = netxen_nic_get_drvinfo,
867 .get_regs_len = netxen_nic_get_regs_len,
868 .get_regs = netxen_nic_get_regs,
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800869 .get_link = ethtool_op_get_link,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400870 .get_eeprom_len = netxen_nic_get_eeprom_len,
871 .get_eeprom = netxen_nic_get_eeprom,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400872 .get_ringparam = netxen_nic_get_ringparam,
873 .get_pauseparam = netxen_nic_get_pauseparam,
874 .set_pauseparam = netxen_nic_set_pauseparam,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400875 .set_tx_csum = ethtool_op_set_tx_csum,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400876 .set_sg = ethtool_op_set_sg,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700877 .get_tso = netxen_nic_get_tso,
878 .set_tso = netxen_nic_set_tso,
Dhananjay Phadke4da12942009-02-24 16:38:44 -0800879 .get_wol = netxen_nic_get_wol,
880 .set_wol = netxen_nic_set_wol,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400881 .self_test = netxen_nic_diag_test,
882 .get_strings = netxen_nic_get_strings,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400883 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700884 .get_sset_count = netxen_get_sset_count,
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530885 .get_rx_csum = netxen_nic_get_rx_csum,
886 .set_rx_csum = netxen_nic_set_rx_csum,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700887 .get_coalesce = netxen_get_intr_coalesce,
888 .set_coalesce = netxen_set_intr_coalesce,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400889};