blob: cc0efe213e01f84b95af13e4bbf81dceb3c02a47 [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
405static u32 netxen_nic_get_link(struct net_device *dev)
406{
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) {
462 ret = netxen_flash_unlock(adapter);
463 if (ret < 0) {
464 printk(KERN_ERR "%s: Flash unlock failed.\n",
465 netxen_nic_driver_name);
466 return ret;
467 }
468 printk(KERN_INFO "%s: flash unlocked. \n",
469 netxen_nic_driver_name);
470 ret = netxen_flash_erase_secondary(adapter);
471 if (ret != FLASH_SUCCESS) {
472 printk(KERN_ERR "%s: Flash erase failed.\n",
473 netxen_nic_driver_name);
474 return ret;
475 }
476 printk(KERN_INFO "%s: secondary flash erased successfully.\n",
477 netxen_nic_driver_name);
478 flash_start = 1;
479 return 0;
480 }
481
482 if (offset == BOOTLD_START) {
483 ret = netxen_flash_erase_primary(adapter);
484 if (ret != FLASH_SUCCESS) {
485 printk(KERN_ERR "%s: Flash erase failed.\n",
486 netxen_nic_driver_name);
487 return ret;
488 }
489
490 ret = netxen_rom_se(adapter, USER_START);
491 if (ret != FLASH_SUCCESS)
492 return ret;
493 ret = netxen_rom_se(adapter, FIXED_START);
494 if (ret != FLASH_SUCCESS)
495 return ret;
496
497 printk(KERN_INFO "%s: primary flash erased successfully\n",
498 netxen_nic_driver_name);
499
500 ret = netxen_backup_crbinit(adapter);
501 if (ret != FLASH_SUCCESS) {
502 printk(KERN_ERR "%s: CRBinit backup failed.\n",
503 netxen_nic_driver_name);
504 return ret;
505 }
506 printk(KERN_INFO "%s: CRBinit backup done.\n",
507 netxen_nic_driver_name);
508 ready_to_flash = 1;
509 }
510
511 if (!ready_to_flash) {
512 printk(KERN_ERR "%s: Invalid write sequence, returning...\n",
513 netxen_nic_driver_name);
514 return -EINVAL;
515 }
516
517 return netxen_rom_fast_write_words(adapter, offset, bytes, eeprom->len);
518}
519
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400520static void
521netxen_nic_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
522{
523 struct netxen_port *port = netdev_priv(dev);
524 struct netxen_adapter *adapter = port->adapter;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800525 int i;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400526
527 ring->rx_pending = 0;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800528 ring->rx_jumbo_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400529 for (i = 0; i < MAX_RCV_CTX; ++i) {
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800530 ring->rx_pending += adapter->recv_ctx[i].
531 rcv_desc[RCV_DESC_NORMAL_CTXID].rcv_pending;
532 ring->rx_jumbo_pending += adapter->recv_ctx[i].
533 rcv_desc[RCV_DESC_JUMBO_CTXID].rcv_pending;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400534 }
535
536 ring->rx_max_pending = adapter->max_rx_desc_count;
537 ring->tx_max_pending = adapter->max_tx_desc_count;
Amit S. Kaleed25ffa2006-12-04 09:23:25 -0800538 ring->rx_jumbo_max_pending = adapter->max_jumbo_rx_desc_count;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400539 ring->rx_mini_max_pending = 0;
540 ring->rx_mini_pending = 0;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400541 ring->rx_jumbo_pending = 0;
542}
543
544static void
545netxen_nic_get_pauseparam(struct net_device *dev,
546 struct ethtool_pauseparam *pause)
547{
548 struct netxen_port *port = netdev_priv(dev);
549 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab9c2007-01-02 10:39:10 +0000550 __u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400551
552 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
553 /* get flow control settings */
554 netxen_nic_read_w0(adapter,
555 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
Al Viroa608ab9c2007-01-02 10:39:10 +0000556 &val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400557 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
558 pause->tx_pause = netxen_gb_get_tx_flowctl(val);
559 /* get autoneg settings */
560 pause->autoneg = port->link_autoneg;
561 }
562}
563
564static int
565netxen_nic_set_pauseparam(struct net_device *dev,
566 struct ethtool_pauseparam *pause)
567{
568 struct netxen_port *port = netdev_priv(dev);
569 struct netxen_adapter *adapter = port->adapter;
Al Viroa608ab9c2007-01-02 10:39:10 +0000570 __u32 val;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400571 unsigned int autoneg;
572
573 /* read mode */
574 if (adapter->ahw.board_type == NETXEN_NIC_GBE) {
575 /* set flow control */
576 netxen_nic_read_w0(adapter,
577 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
578 (u32 *) & val);
579 if (pause->tx_pause)
580 netxen_gb_tx_flowctl(val);
581 else
582 netxen_gb_unset_tx_flowctl(val);
583 if (pause->rx_pause)
584 netxen_gb_rx_flowctl(val);
585 else
586 netxen_gb_unset_rx_flowctl(val);
587
588 netxen_nic_write_w0(adapter,
589 NETXEN_NIU_GB_MAC_CONFIG_0(port->portnum),
Al Viroa608ab9c2007-01-02 10:39:10 +0000590 *&val);
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400591 /* set autoneg */
592 autoneg = pause->autoneg;
Amit S. Kale80922fb2006-12-04 09:18:00 -0800593 if (adapter->phy_write
594 && adapter->phy_write(adapter, port->portnum,
595 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
Al Viroa608ab9c2007-01-02 10:39:10 +0000596 autoneg) != 0)
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400597 return -EIO;
598 else {
599 port->link_autoneg = pause->autoneg;
600 return 0;
601 }
602 } else
603 return -EOPNOTSUPP;
604}
605
606static int netxen_nic_reg_test(struct net_device *dev)
607{
608 struct netxen_port *port = netdev_priv(dev);
609 struct netxen_adapter *adapter = port->adapter;
610 u32 data_read, data_written, save;
Al Viroa608ab9c2007-01-02 10:39:10 +0000611 __u32 mode;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400612
613 /*
614 * first test the "Read Only" registers by writing which mode
615 */
616 netxen_nic_read_w0(adapter, NETXEN_NIU_MODE, &mode);
617 if (netxen_get_niu_enable_ge(mode)) { /* GB Mode */
618 netxen_nic_read_w0(adapter,
619 NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum),
620 &data_read);
621
622 save = data_read;
623 if (data_read)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800624 data_written = data_read & NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400625 else
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800626 data_written = NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400627 netxen_nic_write_w0(adapter,
628 NETXEN_NIU_GB_MII_MGMT_STATUS(port->
629 portnum),
630 data_written);
631 netxen_nic_read_w0(adapter,
632 NETXEN_NIU_GB_MII_MGMT_STATUS(port->portnum),
633 &data_read);
634
635 if (data_written == data_read) {
636 netxen_nic_write_w0(adapter,
637 NETXEN_NIU_GB_MII_MGMT_STATUS(port->
638 portnum),
639 save);
640
641 return 0;
642 }
643
644 /* netxen_niu_gb_mii_mgmt_indicators is read only */
645 netxen_nic_read_w0(adapter,
646 NETXEN_NIU_GB_MII_MGMT_INDICATE(port->
647 portnum),
648 &data_read);
649
650 save = data_read;
651 if (data_read)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800652 data_written = data_read & NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400653 else
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800654 data_written = NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400655 netxen_nic_write_w0(adapter,
656 NETXEN_NIU_GB_MII_MGMT_INDICATE(port->
657 portnum),
658 data_written);
659
660 netxen_nic_read_w0(adapter,
661 NETXEN_NIU_GB_MII_MGMT_INDICATE(port->
662 portnum),
663 &data_read);
664
665 if (data_written == data_read) {
666 netxen_nic_write_w0(adapter,
667 NETXEN_NIU_GB_MII_MGMT_INDICATE
668 (port->portnum), save);
669 return 0;
670 }
671
672 /* netxen_niu_gb_interface_status is read only */
673 netxen_nic_read_w0(adapter,
674 NETXEN_NIU_GB_INTERFACE_STATUS(port->
675 portnum),
676 &data_read);
677
678 save = data_read;
679 if (data_read)
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800680 data_written = data_read & NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400681 else
Amit S. Kalecb8011a2006-11-29 09:00:10 -0800682 data_written = NETXEN_NIC_INVALID_DATA;
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400683 netxen_nic_write_w0(adapter,
684 NETXEN_NIU_GB_INTERFACE_STATUS(port->
685 portnum),
686 data_written);
687
688 netxen_nic_read_w0(adapter,
689 NETXEN_NIU_GB_INTERFACE_STATUS(port->
690 portnum),
691 &data_read);
692
693 if (data_written == data_read) {
694 netxen_nic_write_w0(adapter,
695 NETXEN_NIU_GB_INTERFACE_STATUS
696 (port->portnum), save);
697
698 return 0;
699 }
700 } /* GB Mode */
701 return 1;
702}
703
704static int netxen_nic_diag_test_count(struct net_device *dev)
705{
706 return NETXEN_NIC_TEST_LEN;
707}
708
709static void
710netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
711 u64 * data)
712{
713 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { /* offline tests */
714 /* link test */
715 if (!(data[4] = (u64) netxen_nic_get_link(dev)))
716 eth_test->flags |= ETH_TEST_FL_FAILED;
717
718 if (netif_running(dev))
719 dev->stop(dev);
720
721 /* register tests */
722 if (!(data[0] = netxen_nic_reg_test(dev)))
723 eth_test->flags |= ETH_TEST_FL_FAILED;
724 /* other tests pass as of now */
725 data[1] = data[2] = data[3] = 1;
726 if (netif_running(dev))
727 dev->open(dev);
728 } else { /* online tests */
729 /* link test */
730 if (!(data[4] = (u64) netxen_nic_get_link(dev)))
731 eth_test->flags |= ETH_TEST_FL_FAILED;
732
733 /* other tests pass by default */
734 data[0] = data[1] = data[2] = data[3] = 1;
735 }
736}
737
738static void
739netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
740{
741 int index;
742
743 switch (stringset) {
744 case ETH_SS_TEST:
745 memcpy(data, *netxen_nic_gstrings_test,
746 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
747 break;
748 case ETH_SS_STATS:
749 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
750 memcpy(data + index * ETH_GSTRING_LEN,
751 netxen_nic_gstrings_stats[index].stat_string,
752 ETH_GSTRING_LEN);
753 }
754 break;
755 }
756}
757
758static int netxen_nic_get_stats_count(struct net_device *dev)
759{
760 return NETXEN_NIC_STATS_LEN;
761}
762
763static void
764netxen_nic_get_ethtool_stats(struct net_device *dev,
765 struct ethtool_stats *stats, u64 * data)
766{
767 struct netxen_port *port = netdev_priv(dev);
768 int index;
769
770 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
771 char *p =
772 (char *)port + netxen_nic_gstrings_stats[index].stat_offset;
773 data[index] =
774 (netxen_nic_gstrings_stats[index].sizeof_stat ==
775 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
776 }
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400777}
778
779struct ethtool_ops netxen_nic_ethtool_ops = {
780 .get_settings = netxen_nic_get_settings,
781 .set_settings = netxen_nic_set_settings,
782 .get_drvinfo = netxen_nic_get_drvinfo,
783 .get_regs_len = netxen_nic_get_regs_len,
784 .get_regs = netxen_nic_get_regs,
785 .get_wol = netxen_nic_get_wol,
786 .get_link = netxen_nic_get_link,
787 .get_eeprom_len = netxen_nic_get_eeprom_len,
788 .get_eeprom = netxen_nic_get_eeprom,
Amit S. Kale27d2ab52007-02-05 07:40:49 -0800789 .set_eeprom = netxen_nic_set_eeprom,
Amit S. Kale3d396eb2006-10-21 15:33:03 -0400790 .get_ringparam = netxen_nic_get_ringparam,
791 .get_pauseparam = netxen_nic_get_pauseparam,
792 .set_pauseparam = netxen_nic_set_pauseparam,
793 .get_tx_csum = ethtool_op_get_tx_csum,
794 .set_tx_csum = ethtool_op_set_tx_csum,
795 .get_sg = ethtool_op_get_sg,
796 .set_sg = ethtool_op_set_sg,
797 .get_tso = ethtool_op_get_tso,
798 .set_tso = ethtool_op_set_tso,
799 .self_test_count = netxen_nic_diag_test_count,
800 .self_test = netxen_nic_diag_test,
801 .get_strings = netxen_nic_get_strings,
802 .get_stats_count = netxen_nic_get_stats_count,
803 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
804 .get_perm_addr = ethtool_op_get_perm_addr,
805};