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