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