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