Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Ajit Khaparde | 294aedc | 2010-02-19 13:54:58 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2010 ServerEngines |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. The full GNU General |
| 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
| 10 | * Contact Information: |
| 11 | * linux-drivers@serverengines.com |
| 12 | * |
| 13 | * ServerEngines |
| 14 | * 209 N. Fair Oaks Ave |
| 15 | * Sunnyvale, CA 94085 |
| 16 | */ |
| 17 | |
| 18 | #include "be.h" |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 19 | #include "be_cmds.h" |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 20 | #include <linux/ethtool.h> |
| 21 | |
| 22 | struct be_ethtool_stat { |
| 23 | char desc[ETH_GSTRING_LEN]; |
| 24 | int type; |
| 25 | int size; |
| 26 | int offset; |
| 27 | }; |
| 28 | |
| 29 | enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT, ERXSTAT}; |
| 30 | #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \ |
| 31 | offsetof(_struct, field) |
| 32 | #define NETSTAT_INFO(field) #field, NETSTAT,\ |
| 33 | FIELDINFO(struct net_device_stats,\ |
| 34 | field) |
| 35 | #define DRVSTAT_INFO(field) #field, DRVSTAT,\ |
| 36 | FIELDINFO(struct be_drvr_stats, field) |
| 37 | #define MISCSTAT_INFO(field) #field, MISCSTAT,\ |
| 38 | FIELDINFO(struct be_rxf_stats, field) |
| 39 | #define PORTSTAT_INFO(field) #field, PORTSTAT,\ |
| 40 | FIELDINFO(struct be_port_rxf_stats, \ |
| 41 | field) |
| 42 | #define ERXSTAT_INFO(field) #field, ERXSTAT,\ |
| 43 | FIELDINFO(struct be_erx_stats, field) |
| 44 | |
| 45 | static const struct be_ethtool_stat et_stats[] = { |
| 46 | {NETSTAT_INFO(rx_packets)}, |
| 47 | {NETSTAT_INFO(tx_packets)}, |
| 48 | {NETSTAT_INFO(rx_bytes)}, |
| 49 | {NETSTAT_INFO(tx_bytes)}, |
| 50 | {NETSTAT_INFO(rx_errors)}, |
| 51 | {NETSTAT_INFO(tx_errors)}, |
| 52 | {NETSTAT_INFO(rx_dropped)}, |
| 53 | {NETSTAT_INFO(tx_dropped)}, |
| 54 | {DRVSTAT_INFO(be_tx_reqs)}, |
| 55 | {DRVSTAT_INFO(be_tx_stops)}, |
| 56 | {DRVSTAT_INFO(be_fwd_reqs)}, |
| 57 | {DRVSTAT_INFO(be_tx_wrbs)}, |
Ajit Khaparde | b7b83ac | 2009-11-29 17:57:22 +0000 | [diff] [blame] | 58 | {DRVSTAT_INFO(be_rx_polls)}, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 59 | {DRVSTAT_INFO(be_tx_events)}, |
| 60 | {DRVSTAT_INFO(be_rx_events)}, |
| 61 | {DRVSTAT_INFO(be_tx_compl)}, |
| 62 | {DRVSTAT_INFO(be_rx_compl)}, |
| 63 | {DRVSTAT_INFO(be_ethrx_post_fail)}, |
| 64 | {DRVSTAT_INFO(be_802_3_dropped_frames)}, |
| 65 | {DRVSTAT_INFO(be_802_3_malformed_frames)}, |
| 66 | {DRVSTAT_INFO(be_tx_rate)}, |
| 67 | {DRVSTAT_INFO(be_rx_rate)}, |
| 68 | {PORTSTAT_INFO(rx_unicast_frames)}, |
| 69 | {PORTSTAT_INFO(rx_multicast_frames)}, |
| 70 | {PORTSTAT_INFO(rx_broadcast_frames)}, |
| 71 | {PORTSTAT_INFO(rx_crc_errors)}, |
| 72 | {PORTSTAT_INFO(rx_alignment_symbol_errors)}, |
| 73 | {PORTSTAT_INFO(rx_pause_frames)}, |
| 74 | {PORTSTAT_INFO(rx_control_frames)}, |
| 75 | {PORTSTAT_INFO(rx_in_range_errors)}, |
| 76 | {PORTSTAT_INFO(rx_out_range_errors)}, |
| 77 | {PORTSTAT_INFO(rx_frame_too_long)}, |
| 78 | {PORTSTAT_INFO(rx_address_match_errors)}, |
| 79 | {PORTSTAT_INFO(rx_vlan_mismatch)}, |
| 80 | {PORTSTAT_INFO(rx_dropped_too_small)}, |
| 81 | {PORTSTAT_INFO(rx_dropped_too_short)}, |
| 82 | {PORTSTAT_INFO(rx_dropped_header_too_small)}, |
| 83 | {PORTSTAT_INFO(rx_dropped_tcp_length)}, |
| 84 | {PORTSTAT_INFO(rx_dropped_runt)}, |
| 85 | {PORTSTAT_INFO(rx_fifo_overflow)}, |
| 86 | {PORTSTAT_INFO(rx_input_fifo_overflow)}, |
| 87 | {PORTSTAT_INFO(rx_ip_checksum_errs)}, |
| 88 | {PORTSTAT_INFO(rx_tcp_checksum_errs)}, |
| 89 | {PORTSTAT_INFO(rx_udp_checksum_errs)}, |
| 90 | {PORTSTAT_INFO(rx_non_rss_packets)}, |
| 91 | {PORTSTAT_INFO(rx_ipv4_packets)}, |
| 92 | {PORTSTAT_INFO(rx_ipv6_packets)}, |
Ajit Khaparde | def824c | 2010-08-25 00:32:56 +0000 | [diff] [blame^] | 93 | {PORTSTAT_INFO(rx_switched_unicast_packets)}, |
| 94 | {PORTSTAT_INFO(rx_switched_multicast_packets)}, |
| 95 | {PORTSTAT_INFO(rx_switched_broadcast_packets)}, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 96 | {PORTSTAT_INFO(tx_unicastframes)}, |
| 97 | {PORTSTAT_INFO(tx_multicastframes)}, |
| 98 | {PORTSTAT_INFO(tx_broadcastframes)}, |
| 99 | {PORTSTAT_INFO(tx_pauseframes)}, |
| 100 | {PORTSTAT_INFO(tx_controlframes)}, |
| 101 | {MISCSTAT_INFO(rx_drops_no_pbuf)}, |
| 102 | {MISCSTAT_INFO(rx_drops_no_txpb)}, |
| 103 | {MISCSTAT_INFO(rx_drops_no_erx_descr)}, |
| 104 | {MISCSTAT_INFO(rx_drops_no_tpre_descr)}, |
| 105 | {MISCSTAT_INFO(rx_drops_too_many_frags)}, |
| 106 | {MISCSTAT_INFO(rx_drops_invalid_ring)}, |
| 107 | {MISCSTAT_INFO(forwarded_packets)}, |
| 108 | {MISCSTAT_INFO(rx_drops_mtu)}, |
| 109 | {ERXSTAT_INFO(rx_drops_no_fragments)}, |
| 110 | }; |
| 111 | #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats) |
| 112 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 113 | static const char et_self_tests[][ETH_GSTRING_LEN] = { |
| 114 | "MAC Loopback test", |
| 115 | "PHY Loopback test", |
| 116 | "External Loopback test", |
| 117 | "DDR DMA test" |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 118 | "Link test" |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests) |
| 122 | #define BE_MAC_LOOPBACK 0x0 |
| 123 | #define BE_PHY_LOOPBACK 0x1 |
| 124 | #define BE_ONE_PORT_EXT_LOOPBACK 0x2 |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 125 | #define BE_NO_LOOPBACK 0xff |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 126 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 127 | static void |
| 128 | be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) |
| 129 | { |
| 130 | struct be_adapter *adapter = netdev_priv(netdev); |
| 131 | |
| 132 | strcpy(drvinfo->driver, DRV_NAME); |
| 133 | strcpy(drvinfo->version, DRV_VER); |
| 134 | strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN); |
| 135 | strcpy(drvinfo->bus_info, pci_name(adapter->pdev)); |
| 136 | drvinfo->testinfo_len = 0; |
| 137 | drvinfo->regdump_len = 0; |
| 138 | drvinfo->eedump_len = 0; |
| 139 | } |
| 140 | |
| 141 | static int |
| 142 | be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) |
| 143 | { |
| 144 | struct be_adapter *adapter = netdev_priv(netdev); |
| 145 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 146 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
| 147 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 148 | coalesce->rx_coalesce_usecs = rx_eq->cur_eqd; |
| 149 | coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd; |
| 150 | coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd; |
| 151 | |
| 152 | coalesce->tx_coalesce_usecs = tx_eq->cur_eqd; |
| 153 | coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd; |
| 154 | coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd; |
| 155 | |
| 156 | coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic; |
| 157 | coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic; |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | /* |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 163 | * This routine is used to set interrup coalescing delay |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 164 | */ |
| 165 | static int |
| 166 | be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) |
| 167 | { |
| 168 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 169 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 170 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
| 171 | u32 tx_max, tx_min, tx_cur; |
| 172 | u32 rx_max, rx_min, rx_cur; |
| 173 | int status = 0; |
| 174 | |
| 175 | if (coalesce->use_adaptive_tx_coalesce == 1) |
| 176 | return -EINVAL; |
| 177 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 178 | /* if AIC is being turned on now, start with an EQD of 0 */ |
| 179 | if (rx_eq->enable_aic == 0 && |
| 180 | coalesce->use_adaptive_rx_coalesce == 1) { |
| 181 | rx_eq->cur_eqd = 0; |
| 182 | } |
| 183 | rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce; |
| 184 | |
| 185 | rx_max = coalesce->rx_coalesce_usecs_high; |
| 186 | rx_min = coalesce->rx_coalesce_usecs_low; |
| 187 | rx_cur = coalesce->rx_coalesce_usecs; |
| 188 | |
| 189 | tx_max = coalesce->tx_coalesce_usecs_high; |
| 190 | tx_min = coalesce->tx_coalesce_usecs_low; |
| 191 | tx_cur = coalesce->tx_coalesce_usecs; |
| 192 | |
| 193 | if (tx_cur > BE_MAX_EQD) |
| 194 | tx_cur = BE_MAX_EQD; |
| 195 | if (tx_eq->cur_eqd != tx_cur) { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 196 | status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 197 | if (!status) |
| 198 | tx_eq->cur_eqd = tx_cur; |
| 199 | } |
| 200 | |
| 201 | if (rx_eq->enable_aic) { |
| 202 | if (rx_max > BE_MAX_EQD) |
| 203 | rx_max = BE_MAX_EQD; |
| 204 | if (rx_min > rx_max) |
| 205 | rx_min = rx_max; |
| 206 | rx_eq->max_eqd = rx_max; |
| 207 | rx_eq->min_eqd = rx_min; |
| 208 | if (rx_eq->cur_eqd > rx_max) |
| 209 | rx_eq->cur_eqd = rx_max; |
| 210 | if (rx_eq->cur_eqd < rx_min) |
| 211 | rx_eq->cur_eqd = rx_min; |
| 212 | } else { |
| 213 | if (rx_cur > BE_MAX_EQD) |
| 214 | rx_cur = BE_MAX_EQD; |
| 215 | if (rx_eq->cur_eqd != rx_cur) { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 216 | status = be_cmd_modify_eqd(adapter, rx_eq->q.id, |
| 217 | rx_cur); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 218 | if (!status) |
| 219 | rx_eq->cur_eqd = rx_cur; |
| 220 | } |
| 221 | } |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static u32 be_get_rx_csum(struct net_device *netdev) |
| 226 | { |
| 227 | struct be_adapter *adapter = netdev_priv(netdev); |
| 228 | |
| 229 | return adapter->rx_csum; |
| 230 | } |
| 231 | |
| 232 | static int be_set_rx_csum(struct net_device *netdev, uint32_t data) |
| 233 | { |
| 234 | struct be_adapter *adapter = netdev_priv(netdev); |
| 235 | |
| 236 | if (data) |
| 237 | adapter->rx_csum = true; |
| 238 | else |
| 239 | adapter->rx_csum = false; |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | static void |
| 245 | be_get_ethtool_stats(struct net_device *netdev, |
| 246 | struct ethtool_stats *stats, uint64_t *data) |
| 247 | { |
| 248 | struct be_adapter *adapter = netdev_priv(netdev); |
| 249 | struct be_drvr_stats *drvr_stats = &adapter->stats.drvr_stats; |
| 250 | struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va); |
| 251 | struct be_rxf_stats *rxf_stats = &hw_stats->rxf; |
| 252 | struct be_port_rxf_stats *port_stats = |
| 253 | &rxf_stats->port[adapter->port_num]; |
Ajit Khaparde | 78122a5 | 2009-10-07 03:11:20 -0700 | [diff] [blame] | 254 | struct net_device_stats *net_stats = &netdev->stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 255 | struct be_erx_stats *erx_stats = &hw_stats->erx; |
| 256 | void *p = NULL; |
| 257 | int i; |
| 258 | |
| 259 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { |
| 260 | switch (et_stats[i].type) { |
| 261 | case NETSTAT: |
| 262 | p = net_stats; |
| 263 | break; |
| 264 | case DRVSTAT: |
| 265 | p = drvr_stats; |
| 266 | break; |
| 267 | case PORTSTAT: |
| 268 | p = port_stats; |
| 269 | break; |
| 270 | case MISCSTAT: |
| 271 | p = rxf_stats; |
| 272 | break; |
| 273 | case ERXSTAT: /* Currently only one ERX stat is provided */ |
| 274 | p = (u32 *)erx_stats + adapter->rx_obj.q.id; |
| 275 | break; |
| 276 | } |
| 277 | |
| 278 | p = (u8 *)p + et_stats[i].offset; |
| 279 | data[i] = (et_stats[i].size == sizeof(u64)) ? |
| 280 | *(u64 *)p: *(u32 *)p; |
| 281 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static void |
| 285 | be_get_stat_strings(struct net_device *netdev, uint32_t stringset, |
| 286 | uint8_t *data) |
| 287 | { |
| 288 | int i; |
| 289 | switch (stringset) { |
| 290 | case ETH_SS_STATS: |
| 291 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { |
| 292 | memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN); |
| 293 | data += ETH_GSTRING_LEN; |
| 294 | } |
| 295 | break; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 296 | case ETH_SS_TEST: |
| 297 | for (i = 0; i < ETHTOOL_TESTS_NUM; i++) { |
| 298 | memcpy(data, et_self_tests[i], ETH_GSTRING_LEN); |
| 299 | data += ETH_GSTRING_LEN; |
| 300 | } |
| 301 | break; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 305 | static int be_get_sset_count(struct net_device *netdev, int stringset) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 306 | { |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 307 | switch (stringset) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 308 | case ETH_SS_TEST: |
| 309 | return ETHTOOL_TESTS_NUM; |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 310 | case ETH_SS_STATS: |
| 311 | return ETHTOOL_STATS_NUM; |
| 312 | default: |
| 313 | return -EINVAL; |
| 314 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 318 | { |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 319 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 320 | struct be_dma_mem phy_cmd; |
| 321 | struct be_cmd_resp_get_phy_info *resp; |
| 322 | u8 mac_speed = 0; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 323 | u16 link_speed = 0; |
| 324 | bool link_up = false; |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 325 | int status; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 326 | u16 intf_type; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 327 | |
Ajit Khaparde | 48e9989 | 2010-07-29 06:17:17 +0000 | [diff] [blame] | 328 | if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) { |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 329 | status = be_cmd_link_status_query(adapter, &link_up, |
| 330 | &mac_speed, &link_speed); |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 331 | |
Ajit Khaparde | 48e9989 | 2010-07-29 06:17:17 +0000 | [diff] [blame] | 332 | be_link_status_update(adapter, link_up); |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 333 | /* link_speed is in units of 10 Mbps */ |
| 334 | if (link_speed) { |
| 335 | ecmd->speed = link_speed*10; |
| 336 | } else { |
| 337 | switch (mac_speed) { |
| 338 | case PHY_LINK_SPEED_1GBPS: |
| 339 | ecmd->speed = SPEED_1000; |
| 340 | break; |
| 341 | case PHY_LINK_SPEED_10GBPS: |
| 342 | ecmd->speed = SPEED_10000; |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 347 | phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info); |
| 348 | phy_cmd.va = pci_alloc_consistent(adapter->pdev, phy_cmd.size, |
| 349 | &phy_cmd.dma); |
| 350 | if (!phy_cmd.va) { |
| 351 | dev_err(&adapter->pdev->dev, "Memory alloc failure\n"); |
| 352 | return -ENOMEM; |
| 353 | } |
| 354 | status = be_cmd_get_phy_info(adapter, &phy_cmd); |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 355 | if (!status) { |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 356 | resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va; |
| 357 | intf_type = le16_to_cpu(resp->interface_type); |
| 358 | |
| 359 | switch (intf_type) { |
| 360 | case PHY_TYPE_XFP_10GB: |
| 361 | case PHY_TYPE_SFP_1GB: |
| 362 | case PHY_TYPE_SFP_PLUS_10GB: |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 363 | ecmd->port = PORT_FIBRE; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 364 | break; |
| 365 | default: |
| 366 | ecmd->port = PORT_TP; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 367 | break; |
| 368 | } |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 369 | |
| 370 | switch (intf_type) { |
| 371 | case PHY_TYPE_KR_10GB: |
| 372 | case PHY_TYPE_KX4_10GB: |
| 373 | ecmd->autoneg = AUTONEG_ENABLE; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 374 | ecmd->transceiver = XCVR_INTERNAL; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 375 | break; |
| 376 | default: |
| 377 | ecmd->autoneg = AUTONEG_DISABLE; |
| 378 | ecmd->transceiver = XCVR_EXTERNAL; |
| 379 | break; |
| 380 | } |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 381 | } |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 382 | |
| 383 | /* Save for future use */ |
| 384 | adapter->link_speed = ecmd->speed; |
| 385 | adapter->port_type = ecmd->port; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 386 | adapter->transceiver = ecmd->transceiver; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 387 | adapter->autoneg = ecmd->autoneg; |
| 388 | pci_free_consistent(adapter->pdev, phy_cmd.size, |
| 389 | phy_cmd.va, phy_cmd.dma); |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 390 | } else { |
| 391 | ecmd->speed = adapter->link_speed; |
| 392 | ecmd->port = adapter->port_type; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 393 | ecmd->transceiver = adapter->transceiver; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 394 | ecmd->autoneg = adapter->autoneg; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 395 | } |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 396 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 397 | ecmd->duplex = DUPLEX_FULL; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 398 | ecmd->phy_address = adapter->port_num; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 399 | switch (ecmd->port) { |
| 400 | case PORT_FIBRE: |
| 401 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); |
| 402 | break; |
| 403 | case PORT_TP: |
| 404 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP); |
| 405 | break; |
| 406 | case PORT_AUI: |
| 407 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI); |
| 408 | break; |
| 409 | } |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 410 | |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 411 | if (ecmd->autoneg) { |
| 412 | ecmd->supported |= SUPPORTED_1000baseT_Full; |
| 413 | ecmd->supported |= SUPPORTED_Autoneg; |
| 414 | ecmd->advertising |= (ADVERTISED_10000baseT_Full | |
| 415 | ADVERTISED_1000baseT_Full); |
| 416 | } |
| 417 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static void |
| 422 | be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) |
| 423 | { |
| 424 | struct be_adapter *adapter = netdev_priv(netdev); |
| 425 | |
| 426 | ring->rx_max_pending = adapter->rx_obj.q.len; |
| 427 | ring->tx_max_pending = adapter->tx_obj.q.len; |
| 428 | |
| 429 | ring->rx_pending = atomic_read(&adapter->rx_obj.q.used); |
| 430 | ring->tx_pending = atomic_read(&adapter->tx_obj.q.used); |
| 431 | } |
| 432 | |
| 433 | static void |
| 434 | be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) |
| 435 | { |
| 436 | struct be_adapter *adapter = netdev_priv(netdev); |
| 437 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 438 | be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause); |
Ajit Khaparde | 03a980d | 2009-04-13 15:41:50 -0700 | [diff] [blame] | 439 | ecmd->autoneg = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | static int |
| 443 | be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) |
| 444 | { |
| 445 | struct be_adapter *adapter = netdev_priv(netdev); |
| 446 | int status; |
| 447 | |
Ajit Khaparde | 03a980d | 2009-04-13 15:41:50 -0700 | [diff] [blame] | 448 | if (ecmd->autoneg != 0) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 449 | return -EINVAL; |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 450 | adapter->tx_fc = ecmd->tx_pause; |
| 451 | adapter->rx_fc = ecmd->rx_pause; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 452 | |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 453 | status = be_cmd_set_flow_control(adapter, |
| 454 | adapter->tx_fc, adapter->rx_fc); |
| 455 | if (status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 456 | dev_warn(&adapter->pdev->dev, "Pause param set failed.\n"); |
| 457 | |
| 458 | return status; |
| 459 | } |
| 460 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 461 | static int |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 462 | be_phys_id(struct net_device *netdev, u32 data) |
| 463 | { |
| 464 | struct be_adapter *adapter = netdev_priv(netdev); |
| 465 | int status; |
| 466 | u32 cur; |
| 467 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 468 | be_cmd_get_beacon_state(adapter, adapter->port_num, &cur); |
| 469 | |
| 470 | if (cur == BEACON_STATE_ENABLED) |
| 471 | return 0; |
| 472 | |
| 473 | if (data < 2) |
| 474 | data = 2; |
| 475 | |
| 476 | status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0, |
| 477 | BEACON_STATE_ENABLED); |
| 478 | set_current_state(TASK_INTERRUPTIBLE); |
| 479 | schedule_timeout(data*HZ); |
| 480 | |
| 481 | status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0, |
| 482 | BEACON_STATE_DISABLED); |
| 483 | |
| 484 | return status; |
| 485 | } |
| 486 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 487 | static void |
| 488 | be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 489 | { |
| 490 | struct be_adapter *adapter = netdev_priv(netdev); |
| 491 | |
| 492 | wol->supported = WAKE_MAGIC; |
| 493 | if (adapter->wol) |
| 494 | wol->wolopts = WAKE_MAGIC; |
| 495 | else |
| 496 | wol->wolopts = 0; |
| 497 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | static int |
| 501 | be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 502 | { |
| 503 | struct be_adapter *adapter = netdev_priv(netdev); |
| 504 | |
| 505 | if (wol->wolopts & ~WAKE_MAGIC) |
| 506 | return -EINVAL; |
| 507 | |
| 508 | if (wol->wolopts & WAKE_MAGIC) |
| 509 | adapter->wol = true; |
| 510 | else |
| 511 | adapter->wol = false; |
| 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 516 | static int |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 517 | be_test_ddr_dma(struct be_adapter *adapter) |
| 518 | { |
| 519 | int ret, i; |
| 520 | struct be_dma_mem ddrdma_cmd; |
wzt wzt | c0e4d4b | 2010-03-25 20:12:59 +0000 | [diff] [blame] | 521 | u64 pattern[2] = {0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL}; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 522 | |
| 523 | ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test); |
| 524 | ddrdma_cmd.va = pci_alloc_consistent(adapter->pdev, ddrdma_cmd.size, |
| 525 | &ddrdma_cmd.dma); |
| 526 | if (!ddrdma_cmd.va) { |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 527 | dev_err(&adapter->pdev->dev, "Memory allocation failure\n"); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 528 | return -ENOMEM; |
| 529 | } |
| 530 | |
| 531 | for (i = 0; i < 2; i++) { |
| 532 | ret = be_cmd_ddr_dma_test(adapter, pattern[i], |
| 533 | 4096, &ddrdma_cmd); |
| 534 | if (ret != 0) |
| 535 | goto err; |
| 536 | } |
| 537 | |
| 538 | err: |
| 539 | pci_free_consistent(adapter->pdev, ddrdma_cmd.size, |
| 540 | ddrdma_cmd.va, ddrdma_cmd.dma); |
| 541 | return ret; |
| 542 | } |
| 543 | |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 544 | static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type, |
| 545 | u64 *status) |
| 546 | { |
| 547 | be_cmd_set_loopback(adapter, adapter->port_num, |
| 548 | loopback_type, 1); |
| 549 | *status = be_cmd_loopback_test(adapter, adapter->port_num, |
| 550 | loopback_type, 1500, |
| 551 | 2, 0xabc); |
| 552 | be_cmd_set_loopback(adapter, adapter->port_num, |
| 553 | BE_NO_LOOPBACK, 1); |
| 554 | return *status; |
| 555 | } |
| 556 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 557 | static void |
| 558 | be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data) |
| 559 | { |
| 560 | struct be_adapter *adapter = netdev_priv(netdev); |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 561 | bool link_up; |
| 562 | u8 mac_speed = 0; |
| 563 | u16 qos_link_speed = 0; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 564 | |
| 565 | memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM); |
| 566 | |
| 567 | if (test->flags & ETH_TEST_FL_OFFLINE) { |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 568 | if (be_loopback_test(adapter, BE_MAC_LOOPBACK, |
| 569 | &data[0]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 570 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 571 | } |
| 572 | if (be_loopback_test(adapter, BE_PHY_LOOPBACK, |
| 573 | &data[1]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 574 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 575 | } |
| 576 | if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK, |
| 577 | &data[2]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 578 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 579 | } |
Sarveshwar Bandi | 8f47afe | 2010-01-19 05:15:00 +0000 | [diff] [blame] | 580 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 581 | |
Sarveshwar Bandi | 8f47afe | 2010-01-19 05:15:00 +0000 | [diff] [blame] | 582 | if (be_test_ddr_dma(adapter) != 0) { |
| 583 | data[3] = 1; |
| 584 | test->flags |= ETH_TEST_FL_FAILED; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 587 | if (be_cmd_link_status_query(adapter, &link_up, &mac_speed, |
| 588 | &qos_link_speed) != 0) { |
| 589 | test->flags |= ETH_TEST_FL_FAILED; |
| 590 | data[4] = -1; |
| 591 | } else if (mac_speed) { |
| 592 | data[4] = 1; |
| 593 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | static int |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 597 | be_do_flash(struct net_device *netdev, struct ethtool_flash *efl) |
| 598 | { |
| 599 | struct be_adapter *adapter = netdev_priv(netdev); |
| 600 | char file_name[ETHTOOL_FLASH_MAX_FILENAME]; |
| 601 | u32 region; |
| 602 | |
| 603 | file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; |
| 604 | strcpy(file_name, efl->data); |
| 605 | region = efl->region; |
| 606 | |
| 607 | return be_load_fw(adapter, file_name); |
| 608 | } |
| 609 | |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 610 | static int |
| 611 | be_get_eeprom_len(struct net_device *netdev) |
| 612 | { |
| 613 | return BE_READ_SEEPROM_LEN; |
| 614 | } |
| 615 | |
| 616 | static int |
| 617 | be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, |
| 618 | uint8_t *data) |
| 619 | { |
| 620 | struct be_adapter *adapter = netdev_priv(netdev); |
| 621 | struct be_dma_mem eeprom_cmd; |
| 622 | struct be_cmd_resp_seeprom_read *resp; |
| 623 | int status; |
| 624 | |
| 625 | if (!eeprom->len) |
| 626 | return -EINVAL; |
| 627 | |
| 628 | eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16); |
| 629 | |
| 630 | memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem)); |
| 631 | eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read); |
| 632 | eeprom_cmd.va = pci_alloc_consistent(adapter->pdev, eeprom_cmd.size, |
| 633 | &eeprom_cmd.dma); |
| 634 | |
| 635 | if (!eeprom_cmd.va) { |
| 636 | dev_err(&adapter->pdev->dev, |
| 637 | "Memory allocation failure. Could not read eeprom\n"); |
| 638 | return -ENOMEM; |
| 639 | } |
| 640 | |
| 641 | status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd); |
| 642 | |
| 643 | if (!status) { |
| 644 | resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va; |
Ajit Khaparde | c0ad984 | 2010-02-08 17:51:26 +0000 | [diff] [blame] | 645 | memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 646 | } |
| 647 | pci_free_consistent(adapter->pdev, eeprom_cmd.size, eeprom_cmd.va, |
| 648 | eeprom_cmd.dma); |
| 649 | |
| 650 | return status; |
| 651 | } |
| 652 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 653 | const struct ethtool_ops be_ethtool_ops = { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 654 | .get_settings = be_get_settings, |
| 655 | .get_drvinfo = be_get_drvinfo, |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 656 | .get_wol = be_get_wol, |
| 657 | .set_wol = be_set_wol, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 658 | .get_link = ethtool_op_get_link, |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 659 | .get_eeprom_len = be_get_eeprom_len, |
| 660 | .get_eeprom = be_read_eeprom, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 661 | .get_coalesce = be_get_coalesce, |
| 662 | .set_coalesce = be_set_coalesce, |
| 663 | .get_ringparam = be_get_ringparam, |
| 664 | .get_pauseparam = be_get_pauseparam, |
| 665 | .set_pauseparam = be_set_pauseparam, |
| 666 | .get_rx_csum = be_get_rx_csum, |
| 667 | .set_rx_csum = be_set_rx_csum, |
| 668 | .get_tx_csum = ethtool_op_get_tx_csum, |
Ajit Khaparde | 583e3f3 | 2009-10-05 02:22:19 +0000 | [diff] [blame] | 669 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 670 | .get_sg = ethtool_op_get_sg, |
| 671 | .set_sg = ethtool_op_set_sg, |
| 672 | .get_tso = ethtool_op_get_tso, |
| 673 | .set_tso = ethtool_op_set_tso, |
| 674 | .get_strings = be_get_stat_strings, |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 675 | .phys_id = be_phys_id, |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 676 | .get_sset_count = be_get_sset_count, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 677 | .get_ethtool_stats = be_get_ethtool_stats, |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 678 | .flash_device = be_do_flash, |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 679 | .self_test = be_self_test, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 680 | }; |