blob: 8b4bdfd6a11786cc7b619b12a4b5bbe5e0ef1150 [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 <asm/uaccess.h>
34#include <linux/pci.h>
35#include <asm/io.h>
36#include <linux/netdevice.h>
37#include <linux/ethtool.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040038
Amit S. Kale3d396eb2006-10-21 15:33:03 -040039#include "netxen_nic.h"
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070040#include "netxen_nic_hw.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040041#include "netxen_nic_phan_reg.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040042
43struct netxen_nic_stats {
44 char stat_string[ETH_GSTRING_LEN];
45 int sizeof_stat;
46 int stat_offset;
47};
48
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070049#define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
50 offsetof(struct netxen_adapter, m)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040051
Amit S. Kalecb8011a2006-11-29 09:00:10 -080052#define NETXEN_NIC_PORT_WINDOW 0x10000
53#define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
54
Amit S. Kale3d396eb2006-10-21 15:33:03 -040055static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
56 {"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)},
57 {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
58 {"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)},
59 {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
60 {"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)},
61 {"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)},
62 {"polled", NETXEN_NIC_STAT(stats.polled)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040063 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040064 {"csummed", NETXEN_NIC_STAT(stats.csummed)},
65 {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
66 {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
67 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
68};
69
Stephen Hemminger92104e92006-12-15 07:57:08 -080070#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040071
72static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -080073 "Register_Test_on_offline",
Amit S. Kale3d396eb2006-10-21 15:33:03 -040074 "Link_Test_on_offline"
75};
76
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +020077#define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040078
79#define NETXEN_NIC_REGS_COUNT 42
80#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
81#define NETXEN_MAX_EEPROM_LEN 1024
82
83static int netxen_nic_get_eeprom_len(struct net_device *dev)
84{
Mithlesh Thukral0d047612007-06-07 04:36:36 -070085 return NETXEN_FLASH_TOTAL_SIZE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040086}
87
88static void
89netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
90{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070091 struct netxen_adapter *adapter = netdev_priv(dev);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070092 unsigned long flags;
Amit S. Kalecb8011a2006-11-29 09:00:10 -080093 u32 fw_major = 0;
94 u32 fw_minor = 0;
95 u32 fw_build = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040096
Amit S. Kale80922fb2006-12-04 09:18:00 -080097 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -040098 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -070099 write_lock_irqsave(&adapter->adapter_lock, flags);
100 fw_major = adapter->pci_read_normalize(adapter,
101 NETXEN_FW_VERSION_MAJOR);
102 fw_minor = adapter->pci_read_normalize(adapter,
103 NETXEN_FW_VERSION_MINOR);
104 fw_build = adapter->pci_read_normalize(adapter,
105 NETXEN_FW_VERSION_SUB);
106 write_unlock_irqrestore(&adapter->adapter_lock, flags);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400107 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
108
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700109 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400110 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
111 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
112}
113
114static int
115netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
116{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700117 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400118
119 /* read which mode */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000120 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400121 ecmd->supported = (SUPPORTED_10baseT_Half |
122 SUPPORTED_10baseT_Full |
123 SUPPORTED_100baseT_Half |
124 SUPPORTED_100baseT_Full |
125 SUPPORTED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800126 SUPPORTED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400127
128 ecmd->advertising = (ADVERTISED_100baseT_Half |
129 ADVERTISED_100baseT_Full |
130 ADVERTISED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800131 ADVERTISED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400132
133 ecmd->port = PORT_TP;
134
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800135 ecmd->speed = adapter->link_speed;
136 ecmd->duplex = adapter->link_duplex;
137 ecmd->autoneg = adapter->link_autoneg;
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700138
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000139 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700140 u32 val;
141
142 adapter->hw_read_wx(adapter, NETXEN_PORT_MODE_ADDR, &val, 4);
143 if (val == NETXEN_PORT_MODE_802_3_AP) {
144 ecmd->supported = SUPPORTED_1000baseT_Full;
145 ecmd->advertising = ADVERTISED_1000baseT_Full;
146 } else {
147 ecmd->supported = SUPPORTED_10000baseT_Full;
148 ecmd->advertising = ADVERTISED_10000baseT_Full;
149 }
150
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400151 ecmd->port = PORT_TP;
152
Dhananjay Phadke24a7a452008-08-01 03:14:55 -0700153 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
154 u16 pcifn = adapter->ahw.pci_func;
155
156 adapter->hw_read_wx(adapter,
157 P3_LINK_SPEED_REG(pcifn), &val, 4);
158 ecmd->speed = P3_LINK_SPEED_MHZ *
159 P3_LINK_SPEED_VAL(pcifn, val);
160 } else
161 ecmd->speed = SPEED_10000;
162
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400163 ecmd->duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400164 ecmd->autoneg = AUTONEG_DISABLE;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800165 } else
166 return -EIO;
167
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800168 ecmd->phy_address = adapter->physical_port;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800169 ecmd->transceiver = XCVR_EXTERNAL;
170
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000171 switch ((netxen_brdtype_t)adapter->ahw.board_type) {
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800172 case NETXEN_BRDTYPE_P2_SB35_4G:
173 case NETXEN_BRDTYPE_P2_SB31_2G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700174 case NETXEN_BRDTYPE_P3_REF_QG:
175 case NETXEN_BRDTYPE_P3_4_GB:
176 case NETXEN_BRDTYPE_P3_4_GB_MM:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700177
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800178 ecmd->supported |= SUPPORTED_Autoneg;
179 ecmd->advertising |= ADVERTISED_Autoneg;
180 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700181 case NETXEN_BRDTYPE_P3_10G_CX4:
182 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800183 case NETXEN_BRDTYPE_P3_10000_BASE_T:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800184 ecmd->supported |= SUPPORTED_TP;
185 ecmd->advertising |= ADVERTISED_TP;
186 ecmd->port = PORT_TP;
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000187 ecmd->autoneg = (adapter->ahw.board_type ==
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800188 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700189 (AUTONEG_DISABLE) : (adapter->link_autoneg);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800190 break;
191 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
192 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700193 case NETXEN_BRDTYPE_P3_IMEZ:
194 case NETXEN_BRDTYPE_P3_XG_LOM:
195 case NETXEN_BRDTYPE_P3_HMEZ:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800196 ecmd->supported |= SUPPORTED_MII;
197 ecmd->advertising |= ADVERTISED_MII;
198 ecmd->port = PORT_FIBRE;
199 ecmd->autoneg = AUTONEG_DISABLE;
200 break;
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700201 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
Dhananjay Phadkea70f9392008-08-01 03:14:56 -0700202 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
203 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800204 ecmd->advertising |= ADVERTISED_TP;
205 ecmd->supported |= SUPPORTED_TP;
206 case NETXEN_BRDTYPE_P2_SB31_10G:
Dhananjay Phadkee4c93c82008-07-21 19:44:02 -0700207 case NETXEN_BRDTYPE_P3_10G_XFP:
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800208 ecmd->supported |= SUPPORTED_FIBRE;
209 ecmd->advertising |= ADVERTISED_FIBRE;
210 ecmd->port = PORT_FIBRE;
211 ecmd->autoneg = AUTONEG_DISABLE;
212 break;
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800213 case NETXEN_BRDTYPE_P3_10G_TP:
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000214 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Dhananjay Phadkec7860a22009-01-14 20:48:32 -0800215 ecmd->autoneg = AUTONEG_DISABLE;
216 ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
217 ecmd->advertising |=
218 (ADVERTISED_FIBRE | ADVERTISED_TP);
219 ecmd->port = PORT_FIBRE;
220 } else {
221 ecmd->autoneg = AUTONEG_ENABLE;
222 ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg);
223 ecmd->advertising |=
224 (ADVERTISED_TP | ADVERTISED_Autoneg);
225 ecmd->port = PORT_TP;
226 }
227 break;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800228 default:
Amit S. Kale71bd7872006-12-01 05:36:22 -0800229 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000230 (netxen_brdtype_t)adapter->ahw.board_type);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800231 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400232 }
233
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800234 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400235}
236
237static int
238netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
239{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700240 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000241 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400242
243 /* read which mode */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000244 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400245 /* autonegotiation */
Amit S. Kale80922fb2006-12-04 09:18:00 -0800246 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700247 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800248 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab9c2007-01-02 10:39:10 +0000249 ecmd->autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400250 return -EIO;
251 else
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700252 adapter->link_autoneg = ecmd->autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400253
Amit S. Kale80922fb2006-12-04 09:18:00 -0800254 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700255 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800256 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
257 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400258 return -EIO;
259
260 /* speed */
261 switch (ecmd->speed) {
262 case SPEED_10:
263 netxen_set_phy_speed(status, 0);
264 break;
265 case SPEED_100:
266 netxen_set_phy_speed(status, 1);
267 break;
268 case SPEED_1000:
269 netxen_set_phy_speed(status, 2);
270 break;
271 }
272 /* set duplex mode */
273 if (ecmd->duplex == DUPLEX_HALF)
274 netxen_clear_phy_duplex(status);
275 if (ecmd->duplex == DUPLEX_FULL)
276 netxen_set_phy_duplex(status);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800277 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700278 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800279 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
280 *((int *)&status)) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400281 return -EIO;
282 else {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700283 adapter->link_speed = ecmd->speed;
284 adapter->link_duplex = ecmd->duplex;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400285 }
286 } else
287 return -EOPNOTSUPP;
288
Stephen Hemminger1abd2662008-11-21 17:32:15 -0800289 if (!netif_running(dev))
290 return 0;
291
292 dev->netdev_ops->ndo_stop(dev);
293 return dev->netdev_ops->ndo_open(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400294}
295
296static int netxen_nic_get_regs_len(struct net_device *dev)
297{
298 return NETXEN_NIC_REGS_LEN;
299}
300
301struct netxen_niu_regs {
Al Viroa608ab9c2007-01-02 10:39:10 +0000302 __u32 reg[NETXEN_NIC_REGS_COUNT];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400303};
304
305static struct netxen_niu_regs niu_registers[] = {
306 {
307 /* GB Mode */
308 {
309 NETXEN_NIU_GB_SERDES_RESET,
310 NETXEN_NIU_GB0_MII_MODE,
311 NETXEN_NIU_GB1_MII_MODE,
312 NETXEN_NIU_GB2_MII_MODE,
313 NETXEN_NIU_GB3_MII_MODE,
314 NETXEN_NIU_GB0_GMII_MODE,
315 NETXEN_NIU_GB1_GMII_MODE,
316 NETXEN_NIU_GB2_GMII_MODE,
317 NETXEN_NIU_GB3_GMII_MODE,
318 NETXEN_NIU_REMOTE_LOOPBACK,
319 NETXEN_NIU_GB0_HALF_DUPLEX,
320 NETXEN_NIU_GB1_HALF_DUPLEX,
321 NETXEN_NIU_RESET_SYS_FIFOS,
322 NETXEN_NIU_GB_CRC_DROP,
323 NETXEN_NIU_GB_DROP_WRONGADDR,
324 NETXEN_NIU_TEST_MUX_CTL,
325
326 NETXEN_NIU_GB_MAC_CONFIG_0(0),
327 NETXEN_NIU_GB_MAC_CONFIG_1(0),
328 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
329 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
330 NETXEN_NIU_GB_TEST_REG(0),
331 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
332 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
333 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
334 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
335 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
336 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
337 NETXEN_NIU_GB_INTERFACE_CTRL(0),
338 NETXEN_NIU_GB_INTERFACE_STATUS(0),
339 NETXEN_NIU_GB_STATION_ADDR_0(0),
340 NETXEN_NIU_GB_STATION_ADDR_1(0),
341 -1,
342 }
343 },
344 {
345 /* XG Mode */
346 {
347 NETXEN_NIU_XG_SINGLE_TERM,
348 NETXEN_NIU_XG_DRIVE_HI,
349 NETXEN_NIU_XG_DRIVE_LO,
350 NETXEN_NIU_XG_DTX,
351 NETXEN_NIU_XG_DEQ,
352 NETXEN_NIU_XG_WORD_ALIGN,
353 NETXEN_NIU_XG_RESET,
354 NETXEN_NIU_XG_POWER_DOWN,
355 NETXEN_NIU_XG_RESET_PLL,
356 NETXEN_NIU_XG_SERDES_LOOPBACK,
357 NETXEN_NIU_XG_DO_BYTE_ALIGN,
358 NETXEN_NIU_XG_TX_ENABLE,
359 NETXEN_NIU_XG_RX_ENABLE,
360 NETXEN_NIU_XG_STATUS,
361 NETXEN_NIU_XG_PAUSE_THRESHOLD,
362 NETXEN_NIU_XGE_CONFIG_0,
363 NETXEN_NIU_XGE_CONFIG_1,
364 NETXEN_NIU_XGE_IPG,
365 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
366 NETXEN_NIU_XGE_STATION_ADDR_0_1,
367 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
368 NETXEN_NIU_XGE_STATUS,
369 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
370 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
371 NETXEN_NIU_XGE_TX_BYTE_CNT,
372 NETXEN_NIU_XGE_TX_FRAME_CNT,
373 NETXEN_NIU_XGE_RX_BYTE_CNT,
374 NETXEN_NIU_XGE_RX_FRAME_CNT,
375 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
376 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
377 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
378 NETXEN_NIU_XGE_CRC_ERROR_CNT,
379 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
380 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
381 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
382 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
383 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
384 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
385 -1,
386 }
387 }
388};
389
390static void
391netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
392{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700393 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000394 __u32 mode, *regs_buff = p;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400395 int i, window;
396
397 memset(p, 0, NETXEN_NIC_REGS_LEN);
398 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700399 (adapter->pdev)->device;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400400 /* which mode */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700401 adapter->hw_read_wx(adapter, NETXEN_NIU_MODE, &regs_buff[0], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400402 mode = regs_buff[0];
403
404 /* Common registers to all the modes */
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700405 adapter->hw_read_wx(adapter,
406 NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER, &regs_buff[2], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400407 /* GB/XGB Mode */
408 mode = (mode / 2) - 1;
409 window = 0;
410 if (mode <= 1) {
411 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
412 /* GB: port specific registers */
413 if (mode == 0 && i >= 19)
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700414 window = adapter->physical_port *
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700415 NETXEN_NIC_PORT_WINDOW;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400416
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700417 adapter->hw_read_wx(adapter,
418 niu_registers[mode].reg[i - 3] + window,
419 &regs_buff[i], 4);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400420 }
421
422 }
423}
424
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800425static u32 netxen_nic_test_link(struct net_device *dev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400426{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700427 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000428 __u32 status;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800429 int val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400430
431 /* read which mode */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000432 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Amit S. Kale80922fb2006-12-04 09:18:00 -0800433 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700434 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800435 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
436 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400437 return -EIO;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800438 else {
439 val = netxen_get_phy_link(status);
440 return !val;
441 }
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000442 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700443 val = adapter->pci_read_normalize(adapter, CRB_XG_STATE);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800444 return (val == XG_LINK_UP) ? 0 : 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400445 }
446 return -EIO;
447}
448
449static int
450netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
451 u8 * bytes)
452{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700453 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400454 int offset;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800455 int ret;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400456
457 if (eeprom->len == 0)
458 return -EINVAL;
459
Jeff Garzik47906542007-11-23 21:23:36 -0500460 eeprom->magic = (adapter->pdev)->vendor |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700461 ((adapter->pdev)->device << 16);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800462 offset = eeprom->offset;
463
Jeff Garzik47906542007-11-23 21:23:36 -0500464 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800465 eeprom->len);
466 if (ret < 0)
467 return ret;
468
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400469 return 0;
470}
471
472static void
473netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
474{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700475 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400476
477 ring->rx_pending = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800478 ring->rx_jumbo_pending = 0;
Dhananjay Phadkebecf46a2009-03-09 08:50:55 +0000479 ring->rx_pending += adapter->recv_ctx.
480 rds_rings[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
481 ring->rx_jumbo_pending += adapter->recv_ctx.
482 rds_rings[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530483 ring->tx_pending = adapter->max_tx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400484
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000485 if (adapter->ahw.port_type == NETXEN_NIC_GBE)
Dhananjay Phadke32ec8032009-01-26 12:35:19 -0800486 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
487 else
488 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530489 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
490 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400491 ring->rx_mini_max_pending = 0;
492 ring->rx_mini_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400493}
494
495static void
496netxen_nic_get_pauseparam(struct net_device *dev,
497 struct ethtool_pauseparam *pause)
498{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700499 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000500 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700501 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400502
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000503 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700504 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
505 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400506 /* get flow control settings */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700507 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
508 &val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400509 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700510 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
511 switch (port) {
512 case 0:
513 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
514 break;
515 case 1:
516 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
517 break;
518 case 2:
519 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
520 break;
521 case 3:
522 default:
523 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
524 break;
525 }
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000526 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700527 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
528 return;
529 pause->rx_pause = 1;
530 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
531 if (port == 0)
532 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
533 else
534 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
535 } else {
Jeff Garzik47906542007-11-23 21:23:36 -0500536 printk(KERN_ERR"%s: Unknown board type: %x\n",
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000537 netxen_nic_driver_name, adapter->ahw.port_type);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400538 }
539}
540
541static int
542netxen_nic_set_pauseparam(struct net_device *dev,
543 struct ethtool_pauseparam *pause)
544{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700545 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000546 __u32 val;
Dhananjay Phadke3276fba2008-06-15 22:59:44 -0700547 int port = adapter->physical_port;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400548 /* read mode */
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000549 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700550 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
551 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400552 /* set flow control */
553 netxen_nic_read_w0(adapter,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700554 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
Jeff Garzik47906542007-11-23 21:23:36 -0500555
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400556 if (pause->rx_pause)
557 netxen_gb_rx_flowctl(val);
558 else
559 netxen_gb_unset_rx_flowctl(val);
560
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700561 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
562 val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400563 /* set autoneg */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700564 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
565 switch (port) {
566 case 0:
567 if (pause->tx_pause)
568 netxen_gb_unset_gb0_mask(val);
569 else
570 netxen_gb_set_gb0_mask(val);
571 break;
572 case 1:
573 if (pause->tx_pause)
574 netxen_gb_unset_gb1_mask(val);
575 else
576 netxen_gb_set_gb1_mask(val);
577 break;
578 case 2:
579 if (pause->tx_pause)
580 netxen_gb_unset_gb2_mask(val);
581 else
582 netxen_gb_set_gb2_mask(val);
583 break;
584 case 3:
585 default:
586 if (pause->tx_pause)
587 netxen_gb_unset_gb3_mask(val);
588 else
589 netxen_gb_set_gb3_mask(val);
590 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400591 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700592 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000593 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700594 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
595 return -EIO;
596 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
597 if (port == 0) {
598 if (pause->tx_pause)
599 netxen_xg_unset_xg0_mask(val);
600 else
601 netxen_xg_set_xg0_mask(val);
602 } else {
603 if (pause->tx_pause)
604 netxen_xg_unset_xg1_mask(val);
605 else
606 netxen_xg_set_xg1_mask(val);
607 }
Jeff Garzik47906542007-11-23 21:23:36 -0500608 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700609 } else {
610 printk(KERN_ERR "%s: Unknown board type: %x\n",
Jeff Garzik47906542007-11-23 21:23:36 -0500611 netxen_nic_driver_name,
Dhananjay Phadke1e2d0052009-03-09 08:50:56 +0000612 adapter->ahw.port_type);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700613 }
614 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400615}
616
617static int netxen_nic_reg_test(struct net_device *dev)
618{
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800619 struct netxen_adapter *adapter = netdev_priv(dev);
620 u32 data_read, data_written;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400621
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800622 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
623 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400624 return 1;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800625
626 data_written = (u32)0xa5a5a5a5;
627
628 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
Dhananjay Phadke3ce06a32008-07-21 19:44:03 -0700629 data_read = adapter->pci_read_normalize(adapter, CRB_SCRATCHPAD_TEST);
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800630 if (data_written != data_read)
631 return 1;
632
633 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400634}
635
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700636static int netxen_get_sset_count(struct net_device *dev, int sset)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400637{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700638 switch (sset) {
639 case ETH_SS_TEST:
640 return NETXEN_NIC_TEST_LEN;
641 case ETH_SS_STATS:
642 return NETXEN_NIC_STATS_LEN;
643 default:
644 return -EOPNOTSUPP;
645 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400646}
647
648static void
649netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
650 u64 * data)
651{
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700652 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
653 if ((data[0] = netxen_nic_reg_test(dev)))
654 eth_test->flags |= ETH_TEST_FL_FAILED;
655 /* link test */
656 if ((data[1] = (u64) netxen_nic_test_link(dev)))
657 eth_test->flags |= ETH_TEST_FL_FAILED;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400658}
659
660static void
661netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
662{
663 int index;
664
665 switch (stringset) {
666 case ETH_SS_TEST:
667 memcpy(data, *netxen_nic_gstrings_test,
668 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
669 break;
670 case ETH_SS_STATS:
671 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
672 memcpy(data + index * ETH_GSTRING_LEN,
673 netxen_nic_gstrings_stats[index].stat_string,
674 ETH_GSTRING_LEN);
675 }
676 break;
677 }
678}
679
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400680static void
681netxen_nic_get_ethtool_stats(struct net_device *dev,
682 struct ethtool_stats *stats, u64 * data)
683{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700684 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400685 int index;
686
687 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
688 char *p =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700689 (char *)adapter +
690 netxen_nic_gstrings_stats[index].stat_offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400691 data[index] =
692 (netxen_nic_gstrings_stats[index].sizeof_stat ==
693 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
694 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400695}
696
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530697static u32 netxen_nic_get_rx_csum(struct net_device *dev)
698{
699 struct netxen_adapter *adapter = netdev_priv(dev);
700 return adapter->rx_csum;
701}
702
703static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
704{
705 struct netxen_adapter *adapter = netdev_priv(dev);
706 adapter->rx_csum = !!data;
707 return 0;
708}
709
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700710static u32 netxen_nic_get_tso(struct net_device *dev)
711{
712 struct netxen_adapter *adapter = netdev_priv(dev);
713
714 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
715 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
716
717 return (dev->features & NETIF_F_TSO) != 0;
718}
719
720static int netxen_nic_set_tso(struct net_device *dev, u32 data)
721{
722 if (data) {
723 struct netxen_adapter *adapter = netdev_priv(dev);
724
725 dev->features |= NETIF_F_TSO;
726 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
727 dev->features |= NETIF_F_TSO6;
728 } else
729 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
730
731 return 0;
732}
733
Dhananjay Phadke4da12942009-02-24 16:38:44 -0800734static void
735netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
736{
737 struct netxen_adapter *adapter = netdev_priv(dev);
738 u32 wol_cfg = 0;
739
740 wol->supported = 0;
741 wol->wolopts = 0;
742
743 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
744 return;
745
746 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG_NV);
747 if (wol_cfg & (1UL << adapter->portnum))
748 wol->supported |= WAKE_MAGIC;
749
750 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG);
751 if (wol_cfg & (1UL << adapter->portnum))
752 wol->wolopts |= WAKE_MAGIC;
753}
754
755static int
756netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
757{
758 struct netxen_adapter *adapter = netdev_priv(dev);
759 u32 wol_cfg = 0;
760
761 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
762 return -EOPNOTSUPP;
763
764 if (wol->wolopts & ~WAKE_MAGIC)
765 return -EOPNOTSUPP;
766
767 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG_NV);
768 if (!(wol_cfg & (1 << adapter->portnum)))
769 return -EOPNOTSUPP;
770
771 wol_cfg = netxen_nic_reg_read(adapter, NETXEN_WOL_CONFIG);
772 if (wol->wolopts & WAKE_MAGIC)
773 wol_cfg |= 1UL << adapter->portnum;
774 else
775 wol_cfg &= ~(1UL << adapter->portnum);
776 netxen_nic_reg_write(adapter, NETXEN_WOL_CONFIG, wol_cfg);
777
778 return 0;
779}
780
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700781/*
782 * Set the coalescing parameters. Currently only normal is supported.
783 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
784 * firmware coalescing to default.
785 */
786static int netxen_set_intr_coalesce(struct net_device *netdev,
787 struct ethtool_coalesce *ethcoal)
788{
789 struct netxen_adapter *adapter = netdev_priv(netdev);
790
791 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
792 return -EINVAL;
793
794 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
795 return -EINVAL;
796
797 /*
798 * Return Error if unsupported values or
799 * unsupported parameters are set.
800 */
801 if (ethcoal->rx_coalesce_usecs > 0xffff ||
802 ethcoal->rx_max_coalesced_frames > 0xffff ||
803 ethcoal->tx_coalesce_usecs > 0xffff ||
804 ethcoal->tx_max_coalesced_frames > 0xffff ||
805 ethcoal->rx_coalesce_usecs_irq ||
806 ethcoal->rx_max_coalesced_frames_irq ||
807 ethcoal->tx_coalesce_usecs_irq ||
808 ethcoal->tx_max_coalesced_frames_irq ||
809 ethcoal->stats_block_coalesce_usecs ||
810 ethcoal->use_adaptive_rx_coalesce ||
811 ethcoal->use_adaptive_tx_coalesce ||
812 ethcoal->pkt_rate_low ||
813 ethcoal->rx_coalesce_usecs_low ||
814 ethcoal->rx_max_coalesced_frames_low ||
815 ethcoal->tx_coalesce_usecs_low ||
816 ethcoal->tx_max_coalesced_frames_low ||
817 ethcoal->pkt_rate_high ||
818 ethcoal->rx_coalesce_usecs_high ||
819 ethcoal->rx_max_coalesced_frames_high ||
820 ethcoal->tx_coalesce_usecs_high ||
821 ethcoal->tx_max_coalesced_frames_high)
822 return -EINVAL;
823
824 if (!ethcoal->rx_coalesce_usecs ||
825 !ethcoal->rx_max_coalesced_frames) {
826 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
827 adapter->coal.normal.data.rx_time_us =
828 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
829 adapter->coal.normal.data.rx_packets =
830 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
831 } else {
832 adapter->coal.flags = 0;
833 adapter->coal.normal.data.rx_time_us =
834 ethcoal->rx_coalesce_usecs;
835 adapter->coal.normal.data.rx_packets =
836 ethcoal->rx_max_coalesced_frames;
837 }
838 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
839 adapter->coal.normal.data.tx_packets =
840 ethcoal->tx_max_coalesced_frames;
841
842 netxen_config_intr_coalesce(adapter);
843
844 return 0;
845}
846
847static int netxen_get_intr_coalesce(struct net_device *netdev,
848 struct ethtool_coalesce *ethcoal)
849{
850 struct netxen_adapter *adapter = netdev_priv(netdev);
851
852 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
853 return -EINVAL;
854
855 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
856 return -EINVAL;
857
858 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
859 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
860 ethcoal->rx_max_coalesced_frames =
861 adapter->coal.normal.data.rx_packets;
862 ethcoal->tx_max_coalesced_frames =
863 adapter->coal.normal.data.tx_packets;
864
865 return 0;
866}
867
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400868struct ethtool_ops netxen_nic_ethtool_ops = {
869 .get_settings = netxen_nic_get_settings,
870 .set_settings = netxen_nic_set_settings,
871 .get_drvinfo = netxen_nic_get_drvinfo,
872 .get_regs_len = netxen_nic_get_regs_len,
873 .get_regs = netxen_nic_get_regs,
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800874 .get_link = ethtool_op_get_link,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400875 .get_eeprom_len = netxen_nic_get_eeprom_len,
876 .get_eeprom = netxen_nic_get_eeprom,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400877 .get_ringparam = netxen_nic_get_ringparam,
878 .get_pauseparam = netxen_nic_get_pauseparam,
879 .set_pauseparam = netxen_nic_set_pauseparam,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400880 .set_tx_csum = ethtool_op_set_tx_csum,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400881 .set_sg = ethtool_op_set_sg,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700882 .get_tso = netxen_nic_get_tso,
883 .set_tso = netxen_nic_set_tso,
Dhananjay Phadke4da12942009-02-24 16:38:44 -0800884 .get_wol = netxen_nic_get_wol,
885 .set_wol = netxen_nic_set_wol,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400886 .self_test = netxen_nic_diag_test,
887 .get_strings = netxen_nic_get_strings,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400888 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700889 .get_sset_count = netxen_get_sset_count,
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530890 .get_rx_csum = netxen_nic_get_rx_csum,
891 .set_rx_csum = netxen_nic_set_rx_csum,
Dhananjay Phadkecd1f8162008-07-21 19:44:09 -0700892 .get_coalesce = netxen_get_intr_coalesce,
893 .set_coalesce = netxen_set_intr_coalesce,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400894};