blob: 6e98d830eefb48a4542dc8cb077f2d4df029882f [file] [log] [blame]
Amit S. Kale3d396eb2006-10-21 15:33:03 -04001/*
2 * Copyright (C) 2003 - 2006 NetXen, Inc.
3 * All rights reserved.
Amit S. Kale80922fb2006-12-04 09:18:00 -08004 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -04005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
Amit S. Kale80922fb2006-12-04 09:18:00 -08009 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040010 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Amit S. Kale80922fb2006-12-04 09:18:00 -080014 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040015 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 * MA 02111-1307, USA.
Amit S. Kale80922fb2006-12-04 09:18:00 -080019 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040020 * The full GNU General Public License is included in this distribution
21 * in the file called LICENSE.
Amit S. Kale80922fb2006-12-04 09:18:00 -080022 *
Amit S. Kale3d396eb2006-10-21 15:33:03 -040023 * Contact Information:
24 * info@netxen.com
25 * NetXen,
26 * 3965 Freedom Circle, Fourth floor,
27 * Santa Clara, CA 95054
28 *
29 *
30 * ethtool support for netxen nic
31 *
32 */
33
34#include <linux/types.h>
Amit S. Kale27d2ab52007-02-05 07:40:49 -080035#include <linux/delay.h>
Amit S. Kale3d396eb2006-10-21 15:33:03 -040036#include <asm/uaccess.h>
37#include <linux/pci.h>
38#include <asm/io.h>
39#include <linux/netdevice.h>
40#include <linux/ethtool.h>
41#include <linux/version.h>
42
Amit S. Kale3d396eb2006-10-21 15:33:03 -040043#include "netxen_nic.h"
Mithlesh Thukral6c80b182007-04-20 07:55:26 -070044#include "netxen_nic_hw.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040045#include "netxen_nic_phan_reg.h"
Amit S. Kale3d396eb2006-10-21 15:33:03 -040046
47struct netxen_nic_stats {
48 char stat_string[ETH_GSTRING_LEN];
49 int sizeof_stat;
50 int stat_offset;
51};
52
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070053#define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
54 offsetof(struct netxen_adapter, m)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040055
Amit S. Kalecb8011a2006-11-29 09:00:10 -080056#define NETXEN_NIC_PORT_WINDOW 0x10000
57#define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
58
Amit S. Kale3d396eb2006-10-21 15:33:03 -040059static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
60 {"rcvd_bad_skb", NETXEN_NIC_STAT(stats.rcvdbadskb)},
61 {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
62 {"xmited_frames", NETXEN_NIC_STAT(stats.xmitedframes)},
63 {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
64 {"bad_skb_len", NETXEN_NIC_STAT(stats.badskblen)},
65 {"no_cmd_desc", NETXEN_NIC_STAT(stats.nocmddescriptor)},
66 {"polled", NETXEN_NIC_STAT(stats.polled)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040067 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
Amit S. Kale3d396eb2006-10-21 15:33:03 -040068 {"csummed", NETXEN_NIC_STAT(stats.csummed)},
69 {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
70 {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
71 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
72};
73
Stephen Hemminger92104e92006-12-15 07:57:08 -080074#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040075
76static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -080077 "Register_Test_on_offline",
Amit S. Kale3d396eb2006-10-21 15:33:03 -040078 "Link_Test_on_offline"
79};
80
Alejandro Martinez Ruiz4c3616c2007-10-18 10:00:15 +020081#define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040082
83#define NETXEN_NIC_REGS_COUNT 42
84#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
85#define NETXEN_MAX_EEPROM_LEN 1024
86
87static int netxen_nic_get_eeprom_len(struct net_device *dev)
88{
Mithlesh Thukral0d047612007-06-07 04:36:36 -070089 return NETXEN_FLASH_TOTAL_SIZE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040090}
91
92static void
93netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
94{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -070095 struct netxen_adapter *adapter = netdev_priv(dev);
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);
102 fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
103 NETXEN_FW_VERSION_MAJOR));
104 fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
105 NETXEN_FW_VERSION_MINOR));
106 fw_build = readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));
107 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. Kale71bd7872006-12-01 05:36:22 -0800118 struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400119
120 /* read which mode */
121 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
122 ecmd->supported = (SUPPORTED_10baseT_Half |
123 SUPPORTED_10baseT_Full |
124 SUPPORTED_100baseT_Half |
125 SUPPORTED_100baseT_Full |
126 SUPPORTED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800127 SUPPORTED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400128
129 ecmd->advertising = (ADVERTISED_100baseT_Half |
130 ADVERTISED_100baseT_Full |
131 ADVERTISED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800132 ADVERTISED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400133
134 ecmd->port = PORT_TP;
135
136 if (netif_running(dev)) {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700137 ecmd->speed = adapter->link_speed;
138 ecmd->duplex = adapter->link_duplex;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400139 } else
140 return -EIO; /* link absent */
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800141 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400142 ecmd->supported = (SUPPORTED_TP |
143 SUPPORTED_1000baseT_Full |
144 SUPPORTED_10000baseT_Full);
145 ecmd->advertising = (ADVERTISED_TP |
146 ADVERTISED_1000baseT_Full |
147 ADVERTISED_10000baseT_Full);
148 ecmd->port = PORT_TP;
149
150 ecmd->speed = SPEED_10000;
151 ecmd->duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400152 ecmd->autoneg = AUTONEG_DISABLE;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800153 } else
154 return -EIO;
155
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700156 ecmd->phy_address = adapter->portnum;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800157 ecmd->transceiver = XCVR_EXTERNAL;
158
159 switch ((netxen_brdtype_t) boardinfo->board_type) {
160 case NETXEN_BRDTYPE_P2_SB35_4G:
161 case NETXEN_BRDTYPE_P2_SB31_2G:
162 ecmd->supported |= SUPPORTED_Autoneg;
163 ecmd->advertising |= ADVERTISED_Autoneg;
164 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
165 ecmd->supported |= SUPPORTED_TP;
166 ecmd->advertising |= ADVERTISED_TP;
167 ecmd->port = PORT_TP;
168 ecmd->autoneg = (boardinfo->board_type ==
169 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700170 (AUTONEG_DISABLE) : (adapter->link_autoneg);
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800171 break;
172 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
173 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
174 ecmd->supported |= SUPPORTED_MII;
175 ecmd->advertising |= ADVERTISED_MII;
176 ecmd->port = PORT_FIBRE;
177 ecmd->autoneg = AUTONEG_DISABLE;
178 break;
179 case NETXEN_BRDTYPE_P2_SB31_10G:
180 ecmd->supported |= SUPPORTED_FIBRE;
181 ecmd->advertising |= ADVERTISED_FIBRE;
182 ecmd->port = PORT_FIBRE;
183 ecmd->autoneg = AUTONEG_DISABLE;
184 break;
185 default:
Amit S. Kale71bd7872006-12-01 05:36:22 -0800186 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800187 (netxen_brdtype_t) boardinfo->board_type);
188 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400189 }
190
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800191 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400192}
193
194static int
195netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
196{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700197 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000198 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400199
200 /* read which mode */
201 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
202 /* autonegotiation */
Amit S. Kale80922fb2006-12-04 09:18:00 -0800203 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700204 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800205 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab9c2007-01-02 10:39:10 +0000206 ecmd->autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400207 return -EIO;
208 else
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700209 adapter->link_autoneg = ecmd->autoneg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400210
Amit S. Kale80922fb2006-12-04 09:18:00 -0800211 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700212 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800213 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
214 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400215 return -EIO;
216
217 /* speed */
218 switch (ecmd->speed) {
219 case SPEED_10:
220 netxen_set_phy_speed(status, 0);
221 break;
222 case SPEED_100:
223 netxen_set_phy_speed(status, 1);
224 break;
225 case SPEED_1000:
226 netxen_set_phy_speed(status, 2);
227 break;
228 }
229 /* set duplex mode */
230 if (ecmd->duplex == DUPLEX_HALF)
231 netxen_clear_phy_duplex(status);
232 if (ecmd->duplex == DUPLEX_FULL)
233 netxen_set_phy_duplex(status);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800234 if (adapter->phy_write
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700235 && adapter->phy_write(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800236 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
237 *((int *)&status)) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400238 return -EIO;
239 else {
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700240 adapter->link_speed = ecmd->speed;
241 adapter->link_duplex = ecmd->duplex;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400242 }
243 } else
244 return -EOPNOTSUPP;
245
246 if (netif_running(dev)) {
247 dev->stop(dev);
248 dev->open(dev);
249 }
250 return 0;
251}
252
253static int netxen_nic_get_regs_len(struct net_device *dev)
254{
255 return NETXEN_NIC_REGS_LEN;
256}
257
258struct netxen_niu_regs {
Al Viroa608ab9c2007-01-02 10:39:10 +0000259 __u32 reg[NETXEN_NIC_REGS_COUNT];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400260};
261
262static struct netxen_niu_regs niu_registers[] = {
263 {
264 /* GB Mode */
265 {
266 NETXEN_NIU_GB_SERDES_RESET,
267 NETXEN_NIU_GB0_MII_MODE,
268 NETXEN_NIU_GB1_MII_MODE,
269 NETXEN_NIU_GB2_MII_MODE,
270 NETXEN_NIU_GB3_MII_MODE,
271 NETXEN_NIU_GB0_GMII_MODE,
272 NETXEN_NIU_GB1_GMII_MODE,
273 NETXEN_NIU_GB2_GMII_MODE,
274 NETXEN_NIU_GB3_GMII_MODE,
275 NETXEN_NIU_REMOTE_LOOPBACK,
276 NETXEN_NIU_GB0_HALF_DUPLEX,
277 NETXEN_NIU_GB1_HALF_DUPLEX,
278 NETXEN_NIU_RESET_SYS_FIFOS,
279 NETXEN_NIU_GB_CRC_DROP,
280 NETXEN_NIU_GB_DROP_WRONGADDR,
281 NETXEN_NIU_TEST_MUX_CTL,
282
283 NETXEN_NIU_GB_MAC_CONFIG_0(0),
284 NETXEN_NIU_GB_MAC_CONFIG_1(0),
285 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
286 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
287 NETXEN_NIU_GB_TEST_REG(0),
288 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
289 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
290 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
291 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
292 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
293 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
294 NETXEN_NIU_GB_INTERFACE_CTRL(0),
295 NETXEN_NIU_GB_INTERFACE_STATUS(0),
296 NETXEN_NIU_GB_STATION_ADDR_0(0),
297 NETXEN_NIU_GB_STATION_ADDR_1(0),
298 -1,
299 }
300 },
301 {
302 /* XG Mode */
303 {
304 NETXEN_NIU_XG_SINGLE_TERM,
305 NETXEN_NIU_XG_DRIVE_HI,
306 NETXEN_NIU_XG_DRIVE_LO,
307 NETXEN_NIU_XG_DTX,
308 NETXEN_NIU_XG_DEQ,
309 NETXEN_NIU_XG_WORD_ALIGN,
310 NETXEN_NIU_XG_RESET,
311 NETXEN_NIU_XG_POWER_DOWN,
312 NETXEN_NIU_XG_RESET_PLL,
313 NETXEN_NIU_XG_SERDES_LOOPBACK,
314 NETXEN_NIU_XG_DO_BYTE_ALIGN,
315 NETXEN_NIU_XG_TX_ENABLE,
316 NETXEN_NIU_XG_RX_ENABLE,
317 NETXEN_NIU_XG_STATUS,
318 NETXEN_NIU_XG_PAUSE_THRESHOLD,
319 NETXEN_NIU_XGE_CONFIG_0,
320 NETXEN_NIU_XGE_CONFIG_1,
321 NETXEN_NIU_XGE_IPG,
322 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
323 NETXEN_NIU_XGE_STATION_ADDR_0_1,
324 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
325 NETXEN_NIU_XGE_STATUS,
326 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
327 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
328 NETXEN_NIU_XGE_TX_BYTE_CNT,
329 NETXEN_NIU_XGE_TX_FRAME_CNT,
330 NETXEN_NIU_XGE_RX_BYTE_CNT,
331 NETXEN_NIU_XGE_RX_FRAME_CNT,
332 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
333 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
334 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
335 NETXEN_NIU_XGE_CRC_ERROR_CNT,
336 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
337 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
338 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
339 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
340 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
341 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
342 -1,
343 }
344 }
345};
346
347static void
348netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
349{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700350 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000351 __u32 mode, *regs_buff = p;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400352 void __iomem *addr;
353 int i, window;
354
355 memset(p, 0, NETXEN_NIC_REGS_LEN);
356 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700357 (adapter->pdev)->device;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400358 /* which mode */
359 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_MODE, &regs_buff[0]);
360 mode = regs_buff[0];
361
362 /* Common registers to all the modes */
363 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER,
364 &regs_buff[2]);
365 /* GB/XGB Mode */
366 mode = (mode / 2) - 1;
367 window = 0;
368 if (mode <= 1) {
369 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
370 /* GB: port specific registers */
371 if (mode == 0 && i >= 19)
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700372 window = physical_port[adapter->portnum] *
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700373 NETXEN_NIC_PORT_WINDOW;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400374
375 NETXEN_NIC_LOCKED_READ_REG(niu_registers[mode].
376 reg[i - 3] + window,
377 &regs_buff[i]);
378 }
379
380 }
381}
382
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800383static u32 netxen_nic_test_link(struct net_device *dev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400384{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700385 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000386 __u32 status;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800387 int val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400388
389 /* read which mode */
390 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Amit S. Kale80922fb2006-12-04 09:18:00 -0800391 if (adapter->phy_read
Mithlesh Thukral13ba9c72007-04-20 07:53:05 -0700392 && adapter->phy_read(adapter,
Amit S. Kale80922fb2006-12-04 09:18:00 -0800393 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
394 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400395 return -EIO;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800396 else {
397 val = netxen_get_phy_link(status);
398 return !val;
399 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400400 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800401 val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
402 return (val == XG_LINK_UP) ? 0 : 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400403 }
404 return -EIO;
405}
406
407static int
408netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
409 u8 * bytes)
410{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700411 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400412 int offset;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800413 int ret;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400414
415 if (eeprom->len == 0)
416 return -EINVAL;
417
Jeff Garzik47906542007-11-23 21:23:36 -0500418 eeprom->magic = (adapter->pdev)->vendor |
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700419 ((adapter->pdev)->device << 16);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800420 offset = eeprom->offset;
421
Jeff Garzik47906542007-11-23 21:23:36 -0500422 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800423 eeprom->len);
424 if (ret < 0)
425 return ret;
426
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400427 return 0;
428}
429
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800430static int
431netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
432 u8 * bytes)
433{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700434 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800435 int offset = eeprom->offset;
436 static int flash_start;
437 static int ready_to_flash;
438 int ret;
439
440 if (flash_start == 0) {
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800441 netxen_halt_pegs(adapter);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800442 ret = netxen_flash_unlock(adapter);
443 if (ret < 0) {
444 printk(KERN_ERR "%s: Flash unlock failed.\n",
445 netxen_nic_driver_name);
446 return ret;
447 }
Jeff Garzik47906542007-11-23 21:23:36 -0500448 printk(KERN_INFO "%s: flash unlocked. \n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800449 netxen_nic_driver_name);
Linsys Contractor Mithlesh Thukralb58ecad2007-03-13 04:15:06 -0800450 last_schedule_time = jiffies;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800451 ret = netxen_flash_erase_secondary(adapter);
452 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500453 printk(KERN_ERR "%s: Flash erase failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800454 netxen_nic_driver_name);
455 return ret;
456 }
Jeff Garzik47906542007-11-23 21:23:36 -0500457 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800458 netxen_nic_driver_name);
459 flash_start = 1;
460 return 0;
461 }
462
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700463 if (offset == NETXEN_BOOTLD_START) {
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800464 ret = netxen_flash_erase_primary(adapter);
465 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500466 printk(KERN_ERR "%s: Flash erase failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800467 netxen_nic_driver_name);
468 return ret;
469 }
470
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700471 ret = netxen_rom_se(adapter, NETXEN_USER_START);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800472 if (ret != FLASH_SUCCESS)
473 return ret;
Mithlesh Thukral0d047612007-06-07 04:36:36 -0700474 ret = netxen_rom_se(adapter, NETXEN_FIXED_START);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800475 if (ret != FLASH_SUCCESS)
476 return ret;
477
Jeff Garzik47906542007-11-23 21:23:36 -0500478 printk(KERN_INFO "%s: primary flash erased successfully\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800479 netxen_nic_driver_name);
480
481 ret = netxen_backup_crbinit(adapter);
482 if (ret != FLASH_SUCCESS) {
Jeff Garzik47906542007-11-23 21:23:36 -0500483 printk(KERN_ERR "%s: CRBinit backup failed.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800484 netxen_nic_driver_name);
485 return ret;
486 }
Jeff Garzik47906542007-11-23 21:23:36 -0500487 printk(KERN_INFO "%s: CRBinit backup done.\n",
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800488 netxen_nic_driver_name);
489 ready_to_flash = 1;
490 }
491
492 if (!ready_to_flash) {
493 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
494 netxen_nic_driver_name);
495 return -EINVAL;
496 }
497
498 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
499}
500
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400501static void
502netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
503{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700504 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800505 int i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400506
507 ring->rx_pending = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800508 ring->rx_jumbo_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400509 for (i = 0; i < MAX_RCV_CTX; ++i) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800510 ring->rx_pending += adapter->recv_ctx[i].
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530511 rcv_desc[RCV_DESC_NORMAL_CTXID].max_rx_desc_count;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800512 ring->rx_jumbo_pending += adapter->recv_ctx[i].
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530513 rcv_desc[RCV_DESC_JUMBO_CTXID].max_rx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400514 }
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530515 ring->tx_pending = adapter->max_tx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400516
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530517 ring->rx_max_pending = MAX_RCV_DESCRIPTORS;
518 ring->tx_max_pending = MAX_CMD_DESCRIPTORS_HOST;
519 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400520 ring->rx_mini_max_pending = 0;
521 ring->rx_mini_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400522}
523
524static void
525netxen_nic_get_pauseparam(struct net_device *dev,
526 struct ethtool_pauseparam *pause)
527{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700528 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000529 __u32 val;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700530 int port = physical_port[adapter->portnum];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400531
532 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700533 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
534 return;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400535 /* get flow control settings */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700536 netxen_nic_read_w0(adapter,NETXEN_NIU_GB_MAC_CONFIG_0(port),
537 &val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400538 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700539 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
540 switch (port) {
541 case 0:
542 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
543 break;
544 case 1:
545 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
546 break;
547 case 2:
548 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
549 break;
550 case 3:
551 default:
552 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
553 break;
554 }
555 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
556 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
557 return;
558 pause->rx_pause = 1;
559 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
560 if (port == 0)
561 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
562 else
563 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
564 } else {
Jeff Garzik47906542007-11-23 21:23:36 -0500565 printk(KERN_ERR"%s: Unknown board type: %x\n",
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700566 netxen_nic_driver_name, adapter->ahw.board_type);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400567 }
568}
569
570static int
571netxen_nic_set_pauseparam(struct net_device *dev,
572 struct ethtool_pauseparam *pause)
573{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700574 struct netxen_adapter *adapter = netdev_priv(dev);
Al Viroa608ab9c2007-01-02 10:39:10 +0000575 __u32 val;
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700576 int port = physical_port[adapter->portnum];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400577 /* read mode */
578 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700579 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
580 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400581 /* set flow control */
582 netxen_nic_read_w0(adapter,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700583 NETXEN_NIU_GB_MAC_CONFIG_0(port), &val);
Jeff Garzik47906542007-11-23 21:23:36 -0500584
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400585 if (pause->rx_pause)
586 netxen_gb_rx_flowctl(val);
587 else
588 netxen_gb_unset_rx_flowctl(val);
589
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700590 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
591 val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400592 /* set autoneg */
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700593 netxen_nic_read_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, &val);
594 switch (port) {
595 case 0:
596 if (pause->tx_pause)
597 netxen_gb_unset_gb0_mask(val);
598 else
599 netxen_gb_set_gb0_mask(val);
600 break;
601 case 1:
602 if (pause->tx_pause)
603 netxen_gb_unset_gb1_mask(val);
604 else
605 netxen_gb_set_gb1_mask(val);
606 break;
607 case 2:
608 if (pause->tx_pause)
609 netxen_gb_unset_gb2_mask(val);
610 else
611 netxen_gb_set_gb2_mask(val);
612 break;
613 case 3:
614 default:
615 if (pause->tx_pause)
616 netxen_gb_unset_gb3_mask(val);
617 else
618 netxen_gb_set_gb3_mask(val);
619 break;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400620 }
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700621 netxen_nic_write_w0(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
622 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
623 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
624 return -EIO;
625 netxen_nic_read_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, &val);
626 if (port == 0) {
627 if (pause->tx_pause)
628 netxen_xg_unset_xg0_mask(val);
629 else
630 netxen_xg_set_xg0_mask(val);
631 } else {
632 if (pause->tx_pause)
633 netxen_xg_unset_xg1_mask(val);
634 else
635 netxen_xg_set_xg1_mask(val);
636 }
Jeff Garzik47906542007-11-23 21:23:36 -0500637 netxen_nic_write_w0(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700638 } else {
639 printk(KERN_ERR "%s: Unknown board type: %x\n",
Jeff Garzik47906542007-11-23 21:23:36 -0500640 netxen_nic_driver_name,
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700641 adapter->ahw.board_type);
642 }
643 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400644}
645
646static int netxen_nic_reg_test(struct net_device *dev)
647{
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800648 struct netxen_adapter *adapter = netdev_priv(dev);
649 u32 data_read, data_written;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400650
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800651 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
652 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400653 return 1;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800654
655 data_written = (u32)0xa5a5a5a5;
656
657 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
658 data_read = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_SCRATCHPAD_TEST));
659 if (data_written != data_read)
660 return 1;
661
662 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400663}
664
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700665static int netxen_get_sset_count(struct net_device *dev, int sset)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400666{
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700667 switch (sset) {
668 case ETH_SS_TEST:
669 return NETXEN_NIC_TEST_LEN;
670 case ETH_SS_STATS:
671 return NETXEN_NIC_STATS_LEN;
672 default:
673 return -EOPNOTSUPP;
674 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400675}
676
677static void
678netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
679 u64 * data)
680{
Mithlesh Thukral6c80b182007-04-20 07:55:26 -0700681 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
682 if ((data[0] = netxen_nic_reg_test(dev)))
683 eth_test->flags |= ETH_TEST_FL_FAILED;
684 /* link test */
685 if ((data[1] = (u64) netxen_nic_test_link(dev)))
686 eth_test->flags |= ETH_TEST_FL_FAILED;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400687}
688
689static void
690netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
691{
692 int index;
693
694 switch (stringset) {
695 case ETH_SS_TEST:
696 memcpy(data, *netxen_nic_gstrings_test,
697 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
698 break;
699 case ETH_SS_STATS:
700 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
701 memcpy(data + index * ETH_GSTRING_LEN,
702 netxen_nic_gstrings_stats[index].stat_string,
703 ETH_GSTRING_LEN);
704 }
705 break;
706 }
707}
708
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400709static void
710netxen_nic_get_ethtool_stats(struct net_device *dev,
711 struct ethtool_stats *stats, u64 * data)
712{
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700713 struct netxen_adapter *adapter = netdev_priv(dev);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400714 int index;
715
716 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
717 char *p =
Mithlesh Thukral3176ff32007-04-20 07:52:37 -0700718 (char *)adapter +
719 netxen_nic_gstrings_stats[index].stat_offset;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400720 data[index] =
721 (netxen_nic_gstrings_stats[index].sizeof_stat ==
722 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
723 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400724}
725
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530726static u32 netxen_nic_get_rx_csum(struct net_device *dev)
727{
728 struct netxen_adapter *adapter = netdev_priv(dev);
729 return adapter->rx_csum;
730}
731
732static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
733{
734 struct netxen_adapter *adapter = netdev_priv(dev);
735 adapter->rx_csum = !!data;
736 return 0;
737}
738
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400739struct ethtool_ops netxen_nic_ethtool_ops = {
740 .get_settings = netxen_nic_get_settings,
741 .set_settings = netxen_nic_set_settings,
742 .get_drvinfo = netxen_nic_get_drvinfo,
743 .get_regs_len = netxen_nic_get_regs_len,
744 .get_regs = netxen_nic_get_regs,
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800745 .get_link = ethtool_op_get_link,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400746 .get_eeprom_len = netxen_nic_get_eeprom_len,
747 .get_eeprom = netxen_nic_get_eeprom,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800748 .set_eeprom = netxen_nic_set_eeprom,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400749 .get_ringparam = netxen_nic_get_ringparam,
750 .get_pauseparam = netxen_nic_get_pauseparam,
751 .set_pauseparam = netxen_nic_set_pauseparam,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400752 .set_tx_csum = ethtool_op_set_tx_csum,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400753 .set_sg = ethtool_op_set_sg,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400754 .set_tso = ethtool_op_set_tso,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400755 .self_test = netxen_nic_diag_test,
756 .get_strings = netxen_nic_get_strings,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400757 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700758 .get_sset_count = netxen_get_sset_count,
Dhananjay Phadke200eef22007-09-03 10:33:35 +0530759 .get_rx_csum = netxen_nic_get_rx_csum,
760 .set_rx_csum = netxen_nic_set_rx_csum,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400761};