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