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