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