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