blob: 6252e9a8727854719cf2323fe5f5f61a867ea54f [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] = {
85 "Register_Test_offline", "EEPROM_Test_offline",
86 "Interrupt_Test_offline", "Loopback_Test_offline",
87 "Link_Test_on_offline"
88};
89
90#define NETXEN_NIC_TEST_LEN sizeof(netxen_nic_gstrings_test) / ETH_GSTRING_LEN
91
92#define NETXEN_NIC_REGS_COUNT 42
93#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
94#define NETXEN_MAX_EEPROM_LEN 1024
95
96static int netxen_nic_get_eeprom_len(struct net_device *dev)
97{
Amit S. Kale27d2ab52007-02-05 07:40:49 -080098 return FLASH_TOTAL_SIZE;
Amit S. Kale3d396eb2006-10-21 15:33:03 -040099}
100
101static void
102netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
103{
104 struct netxen_port *port = netdev_priv(dev);
105 struct netxen_adapter *adapter = port->adapter;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800106 u32 fw_major = 0;
107 u32 fw_minor = 0;
108 u32 fw_build = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400109
Amit S. Kale80922fb2006-12-04 09:18:00 -0800110 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400111 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
112 fw_major = readl(NETXEN_CRB_NORMALIZE(adapter,
113 NETXEN_FW_VERSION_MAJOR));
114 fw_minor = readl(NETXEN_CRB_NORMALIZE(adapter,
115 NETXEN_FW_VERSION_MINOR));
116 fw_build = readl(NETXEN_CRB_NORMALIZE(adapter, NETXEN_FW_VERSION_SUB));
117 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
118
119 strncpy(drvinfo->bus_info, pci_name(port->pdev), 32);
120 drvinfo->n_stats = NETXEN_NIC_STATS_LEN;
121 drvinfo->testinfo_len = NETXEN_NIC_TEST_LEN;
122 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
123 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
124}
125
126static int
127netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
128{
129 struct netxen_port *port = netdev_priv(dev);
130 struct netxen_adapter *adapter = port->adapter;
Amit S. Kale71bd7872006-12-01 05:36:22 -0800131 struct netxen_board_info *boardinfo = &adapter->ahw.boardcfg;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400132
133 /* read which mode */
134 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
135 ecmd->supported = (SUPPORTED_10baseT_Half |
136 SUPPORTED_10baseT_Full |
137 SUPPORTED_100baseT_Half |
138 SUPPORTED_100baseT_Full |
139 SUPPORTED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800140 SUPPORTED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400141
142 ecmd->advertising = (ADVERTISED_100baseT_Half |
143 ADVERTISED_100baseT_Full |
144 ADVERTISED_1000baseT_Half |
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800145 ADVERTISED_1000baseT_Full);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400146
147 ecmd->port = PORT_TP;
148
149 if (netif_running(dev)) {
150 ecmd->speed = port->link_speed;
151 ecmd->duplex = port->link_duplex;
152 } else
153 return -EIO; /* link absent */
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800154 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400155 ecmd->supported = (SUPPORTED_TP |
156 SUPPORTED_1000baseT_Full |
157 SUPPORTED_10000baseT_Full);
158 ecmd->advertising = (ADVERTISED_TP |
159 ADVERTISED_1000baseT_Full |
160 ADVERTISED_10000baseT_Full);
161 ecmd->port = PORT_TP;
162
163 ecmd->speed = SPEED_10000;
164 ecmd->duplex = DUPLEX_FULL;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400165 ecmd->autoneg = AUTONEG_DISABLE;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800166 } else
167 return -EIO;
168
169 ecmd->phy_address = port->portnum;
170 ecmd->transceiver = XCVR_EXTERNAL;
171
172 switch ((netxen_brdtype_t) boardinfo->board_type) {
173 case NETXEN_BRDTYPE_P2_SB35_4G:
174 case NETXEN_BRDTYPE_P2_SB31_2G:
175 ecmd->supported |= SUPPORTED_Autoneg;
176 ecmd->advertising |= ADVERTISED_Autoneg;
177 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
178 ecmd->supported |= SUPPORTED_TP;
179 ecmd->advertising |= ADVERTISED_TP;
180 ecmd->port = PORT_TP;
181 ecmd->autoneg = (boardinfo->board_type ==
182 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
183 (AUTONEG_DISABLE) : (port->link_autoneg);
184 break;
185 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
186 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
187 ecmd->supported |= SUPPORTED_MII;
188 ecmd->advertising |= ADVERTISED_MII;
189 ecmd->port = PORT_FIBRE;
190 ecmd->autoneg = AUTONEG_DISABLE;
191 break;
192 case NETXEN_BRDTYPE_P2_SB31_10G:
193 ecmd->supported |= SUPPORTED_FIBRE;
194 ecmd->advertising |= ADVERTISED_FIBRE;
195 ecmd->port = PORT_FIBRE;
196 ecmd->autoneg = AUTONEG_DISABLE;
197 break;
198 default:
Amit S. Kale71bd7872006-12-01 05:36:22 -0800199 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800200 (netxen_brdtype_t) boardinfo->board_type);
201 return -EIO;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400202 }
203
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800204 return 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400205}
206
207static int
208netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
209{
210 struct netxen_port *port = netdev_priv(dev);
211 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab9c2007-01-02 10:39:10 +0000212 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400213
214 /* read which mode */
215 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
216 /* autonegotiation */
Amit S. Kale80922fb2006-12-04 09:18:00 -0800217 if (adapter->phy_write
218 && adapter->phy_write(adapter, port->portnum,
219 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab9c2007-01-02 10:39:10 +0000220 ecmd->autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400221 return -EIO;
222 else
223 port->link_autoneg = ecmd->autoneg;
224
Amit S. Kale80922fb2006-12-04 09:18:00 -0800225 if (adapter->phy_read
226 && adapter->phy_read(adapter, port->portnum,
227 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
228 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400229 return -EIO;
230
231 /* speed */
232 switch (ecmd->speed) {
233 case SPEED_10:
234 netxen_set_phy_speed(status, 0);
235 break;
236 case SPEED_100:
237 netxen_set_phy_speed(status, 1);
238 break;
239 case SPEED_1000:
240 netxen_set_phy_speed(status, 2);
241 break;
242 }
243 /* set duplex mode */
244 if (ecmd->duplex == DUPLEX_HALF)
245 netxen_clear_phy_duplex(status);
246 if (ecmd->duplex == DUPLEX_FULL)
247 netxen_set_phy_duplex(status);
Amit S. Kale80922fb2006-12-04 09:18:00 -0800248 if (adapter->phy_write
249 && adapter->phy_write(adapter, port->portnum,
250 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
251 *((int *)&status)) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400252 return -EIO;
253 else {
254 port->link_speed = ecmd->speed;
255 port->link_duplex = ecmd->duplex;
256 }
257 } else
258 return -EOPNOTSUPP;
259
260 if (netif_running(dev)) {
261 dev->stop(dev);
262 dev->open(dev);
263 }
264 return 0;
265}
266
267static int netxen_nic_get_regs_len(struct net_device *dev)
268{
269 return NETXEN_NIC_REGS_LEN;
270}
271
272struct netxen_niu_regs {
Al Viroa608ab9c2007-01-02 10:39:10 +0000273 __u32 reg[NETXEN_NIC_REGS_COUNT];
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400274};
275
276static struct netxen_niu_regs niu_registers[] = {
277 {
278 /* GB Mode */
279 {
280 NETXEN_NIU_GB_SERDES_RESET,
281 NETXEN_NIU_GB0_MII_MODE,
282 NETXEN_NIU_GB1_MII_MODE,
283 NETXEN_NIU_GB2_MII_MODE,
284 NETXEN_NIU_GB3_MII_MODE,
285 NETXEN_NIU_GB0_GMII_MODE,
286 NETXEN_NIU_GB1_GMII_MODE,
287 NETXEN_NIU_GB2_GMII_MODE,
288 NETXEN_NIU_GB3_GMII_MODE,
289 NETXEN_NIU_REMOTE_LOOPBACK,
290 NETXEN_NIU_GB0_HALF_DUPLEX,
291 NETXEN_NIU_GB1_HALF_DUPLEX,
292 NETXEN_NIU_RESET_SYS_FIFOS,
293 NETXEN_NIU_GB_CRC_DROP,
294 NETXEN_NIU_GB_DROP_WRONGADDR,
295 NETXEN_NIU_TEST_MUX_CTL,
296
297 NETXEN_NIU_GB_MAC_CONFIG_0(0),
298 NETXEN_NIU_GB_MAC_CONFIG_1(0),
299 NETXEN_NIU_GB_HALF_DUPLEX_CTRL(0),
300 NETXEN_NIU_GB_MAX_FRAME_SIZE(0),
301 NETXEN_NIU_GB_TEST_REG(0),
302 NETXEN_NIU_GB_MII_MGMT_CONFIG(0),
303 NETXEN_NIU_GB_MII_MGMT_COMMAND(0),
304 NETXEN_NIU_GB_MII_MGMT_ADDR(0),
305 NETXEN_NIU_GB_MII_MGMT_CTRL(0),
306 NETXEN_NIU_GB_MII_MGMT_STATUS(0),
307 NETXEN_NIU_GB_MII_MGMT_INDICATE(0),
308 NETXEN_NIU_GB_INTERFACE_CTRL(0),
309 NETXEN_NIU_GB_INTERFACE_STATUS(0),
310 NETXEN_NIU_GB_STATION_ADDR_0(0),
311 NETXEN_NIU_GB_STATION_ADDR_1(0),
312 -1,
313 }
314 },
315 {
316 /* XG Mode */
317 {
318 NETXEN_NIU_XG_SINGLE_TERM,
319 NETXEN_NIU_XG_DRIVE_HI,
320 NETXEN_NIU_XG_DRIVE_LO,
321 NETXEN_NIU_XG_DTX,
322 NETXEN_NIU_XG_DEQ,
323 NETXEN_NIU_XG_WORD_ALIGN,
324 NETXEN_NIU_XG_RESET,
325 NETXEN_NIU_XG_POWER_DOWN,
326 NETXEN_NIU_XG_RESET_PLL,
327 NETXEN_NIU_XG_SERDES_LOOPBACK,
328 NETXEN_NIU_XG_DO_BYTE_ALIGN,
329 NETXEN_NIU_XG_TX_ENABLE,
330 NETXEN_NIU_XG_RX_ENABLE,
331 NETXEN_NIU_XG_STATUS,
332 NETXEN_NIU_XG_PAUSE_THRESHOLD,
333 NETXEN_NIU_XGE_CONFIG_0,
334 NETXEN_NIU_XGE_CONFIG_1,
335 NETXEN_NIU_XGE_IPG,
336 NETXEN_NIU_XGE_STATION_ADDR_0_HI,
337 NETXEN_NIU_XGE_STATION_ADDR_0_1,
338 NETXEN_NIU_XGE_STATION_ADDR_1_LO,
339 NETXEN_NIU_XGE_STATUS,
340 NETXEN_NIU_XGE_MAX_FRAME_SIZE,
341 NETXEN_NIU_XGE_PAUSE_FRAME_VALUE,
342 NETXEN_NIU_XGE_TX_BYTE_CNT,
343 NETXEN_NIU_XGE_TX_FRAME_CNT,
344 NETXEN_NIU_XGE_RX_BYTE_CNT,
345 NETXEN_NIU_XGE_RX_FRAME_CNT,
346 NETXEN_NIU_XGE_AGGR_ERROR_CNT,
347 NETXEN_NIU_XGE_MULTICAST_FRAME_CNT,
348 NETXEN_NIU_XGE_UNICAST_FRAME_CNT,
349 NETXEN_NIU_XGE_CRC_ERROR_CNT,
350 NETXEN_NIU_XGE_OVERSIZE_FRAME_ERR,
351 NETXEN_NIU_XGE_UNDERSIZE_FRAME_ERR,
352 NETXEN_NIU_XGE_LOCAL_ERROR_CNT,
353 NETXEN_NIU_XGE_REMOTE_ERROR_CNT,
354 NETXEN_NIU_XGE_CONTROL_CHAR_CNT,
355 NETXEN_NIU_XGE_PAUSE_FRAME_CNT,
356 -1,
357 }
358 }
359};
360
361static void
362netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
363{
364 struct netxen_port *port = netdev_priv(dev);
365 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab9c2007-01-02 10:39:10 +0000366 __u32 mode, *regs_buff = p;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400367 void __iomem *addr;
368 int i, window;
369
370 memset(p, 0, NETXEN_NIC_REGS_LEN);
371 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
372 (port->pdev)->device;
373 /* which mode */
374 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_MODE, &regs_buff[0]);
375 mode = regs_buff[0];
376
377 /* Common registers to all the modes */
378 NETXEN_NIC_LOCKED_READ_REG(NETXEN_NIU_STRAP_VALUE_SAVE_HIGHER,
379 &regs_buff[2]);
380 /* GB/XGB Mode */
381 mode = (mode / 2) - 1;
382 window = 0;
383 if (mode <= 1) {
384 for (i = 3; niu_registers[mode].reg[i - 3] != -1; i++) {
385 /* GB: port specific registers */
386 if (mode == 0 && i >= 19)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800387 window = port->portnum * NETXEN_NIC_PORT_WINDOW;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400388
389 NETXEN_NIC_LOCKED_READ_REG(niu_registers[mode].
390 reg[i - 3] + window,
391 &regs_buff[i]);
392 }
393
394 }
395}
396
397static void
398netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
399{
400 wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC;
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800401 /* options can be added depending upon the mode */
402 wol->wolopts = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400403}
404
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800405static u32 netxen_nic_test_link(struct net_device *dev)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400406{
407 struct netxen_port *port = netdev_priv(dev);
408 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab9c2007-01-02 10:39:10 +0000409 __u32 status;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400410
411 /* read which mode */
412 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
Amit S. Kale80922fb2006-12-04 09:18:00 -0800413 if (adapter->phy_read
414 && adapter->phy_read(adapter, port->portnum,
415 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
416 &status) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400417 return -EIO;
418 else
419 return (netxen_get_phy_link(status));
420 } else if (adapter->ahw.board_type == NETXEN_NIC_XGBE) {
421 int val = readl(NETXEN_CRB_NORMALIZE(adapter, CRB_XG_STATE));
422 return val == XG_LINK_UP;
423 }
424 return -EIO;
425}
426
427static int
428netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
429 u8 * bytes)
430{
431 struct netxen_port *port = netdev_priv(dev);
432 struct netxen_adapter *adapter = port->adapter;
433 int offset;
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800434 int ret;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400435
436 if (eeprom->len == 0)
437 return -EINVAL;
438
439 eeprom->magic = (port->pdev)->vendor | ((port->pdev)->device << 16);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800440 offset = eeprom->offset;
441
442 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
443 eeprom->len);
444 if (ret < 0)
445 return ret;
446
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400447 return 0;
448}
449
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800450static int
451netxen_nic_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
452 u8 * bytes)
453{
454 struct netxen_port *port = netdev_priv(dev);
455 struct netxen_adapter *adapter = port->adapter;
456 int offset = eeprom->offset;
457 static int flash_start;
458 static int ready_to_flash;
459 int ret;
460
461 if (flash_start == 0) {
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800462 netxen_halt_pegs(adapter);
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800463 ret = netxen_flash_unlock(adapter);
464 if (ret < 0) {
465 printk(KERN_ERR "%s: Flash unlock failed.\n",
466 netxen_nic_driver_name);
467 return ret;
468 }
469 printk(KERN_INFO "%s: flash unlocked. \n",
470 netxen_nic_driver_name);
471 ret = netxen_flash_erase_secondary(adapter);
472 if (ret != FLASH_SUCCESS) {
473 printk(KERN_ERR "%s: Flash erase failed.\n",
474 netxen_nic_driver_name);
475 return ret;
476 }
477 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
478 netxen_nic_driver_name);
479 flash_start = 1;
480 return 0;
481 }
482
483 if (offset == BOOTLD_START) {
484 ret = netxen_flash_erase_primary(adapter);
485 if (ret != FLASH_SUCCESS) {
486 printk(KERN_ERR "%s: Flash erase failed.\n",
487 netxen_nic_driver_name);
488 return ret;
489 }
490
491 ret = netxen_rom_se(adapter, USER_START);
492 if (ret != FLASH_SUCCESS)
493 return ret;
494 ret = netxen_rom_se(adapter, FIXED_START);
495 if (ret != FLASH_SUCCESS)
496 return ret;
497
498 printk(KERN_INFO "%s: primary flash erased successfully\n",
499 netxen_nic_driver_name);
500
501 ret = netxen_backup_crbinit(adapter);
502 if (ret != FLASH_SUCCESS) {
503 printk(KERN_ERR "%s: CRBinit backup failed.\n",
504 netxen_nic_driver_name);
505 return ret;
506 }
507 printk(KERN_INFO "%s: CRBinit backup done.\n",
508 netxen_nic_driver_name);
509 ready_to_flash = 1;
510 }
511
512 if (!ready_to_flash) {
513 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
514 netxen_nic_driver_name);
515 return -EINVAL;
516 }
517
518 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
519}
520
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400521static void
522netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
523{
524 struct netxen_port *port = netdev_priv(dev);
525 struct netxen_adapter *adapter = port->adapter;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800526 int i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400527
528 ring->rx_pending = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800529 ring->rx_jumbo_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400530 for (i = 0; i < MAX_RCV_CTX; ++i) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800531 ring->rx_pending += adapter->recv_ctx[i].
532 rcv_desc[RCV_DESC_NORMAL_CTXID].rcv_pending;
533 ring->rx_jumbo_pending += adapter->recv_ctx[i].
534 rcv_desc[RCV_DESC_JUMBO_CTXID].rcv_pending;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400535 }
536
537 ring->rx_max_pending = adapter->max_rx_desc_count;
538 ring->tx_max_pending = adapter->max_tx_desc_count;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800539 ring->rx_jumbo_max_pending = adapter->max_jumbo_rx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400540 ring->rx_mini_max_pending = 0;
541 ring->rx_mini_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400542 ring->rx_jumbo_pending = 0;
543}
544
545static void
546netxen_nic_get_pauseparam(struct net_device *dev,
547 struct ethtool_pauseparam *pause)
548{
549 struct netxen_port *port = netdev_priv(dev);
550 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab9c2007-01-02 10:39:10 +0000551 __u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400552
553 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
554 /* get flow control settings */
555 netxen_nic_read_w0(adapter,
556 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
Al Viroa608ab9c2007-01-02 10:39:10 +0000557 &val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400558 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
559 pause->tx_pause = netxen_gb_get_tx_flowctl(val);
560 /* get autoneg settings */
561 pause->autoneg = port->link_autoneg;
562 }
563}
564
565static int
566netxen_nic_set_pauseparam(struct net_device *dev,
567 struct ethtool_pauseparam *pause)
568{
569 struct netxen_port *port = netdev_priv(dev);
570 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab9c2007-01-02 10:39:10 +0000571 __u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400572 unsigned int autoneg;
573
574 /* read mode */
575 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
576 /* set flow control */
577 netxen_nic_read_w0(adapter,
578 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
579 (u32 *) & val);
580 if (pause->tx_pause)
581 netxen_gb_tx_flowctl(val);
582 else
583 netxen_gb_unset_tx_flowctl(val);
584 if (pause->rx_pause)
585 netxen_gb_rx_flowctl(val);
586 else
587 netxen_gb_unset_rx_flowctl(val);
588
589 netxen_nic_write_w0(adapter,
590 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
Al Viroa608ab9c2007-01-02 10:39:10 +0000591 *&val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400592 /* set autoneg */
593 autoneg = pause->autoneg;
Amit S. Kale80922fb2006-12-04 09:18:00 -0800594 if (adapter->phy_write
595 && adapter->phy_write(adapter, port->portnum,
596 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab9c2007-01-02 10:39:10 +0000597 autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400598 return -EIO;
599 else {
600 port->link_autoneg = pause->autoneg;
601 return 0;
602 }
603 } else
604 return -EOPNOTSUPP;
605}
606
607static int netxen_nic_reg_test(struct net_device *dev)
608{
609 struct netxen_port *port = netdev_priv(dev);
610 struct netxen_adapter *adapter = port->adapter;
611 u32 data_read, data_written, save;
Al Viroa608ab9c2007-01-02 10:39:10 +0000612 __u32 mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400613
614 /*
615 * first test the "Read Only" registers by writing which mode
616 */
617 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
618 if (netxen_get_niu_enable_ge(mode)) { /* GB Mode */
619 netxen_nic_read_w0(adapter,
620 NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum),
621 &data_read);
622
623 save = data_read;
624 if (data_read)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800625 data_written = data_read & NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400626 else
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800627 data_written = NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400628 netxen_nic_write_w0(adapter,
629 NETXEN_NIU_GB_MII_MGMT_STATUS(port->
630 portnum),
631 data_written);
632 netxen_nic_read_w0(adapter,
633 NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum),
634 &data_read);
635
636 if (data_written == data_read) {
637 netxen_nic_write_w0(adapter,
638 NETXEN_NIU_GB_MII_MGMT_STATUS(port->
639 portnum),
640 save);
641
642 return 0;
643 }
644
645 /* netxen_niu_gb_mii_mgmt_indicators is read only */
646 netxen_nic_read_w0(adapter,
647 NETXEN_NIU_GB_MII_MGMT_INDICATE(port->
648 portnum),
649 &data_read);
650
651 save = data_read;
652 if (data_read)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800653 data_written = data_read & NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400654 else
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800655 data_written = NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400656 netxen_nic_write_w0(adapter,
657 NETXEN_NIU_GB_MII_MGMT_INDICATE(port->
658 portnum),
659 data_written);
660
661 netxen_nic_read_w0(adapter,
662 NETXEN_NIU_GB_MII_MGMT_INDICATE(port->
663 portnum),
664 &data_read);
665
666 if (data_written == data_read) {
667 netxen_nic_write_w0(adapter,
668 NETXEN_NIU_GB_MII_MGMT_INDICATE
669 (port->portnum), save);
670 return 0;
671 }
672
673 /* netxen_niu_gb_interface_status is read only */
674 netxen_nic_read_w0(adapter,
675 NETXEN_NIU_GB_INTERFACE_STATUS(port->
676 portnum),
677 &data_read);
678
679 save = data_read;
680 if (data_read)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800681 data_written = data_read & NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400682 else
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800683 data_written = NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400684 netxen_nic_write_w0(adapter,
685 NETXEN_NIU_GB_INTERFACE_STATUS(port->
686 portnum),
687 data_written);
688
689 netxen_nic_read_w0(adapter,
690 NETXEN_NIU_GB_INTERFACE_STATUS(port->
691 portnum),
692 &data_read);
693
694 if (data_written == data_read) {
695 netxen_nic_write_w0(adapter,
696 NETXEN_NIU_GB_INTERFACE_STATUS
697 (port->portnum), save);
698
699 return 0;
700 }
701 } /* GB Mode */
702 return 1;
703}
704
705static int netxen_nic_diag_test_count(struct net_device *dev)
706{
707 return NETXEN_NIC_TEST_LEN;
708}
709
710static void
711netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
712 u64 * data)
713{
714 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */
715 /* link test */
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800716 if (!(data[4] = (u64) netxen_nic_test_link(dev)))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400717 eth_test->flags |= ETH_TEST_FL_FAILED;
718
719 if (netif_running(dev))
720 dev->stop(dev);
721
722 /* register tests */
723 if (!(data[0] = netxen_nic_reg_test(dev)))
724 eth_test->flags |= ETH_TEST_FL_FAILED;
725 /* other tests pass as of now */
726 data[1] = data[2] = data[3] = 1;
727 if (netif_running(dev))
728 dev->open(dev);
729 } else { /* online tests */
730 /* link test */
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800731 if (!(data[4] = (u64) netxen_nic_test_link(dev)))
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400732 eth_test->flags |= ETH_TEST_FL_FAILED;
733
734 /* other tests pass by default */
735 data[0] = data[1] = data[2] = data[3] = 1;
736 }
737}
738
739static void
740netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
741{
742 int index;
743
744 switch (stringset) {
745 case ETH_SS_TEST:
746 memcpy(data, *netxen_nic_gstrings_test,
747 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
748 break;
749 case ETH_SS_STATS:
750 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
751 memcpy(data + index * ETH_GSTRING_LEN,
752 netxen_nic_gstrings_stats[index].stat_string,
753 ETH_GSTRING_LEN);
754 }
755 break;
756 }
757}
758
759static int netxen_nic_get_stats_count(struct net_device *dev)
760{
761 return NETXEN_NIC_STATS_LEN;
762}
763
764static void
765netxen_nic_get_ethtool_stats(struct net_device *dev,
766 struct ethtool_stats *stats, u64 * data)
767{
768 struct netxen_port *port = netdev_priv(dev);
769 int index;
770
771 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
772 char *p =
773 (char *)port + netxen_nic_gstrings_stats[index].stat_offset;
774 data[index] =
775 (netxen_nic_gstrings_stats[index].sizeof_stat ==
776 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
777 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400778}
779
780struct ethtool_ops netxen_nic_ethtool_ops = {
781 .get_settings = netxen_nic_get_settings,
782 .set_settings = netxen_nic_set_settings,
783 .get_drvinfo = netxen_nic_get_drvinfo,
784 .get_regs_len = netxen_nic_get_regs_len,
785 .get_regs = netxen_nic_get_regs,
786 .get_wol = netxen_nic_get_wol,
Amit S. Kalee45d9ab2007-02-09 05:49:08 -0800787 .get_link = ethtool_op_get_link,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400788 .get_eeprom_len = netxen_nic_get_eeprom_len,
789 .get_eeprom = netxen_nic_get_eeprom,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800790 .set_eeprom = netxen_nic_set_eeprom,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400791 .get_ringparam = netxen_nic_get_ringparam,
792 .get_pauseparam = netxen_nic_get_pauseparam,
793 .set_pauseparam = netxen_nic_set_pauseparam,
794 .get_tx_csum = ethtool_op_get_tx_csum,
795 .set_tx_csum = ethtool_op_set_tx_csum,
796 .get_sg = ethtool_op_get_sg,
797 .set_sg = ethtool_op_set_sg,
798 .get_tso = ethtool_op_get_tso,
799 .set_tso = ethtool_op_set_tso,
800 .self_test_count = netxen_nic_diag_test_count,
801 .self_test = netxen_nic_diag_test,
802 .get_strings = netxen_nic_get_strings,
803 .get_stats_count = netxen_nic_get_stats_count,
804 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
805 .get_perm_addr = ethtool_op_get_perm_addr,
806};