]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/net/netxen/netxen_nic_ethtool.c
netxen: fix ethtool link test
[net-next-2.6.git] / drivers / net / netxen / netxen_nic_ethtool.c
CommitLineData
3d396eb1 1/*
5d242f1c 2 * Copyright (C) 2003 - 2009 NetXen, Inc.
13af7a6e 3 * Copyright (C) 2009 - QLogic Corporation.
3d396eb1 4 * All rights reserved.
80922fbc 5 *
3d396eb1
AK
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
80922fbc 10 *
3d396eb1
AK
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
80922fbc 15 *
3d396eb1
AK
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19 * MA 02111-1307, USA.
80922fbc 20 *
3d396eb1
AK
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.
80922fbc 23 *
3d396eb1
AK
24 */
25
26#include <linux/types.h>
27d2ab54 27#include <linux/delay.h>
3d396eb1
AK
28#include <linux/pci.h>
29#include <asm/io.h>
30#include <linux/netdevice.h>
31#include <linux/ethtool.h>
3d396eb1 32
3d396eb1 33#include "netxen_nic.h"
6c80b18d 34#include "netxen_nic_hw.h"
3d396eb1
AK
35
36struct netxen_nic_stats {
37 char stat_string[ETH_GSTRING_LEN];
38 int sizeof_stat;
39 int stat_offset;
40};
41
3176ff3e
MT
42#define NETXEN_NIC_STAT(m) sizeof(((struct netxen_adapter *)0)->m), \
43 offsetof(struct netxen_adapter, m)
3d396eb1 44
cb8011ad
AK
45#define NETXEN_NIC_PORT_WINDOW 0x10000
46#define NETXEN_NIC_INVALID_DATA 0xDEADBEEF
47
3d396eb1 48static const struct netxen_nic_stats netxen_nic_gstrings_stats[] = {
3d396eb1 49 {"xmit_called", NETXEN_NIC_STAT(stats.xmitcalled)},
3d396eb1 50 {"xmit_finished", NETXEN_NIC_STAT(stats.xmitfinished)},
e98e3350 51 {"rx_dropped", NETXEN_NIC_STAT(stats.rxdropped)},
3d396eb1 52 {"tx_dropped", NETXEN_NIC_STAT(stats.txdropped)},
3d396eb1 53 {"csummed", NETXEN_NIC_STAT(stats.csummed)},
1bb482f8
NK
54 {"rx_pkts", NETXEN_NIC_STAT(stats.rx_pkts)},
55 {"lro_pkts", NETXEN_NIC_STAT(stats.lro_pkts)},
3d396eb1
AK
56 {"rx_bytes", NETXEN_NIC_STAT(stats.rxbytes)},
57 {"tx_bytes", NETXEN_NIC_STAT(stats.txbytes)},
58};
59
92104e94 60#define NETXEN_NIC_STATS_LEN ARRAY_SIZE(netxen_nic_gstrings_stats)
3d396eb1
AK
61
62static const char netxen_nic_gstrings_test[][ETH_GSTRING_LEN] = {
0c25cfe1 63 "Register_Test_on_offline",
3d396eb1
AK
64 "Link_Test_on_offline"
65};
66
4c3616cd 67#define NETXEN_NIC_TEST_LEN ARRAY_SIZE(netxen_nic_gstrings_test)
3d396eb1 68
2d2cf346 69#define NETXEN_NIC_REGS_COUNT 30
3d396eb1
AK
70#define NETXEN_NIC_REGS_LEN (NETXEN_NIC_REGS_COUNT * sizeof(__le32))
71#define NETXEN_MAX_EEPROM_LEN 1024
72
73static int netxen_nic_get_eeprom_len(struct net_device *dev)
74{
0d04761d 75 return NETXEN_FLASH_TOTAL_SIZE;
3d396eb1
AK
76}
77
78static void
79netxen_nic_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
80{
3176ff3e 81 struct netxen_adapter *adapter = netdev_priv(dev);
cb8011ad
AK
82 u32 fw_major = 0;
83 u32 fw_minor = 0;
84 u32 fw_build = 0;
3d396eb1 85
80922fbc 86 strncpy(drvinfo->driver, netxen_nic_driver_name, 32);
3d396eb1 87 strncpy(drvinfo->version, NETXEN_NIC_LINUX_VERSIONID, 32);
f98a9f69
DP
88 fw_major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR);
89 fw_minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR);
90 fw_build = NXRD32(adapter, NETXEN_FW_VERSION_SUB);
3d396eb1
AK
91 sprintf(drvinfo->fw_version, "%d.%d.%d", fw_major, fw_minor, fw_build);
92
3176ff3e 93 strncpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
3d396eb1
AK
94 drvinfo->regdump_len = NETXEN_NIC_REGS_LEN;
95 drvinfo->eedump_len = netxen_nic_get_eeprom_len(dev);
96}
97
98static int
99netxen_nic_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
100{
3176ff3e 101 struct netxen_adapter *adapter = netdev_priv(dev);
3bf26ce3 102 int check_sfp_module = 0;
3d396eb1
AK
103
104 /* read which mode */
1e2d0059 105 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
3d396eb1
AK
106 ecmd->supported = (SUPPORTED_10baseT_Half |
107 SUPPORTED_10baseT_Full |
108 SUPPORTED_100baseT_Half |
109 SUPPORTED_100baseT_Full |
110 SUPPORTED_1000baseT_Half |
cb8011ad 111 SUPPORTED_1000baseT_Full);
3d396eb1
AK
112
113 ecmd->advertising = (ADVERTISED_100baseT_Half |
114 ADVERTISED_100baseT_Full |
115 ADVERTISED_1000baseT_Half |
cb8011ad 116 ADVERTISED_1000baseT_Full);
3d396eb1
AK
117
118 ecmd->port = PORT_TP;
119
c7860a2a
DP
120 ecmd->speed = adapter->link_speed;
121 ecmd->duplex = adapter->link_duplex;
122 ecmd->autoneg = adapter->link_autoneg;
24a7a455 123
1e2d0059 124 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
24a7a455
DP
125 u32 val;
126
f98a9f69 127 val = NXRD32(adapter, NETXEN_PORT_MODE_ADDR);
24a7a455
DP
128 if (val == NETXEN_PORT_MODE_802_3_AP) {
129 ecmd->supported = SUPPORTED_1000baseT_Full;
130 ecmd->advertising = ADVERTISED_1000baseT_Full;
131 } else {
132 ecmd->supported = SUPPORTED_10000baseT_Full;
133 ecmd->advertising = ADVERTISED_10000baseT_Full;
134 }
135
3bf26ce3
DP
136 if (netif_running(dev) && adapter->has_link_events) {
137 ecmd->speed = adapter->link_speed;
138 ecmd->autoneg = adapter->link_autoneg;
139 ecmd->duplex = adapter->link_duplex;
140 goto skip;
141 }
142
3d396eb1
AK
143 ecmd->port = PORT_TP;
144
24a7a455
DP
145 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
146 u16 pcifn = adapter->ahw.pci_func;
147
f98a9f69 148 val = NXRD32(adapter, P3_LINK_SPEED_REG(pcifn));
24a7a455
DP
149 ecmd->speed = P3_LINK_SPEED_MHZ *
150 P3_LINK_SPEED_VAL(pcifn, val);
151 } else
152 ecmd->speed = SPEED_10000;
153
3d396eb1 154 ecmd->duplex = DUPLEX_FULL;
3d396eb1 155 ecmd->autoneg = AUTONEG_DISABLE;
cb8011ad
AK
156 } else
157 return -EIO;
158
3bf26ce3 159skip:
c7860a2a 160 ecmd->phy_address = adapter->physical_port;
cb8011ad
AK
161 ecmd->transceiver = XCVR_EXTERNAL;
162
e98e3350 163 switch (adapter->ahw.board_type) {
cb8011ad
AK
164 case NETXEN_BRDTYPE_P2_SB35_4G:
165 case NETXEN_BRDTYPE_P2_SB31_2G:
e4c93c81
DP
166 case NETXEN_BRDTYPE_P3_REF_QG:
167 case NETXEN_BRDTYPE_P3_4_GB:
168 case NETXEN_BRDTYPE_P3_4_GB_MM:
e4c93c81 169
cb8011ad
AK
170 ecmd->supported |= SUPPORTED_Autoneg;
171 ecmd->advertising |= ADVERTISED_Autoneg;
172 case NETXEN_BRDTYPE_P2_SB31_10G_CX4:
e4c93c81
DP
173 case NETXEN_BRDTYPE_P3_10G_CX4:
174 case NETXEN_BRDTYPE_P3_10G_CX4_LP:
c7860a2a 175 case NETXEN_BRDTYPE_P3_10000_BASE_T:
cb8011ad
AK
176 ecmd->supported |= SUPPORTED_TP;
177 ecmd->advertising |= ADVERTISED_TP;
178 ecmd->port = PORT_TP;
1e2d0059 179 ecmd->autoneg = (adapter->ahw.board_type ==
cb8011ad 180 NETXEN_BRDTYPE_P2_SB31_10G_CX4) ?
3176ff3e 181 (AUTONEG_DISABLE) : (adapter->link_autoneg);
cb8011ad
AK
182 break;
183 case NETXEN_BRDTYPE_P2_SB31_10G_HMEZ:
184 case NETXEN_BRDTYPE_P2_SB31_10G_IMEZ:
e4c93c81
DP
185 case NETXEN_BRDTYPE_P3_IMEZ:
186 case NETXEN_BRDTYPE_P3_XG_LOM:
187 case NETXEN_BRDTYPE_P3_HMEZ:
cb8011ad
AK
188 ecmd->supported |= SUPPORTED_MII;
189 ecmd->advertising |= ADVERTISED_MII;
3bf26ce3 190 ecmd->port = PORT_MII;
cb8011ad
AK
191 ecmd->autoneg = AUTONEG_DISABLE;
192 break;
e4c93c81 193 case NETXEN_BRDTYPE_P3_10G_SFP_PLUS:
a70f9393
DP
194 case NETXEN_BRDTYPE_P3_10G_SFP_CT:
195 case NETXEN_BRDTYPE_P3_10G_SFP_QT:
c7860a2a
DP
196 ecmd->advertising |= ADVERTISED_TP;
197 ecmd->supported |= SUPPORTED_TP;
3bf26ce3
DP
198 check_sfp_module = netif_running(dev) &&
199 adapter->has_link_events;
c7860a2a 200 case NETXEN_BRDTYPE_P2_SB31_10G:
e4c93c81 201 case NETXEN_BRDTYPE_P3_10G_XFP:
cb8011ad
AK
202 ecmd->supported |= SUPPORTED_FIBRE;
203 ecmd->advertising |= ADVERTISED_FIBRE;
204 ecmd->port = PORT_FIBRE;
205 ecmd->autoneg = AUTONEG_DISABLE;
206 break;
c7860a2a 207 case NETXEN_BRDTYPE_P3_10G_TP:
1e2d0059 208 if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
c7860a2a
DP
209 ecmd->autoneg = AUTONEG_DISABLE;
210 ecmd->supported |= (SUPPORTED_FIBRE | SUPPORTED_TP);
211 ecmd->advertising |=
212 (ADVERTISED_FIBRE | ADVERTISED_TP);
213 ecmd->port = PORT_FIBRE;
3bf26ce3
DP
214 check_sfp_module = netif_running(dev) &&
215 adapter->has_link_events;
c7860a2a
DP
216 } else {
217 ecmd->autoneg = AUTONEG_ENABLE;
218 ecmd->supported |= (SUPPORTED_TP |SUPPORTED_Autoneg);
219 ecmd->advertising |=
220 (ADVERTISED_TP | ADVERTISED_Autoneg);
221 ecmd->port = PORT_TP;
222 }
223 break;
cb8011ad 224 default:
71bd7877 225 printk(KERN_ERR "netxen-nic: Unsupported board model %d\n",
e98e3350 226 adapter->ahw.board_type);
cb8011ad 227 return -EIO;
3d396eb1
AK
228 }
229
3bf26ce3
DP
230 if (check_sfp_module) {
231 switch (adapter->module_type) {
232 case LINKEVENT_MODULE_OPTICAL_UNKNOWN:
233 case LINKEVENT_MODULE_OPTICAL_SRLR:
234 case LINKEVENT_MODULE_OPTICAL_LRM:
235 case LINKEVENT_MODULE_OPTICAL_SFP_1G:
236 ecmd->port = PORT_FIBRE;
237 break;
238 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE:
239 case LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN:
240 case LINKEVENT_MODULE_TWINAX:
241 ecmd->port = PORT_TP;
5103c9f7 242 break;
3bf26ce3
DP
243 default:
244 ecmd->port = -1;
245 }
246 }
247
cb8011ad 248 return 0;
3d396eb1
AK
249}
250
251static int
252netxen_nic_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
253{
3176ff3e 254 struct netxen_adapter *adapter = netdev_priv(dev);
a608ab9c 255 __u32 status;
3d396eb1
AK
256
257 /* read which mode */
1e2d0059 258 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
3d396eb1 259 /* autonegotiation */
8e95a202
JP
260 if (adapter->phy_write &&
261 adapter->phy_write(adapter,
262 NETXEN_NIU_GB_MII_MGMT_ADDR_AUTONEG,
263 ecmd->autoneg) != 0)
3d396eb1
AK
264 return -EIO;
265 else
3176ff3e 266 adapter->link_autoneg = ecmd->autoneg;
3d396eb1 267
8e95a202
JP
268 if (adapter->phy_read &&
269 adapter->phy_read(adapter,
270 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
271 &status) != 0)
3d396eb1
AK
272 return -EIO;
273
274 /* speed */
275 switch (ecmd->speed) {
276 case SPEED_10:
277 netxen_set_phy_speed(status, 0);
278 break;
279 case SPEED_100:
280 netxen_set_phy_speed(status, 1);
281 break;
282 case SPEED_1000:
283 netxen_set_phy_speed(status, 2);
284 break;
285 }
286 /* set duplex mode */
287 if (ecmd->duplex == DUPLEX_HALF)
288 netxen_clear_phy_duplex(status);
289 if (ecmd->duplex == DUPLEX_FULL)
290 netxen_set_phy_duplex(status);
8e95a202
JP
291 if (adapter->phy_write &&
292 adapter->phy_write(adapter,
293 NETXEN_NIU_GB_MII_MGMT_ADDR_PHY_STATUS,
294 *((int *)&status)) != 0)
3d396eb1
AK
295 return -EIO;
296 else {
3176ff3e
MT
297 adapter->link_speed = ecmd->speed;
298 adapter->link_duplex = ecmd->duplex;
3d396eb1
AK
299 }
300 } else
301 return -EOPNOTSUPP;
302
1abd266f
SH
303 if (!netif_running(dev))
304 return 0;
305
306 dev->netdev_ops->ndo_stop(dev);
307 return dev->netdev_ops->ndo_open(dev);
3d396eb1
AK
308}
309
310static int netxen_nic_get_regs_len(struct net_device *dev)
311{
312 return NETXEN_NIC_REGS_LEN;
313}
314
3d396eb1
AK
315static void
316netxen_nic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
317{
3176ff3e 318 struct netxen_adapter *adapter = netdev_priv(dev);
2d2cf346
SC
319 struct netxen_recv_context *recv_ctx = &adapter->recv_ctx;
320 struct nx_host_sds_ring *sds_ring;
321 u32 *regs_buff = p;
322 int ring, i = 0;
323 int port = adapter->physical_port;
3d396eb1
AK
324
325 memset(p, 0, NETXEN_NIC_REGS_LEN);
2d2cf346 326
3d396eb1 327 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) |
3176ff3e 328 (adapter->pdev)->device;
3d396eb1 329
2d2cf346
SC
330 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
331 return;
332
333 regs_buff[i++] = NXRD32(adapter, CRB_CMDPEG_STATE);
334 regs_buff[i++] = NXRD32(adapter, CRB_RCVPEG_STATE);
335 regs_buff[i++] = NXRD32(adapter, CRB_FW_CAPABILITIES_1);
336 regs_buff[i++] = NXRDIO(adapter, adapter->crb_int_state_reg);
337 regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_REF_COUNT);
338 regs_buff[i++] = NXRD32(adapter, NX_CRB_DEV_STATE);
339 regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER);
340 regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS1);
341 regs_buff[i++] = NXRD32(adapter, NETXEN_PEG_HALT_STATUS2);
342
343 regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_0+0x3c);
344 regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_1+0x3c);
345 regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_2+0x3c);
346 regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_3+0x3c);
347
348 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
349
350 regs_buff[i++] = NXRD32(adapter, NETXEN_CRB_PEG_NET_4+0x3c);
351 i += 2;
352
353 regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE_P3);
354 regs_buff[i++] = le32_to_cpu(*(adapter->tx_ring->hw_consumer));
355
356 } else {
357 i++;
358
359 regs_buff[i++] = NXRD32(adapter,
360 NETXEN_NIU_XGE_CONFIG_0+(0x10000*port));
361 regs_buff[i++] = NXRD32(adapter,
362 NETXEN_NIU_XGE_CONFIG_1+(0x10000*port));
363
364 regs_buff[i++] = NXRD32(adapter, CRB_XG_STATE);
365 regs_buff[i++] = NXRDIO(adapter,
366 adapter->tx_ring->crb_cmd_consumer);
367 }
368
369 regs_buff[i++] = NXRDIO(adapter, adapter->tx_ring->crb_cmd_producer);
370
371 regs_buff[i++] = NXRDIO(adapter,
372 recv_ctx->rds_rings[0].crb_rcv_producer);
373 regs_buff[i++] = NXRDIO(adapter,
374 recv_ctx->rds_rings[1].crb_rcv_producer);
375
376 regs_buff[i++] = adapter->max_sds_rings;
377
378 for (ring = 0; ring < adapter->max_sds_rings; ring++) {
379 sds_ring = &(recv_ctx->sds_rings[ring]);
380 regs_buff[i++] = NXRDIO(adapter,
381 sds_ring->crb_sts_consumer);
3d396eb1
AK
382 }
383}
384
e45d9ab4 385static u32 netxen_nic_test_link(struct net_device *dev)
3d396eb1 386{
3176ff3e 387 struct netxen_adapter *adapter = netdev_priv(dev);
a4b751d8 388 u32 val, port;
3d396eb1 389
a4b751d8
SC
390 port = adapter->physical_port;
391 if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) {
392 val = NXRD32(adapter, CRB_XG_STATE_P3);
393 val = XG_LINK_STATE_P3(adapter->ahw.pci_func, val);
394 return (val == XG_LINK_UP_P3) ? 0 : 1;
395 } else {
f98a9f69 396 val = NXRD32(adapter, CRB_XG_STATE);
a4b751d8 397 val = (val >> port*8) & 0xff;
0c25cfe1 398 return (val == XG_LINK_UP) ? 0 : 1;
3d396eb1 399 }
3d396eb1
AK
400}
401
402static int
403netxen_nic_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
404 u8 * bytes)
405{
3176ff3e 406 struct netxen_adapter *adapter = netdev_priv(dev);
3d396eb1 407 int offset;
27d2ab54 408 int ret;
3d396eb1
AK
409
410 if (eeprom->len == 0)
411 return -EINVAL;
412
4790654c 413 eeprom->magic = (adapter->pdev)->vendor |
3176ff3e 414 ((adapter->pdev)->device << 16);
27d2ab54
AK
415 offset = eeprom->offset;
416
4790654c 417 ret = netxen_rom_fast_read_words(adapter, offset, bytes,
27d2ab54
AK
418 eeprom->len);
419 if (ret < 0)
420 return ret;
421
3d396eb1
AK
422 return 0;
423}
424
425static void
7042cd8f
AKS
426netxen_nic_get_ringparam(struct net_device *dev,
427 struct ethtool_ringparam *ring)
3d396eb1 428{
3176ff3e 429 struct netxen_adapter *adapter = netdev_priv(dev);
3d396eb1 430
24767ab1
DP
431 ring->rx_pending = adapter->num_rxd;
432 ring->rx_jumbo_pending = adapter->num_jumbo_rxd;
433 ring->rx_jumbo_pending += adapter->num_lro_rxd;
438627c7 434 ring->tx_pending = adapter->num_txd;
3d396eb1 435
24767ab1 436 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
32ec8033 437 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_1G;
24767ab1
DP
438 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_1G;
439 } else {
32ec8033 440 ring->rx_max_pending = MAX_RCV_DESCRIPTORS_10G;
24767ab1
DP
441 ring->rx_jumbo_max_pending = MAX_JUMBO_RCV_DESCRIPTORS_10G;
442 }
443
444 ring->tx_max_pending = MAX_CMD_DESCRIPTORS;
445
3d396eb1
AK
446 ring->rx_mini_max_pending = 0;
447 ring->rx_mini_pending = 0;
3d396eb1
AK
448}
449
7042cd8f
AKS
450static u32
451netxen_validate_ringparam(u32 val, u32 min, u32 max, char *r_name)
452{
453 u32 num_desc;
454 num_desc = max(val, min);
455 num_desc = min(num_desc, max);
456 num_desc = roundup_pow_of_two(num_desc);
457
458 if (val != num_desc) {
459 printk(KERN_INFO "%s: setting %s ring size %d instead of %d\n",
460 netxen_nic_driver_name, r_name, num_desc, val);
461 }
462
463 return num_desc;
464}
465
466static int
467netxen_nic_set_ringparam(struct net_device *dev,
468 struct ethtool_ringparam *ring)
469{
470 struct netxen_adapter *adapter = netdev_priv(dev);
471 u16 max_rcv_desc = MAX_RCV_DESCRIPTORS_10G;
472 u16 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
473 u16 num_rxd, num_jumbo_rxd, num_txd;
474
475 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
476 return -EOPNOTSUPP;
477
478 if (ring->rx_mini_pending)
479 return -EOPNOTSUPP;
480
481 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
482 max_rcv_desc = MAX_RCV_DESCRIPTORS_1G;
483 max_jumbo_desc = MAX_JUMBO_RCV_DESCRIPTORS_10G;
484 }
485
486 num_rxd = netxen_validate_ringparam(ring->rx_pending,
487 MIN_RCV_DESCRIPTORS, max_rcv_desc, "rx");
488
489 num_jumbo_rxd = netxen_validate_ringparam(ring->rx_jumbo_pending,
490 MIN_JUMBO_DESCRIPTORS, max_jumbo_desc, "rx jumbo");
491
492 num_txd = netxen_validate_ringparam(ring->tx_pending,
493 MIN_CMD_DESCRIPTORS, MAX_CMD_DESCRIPTORS, "tx");
494
495 if (num_rxd == adapter->num_rxd && num_txd == adapter->num_txd &&
496 num_jumbo_rxd == adapter->num_jumbo_rxd)
497 return 0;
498
499 adapter->num_rxd = num_rxd;
500 adapter->num_jumbo_rxd = num_jumbo_rxd;
501 adapter->num_txd = num_txd;
502
503 return netxen_nic_reset_context(adapter);
504}
505
3d396eb1
AK
506static void
507netxen_nic_get_pauseparam(struct net_device *dev,
508 struct ethtool_pauseparam *pause)
509{
3176ff3e 510 struct netxen_adapter *adapter = netdev_priv(dev);
a608ab9c 511 __u32 val;
3276fbad 512 int port = adapter->physical_port;
3d396eb1 513
1e2d0059 514 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
6c80b18d
MT
515 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
516 return;
3d396eb1 517 /* get flow control settings */
f98a9f69 518 val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
3d396eb1 519 pause->rx_pause = netxen_gb_get_rx_flowctl(val);
f98a9f69 520 val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
6c80b18d
MT
521 switch (port) {
522 case 0:
523 pause->tx_pause = !(netxen_gb_get_gb0_mask(val));
524 break;
525 case 1:
526 pause->tx_pause = !(netxen_gb_get_gb1_mask(val));
527 break;
528 case 2:
529 pause->tx_pause = !(netxen_gb_get_gb2_mask(val));
530 break;
531 case 3:
532 default:
533 pause->tx_pause = !(netxen_gb_get_gb3_mask(val));
534 break;
535 }
1e2d0059 536 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
6c80b18d
MT
537 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
538 return;
539 pause->rx_pause = 1;
f98a9f69 540 val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
6c80b18d
MT
541 if (port == 0)
542 pause->tx_pause = !(netxen_xg_get_xg0_mask(val));
543 else
544 pause->tx_pause = !(netxen_xg_get_xg1_mask(val));
545 } else {
4790654c 546 printk(KERN_ERR"%s: Unknown board type: %x\n",
1e2d0059 547 netxen_nic_driver_name, adapter->ahw.port_type);
3d396eb1
AK
548 }
549}
550
551static int
552netxen_nic_set_pauseparam(struct net_device *dev,
553 struct ethtool_pauseparam *pause)
554{
3176ff3e 555 struct netxen_adapter *adapter = netdev_priv(dev);
a608ab9c 556 __u32 val;
3276fbad 557 int port = adapter->physical_port;
3d396eb1 558 /* read mode */
1e2d0059 559 if (adapter->ahw.port_type == NETXEN_NIC_GBE) {
6c80b18d
MT
560 if ((port < 0) || (port > NETXEN_NIU_MAX_GBE_PORTS))
561 return -EIO;
3d396eb1 562 /* set flow control */
f98a9f69 563 val = NXRD32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port));
4790654c 564
3d396eb1
AK
565 if (pause->rx_pause)
566 netxen_gb_rx_flowctl(val);
567 else
568 netxen_gb_unset_rx_flowctl(val);
569
f98a9f69 570 NXWR32(adapter, NETXEN_NIU_GB_MAC_CONFIG_0(port),
6c80b18d 571 val);
3d396eb1 572 /* set autoneg */
f98a9f69 573 val = NXRD32(adapter, NETXEN_NIU_GB_PAUSE_CTL);
6c80b18d
MT
574 switch (port) {
575 case 0:
576 if (pause->tx_pause)
577 netxen_gb_unset_gb0_mask(val);
578 else
579 netxen_gb_set_gb0_mask(val);
580 break;
581 case 1:
582 if (pause->tx_pause)
583 netxen_gb_unset_gb1_mask(val);
584 else
585 netxen_gb_set_gb1_mask(val);
586 break;
587 case 2:
588 if (pause->tx_pause)
589 netxen_gb_unset_gb2_mask(val);
590 else
591 netxen_gb_set_gb2_mask(val);
592 break;
593 case 3:
594 default:
595 if (pause->tx_pause)
596 netxen_gb_unset_gb3_mask(val);
597 else
598 netxen_gb_set_gb3_mask(val);
599 break;
600 }
f98a9f69 601 NXWR32(adapter, NETXEN_NIU_GB_PAUSE_CTL, val);
1e2d0059 602 } else if (adapter->ahw.port_type == NETXEN_NIC_XGBE) {
6c80b18d 603 if ((port < 0) || (port > NETXEN_NIU_MAX_XG_PORTS))
3d396eb1 604 return -EIO;
f98a9f69 605 val = NXRD32(adapter, NETXEN_NIU_XG_PAUSE_CTL);
6c80b18d
MT
606 if (port == 0) {
607 if (pause->tx_pause)
608 netxen_xg_unset_xg0_mask(val);
609 else
610 netxen_xg_set_xg0_mask(val);
611 } else {
612 if (pause->tx_pause)
613 netxen_xg_unset_xg1_mask(val);
614 else
615 netxen_xg_set_xg1_mask(val);
3d396eb1 616 }
f98a9f69 617 NXWR32(adapter, NETXEN_NIU_XG_PAUSE_CTL, val);
6c80b18d
MT
618 } else {
619 printk(KERN_ERR "%s: Unknown board type: %x\n",
4790654c 620 netxen_nic_driver_name,
1e2d0059 621 adapter->ahw.port_type);
6c80b18d
MT
622 }
623 return 0;
3d396eb1
AK
624}
625
626static int netxen_nic_reg_test(struct net_device *dev)
627{
0c25cfe1
LCMT
628 struct netxen_adapter *adapter = netdev_priv(dev);
629 u32 data_read, data_written;
3d396eb1 630
f98a9f69 631 data_read = NXRD32(adapter, NETXEN_PCIX_PH_REG(0));
f0e08fac
DP
632 if ((data_read & 0xffff) != adapter->pdev->vendor)
633 return 1;
3d396eb1 634
0c25cfe1 635 data_written = (u32)0xa5a5a5a5;
3d396eb1 636
f98a9f69
DP
637 NXWR32(adapter, CRB_SCRATCHPAD_TEST, data_written);
638 data_read = NXRD32(adapter, CRB_SCRATCHPAD_TEST);
0c25cfe1
LCMT
639 if (data_written != data_read)
640 return 1;
3d396eb1 641
0c25cfe1 642 return 0;
3d396eb1
AK
643}
644
b9f2c044 645static int netxen_get_sset_count(struct net_device *dev, int sset)
3d396eb1 646{
b9f2c044
JG
647 switch (sset) {
648 case ETH_SS_TEST:
649 return NETXEN_NIC_TEST_LEN;
650 case ETH_SS_STATS:
651 return NETXEN_NIC_STATS_LEN;
652 default:
653 return -EOPNOTSUPP;
654 }
3d396eb1
AK
655}
656
657static void
658netxen_nic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
659 u64 * data)
660{
6c80b18d
MT
661 memset(data, 0, sizeof(uint64_t) * NETXEN_NIC_TEST_LEN);
662 if ((data[0] = netxen_nic_reg_test(dev)))
663 eth_test->flags |= ETH_TEST_FL_FAILED;
664 /* link test */
665 if ((data[1] = (u64) netxen_nic_test_link(dev)))
666 eth_test->flags |= ETH_TEST_FL_FAILED;
3d396eb1
AK
667}
668
669static void
670netxen_nic_get_strings(struct net_device *dev, u32 stringset, u8 * data)
671{
672 int index;
673
674 switch (stringset) {
675 case ETH_SS_TEST:
676 memcpy(data, *netxen_nic_gstrings_test,
677 NETXEN_NIC_TEST_LEN * ETH_GSTRING_LEN);
678 break;
679 case ETH_SS_STATS:
680 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
681 memcpy(data + index * ETH_GSTRING_LEN,
682 netxen_nic_gstrings_stats[index].stat_string,
683 ETH_GSTRING_LEN);
684 }
685 break;
686 }
687}
688
3d396eb1
AK
689static void
690netxen_nic_get_ethtool_stats(struct net_device *dev,
691 struct ethtool_stats *stats, u64 * data)
692{
3176ff3e 693 struct netxen_adapter *adapter = netdev_priv(dev);
3d396eb1
AK
694 int index;
695
696 for (index = 0; index < NETXEN_NIC_STATS_LEN; index++) {
697 char *p =
3176ff3e
MT
698 (char *)adapter +
699 netxen_nic_gstrings_stats[index].stat_offset;
3d396eb1
AK
700 data[index] =
701 (netxen_nic_gstrings_stats[index].sizeof_stat ==
702 sizeof(u64)) ? *(u64 *) p : *(u32 *) p;
703 }
3d396eb1
AK
704}
705
200eef20
DP
706static u32 netxen_nic_get_rx_csum(struct net_device *dev)
707{
708 struct netxen_adapter *adapter = netdev_priv(dev);
709 return adapter->rx_csum;
710}
711
712static int netxen_nic_set_rx_csum(struct net_device *dev, u32 data)
713{
714 struct netxen_adapter *adapter = netdev_priv(dev);
715 adapter->rx_csum = !!data;
716 return 0;
717}
718
cd1f8160
DP
719static u32 netxen_nic_get_tso(struct net_device *dev)
720{
721 struct netxen_adapter *adapter = netdev_priv(dev);
722
723 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
724 return (dev->features & (NETIF_F_TSO | NETIF_F_TSO6)) != 0;
725
726 return (dev->features & NETIF_F_TSO) != 0;
727}
728
729static int netxen_nic_set_tso(struct net_device *dev, u32 data)
730{
731 if (data) {
732 struct netxen_adapter *adapter = netdev_priv(dev);
733
734 dev->features |= NETIF_F_TSO;
735 if (NX_IS_REVISION_P3(adapter->ahw.revision_id))
736 dev->features |= NETIF_F_TSO6;
737 } else
738 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
739
740 return 0;
741}
742
4da12942
DP
743static void
744netxen_nic_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
745{
746 struct netxen_adapter *adapter = netdev_priv(dev);
747 u32 wol_cfg = 0;
748
749 wol->supported = 0;
750 wol->wolopts = 0;
751
752 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
753 return;
754
f98a9f69 755 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
4da12942
DP
756 if (wol_cfg & (1UL << adapter->portnum))
757 wol->supported |= WAKE_MAGIC;
758
f98a9f69 759 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
4da12942
DP
760 if (wol_cfg & (1UL << adapter->portnum))
761 wol->wolopts |= WAKE_MAGIC;
762}
763
764static int
765netxen_nic_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
766{
767 struct netxen_adapter *adapter = netdev_priv(dev);
768 u32 wol_cfg = 0;
769
770 if (NX_IS_REVISION_P2(adapter->ahw.revision_id))
771 return -EOPNOTSUPP;
772
773 if (wol->wolopts & ~WAKE_MAGIC)
774 return -EOPNOTSUPP;
775
f98a9f69 776 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG_NV);
4da12942
DP
777 if (!(wol_cfg & (1 << adapter->portnum)))
778 return -EOPNOTSUPP;
779
f98a9f69 780 wol_cfg = NXRD32(adapter, NETXEN_WOL_CONFIG);
4da12942
DP
781 if (wol->wolopts & WAKE_MAGIC)
782 wol_cfg |= 1UL << adapter->portnum;
783 else
784 wol_cfg &= ~(1UL << adapter->portnum);
f98a9f69 785 NXWR32(adapter, NETXEN_WOL_CONFIG, wol_cfg);
4da12942
DP
786
787 return 0;
788}
789
cd1f8160
DP
790/*
791 * Set the coalescing parameters. Currently only normal is supported.
792 * If rx_coalesce_usecs == 0 or rx_max_coalesced_frames == 0 then set the
793 * firmware coalescing to default.
794 */
795static int netxen_set_intr_coalesce(struct net_device *netdev,
796 struct ethtool_coalesce *ethcoal)
797{
798 struct netxen_adapter *adapter = netdev_priv(netdev);
799
800 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
801 return -EINVAL;
802
803 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
804 return -EINVAL;
805
806 /*
807 * Return Error if unsupported values or
808 * unsupported parameters are set.
809 */
810 if (ethcoal->rx_coalesce_usecs > 0xffff ||
811 ethcoal->rx_max_coalesced_frames > 0xffff ||
812 ethcoal->tx_coalesce_usecs > 0xffff ||
813 ethcoal->tx_max_coalesced_frames > 0xffff ||
814 ethcoal->rx_coalesce_usecs_irq ||
815 ethcoal->rx_max_coalesced_frames_irq ||
816 ethcoal->tx_coalesce_usecs_irq ||
817 ethcoal->tx_max_coalesced_frames_irq ||
818 ethcoal->stats_block_coalesce_usecs ||
819 ethcoal->use_adaptive_rx_coalesce ||
820 ethcoal->use_adaptive_tx_coalesce ||
821 ethcoal->pkt_rate_low ||
822 ethcoal->rx_coalesce_usecs_low ||
823 ethcoal->rx_max_coalesced_frames_low ||
824 ethcoal->tx_coalesce_usecs_low ||
825 ethcoal->tx_max_coalesced_frames_low ||
826 ethcoal->pkt_rate_high ||
827 ethcoal->rx_coalesce_usecs_high ||
828 ethcoal->rx_max_coalesced_frames_high ||
829 ethcoal->tx_coalesce_usecs_high ||
830 ethcoal->tx_max_coalesced_frames_high)
831 return -EINVAL;
832
833 if (!ethcoal->rx_coalesce_usecs ||
834 !ethcoal->rx_max_coalesced_frames) {
835 adapter->coal.flags = NETXEN_NIC_INTR_DEFAULT;
836 adapter->coal.normal.data.rx_time_us =
837 NETXEN_DEFAULT_INTR_COALESCE_RX_TIME_US;
838 adapter->coal.normal.data.rx_packets =
839 NETXEN_DEFAULT_INTR_COALESCE_RX_PACKETS;
840 } else {
841 adapter->coal.flags = 0;
842 adapter->coal.normal.data.rx_time_us =
843 ethcoal->rx_coalesce_usecs;
844 adapter->coal.normal.data.rx_packets =
845 ethcoal->rx_max_coalesced_frames;
846 }
847 adapter->coal.normal.data.tx_time_us = ethcoal->tx_coalesce_usecs;
848 adapter->coal.normal.data.tx_packets =
849 ethcoal->tx_max_coalesced_frames;
850
851 netxen_config_intr_coalesce(adapter);
852
853 return 0;
854}
855
856static int netxen_get_intr_coalesce(struct net_device *netdev,
857 struct ethtool_coalesce *ethcoal)
858{
859 struct netxen_adapter *adapter = netdev_priv(netdev);
860
861 if (!NX_IS_REVISION_P3(adapter->ahw.revision_id))
862 return -EINVAL;
863
864 if (adapter->is_up != NETXEN_ADAPTER_UP_MAGIC)
865 return -EINVAL;
866
867 ethcoal->rx_coalesce_usecs = adapter->coal.normal.data.rx_time_us;
868 ethcoal->tx_coalesce_usecs = adapter->coal.normal.data.tx_time_us;
869 ethcoal->rx_max_coalesced_frames =
870 adapter->coal.normal.data.rx_packets;
871 ethcoal->tx_max_coalesced_frames =
872 adapter->coal.normal.data.tx_packets;
873
874 return 0;
875}
876
1bb482f8
NK
877static int netxen_nic_set_flags(struct net_device *netdev, u32 data)
878{
879 struct netxen_adapter *adapter = netdev_priv(netdev);
880 int hw_lro;
881
882 if (!(adapter->capabilities & NX_FW_CAPABILITY_HW_LRO))
883 return -EINVAL;
884
885 ethtool_op_set_flags(netdev, data);
886
887 hw_lro = (data & ETH_FLAG_LRO) ? NETXEN_NIC_LRO_ENABLED : 0;
888
889 if (netxen_config_hw_lro(adapter, hw_lro))
890 return -EIO;
891
892 if ((hw_lro == 0) && netxen_send_lro_cleanup(adapter))
893 return -EIO;
894
895
896 return 0;
897}
898
0fc0b732 899const struct ethtool_ops netxen_nic_ethtool_ops = {
3d396eb1
AK
900 .get_settings = netxen_nic_get_settings,
901 .set_settings = netxen_nic_set_settings,
902 .get_drvinfo = netxen_nic_get_drvinfo,
903 .get_regs_len = netxen_nic_get_regs_len,
904 .get_regs = netxen_nic_get_regs,
e45d9ab4 905 .get_link = ethtool_op_get_link,
3d396eb1
AK
906 .get_eeprom_len = netxen_nic_get_eeprom_len,
907 .get_eeprom = netxen_nic_get_eeprom,
908 .get_ringparam = netxen_nic_get_ringparam,
7042cd8f 909 .set_ringparam = netxen_nic_set_ringparam,
3d396eb1
AK
910 .get_pauseparam = netxen_nic_get_pauseparam,
911 .set_pauseparam = netxen_nic_set_pauseparam,
3d396eb1 912 .set_tx_csum = ethtool_op_set_tx_csum,
3d396eb1 913 .set_sg = ethtool_op_set_sg,
cd1f8160
DP
914 .get_tso = netxen_nic_get_tso,
915 .set_tso = netxen_nic_set_tso,
4da12942
DP
916 .get_wol = netxen_nic_get_wol,
917 .set_wol = netxen_nic_set_wol,
3d396eb1
AK
918 .self_test = netxen_nic_diag_test,
919 .get_strings = netxen_nic_get_strings,
3d396eb1 920 .get_ethtool_stats = netxen_nic_get_ethtool_stats,
b9f2c044 921 .get_sset_count = netxen_get_sset_count,
200eef20
DP
922 .get_rx_csum = netxen_nic_get_rx_csum,
923 .set_rx_csum = netxen_nic_set_rx_csum,
cd1f8160
DP
924 .get_coalesce = netxen_get_intr_coalesce,
925 .set_coalesce = netxen_set_intr_coalesce,
1bb482f8
NK
926 .get_flags = ethtool_op_get_flags,
927 .set_flags = netxen_nic_set_flags,
3d396eb1 928};