blob: ee1b5a24cbe7bbe7457528bdda7a0a5b4cb7feb3 [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
43#include "netxen_nic_hw.h"
44#include "netxen_nic.h"
45#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
53#define NETXEN_NIC_STAT(m) sizeof(((struct netxen_port *)0)->m), \
54 offsetof(struct netxen_port, m)
55
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)},
67 {"uphappy", NETXEN_NIC_STAT(stats.uphappy)},
68 {"updropped", NETXEN_NIC_STAT(stats.updropped)},
69 {"uplcong", NETXEN_NIC_STAT(stats.uplcong)},
70 {"uphcong", NETXEN_NIC_STAT(stats.uphcong)},
71 {"upmcong", NETXEN_NIC_STAT(stats.upmcong)},
72 {"updunno", NETXEN_NIC_STAT(stats.updunno)},
73 {"skb_freed", NETXEN_NIC_STAT(stats.skbfreed)},
74 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
75 {"tx_null_skb", NETXEN_NIC_STAT(stats.txnullskb)},
76 {"csummed", NETXEN_NIC_STAT(stats.csummed)},
77 {"no_rcv", NETXEN_NIC_STAT(stats.no_rcv)},
78 {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
79 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
80};
81
Stephen Hemminger92104e92006-12-15 07:57:08 -080082#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
Amit S. Kale3d396eb2006-10-21 15:33:03 -040083
84static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -080085 "Register_Test_on_offline",
Amit S. Kale3d396eb2006-10-21 15:33:03 -040086 "Link_Test_on_offline"
87};
88
89#define NETXEN_NIC_TEST_LEN sizeof(netxen_nic_gstrings_test) / ETH_GSTRING_LEN
90
91#define NETXEN_NIC_REGS_COUNT 42
92#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
93#define NETXEN_MAX_EEPROM_LEN 1024
94
95static int netxen_nic_get_eeprom_len(struct net_device *dev)
96{
Amit S. Kale27d2ab52007-02-05 07:40:49 -080097 return FLASH_TOTAL_SIZE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040098}
99
100static void
101netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
102{
103 struct netxen_port *port = netdev_priv(dev);
104 struct netxen_adapter *adapter = port->adapter;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800105 u32 fw_major = 0;
106 u32 fw_minor = 0;
107 u32 fw_build = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400108
Amit S. Kale80922fb2006-12-04 09:18:00 -0800109 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400110 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
111 fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
112 NETXEN_FW_VERSION_MAJOR));
113 fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
114 NETXEN_FW_VERSION_MINOR));
115 fw_build = readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));
116 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
117
118 strncpy(drvinfo->bus_info, pci_name(port->pdev), 32);
119 drvinfo->n_stats = NETXEN_NIC_STATS_LEN;
120 drvinfo->testinfo_len = NETXEN_NIC_TEST_LEN;
121 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
122 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
123}
124
125static int
126netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
127{
128 struct netxen_port *port = netdev_priv(dev);
129 struct netxen_adapter *adapter = port->adapter;
Amit S. Kale71bd7872006-12-01 05:36:22 -0800130 struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400131
132 /* read which mode */
133 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
134 ecmd->supported = (SUPPORTED_10baseT_Half |
135 SUPPORTED_10baseT_Full |
136 SUPPORTED_100baseT_Half |
137 SUPPORTED_100baseT_Full |
138 SUPPORTED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800139 SUPPORTED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400140
141 ecmd->advertising = (ADVERTISED_100baseT_Half |
142 ADVERTISED_100baseT_Full |
143 ADVERTISED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800144 ADVERTISED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400145
146 ecmd->port = PORT_TP;
147
148 if (netif_running(dev)) {
149 ecmd->speed = port->link_speed;
150 ecmd->duplex = port->link_duplex;
151 } else
152 return -EIO; /* link absent */
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800153 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400154 ecmd->supported = (SUPPORTED_TP |
155 SUPPORTED_1000baseT_Full |
156 SUPPORTED_10000baseT_Full);
157 ecmd->advertising = (ADVERTISED_TP |
158 ADVERTISED_1000baseT_Full |
159 ADVERTISED_10000baseT_Full);
160 ecmd->port = PORT_TP;
161
162 ecmd->speed = SPEED_10000;
163 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
168 ecmd->phy_address = port->portnum;
169 ecmd->transceiver = XCVR_EXTERNAL;
170
171 switch ((netxen_brdtype_t) boardinfo->board_type) {
172 case NETXEN_BRDTYPE_P2_SB35_4G:
173 case NETXEN_BRDTYPE_P2_SB31_2G:
174 ecmd->supported |= SUPPORTED_Autoneg;
175 ecmd->advertising |= ADVERTISED_Autoneg;
176 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
177 ecmd->supported |= SUPPORTED_TP;
178 ecmd->advertising |= ADVERTISED_TP;
179 ecmd->port = PORT_TP;
180 ecmd->autoneg = (boardinfo->board_type ==
181 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
182 (AUTONEG_DISABLE) : (port->link_autoneg);
183 break;
184 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
185 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
186 ecmd->supported |= SUPPORTED_MII;
187 ecmd->advertising |= ADVERTISED_MII;
188 ecmd->port = PORT_FIBRE;
189 ecmd->autoneg = AUTONEG_DISABLE;
190 break;
191 case NETXEN_BRDTYPE_P2_SB31_10G:
192 ecmd->supported |= SUPPORTED_FIBRE;
193 ecmd->advertising |= ADVERTISED_FIBRE;
194 ecmd->port = PORT_FIBRE;
195 ecmd->autoneg = AUTONEG_DISABLE;
196 break;
197 default:
Amit S. Kale71bd7872006-12-01 05:36:22 -0800198 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800199 (netxen_brdtype_t) boardinfo->board_type);
200 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400201 }
202
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800203 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400204}
205
206static int
207netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
208{
209 struct netxen_port *port = netdev_priv(dev);
210 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab92007-01-02 10:39:10 +0000211 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400212
213 /* read which mode */
214 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
215 /* autonegotiation */
Amit S. Kale80922fb2006-12-04 09:18:00 -0800216 if (adapter->phy_write
217 && adapter->phy_write(adapter, port->portnum,
218 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab92007-01-02 10:39:10 +0000219 ecmd->autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400220 return -EIO;
221 else
222 port->link_autoneg = ecmd->autoneg;
223
Amit S. Kale80922fb2006-12-04 09:18:00 -0800224 if (adapter->phy_read
225 && adapter->phy_read(adapter, port->portnum,
226 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
227 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400228 return -EIO;
229
230 /* speed */
231 switch (ecmd->speed) {
232 case SPEED_10:
233 netxen_set_phy_speed(status, 0);
234 break;
235 case SPEED_100:
236 netxen_set_phy_speed(status, 1);
237 break;
238 case SPEED_1000:
239 netxen_set_phy_speed(status, 2);
240 break;
241 }
242 /* set duplex mode */
243 if (ecmd->duplex == DUPLEX_HALF)
244 netxen_clear_phy_duplex(status);
245 if (ecmd->duplex == DUPLEX_FULL)
246 netxen_set_phy_duplex(status);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800247 if (adapter->phy_write
248 && adapter->phy_write(adapter, port->portnum,
249 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
250 *((int *)&status)) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400251 return -EIO;
252 else {
253 port->link_speed = ecmd->speed;
254 port->link_duplex = ecmd->duplex;
255 }
256 } else
257 return -EOPNOTSUPP;
258
259 if (netif_running(dev)) {
260 dev->stop(dev);
261 dev->open(dev);
262 }
263 return 0;
264}
265
266static int netxen_nic_get_regs_len(struct net_device *dev)
267{
268 return NETXEN_NIC_REGS_LEN;
269}
270
271struct netxen_niu_regs {
Al Viroa608ab92007-01-02 10:39:10 +0000272 __u32 reg[NETXEN_NIC_REGS_COUNT];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400273};
274
275static struct netxen_niu_regs niu_registers[] = {
276 {
277 /* GB Mode */
278 {
279 NETXEN_NIU_GB_SERDES_RESET,
280 NETXEN_NIU_GB0_MII_MODE,
281 NETXEN_NIU_GB1_MII_MODE,
282 NETXEN_NIU_GB2_MII_MODE,
283 NETXEN_NIU_GB3_MII_MODE,
284 NETXEN_NIU_GB0_GMII_MODE,
285 NETXEN_NIU_GB1_GMII_MODE,
286 NETXEN_NIU_GB2_GMII_MODE,
287 NETXEN_NIU_GB3_GMII_MODE,
288 NETXEN_NIU_REMOTE_LOOPBACK,
289 NETXEN_NIU_GB0_HALF_DUPLEX,
290 NETXEN_NIU_GB1_HALF_DUPLEX,
291 NETXEN_NIU_RESET_SYS_FIFOS,
292 NETXEN_NIU_GB_CRC_DROP,
293 NETXEN_NIU_GB_DROP_WRONGADDR,
294 NETXEN_NIU_TEST_MUX_CTL,
295
296 NETXEN_NIU_GB_MAC_CONFIG_0(0),
297 NETXEN_NIU_GB_MAC_CONFIG_1(0),
298 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
299 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
300 NETXEN_NIU_GB_TEST_REG(0),
301 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
302 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
303 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
304 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
305 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
306 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
307 NETXEN_NIU_GB_INTERFACE_CTRL(0),
308 NETXEN_NIU_GB_INTERFACE_STATUS(0),
309 NETXEN_NIU_GB_STATION_ADDR_0(0),
310 NETXEN_NIU_GB_STATION_ADDR_1(0),
311 -1,
312 }
313 },
314 {
315 /* XG Mode */
316 {
317 NETXEN_NIU_XG_SINGLE_TERM,
318 NETXEN_NIU_XG_DRIVE_HI,
319 NETXEN_NIU_XG_DRIVE_LO,
320 NETXEN_NIU_XG_DTX,
321 NETXEN_NIU_XG_DEQ,
322 NETXEN_NIU_XG_WORD_ALIGN,
323 NETXEN_NIU_XG_RESET,
324 NETXEN_NIU_XG_POWER_DOWN,
325 NETXEN_NIU_XG_RESET_PLL,
326 NETXEN_NIU_XG_SERDES_LOOPBACK,
327 NETXEN_NIU_XG_DO_BYTE_ALIGN,
328 NETXEN_NIU_XG_TX_ENABLE,
329 NETXEN_NIU_XG_RX_ENABLE,
330 NETXEN_NIU_XG_STATUS,
331 NETXEN_NIU_XG_PAUSE_THRESHOLD,
332 NETXEN_NIU_XGE_CONFIG_0,
333 NETXEN_NIU_XGE_CONFIG_1,
334 NETXEN_NIU_XGE_IPG,
335 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
336 NETXEN_NIU_XGE_STATION_ADDR_0_1,
337 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
338 NETXEN_NIU_XGE_STATUS,
339 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
340 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
341 NETXEN_NIU_XGE_TX_BYTE_CNT,
342 NETXEN_NIU_XGE_TX_FRAME_CNT,
343 NETXEN_NIU_XGE_RX_BYTE_CNT,
344 NETXEN_NIU_XGE_RX_FRAME_CNT,
345 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
346 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
347 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
348 NETXEN_NIU_XGE_CRC_ERROR_CNT,
349 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
350 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
351 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
352 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
353 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
354 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
355 -1,
356 }
357 }
358};
359
360static void
361netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
362{
363 struct netxen_port *port = netdev_priv(dev);
364 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab92007-01-02 10:39:10 +0000365 __u32 mode, *regs_buff = p;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400366 void __iomem *addr;
367 int i, window;
368
369 memset(p, 0, NETXEN_NIC_REGS_LEN);
370 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
371 (port->pdev)->device;
372 /* which mode */
373 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_MODE, &regs_buff[0]);
374 mode = regs_buff[0];
375
376 /* Common registers to all the modes */
377 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER,
378 &regs_buff[2]);
379 /* GB/XGB Mode */
380 mode = (mode / 2) - 1;
381 window = 0;
382 if (mode <= 1) {
383 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
384 /* GB: port specific registers */
385 if (mode == 0 && i >= 19)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800386 window = port->portnum * NETXEN_NIC_PORT_WINDOW;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400387
388 NETXEN_NIC_LOCKED_READ_REG(niu_registers[mode].
389 reg[i - 3] + window,
390 &regs_buff[i]);
391 }
392
393 }
394}
395
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800396static u32 netxen_nic_test_link(struct net_device *dev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400397{
398 struct netxen_port *port = netdev_priv(dev);
399 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab92007-01-02 10:39:10 +0000400 __u32 status;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800401 int val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400402
403 /* read which mode */
404 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Amit S. Kale80922fb2006-12-04 09:18:00 -0800405 if (adapter->phy_read
406 && adapter->phy_read(adapter, port->portnum,
407 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
408 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400409 return -EIO;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800410 else {
411 val = netxen_get_phy_link(status);
412 return !val;
413 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400414 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800415 val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
416 return (val == XG_LINK_UP) ? 0 : 1;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400417 }
418 return -EIO;
419}
420
421static int
422netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
423 u8 * bytes)
424{
425 struct netxen_port *port = netdev_priv(dev);
426 struct netxen_adapter *adapter = port->adapter;
427 int offset;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800428 int ret;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400429
430 if (eeprom->len == 0)
431 return -EINVAL;
432
433 eeprom->magic = (port->pdev)->vendor | ((port->pdev)->device << 16);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800434 offset = eeprom->offset;
435
436 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
437 eeprom->len);
438 if (ret < 0)
439 return ret;
440
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400441 return 0;
442}
443
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800444static int
445netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
446 u8 * bytes)
447{
448 struct netxen_port *port = netdev_priv(dev);
449 struct netxen_adapter *adapter = port->adapter;
450 int offset = eeprom->offset;
451 static int flash_start;
452 static int ready_to_flash;
453 int ret;
454
455 if (flash_start == 0) {
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800456 netxen_halt_pegs(adapter);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800457 ret = netxen_flash_unlock(adapter);
458 if (ret < 0) {
459 printk(KERN_ERR "%s: Flash unlock failed.\n",
460 netxen_nic_driver_name);
461 return ret;
462 }
463 printk(KERN_INFO "%s: flash unlocked. \n",
464 netxen_nic_driver_name);
Linsys Contractor Mithlesh Thukralb58ecad2007-03-13 04:15:06 -0800465 last_schedule_time = jiffies;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800466 ret = netxen_flash_erase_secondary(adapter);
467 if (ret != FLASH_SUCCESS) {
468 printk(KERN_ERR "%s: Flash erase failed.\n",
469 netxen_nic_driver_name);
470 return ret;
471 }
472 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
473 netxen_nic_driver_name);
474 flash_start = 1;
475 return 0;
476 }
477
478 if (offset == BOOTLD_START) {
479 ret = netxen_flash_erase_primary(adapter);
480 if (ret != FLASH_SUCCESS) {
481 printk(KERN_ERR "%s: Flash erase failed.\n",
482 netxen_nic_driver_name);
483 return ret;
484 }
485
486 ret = netxen_rom_se(adapter, USER_START);
487 if (ret != FLASH_SUCCESS)
488 return ret;
489 ret = netxen_rom_se(adapter, FIXED_START);
490 if (ret != FLASH_SUCCESS)
491 return ret;
492
493 printk(KERN_INFO "%s: primary flash erased successfully\n",
494 netxen_nic_driver_name);
495
496 ret = netxen_backup_crbinit(adapter);
497 if (ret != FLASH_SUCCESS) {
498 printk(KERN_ERR "%s: CRBinit backup failed.\n",
499 netxen_nic_driver_name);
500 return ret;
501 }
502 printk(KERN_INFO "%s: CRBinit backup done.\n",
503 netxen_nic_driver_name);
504 ready_to_flash = 1;
505 }
506
507 if (!ready_to_flash) {
508 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
509 netxen_nic_driver_name);
510 return -EINVAL;
511 }
512
513 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
514}
515
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400516static void
517netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
518{
519 struct netxen_port *port = netdev_priv(dev);
520 struct netxen_adapter *adapter = port->adapter;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800521 int i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400522
523 ring->rx_pending = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800524 ring->rx_jumbo_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400525 for (i = 0; i < MAX_RCV_CTX; ++i) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800526 ring->rx_pending += adapter->recv_ctx[i].
527 rcv_desc[RCV_DESC_NORMAL_CTXID].rcv_pending;
528 ring->rx_jumbo_pending += adapter->recv_ctx[i].
529 rcv_desc[RCV_DESC_JUMBO_CTXID].rcv_pending;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400530 }
531
532 ring->rx_max_pending = adapter->max_rx_desc_count;
533 ring->tx_max_pending = adapter->max_tx_desc_count;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800534 ring->rx_jumbo_max_pending = adapter->max_jumbo_rx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400535 ring->rx_mini_max_pending = 0;
536 ring->rx_mini_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400537 ring->rx_jumbo_pending = 0;
538}
539
540static void
541netxen_nic_get_pauseparam(struct net_device *dev,
542 struct ethtool_pauseparam *pause)
543{
544 struct netxen_port *port = netdev_priv(dev);
545 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab92007-01-02 10:39:10 +0000546 __u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400547
548 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
549 /* get flow control settings */
550 netxen_nic_read_w0(adapter,
551 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
Al Viroa608ab92007-01-02 10:39:10 +0000552 &val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400553 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
554 pause->tx_pause = netxen_gb_get_tx_flowctl(val);
555 /* get autoneg settings */
556 pause->autoneg = port->link_autoneg;
557 }
558}
559
560static int
561netxen_nic_set_pauseparam(struct net_device *dev,
562 struct ethtool_pauseparam *pause)
563{
564 struct netxen_port *port = netdev_priv(dev);
565 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab92007-01-02 10:39:10 +0000566 __u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400567 unsigned int autoneg;
568
569 /* read mode */
570 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
571 /* set flow control */
572 netxen_nic_read_w0(adapter,
573 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
574 (u32 *) & val);
575 if (pause->tx_pause)
576 netxen_gb_tx_flowctl(val);
577 else
578 netxen_gb_unset_tx_flowctl(val);
579 if (pause->rx_pause)
580 netxen_gb_rx_flowctl(val);
581 else
582 netxen_gb_unset_rx_flowctl(val);
583
584 netxen_nic_write_w0(adapter,
585 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
Al Viroa608ab92007-01-02 10:39:10 +0000586 *&val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400587 /* set autoneg */
588 autoneg = pause->autoneg;
Amit S. Kale80922fb2006-12-04 09:18:00 -0800589 if (adapter->phy_write
590 && adapter->phy_write(adapter, port->portnum,
591 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab92007-01-02 10:39:10 +0000592 autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400593 return -EIO;
594 else {
595 port->link_autoneg = pause->autoneg;
596 return 0;
597 }
598 } else
599 return -EOPNOTSUPP;
600}
601
602static int netxen_nic_reg_test(struct net_device *dev)
603{
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800604 struct netxen_adapter *adapter = netdev_priv(dev);
605 u32 data_read, data_written;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400606
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800607 netxen_nic_read_w0(adapter, NETXEN_PCIX_PH_REG(0), &data_read);
608 if ((data_read & 0xffff) != PHAN_VENDOR_ID)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400609 return 1;
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800610
611 data_written = (u32)0xa5a5a5a5;
612
613 netxen_nic_reg_write(adapter, CRB_SCRATCHPAD_TEST, data_written);
614 data_read = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_SCRATCHPAD_TEST));
615 if (data_written != data_read)
616 return 1;
617
618 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400619}
620
621static int netxen_nic_diag_test_count(struct net_device *dev)
622{
623 return NETXEN_NIC_TEST_LEN;
624}
625
626static void
627netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
628 u64 * data)
629{
630 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */
631 /* link test */
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800632 if ((data[1] = (u64) netxen_nic_test_link(dev)))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400633 eth_test->flags |= ETH_TEST_FL_FAILED;
634
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400635 /* register tests */
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800636 if ((data[0] = netxen_nic_reg_test(dev)))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400637 eth_test->flags |= ETH_TEST_FL_FAILED;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400638 } else { /* online tests */
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800639 /* register tests */
640 if((data[0] = netxen_nic_reg_test(dev)))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400641 eth_test->flags |= ETH_TEST_FL_FAILED;
642
Linsys Contractor Mithlesh Thukral0c25cfe2007-02-28 05:14:07 -0800643 /* link test */
644 if ((data[1] = (u64) netxen_nic_test_link(dev)))
645 eth_test->flags |= ETH_TEST_FL_FAILED;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400646 }
647}
648
649static void
650netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
651{
652 int index;
653
654 switch (stringset) {
655 case ETH_SS_TEST:
656 memcpy(data, *netxen_nic_gstrings_test,
657 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
658 break;
659 case ETH_SS_STATS:
660 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
661 memcpy(data + index * ETH_GSTRING_LEN,
662 netxen_nic_gstrings_stats[index].stat_string,
663 ETH_GSTRING_LEN);
664 }
665 break;
666 }
667}
668
669static int netxen_nic_get_stats_count(struct net_device *dev)
670{
671 return NETXEN_NIC_STATS_LEN;
672}
673
674static void
675netxen_nic_get_ethtool_stats(struct net_device *dev,
676 struct ethtool_stats *stats, u64 * data)
677{
678 struct netxen_port *port = netdev_priv(dev);
679 int index;
680
681 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
682 char *p =
683 (char *)port + netxen_nic_gstrings_stats[index].stat_offset;
684 data[index] =
685 (netxen_nic_gstrings_stats[index].sizeof_stat ==
686 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
687 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400688}
689
690struct ethtool_ops netxen_nic_ethtool_ops = {
691 .get_settings = netxen_nic_get_settings,
692 .set_settings = netxen_nic_set_settings,
693 .get_drvinfo = netxen_nic_get_drvinfo,
694 .get_regs_len = netxen_nic_get_regs_len,
695 .get_regs = netxen_nic_get_regs,
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800696 .get_link = ethtool_op_get_link,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400697 .get_eeprom_len = netxen_nic_get_eeprom_len,
698 .get_eeprom = netxen_nic_get_eeprom,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800699 .set_eeprom = netxen_nic_set_eeprom,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400700 .get_ringparam = netxen_nic_get_ringparam,
701 .get_pauseparam = netxen_nic_get_pauseparam,
702 .set_pauseparam = netxen_nic_set_pauseparam,
703 .get_tx_csum = ethtool_op_get_tx_csum,
704 .set_tx_csum = ethtool_op_set_tx_csum,
705 .get_sg = ethtool_op_get_sg,
706 .set_sg = ethtool_op_set_sg,
707 .get_tso = ethtool_op_get_tso,
708 .set_tso = ethtool_op_set_tso,
709 .self_test_count = netxen_nic_diag_test_count,
710 .self_test = netxen_nic_diag_test,
711 .get_strings = netxen_nic_get_strings,
712 .get_stats_count = netxen_nic_get_stats_count,
713 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
714 .get_perm_addr = ethtool_op_get_perm_addr,
715};