Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 - 2009 ServerEngines |
| 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)}, |
| 93 | {PORTSTAT_INFO(tx_unicastframes)}, |
| 94 | {PORTSTAT_INFO(tx_multicastframes)}, |
| 95 | {PORTSTAT_INFO(tx_broadcastframes)}, |
| 96 | {PORTSTAT_INFO(tx_pauseframes)}, |
| 97 | {PORTSTAT_INFO(tx_controlframes)}, |
| 98 | {MISCSTAT_INFO(rx_drops_no_pbuf)}, |
| 99 | {MISCSTAT_INFO(rx_drops_no_txpb)}, |
| 100 | {MISCSTAT_INFO(rx_drops_no_erx_descr)}, |
| 101 | {MISCSTAT_INFO(rx_drops_no_tpre_descr)}, |
| 102 | {MISCSTAT_INFO(rx_drops_too_many_frags)}, |
| 103 | {MISCSTAT_INFO(rx_drops_invalid_ring)}, |
| 104 | {MISCSTAT_INFO(forwarded_packets)}, |
| 105 | {MISCSTAT_INFO(rx_drops_mtu)}, |
| 106 | {ERXSTAT_INFO(rx_drops_no_fragments)}, |
| 107 | }; |
| 108 | #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats) |
| 109 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 110 | static const char et_self_tests[][ETH_GSTRING_LEN] = { |
| 111 | "MAC Loopback test", |
| 112 | "PHY Loopback test", |
| 113 | "External Loopback test", |
| 114 | "DDR DMA test" |
| 115 | }; |
| 116 | |
| 117 | #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests) |
| 118 | #define BE_MAC_LOOPBACK 0x0 |
| 119 | #define BE_PHY_LOOPBACK 0x1 |
| 120 | #define BE_ONE_PORT_EXT_LOOPBACK 0x2 |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame^] | 121 | #define BE_NO_LOOPBACK 0xff |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 122 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 123 | static void |
| 124 | be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) |
| 125 | { |
| 126 | struct be_adapter *adapter = netdev_priv(netdev); |
| 127 | |
| 128 | strcpy(drvinfo->driver, DRV_NAME); |
| 129 | strcpy(drvinfo->version, DRV_VER); |
| 130 | strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN); |
| 131 | strcpy(drvinfo->bus_info, pci_name(adapter->pdev)); |
| 132 | drvinfo->testinfo_len = 0; |
| 133 | drvinfo->regdump_len = 0; |
| 134 | drvinfo->eedump_len = 0; |
| 135 | } |
| 136 | |
| 137 | static int |
| 138 | be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) |
| 139 | { |
| 140 | struct be_adapter *adapter = netdev_priv(netdev); |
| 141 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 142 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
| 143 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 144 | coalesce->rx_coalesce_usecs = rx_eq->cur_eqd; |
| 145 | coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd; |
| 146 | coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd; |
| 147 | |
| 148 | coalesce->tx_coalesce_usecs = tx_eq->cur_eqd; |
| 149 | coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd; |
| 150 | coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd; |
| 151 | |
| 152 | coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic; |
| 153 | coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic; |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 159 | * This routine is used to set interrup coalescing delay |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 160 | */ |
| 161 | static int |
| 162 | be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) |
| 163 | { |
| 164 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 165 | struct be_eq_obj *rx_eq = &adapter->rx_eq; |
| 166 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
| 167 | u32 tx_max, tx_min, tx_cur; |
| 168 | u32 rx_max, rx_min, rx_cur; |
| 169 | int status = 0; |
| 170 | |
| 171 | if (coalesce->use_adaptive_tx_coalesce == 1) |
| 172 | return -EINVAL; |
| 173 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 174 | /* if AIC is being turned on now, start with an EQD of 0 */ |
| 175 | if (rx_eq->enable_aic == 0 && |
| 176 | coalesce->use_adaptive_rx_coalesce == 1) { |
| 177 | rx_eq->cur_eqd = 0; |
| 178 | } |
| 179 | rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce; |
| 180 | |
| 181 | rx_max = coalesce->rx_coalesce_usecs_high; |
| 182 | rx_min = coalesce->rx_coalesce_usecs_low; |
| 183 | rx_cur = coalesce->rx_coalesce_usecs; |
| 184 | |
| 185 | tx_max = coalesce->tx_coalesce_usecs_high; |
| 186 | tx_min = coalesce->tx_coalesce_usecs_low; |
| 187 | tx_cur = coalesce->tx_coalesce_usecs; |
| 188 | |
| 189 | if (tx_cur > BE_MAX_EQD) |
| 190 | tx_cur = BE_MAX_EQD; |
| 191 | if (tx_eq->cur_eqd != tx_cur) { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 192 | status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 193 | if (!status) |
| 194 | tx_eq->cur_eqd = tx_cur; |
| 195 | } |
| 196 | |
| 197 | if (rx_eq->enable_aic) { |
| 198 | if (rx_max > BE_MAX_EQD) |
| 199 | rx_max = BE_MAX_EQD; |
| 200 | if (rx_min > rx_max) |
| 201 | rx_min = rx_max; |
| 202 | rx_eq->max_eqd = rx_max; |
| 203 | rx_eq->min_eqd = rx_min; |
| 204 | if (rx_eq->cur_eqd > rx_max) |
| 205 | rx_eq->cur_eqd = rx_max; |
| 206 | if (rx_eq->cur_eqd < rx_min) |
| 207 | rx_eq->cur_eqd = rx_min; |
| 208 | } else { |
| 209 | if (rx_cur > BE_MAX_EQD) |
| 210 | rx_cur = BE_MAX_EQD; |
| 211 | if (rx_eq->cur_eqd != rx_cur) { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 212 | status = be_cmd_modify_eqd(adapter, rx_eq->q.id, |
| 213 | rx_cur); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 214 | if (!status) |
| 215 | rx_eq->cur_eqd = rx_cur; |
| 216 | } |
| 217 | } |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | static u32 be_get_rx_csum(struct net_device *netdev) |
| 222 | { |
| 223 | struct be_adapter *adapter = netdev_priv(netdev); |
| 224 | |
| 225 | return adapter->rx_csum; |
| 226 | } |
| 227 | |
| 228 | static int be_set_rx_csum(struct net_device *netdev, uint32_t data) |
| 229 | { |
| 230 | struct be_adapter *adapter = netdev_priv(netdev); |
| 231 | |
| 232 | if (data) |
| 233 | adapter->rx_csum = true; |
| 234 | else |
| 235 | adapter->rx_csum = false; |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | static void |
| 241 | be_get_ethtool_stats(struct net_device *netdev, |
| 242 | struct ethtool_stats *stats, uint64_t *data) |
| 243 | { |
| 244 | struct be_adapter *adapter = netdev_priv(netdev); |
| 245 | struct be_drvr_stats *drvr_stats = &adapter->stats.drvr_stats; |
| 246 | struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va); |
| 247 | struct be_rxf_stats *rxf_stats = &hw_stats->rxf; |
| 248 | struct be_port_rxf_stats *port_stats = |
| 249 | &rxf_stats->port[adapter->port_num]; |
Ajit Khaparde | 78122a5 | 2009-10-07 03:11:20 -0700 | [diff] [blame] | 250 | struct net_device_stats *net_stats = &netdev->stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 251 | struct be_erx_stats *erx_stats = &hw_stats->erx; |
| 252 | void *p = NULL; |
| 253 | int i; |
| 254 | |
| 255 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { |
| 256 | switch (et_stats[i].type) { |
| 257 | case NETSTAT: |
| 258 | p = net_stats; |
| 259 | break; |
| 260 | case DRVSTAT: |
| 261 | p = drvr_stats; |
| 262 | break; |
| 263 | case PORTSTAT: |
| 264 | p = port_stats; |
| 265 | break; |
| 266 | case MISCSTAT: |
| 267 | p = rxf_stats; |
| 268 | break; |
| 269 | case ERXSTAT: /* Currently only one ERX stat is provided */ |
| 270 | p = (u32 *)erx_stats + adapter->rx_obj.q.id; |
| 271 | break; |
| 272 | } |
| 273 | |
| 274 | p = (u8 *)p + et_stats[i].offset; |
| 275 | data[i] = (et_stats[i].size == sizeof(u64)) ? |
| 276 | *(u64 *)p: *(u32 *)p; |
| 277 | } |
| 278 | |
| 279 | return; |
| 280 | } |
| 281 | |
| 282 | static void |
| 283 | be_get_stat_strings(struct net_device *netdev, uint32_t stringset, |
| 284 | uint8_t *data) |
| 285 | { |
| 286 | int i; |
| 287 | switch (stringset) { |
| 288 | case ETH_SS_STATS: |
| 289 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { |
| 290 | memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN); |
| 291 | data += ETH_GSTRING_LEN; |
| 292 | } |
| 293 | break; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 294 | case ETH_SS_TEST: |
| 295 | for (i = 0; i < ETHTOOL_TESTS_NUM; i++) { |
| 296 | memcpy(data, et_self_tests[i], ETH_GSTRING_LEN); |
| 297 | data += ETH_GSTRING_LEN; |
| 298 | } |
| 299 | break; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 303 | static int be_get_sset_count(struct net_device *netdev, int stringset) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 304 | { |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 305 | switch (stringset) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 306 | case ETH_SS_TEST: |
| 307 | return ETHTOOL_TESTS_NUM; |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 308 | case ETH_SS_STATS: |
| 309 | return ETHTOOL_STATS_NUM; |
| 310 | default: |
| 311 | return -EINVAL; |
| 312 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 316 | { |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 317 | struct be_adapter *adapter = netdev_priv(netdev); |
| 318 | u8 mac_speed = 0, connector = 0; |
| 319 | u16 link_speed = 0; |
| 320 | bool link_up = false; |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 321 | int status; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 322 | |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 323 | if (adapter->link_speed < 0) { |
| 324 | status = be_cmd_link_status_query(adapter, &link_up, |
| 325 | &mac_speed, &link_speed); |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 326 | |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 327 | /* link_speed is in units of 10 Mbps */ |
| 328 | if (link_speed) { |
| 329 | ecmd->speed = link_speed*10; |
| 330 | } else { |
| 331 | switch (mac_speed) { |
| 332 | case PHY_LINK_SPEED_1GBPS: |
| 333 | ecmd->speed = SPEED_1000; |
| 334 | break; |
| 335 | case PHY_LINK_SPEED_10GBPS: |
| 336 | ecmd->speed = SPEED_10000; |
| 337 | break; |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | status = be_cmd_read_port_type(adapter, adapter->port_num, |
| 342 | &connector); |
| 343 | switch (connector) { |
| 344 | case 7: |
| 345 | ecmd->port = PORT_FIBRE; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 346 | break; |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 347 | default: |
| 348 | ecmd->port = PORT_TP; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 349 | break; |
| 350 | } |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 351 | |
| 352 | /* Save for future use */ |
| 353 | adapter->link_speed = ecmd->speed; |
| 354 | adapter->port_type = ecmd->port; |
| 355 | } else { |
| 356 | ecmd->speed = adapter->link_speed; |
| 357 | ecmd->port = adapter->port_type; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 358 | } |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 359 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 360 | ecmd->duplex = DUPLEX_FULL; |
| 361 | ecmd->autoneg = AUTONEG_DISABLE; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 362 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP); |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 363 | ecmd->phy_address = adapter->port_num; |
| 364 | ecmd->transceiver = XCVR_INTERNAL; |
| 365 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | static void |
| 370 | be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) |
| 371 | { |
| 372 | struct be_adapter *adapter = netdev_priv(netdev); |
| 373 | |
| 374 | ring->rx_max_pending = adapter->rx_obj.q.len; |
| 375 | ring->tx_max_pending = adapter->tx_obj.q.len; |
| 376 | |
| 377 | ring->rx_pending = atomic_read(&adapter->rx_obj.q.used); |
| 378 | ring->tx_pending = atomic_read(&adapter->tx_obj.q.used); |
| 379 | } |
| 380 | |
| 381 | static void |
| 382 | be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) |
| 383 | { |
| 384 | struct be_adapter *adapter = netdev_priv(netdev); |
| 385 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 386 | be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause); |
Ajit Khaparde | 03a980d | 2009-04-13 15:41:50 -0700 | [diff] [blame] | 387 | ecmd->autoneg = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | static int |
| 391 | be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) |
| 392 | { |
| 393 | struct be_adapter *adapter = netdev_priv(netdev); |
| 394 | int status; |
| 395 | |
Ajit Khaparde | 03a980d | 2009-04-13 15:41:50 -0700 | [diff] [blame] | 396 | if (ecmd->autoneg != 0) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 397 | return -EINVAL; |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 398 | adapter->tx_fc = ecmd->tx_pause; |
| 399 | adapter->rx_fc = ecmd->rx_pause; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 400 | |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 401 | status = be_cmd_set_flow_control(adapter, |
| 402 | adapter->tx_fc, adapter->rx_fc); |
| 403 | if (status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 404 | dev_warn(&adapter->pdev->dev, "Pause param set failed.\n"); |
| 405 | |
| 406 | return status; |
| 407 | } |
| 408 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 409 | static int |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 410 | be_phys_id(struct net_device *netdev, u32 data) |
| 411 | { |
| 412 | struct be_adapter *adapter = netdev_priv(netdev); |
| 413 | int status; |
| 414 | u32 cur; |
| 415 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 416 | be_cmd_get_beacon_state(adapter, adapter->port_num, &cur); |
| 417 | |
| 418 | if (cur == BEACON_STATE_ENABLED) |
| 419 | return 0; |
| 420 | |
| 421 | if (data < 2) |
| 422 | data = 2; |
| 423 | |
| 424 | status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0, |
| 425 | BEACON_STATE_ENABLED); |
| 426 | set_current_state(TASK_INTERRUPTIBLE); |
| 427 | schedule_timeout(data*HZ); |
| 428 | |
| 429 | status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0, |
| 430 | BEACON_STATE_DISABLED); |
| 431 | |
| 432 | return status; |
| 433 | } |
| 434 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 435 | static void |
| 436 | be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 437 | { |
| 438 | struct be_adapter *adapter = netdev_priv(netdev); |
| 439 | |
| 440 | wol->supported = WAKE_MAGIC; |
| 441 | if (adapter->wol) |
| 442 | wol->wolopts = WAKE_MAGIC; |
| 443 | else |
| 444 | wol->wolopts = 0; |
| 445 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 446 | return; |
| 447 | } |
| 448 | |
| 449 | static int |
| 450 | be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 451 | { |
| 452 | struct be_adapter *adapter = netdev_priv(netdev); |
| 453 | |
| 454 | if (wol->wolopts & ~WAKE_MAGIC) |
| 455 | return -EINVAL; |
| 456 | |
| 457 | if (wol->wolopts & WAKE_MAGIC) |
| 458 | adapter->wol = true; |
| 459 | else |
| 460 | adapter->wol = false; |
| 461 | |
| 462 | return 0; |
| 463 | } |
| 464 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 465 | static int |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 466 | be_test_ddr_dma(struct be_adapter *adapter) |
| 467 | { |
| 468 | int ret, i; |
| 469 | struct be_dma_mem ddrdma_cmd; |
| 470 | u64 pattern[2] = {0x5a5a5a5a5a5a5a5a, 0xa5a5a5a5a5a5a5a5}; |
| 471 | |
| 472 | ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test); |
| 473 | ddrdma_cmd.va = pci_alloc_consistent(adapter->pdev, ddrdma_cmd.size, |
| 474 | &ddrdma_cmd.dma); |
| 475 | if (!ddrdma_cmd.va) { |
| 476 | dev_err(&adapter->pdev->dev, "Memory allocation failure \n"); |
| 477 | return -ENOMEM; |
| 478 | } |
| 479 | |
| 480 | for (i = 0; i < 2; i++) { |
| 481 | ret = be_cmd_ddr_dma_test(adapter, pattern[i], |
| 482 | 4096, &ddrdma_cmd); |
| 483 | if (ret != 0) |
| 484 | goto err; |
| 485 | } |
| 486 | |
| 487 | err: |
| 488 | pci_free_consistent(adapter->pdev, ddrdma_cmd.size, |
| 489 | ddrdma_cmd.va, ddrdma_cmd.dma); |
| 490 | return ret; |
| 491 | } |
| 492 | |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame^] | 493 | static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type, |
| 494 | u64 *status) |
| 495 | { |
| 496 | be_cmd_set_loopback(adapter, adapter->port_num, |
| 497 | loopback_type, 1); |
| 498 | *status = be_cmd_loopback_test(adapter, adapter->port_num, |
| 499 | loopback_type, 1500, |
| 500 | 2, 0xabc); |
| 501 | be_cmd_set_loopback(adapter, adapter->port_num, |
| 502 | BE_NO_LOOPBACK, 1); |
| 503 | return *status; |
| 504 | } |
| 505 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 506 | static void |
| 507 | be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data) |
| 508 | { |
| 509 | struct be_adapter *adapter = netdev_priv(netdev); |
| 510 | |
| 511 | memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM); |
| 512 | |
| 513 | if (test->flags & ETH_TEST_FL_OFFLINE) { |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame^] | 514 | if (be_loopback_test(adapter, BE_MAC_LOOPBACK, |
| 515 | &data[0]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 516 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame^] | 517 | } |
| 518 | if (be_loopback_test(adapter, BE_PHY_LOOPBACK, |
| 519 | &data[1]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 520 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame^] | 521 | } |
| 522 | if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK, |
| 523 | &data[2]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 524 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame^] | 525 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 526 | |
| 527 | data[3] = be_test_ddr_dma(adapter); |
| 528 | if (data[3] != 0) |
| 529 | test->flags |= ETH_TEST_FL_FAILED; |
| 530 | } |
| 531 | |
| 532 | } |
| 533 | |
| 534 | static int |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 535 | be_do_flash(struct net_device *netdev, struct ethtool_flash *efl) |
| 536 | { |
| 537 | struct be_adapter *adapter = netdev_priv(netdev); |
| 538 | char file_name[ETHTOOL_FLASH_MAX_FILENAME]; |
| 539 | u32 region; |
| 540 | |
| 541 | file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; |
| 542 | strcpy(file_name, efl->data); |
| 543 | region = efl->region; |
| 544 | |
| 545 | return be_load_fw(adapter, file_name); |
| 546 | } |
| 547 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 548 | const struct ethtool_ops be_ethtool_ops = { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 549 | .get_settings = be_get_settings, |
| 550 | .get_drvinfo = be_get_drvinfo, |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 551 | .get_wol = be_get_wol, |
| 552 | .set_wol = be_set_wol, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 553 | .get_link = ethtool_op_get_link, |
| 554 | .get_coalesce = be_get_coalesce, |
| 555 | .set_coalesce = be_set_coalesce, |
| 556 | .get_ringparam = be_get_ringparam, |
| 557 | .get_pauseparam = be_get_pauseparam, |
| 558 | .set_pauseparam = be_set_pauseparam, |
| 559 | .get_rx_csum = be_get_rx_csum, |
| 560 | .set_rx_csum = be_set_rx_csum, |
| 561 | .get_tx_csum = ethtool_op_get_tx_csum, |
Ajit Khaparde | 583e3f3 | 2009-10-05 02:22:19 +0000 | [diff] [blame] | 562 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 563 | .get_sg = ethtool_op_get_sg, |
| 564 | .set_sg = ethtool_op_set_sg, |
| 565 | .get_tso = ethtool_op_get_tso, |
| 566 | .set_tso = ethtool_op_set_tso, |
| 567 | .get_strings = be_get_stat_strings, |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 568 | .phys_id = be_phys_id, |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 569 | .get_sset_count = be_get_sset_count, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 570 | .get_ethtool_stats = be_get_ethtool_stats, |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 571 | .flash_device = be_do_flash, |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 572 | .self_test = be_self_test, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 573 | }; |