Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2011 Emulex |
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: |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 11 | * linux-drivers@emulex.com |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 12 | * |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 13 | * Emulex |
| 14 | * 3333 Susan Street |
| 15 | * Costa Mesa, CA 92626 |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 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 | |
Ajit Khaparde | f6c4bf3 | 2011-02-20 11:41:04 +0000 | [diff] [blame] | 29 | enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT_TX, DRVSTAT_RX, ERXSTAT, |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 30 | PMEMSTAT, DRVSTAT}; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 31 | #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \ |
| 32 | offsetof(_struct, field) |
| 33 | #define NETSTAT_INFO(field) #field, NETSTAT,\ |
| 34 | FIELDINFO(struct net_device_stats,\ |
| 35 | field) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 36 | #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\ |
| 37 | FIELDINFO(struct be_tx_stats, field) |
| 38 | #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\ |
| 39 | FIELDINFO(struct be_rx_stats, field) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 40 | #define MISCSTAT_INFO(field) #field, MISCSTAT,\ |
| 41 | FIELDINFO(struct be_rxf_stats, field) |
| 42 | #define PORTSTAT_INFO(field) #field, PORTSTAT,\ |
| 43 | FIELDINFO(struct be_port_rxf_stats, \ |
| 44 | field) |
| 45 | #define ERXSTAT_INFO(field) #field, ERXSTAT,\ |
| 46 | FIELDINFO(struct be_erx_stats, field) |
Ajit Khaparde | f6c4bf3 | 2011-02-20 11:41:04 +0000 | [diff] [blame] | 47 | #define PMEMSTAT_INFO(field) #field, PMEMSTAT,\ |
| 48 | FIELDINFO(struct be_pmem_stats, field) |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 49 | #define DRVSTAT_INFO(field) #field, DRVSTAT,\ |
| 50 | FIELDINFO(struct be_drv_stats, \ |
| 51 | field) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 52 | |
| 53 | static const struct be_ethtool_stat et_stats[] = { |
| 54 | {NETSTAT_INFO(rx_packets)}, |
| 55 | {NETSTAT_INFO(tx_packets)}, |
| 56 | {NETSTAT_INFO(rx_bytes)}, |
| 57 | {NETSTAT_INFO(tx_bytes)}, |
| 58 | {NETSTAT_INFO(rx_errors)}, |
| 59 | {NETSTAT_INFO(tx_errors)}, |
| 60 | {NETSTAT_INFO(rx_dropped)}, |
| 61 | {NETSTAT_INFO(tx_dropped)}, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 62 | {DRVSTAT_TX_INFO(be_tx_rate)}, |
| 63 | {DRVSTAT_TX_INFO(be_tx_reqs)}, |
| 64 | {DRVSTAT_TX_INFO(be_tx_wrbs)}, |
| 65 | {DRVSTAT_TX_INFO(be_tx_stops)}, |
| 66 | {DRVSTAT_TX_INFO(be_tx_events)}, |
| 67 | {DRVSTAT_TX_INFO(be_tx_compl)}, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 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)}, |
Ajit Khaparde | f6c4bf3 | 2011-02-20 11:41:04 +0000 | [diff] [blame] | 108 | {MISCSTAT_INFO(rx_drops_mtu)}, |
| 109 | {MISCSTAT_INFO(port0_jabber_events)}, |
| 110 | {MISCSTAT_INFO(port1_jabber_events)}, |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 111 | {PMEMSTAT_INFO(eth_red_drops)}, |
| 112 | {DRVSTAT_INFO(be_on_die_temperature)} |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 113 | }; |
| 114 | #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats) |
| 115 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 116 | /* Stats related to multi RX queues */ |
| 117 | static const struct be_ethtool_stat et_rx_stats[] = { |
| 118 | {DRVSTAT_RX_INFO(rx_bytes)}, |
| 119 | {DRVSTAT_RX_INFO(rx_pkts)}, |
| 120 | {DRVSTAT_RX_INFO(rx_rate)}, |
| 121 | {DRVSTAT_RX_INFO(rx_polls)}, |
| 122 | {DRVSTAT_RX_INFO(rx_events)}, |
| 123 | {DRVSTAT_RX_INFO(rx_compl)}, |
| 124 | {DRVSTAT_RX_INFO(rx_mcast_pkts)}, |
| 125 | {DRVSTAT_RX_INFO(rx_post_fail)}, |
| 126 | {ERXSTAT_INFO(rx_drops_no_fragments)} |
| 127 | }; |
| 128 | #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats)) |
| 129 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 130 | static const char et_self_tests[][ETH_GSTRING_LEN] = { |
| 131 | "MAC Loopback test", |
| 132 | "PHY Loopback test", |
| 133 | "External Loopback test", |
Ajit Khaparde | 4ee7721 | 2011-02-20 11:41:20 +0000 | [diff] [blame] | 134 | "DDR DMA test", |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 135 | "Link test" |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests) |
| 139 | #define BE_MAC_LOOPBACK 0x0 |
| 140 | #define BE_PHY_LOOPBACK 0x1 |
| 141 | #define BE_ONE_PORT_EXT_LOOPBACK 0x2 |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 142 | #define BE_NO_LOOPBACK 0xff |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 143 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 144 | static void |
| 145 | be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) |
| 146 | { |
| 147 | struct be_adapter *adapter = netdev_priv(netdev); |
| 148 | |
| 149 | strcpy(drvinfo->driver, DRV_NAME); |
| 150 | strcpy(drvinfo->version, DRV_VER); |
| 151 | strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN); |
| 152 | strcpy(drvinfo->bus_info, pci_name(adapter->pdev)); |
| 153 | drvinfo->testinfo_len = 0; |
| 154 | drvinfo->regdump_len = 0; |
| 155 | drvinfo->eedump_len = 0; |
| 156 | } |
| 157 | |
| 158 | static int |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame^] | 159 | be_get_reg_len(struct net_device *netdev) |
| 160 | { |
| 161 | struct be_adapter *adapter = netdev_priv(netdev); |
| 162 | u32 log_size = 0; |
| 163 | |
| 164 | be_cmd_get_reg_len(adapter, &log_size); |
| 165 | return log_size; |
| 166 | } |
| 167 | |
| 168 | static void |
| 169 | be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf) |
| 170 | { |
| 171 | struct be_adapter *adapter = netdev_priv(netdev); |
| 172 | |
| 173 | memset(buf, 0, regs->len); |
| 174 | be_cmd_get_regs(adapter, regs->len, buf); |
| 175 | } |
| 176 | |
| 177 | static int |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 178 | be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) |
| 179 | { |
| 180 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 181 | struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 182 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
| 183 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 184 | coalesce->rx_coalesce_usecs = rx_eq->cur_eqd; |
| 185 | coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd; |
| 186 | coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd; |
| 187 | |
| 188 | coalesce->tx_coalesce_usecs = tx_eq->cur_eqd; |
| 189 | coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd; |
| 190 | coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd; |
| 191 | |
| 192 | coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic; |
| 193 | coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic; |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | /* |
Ajit Khaparde | 5be93b9 | 2009-07-21 12:36:19 -0700 | [diff] [blame] | 199 | * This routine is used to set interrup coalescing delay |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 200 | */ |
| 201 | static int |
| 202 | be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce) |
| 203 | { |
| 204 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 205 | struct be_rx_obj *rxo; |
| 206 | struct be_eq_obj *rx_eq; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 207 | struct be_eq_obj *tx_eq = &adapter->tx_eq; |
| 208 | u32 tx_max, tx_min, tx_cur; |
| 209 | u32 rx_max, rx_min, rx_cur; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 210 | int status = 0, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 211 | |
| 212 | if (coalesce->use_adaptive_tx_coalesce == 1) |
| 213 | return -EINVAL; |
| 214 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 215 | for_all_rx_queues(adapter, rxo, i) { |
| 216 | rx_eq = &rxo->rx_eq; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 217 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 218 | if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce) |
| 219 | rx_eq->cur_eqd = 0; |
| 220 | rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce; |
| 221 | |
| 222 | rx_max = coalesce->rx_coalesce_usecs_high; |
| 223 | rx_min = coalesce->rx_coalesce_usecs_low; |
| 224 | rx_cur = coalesce->rx_coalesce_usecs; |
| 225 | |
| 226 | if (rx_eq->enable_aic) { |
| 227 | if (rx_max > BE_MAX_EQD) |
| 228 | rx_max = BE_MAX_EQD; |
| 229 | if (rx_min > rx_max) |
| 230 | rx_min = rx_max; |
| 231 | rx_eq->max_eqd = rx_max; |
| 232 | rx_eq->min_eqd = rx_min; |
| 233 | if (rx_eq->cur_eqd > rx_max) |
| 234 | rx_eq->cur_eqd = rx_max; |
| 235 | if (rx_eq->cur_eqd < rx_min) |
| 236 | rx_eq->cur_eqd = rx_min; |
| 237 | } else { |
| 238 | if (rx_cur > BE_MAX_EQD) |
| 239 | rx_cur = BE_MAX_EQD; |
| 240 | if (rx_eq->cur_eqd != rx_cur) { |
| 241 | status = be_cmd_modify_eqd(adapter, rx_eq->q.id, |
| 242 | rx_cur); |
| 243 | if (!status) |
| 244 | rx_eq->cur_eqd = rx_cur; |
| 245 | } |
| 246 | } |
| 247 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 248 | |
| 249 | tx_max = coalesce->tx_coalesce_usecs_high; |
| 250 | tx_min = coalesce->tx_coalesce_usecs_low; |
| 251 | tx_cur = coalesce->tx_coalesce_usecs; |
| 252 | |
| 253 | if (tx_cur > BE_MAX_EQD) |
| 254 | tx_cur = BE_MAX_EQD; |
| 255 | if (tx_eq->cur_eqd != tx_cur) { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 256 | status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 257 | if (!status) |
| 258 | tx_eq->cur_eqd = tx_cur; |
| 259 | } |
| 260 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | static u32 be_get_rx_csum(struct net_device *netdev) |
| 265 | { |
| 266 | struct be_adapter *adapter = netdev_priv(netdev); |
| 267 | |
| 268 | return adapter->rx_csum; |
| 269 | } |
| 270 | |
| 271 | static int be_set_rx_csum(struct net_device *netdev, uint32_t data) |
| 272 | { |
| 273 | struct be_adapter *adapter = netdev_priv(netdev); |
| 274 | |
| 275 | if (data) |
| 276 | adapter->rx_csum = true; |
| 277 | else |
| 278 | adapter->rx_csum = false; |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static void |
| 284 | be_get_ethtool_stats(struct net_device *netdev, |
| 285 | struct ethtool_stats *stats, uint64_t *data) |
| 286 | { |
| 287 | struct be_adapter *adapter = netdev_priv(netdev); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 288 | struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 289 | struct be_erx_stats *erx_stats = &hw_stats->erx; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 290 | struct be_rx_obj *rxo; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 291 | void *p = NULL; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 292 | int i, j; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 293 | |
| 294 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { |
| 295 | switch (et_stats[i].type) { |
| 296 | case NETSTAT: |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 297 | p = &netdev->stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 298 | break; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 299 | case DRVSTAT_TX: |
| 300 | p = &adapter->tx_stats; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 301 | break; |
| 302 | case PORTSTAT: |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 303 | p = &hw_stats->rxf.port[adapter->port_num]; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 304 | break; |
| 305 | case MISCSTAT: |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 306 | p = &hw_stats->rxf; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 307 | break; |
Ajit Khaparde | f6c4bf3 | 2011-02-20 11:41:04 +0000 | [diff] [blame] | 308 | case PMEMSTAT: |
| 309 | p = &hw_stats->pmem; |
| 310 | break; |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 311 | case DRVSTAT: |
| 312 | p = &adapter->drv_stats; |
| 313 | break; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | p = (u8 *)p + et_stats[i].offset; |
| 317 | data[i] = (et_stats[i].size == sizeof(u64)) ? |
| 318 | *(u64 *)p: *(u32 *)p; |
| 319 | } |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 320 | |
| 321 | for_all_rx_queues(adapter, rxo, j) { |
| 322 | for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) { |
| 323 | switch (et_rx_stats[i].type) { |
| 324 | case DRVSTAT_RX: |
| 325 | p = (u8 *)&rxo->stats + et_rx_stats[i].offset; |
| 326 | break; |
| 327 | case ERXSTAT: |
| 328 | p = (u32 *)erx_stats + rxo->q.id; |
| 329 | break; |
| 330 | } |
| 331 | data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] = |
| 332 | (et_rx_stats[i].size == sizeof(u64)) ? |
| 333 | *(u64 *)p: *(u32 *)p; |
| 334 | } |
| 335 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static void |
| 339 | be_get_stat_strings(struct net_device *netdev, uint32_t stringset, |
| 340 | uint8_t *data) |
| 341 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 342 | struct be_adapter *adapter = netdev_priv(netdev); |
| 343 | int i, j; |
| 344 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 345 | switch (stringset) { |
| 346 | case ETH_SS_STATS: |
| 347 | for (i = 0; i < ETHTOOL_STATS_NUM; i++) { |
| 348 | memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN); |
| 349 | data += ETH_GSTRING_LEN; |
| 350 | } |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 351 | for (i = 0; i < adapter->num_rx_qs; i++) { |
| 352 | for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) { |
| 353 | sprintf(data, "rxq%d: %s", i, |
| 354 | et_rx_stats[j].desc); |
| 355 | data += ETH_GSTRING_LEN; |
| 356 | } |
| 357 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 358 | break; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 359 | case ETH_SS_TEST: |
| 360 | for (i = 0; i < ETHTOOL_TESTS_NUM; i++) { |
| 361 | memcpy(data, et_self_tests[i], ETH_GSTRING_LEN); |
| 362 | data += ETH_GSTRING_LEN; |
| 363 | } |
| 364 | break; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 368 | static int be_get_sset_count(struct net_device *netdev, int stringset) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 369 | { |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 370 | struct be_adapter *adapter = netdev_priv(netdev); |
| 371 | |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 372 | switch (stringset) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 373 | case ETH_SS_TEST: |
| 374 | return ETHTOOL_TESTS_NUM; |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 375 | case ETH_SS_STATS: |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 376 | return ETHTOOL_STATS_NUM + |
| 377 | adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM; |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 378 | default: |
| 379 | return -EINVAL; |
| 380 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) |
| 384 | { |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 385 | struct be_adapter *adapter = netdev_priv(netdev); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 386 | struct be_dma_mem phy_cmd; |
| 387 | struct be_cmd_resp_get_phy_info *resp; |
| 388 | u8 mac_speed = 0; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 389 | u16 link_speed = 0; |
| 390 | bool link_up = false; |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 391 | int status; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 392 | u16 intf_type; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 393 | |
Ajit Khaparde | 48e9989 | 2010-07-29 06:17:17 +0000 | [diff] [blame] | 394 | if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) { |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 395 | status = be_cmd_link_status_query(adapter, &link_up, |
| 396 | &mac_speed, &link_speed); |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 397 | |
Ajit Khaparde | 48e9989 | 2010-07-29 06:17:17 +0000 | [diff] [blame] | 398 | be_link_status_update(adapter, link_up); |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 399 | /* link_speed is in units of 10 Mbps */ |
| 400 | if (link_speed) { |
| 401 | ecmd->speed = link_speed*10; |
| 402 | } else { |
| 403 | switch (mac_speed) { |
| 404 | case PHY_LINK_SPEED_1GBPS: |
| 405 | ecmd->speed = SPEED_1000; |
| 406 | break; |
| 407 | case PHY_LINK_SPEED_10GBPS: |
| 408 | ecmd->speed = SPEED_10000; |
| 409 | break; |
| 410 | } |
| 411 | } |
| 412 | |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 413 | phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 414 | phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, |
| 415 | phy_cmd.size, &phy_cmd.dma, |
| 416 | GFP_KERNEL); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 417 | if (!phy_cmd.va) { |
| 418 | dev_err(&adapter->pdev->dev, "Memory alloc failure\n"); |
| 419 | return -ENOMEM; |
| 420 | } |
| 421 | status = be_cmd_get_phy_info(adapter, &phy_cmd); |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 422 | if (!status) { |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 423 | resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va; |
| 424 | intf_type = le16_to_cpu(resp->interface_type); |
| 425 | |
| 426 | switch (intf_type) { |
| 427 | case PHY_TYPE_XFP_10GB: |
| 428 | case PHY_TYPE_SFP_1GB: |
| 429 | case PHY_TYPE_SFP_PLUS_10GB: |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 430 | ecmd->port = PORT_FIBRE; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 431 | break; |
| 432 | default: |
| 433 | ecmd->port = PORT_TP; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 434 | break; |
| 435 | } |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 436 | |
| 437 | switch (intf_type) { |
| 438 | case PHY_TYPE_KR_10GB: |
| 439 | case PHY_TYPE_KX4_10GB: |
| 440 | ecmd->autoneg = AUTONEG_ENABLE; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 441 | ecmd->transceiver = XCVR_INTERNAL; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 442 | break; |
| 443 | default: |
| 444 | ecmd->autoneg = AUTONEG_DISABLE; |
| 445 | ecmd->transceiver = XCVR_EXTERNAL; |
| 446 | break; |
| 447 | } |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 448 | } |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 449 | |
| 450 | /* Save for future use */ |
| 451 | adapter->link_speed = ecmd->speed; |
| 452 | adapter->port_type = ecmd->port; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 453 | adapter->transceiver = ecmd->transceiver; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 454 | adapter->autoneg = ecmd->autoneg; |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 455 | dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va, |
| 456 | phy_cmd.dma); |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 457 | } else { |
| 458 | ecmd->speed = adapter->link_speed; |
| 459 | ecmd->port = adapter->port_type; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 460 | ecmd->transceiver = adapter->transceiver; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 461 | ecmd->autoneg = adapter->autoneg; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 462 | } |
Ajit Khaparde | 0dffc83 | 2009-11-29 17:57:46 +0000 | [diff] [blame] | 463 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 464 | ecmd->duplex = DUPLEX_FULL; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 465 | ecmd->phy_address = adapter->port_num; |
Sarveshwar Bandi | 16c0214 | 2009-12-23 04:42:51 +0000 | [diff] [blame] | 466 | switch (ecmd->port) { |
| 467 | case PORT_FIBRE: |
| 468 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE); |
| 469 | break; |
| 470 | case PORT_TP: |
| 471 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP); |
| 472 | break; |
| 473 | case PORT_AUI: |
| 474 | ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI); |
| 475 | break; |
| 476 | } |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 477 | |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 478 | if (ecmd->autoneg) { |
| 479 | ecmd->supported |= SUPPORTED_1000baseT_Full; |
| 480 | ecmd->supported |= SUPPORTED_Autoneg; |
| 481 | ecmd->advertising |= (ADVERTISED_10000baseT_Full | |
| 482 | ADVERTISED_1000baseT_Full); |
| 483 | } |
| 484 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static void |
| 489 | be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) |
| 490 | { |
| 491 | struct be_adapter *adapter = netdev_priv(netdev); |
| 492 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 493 | ring->rx_max_pending = adapter->rx_obj[0].q.len; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 494 | ring->tx_max_pending = adapter->tx_obj.q.len; |
| 495 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 496 | ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 497 | ring->tx_pending = atomic_read(&adapter->tx_obj.q.used); |
| 498 | } |
| 499 | |
| 500 | static void |
| 501 | be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) |
| 502 | { |
| 503 | struct be_adapter *adapter = netdev_priv(netdev); |
| 504 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 505 | be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause); |
Ajit Khaparde | 03a980d | 2009-04-13 15:41:50 -0700 | [diff] [blame] | 506 | ecmd->autoneg = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | static int |
| 510 | be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd) |
| 511 | { |
| 512 | struct be_adapter *adapter = netdev_priv(netdev); |
| 513 | int status; |
| 514 | |
Ajit Khaparde | 03a980d | 2009-04-13 15:41:50 -0700 | [diff] [blame] | 515 | if (ecmd->autoneg != 0) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 516 | return -EINVAL; |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 517 | adapter->tx_fc = ecmd->tx_pause; |
| 518 | adapter->rx_fc = ecmd->rx_pause; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 519 | |
Ajit Khaparde | 9e90c96 | 2009-11-06 02:06:59 +0000 | [diff] [blame] | 520 | status = be_cmd_set_flow_control(adapter, |
| 521 | adapter->tx_fc, adapter->rx_fc); |
| 522 | if (status) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 523 | dev_warn(&adapter->pdev->dev, "Pause param set failed.\n"); |
| 524 | |
| 525 | return status; |
| 526 | } |
| 527 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 528 | static int |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 529 | be_phys_id(struct net_device *netdev, u32 data) |
| 530 | { |
| 531 | struct be_adapter *adapter = netdev_priv(netdev); |
| 532 | int status; |
| 533 | u32 cur; |
| 534 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 535 | be_cmd_get_beacon_state(adapter, adapter->hba_port_num, &cur); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 536 | |
| 537 | if (cur == BEACON_STATE_ENABLED) |
| 538 | return 0; |
| 539 | |
| 540 | if (data < 2) |
| 541 | data = 2; |
| 542 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 543 | status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 544 | BEACON_STATE_ENABLED); |
| 545 | set_current_state(TASK_INTERRUPTIBLE); |
| 546 | schedule_timeout(data*HZ); |
| 547 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 548 | status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0, |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 549 | BEACON_STATE_DISABLED); |
| 550 | |
| 551 | return status; |
| 552 | } |
| 553 | |
Ajit Khaparde | dcf96f1 | 2011-02-11 13:39:30 +0000 | [diff] [blame] | 554 | static bool |
| 555 | be_is_wol_supported(struct be_adapter *adapter) |
| 556 | { |
| 557 | if (!be_physfn(adapter)) |
| 558 | return false; |
| 559 | else |
| 560 | return true; |
| 561 | } |
| 562 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 563 | static void |
| 564 | be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 565 | { |
| 566 | struct be_adapter *adapter = netdev_priv(netdev); |
| 567 | |
Ajit Khaparde | dcf96f1 | 2011-02-11 13:39:30 +0000 | [diff] [blame] | 568 | if (be_is_wol_supported(adapter)) |
| 569 | wol->supported = WAKE_MAGIC; |
| 570 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 571 | if (adapter->wol) |
| 572 | wol->wolopts = WAKE_MAGIC; |
| 573 | else |
| 574 | wol->wolopts = 0; |
| 575 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static int |
| 579 | be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) |
| 580 | { |
| 581 | struct be_adapter *adapter = netdev_priv(netdev); |
| 582 | |
| 583 | if (wol->wolopts & ~WAKE_MAGIC) |
| 584 | return -EINVAL; |
| 585 | |
Ajit Khaparde | dcf96f1 | 2011-02-11 13:39:30 +0000 | [diff] [blame] | 586 | if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter)) |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 587 | adapter->wol = true; |
| 588 | else |
| 589 | adapter->wol = false; |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 594 | static int |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 595 | be_test_ddr_dma(struct be_adapter *adapter) |
| 596 | { |
| 597 | int ret, i; |
| 598 | struct be_dma_mem ddrdma_cmd; |
Joe Perches | 215faf9 | 2010-12-21 02:16:10 -0800 | [diff] [blame] | 599 | static const u64 pattern[2] = { |
| 600 | 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL |
| 601 | }; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 602 | |
| 603 | ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 604 | ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size, |
| 605 | &ddrdma_cmd.dma, GFP_KERNEL); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 606 | if (!ddrdma_cmd.va) { |
Frans Pop | 2381a55 | 2010-03-24 07:57:36 +0000 | [diff] [blame] | 607 | dev_err(&adapter->pdev->dev, "Memory allocation failure\n"); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 608 | return -ENOMEM; |
| 609 | } |
| 610 | |
| 611 | for (i = 0; i < 2; i++) { |
| 612 | ret = be_cmd_ddr_dma_test(adapter, pattern[i], |
| 613 | 4096, &ddrdma_cmd); |
| 614 | if (ret != 0) |
| 615 | goto err; |
| 616 | } |
| 617 | |
| 618 | err: |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 619 | dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va, |
| 620 | ddrdma_cmd.dma); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 621 | return ret; |
| 622 | } |
| 623 | |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 624 | static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type, |
| 625 | u64 *status) |
| 626 | { |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 627 | be_cmd_set_loopback(adapter, adapter->hba_port_num, |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 628 | loopback_type, 1); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 629 | *status = be_cmd_loopback_test(adapter, adapter->hba_port_num, |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 630 | loopback_type, 1500, |
| 631 | 2, 0xabc); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 632 | be_cmd_set_loopback(adapter, adapter->hba_port_num, |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 633 | BE_NO_LOOPBACK, 1); |
| 634 | return *status; |
| 635 | } |
| 636 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 637 | static void |
| 638 | be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data) |
| 639 | { |
| 640 | struct be_adapter *adapter = netdev_priv(netdev); |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 641 | bool link_up; |
| 642 | u8 mac_speed = 0; |
| 643 | u16 qos_link_speed = 0; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 644 | |
| 645 | memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM); |
| 646 | |
| 647 | if (test->flags & ETH_TEST_FL_OFFLINE) { |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 648 | if (be_loopback_test(adapter, BE_MAC_LOOPBACK, |
| 649 | &data[0]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 650 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 651 | } |
| 652 | if (be_loopback_test(adapter, BE_PHY_LOOPBACK, |
| 653 | &data[1]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 654 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 655 | } |
| 656 | if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK, |
| 657 | &data[2]) != 0) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 658 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 659 | } |
Sarveshwar Bandi | 8f47afe | 2010-01-19 05:15:00 +0000 | [diff] [blame] | 660 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 661 | |
Sarveshwar Bandi | 8f47afe | 2010-01-19 05:15:00 +0000 | [diff] [blame] | 662 | if (be_test_ddr_dma(adapter) != 0) { |
| 663 | data[3] = 1; |
| 664 | test->flags |= ETH_TEST_FL_FAILED; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 665 | } |
| 666 | |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 667 | if (be_cmd_link_status_query(adapter, &link_up, &mac_speed, |
| 668 | &qos_link_speed) != 0) { |
| 669 | test->flags |= ETH_TEST_FL_FAILED; |
| 670 | data[4] = -1; |
Ajit Khaparde | 4ee7721 | 2011-02-20 11:41:20 +0000 | [diff] [blame] | 671 | } else if (!mac_speed) { |
| 672 | test->flags |= ETH_TEST_FL_FAILED; |
Sarveshwar Bandi | 4276e47 | 2010-01-19 05:15:36 +0000 | [diff] [blame] | 673 | data[4] = 1; |
| 674 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | static int |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 678 | be_do_flash(struct net_device *netdev, struct ethtool_flash *efl) |
| 679 | { |
| 680 | struct be_adapter *adapter = netdev_priv(netdev); |
| 681 | char file_name[ETHTOOL_FLASH_MAX_FILENAME]; |
| 682 | u32 region; |
| 683 | |
| 684 | file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0; |
| 685 | strcpy(file_name, efl->data); |
| 686 | region = efl->region; |
| 687 | |
| 688 | return be_load_fw(adapter, file_name); |
| 689 | } |
| 690 | |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 691 | static int |
| 692 | be_get_eeprom_len(struct net_device *netdev) |
| 693 | { |
| 694 | return BE_READ_SEEPROM_LEN; |
| 695 | } |
| 696 | |
| 697 | static int |
| 698 | be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom, |
| 699 | uint8_t *data) |
| 700 | { |
| 701 | struct be_adapter *adapter = netdev_priv(netdev); |
| 702 | struct be_dma_mem eeprom_cmd; |
| 703 | struct be_cmd_resp_seeprom_read *resp; |
| 704 | int status; |
| 705 | |
| 706 | if (!eeprom->len) |
| 707 | return -EINVAL; |
| 708 | |
| 709 | eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16); |
| 710 | |
| 711 | memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem)); |
| 712 | eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read); |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 713 | eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size, |
| 714 | &eeprom_cmd.dma, GFP_KERNEL); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 715 | |
| 716 | if (!eeprom_cmd.va) { |
| 717 | dev_err(&adapter->pdev->dev, |
| 718 | "Memory allocation failure. Could not read eeprom\n"); |
| 719 | return -ENOMEM; |
| 720 | } |
| 721 | |
| 722 | status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd); |
| 723 | |
| 724 | if (!status) { |
| 725 | resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va; |
Ajit Khaparde | c0ad984 | 2010-02-08 17:51:26 +0000 | [diff] [blame] | 726 | memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 727 | } |
Ivan Vecera | 2b7bceb | 2011-02-02 08:05:12 +0000 | [diff] [blame] | 728 | dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va, |
| 729 | eeprom_cmd.dma); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 730 | |
| 731 | return status; |
| 732 | } |
| 733 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 734 | const struct ethtool_ops be_ethtool_ops = { |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 735 | .get_settings = be_get_settings, |
| 736 | .get_drvinfo = be_get_drvinfo, |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 737 | .get_wol = be_get_wol, |
| 738 | .set_wol = be_set_wol, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 739 | .get_link = ethtool_op_get_link, |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 740 | .get_eeprom_len = be_get_eeprom_len, |
| 741 | .get_eeprom = be_read_eeprom, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 742 | .get_coalesce = be_get_coalesce, |
| 743 | .set_coalesce = be_set_coalesce, |
| 744 | .get_ringparam = be_get_ringparam, |
| 745 | .get_pauseparam = be_get_pauseparam, |
| 746 | .set_pauseparam = be_set_pauseparam, |
| 747 | .get_rx_csum = be_get_rx_csum, |
| 748 | .set_rx_csum = be_set_rx_csum, |
| 749 | .get_tx_csum = ethtool_op_get_tx_csum, |
Ajit Khaparde | 583e3f3 | 2009-10-05 02:22:19 +0000 | [diff] [blame] | 750 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 751 | .get_sg = ethtool_op_get_sg, |
| 752 | .set_sg = ethtool_op_set_sg, |
| 753 | .get_tso = ethtool_op_get_tso, |
| 754 | .set_tso = ethtool_op_set_tso, |
| 755 | .get_strings = be_get_stat_strings, |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 756 | .phys_id = be_phys_id, |
Ben Hutchings | 15f0a39 | 2009-10-01 11:58:24 +0000 | [diff] [blame] | 757 | .get_sset_count = be_get_sset_count, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 758 | .get_ethtool_stats = be_get_ethtool_stats, |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame^] | 759 | .get_regs_len = be_get_reg_len, |
| 760 | .get_regs = be_get_regs, |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 761 | .flash_device = be_do_flash, |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 762 | .self_test = be_self_test, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 763 | }; |