blob: 84e03a74786806c05537ff511eb70c612af85ed1 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Ajit Khaparded2145cd2011-03-16 08:20:46 +00002 * Copyright (C) 2005 - 2011 Emulex
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003 * 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 Khaparded2145cd2011-03-16 08:20:46 +000011 * linux-drivers@emulex.com
Sathya Perla6b7c5b92009-03-11 23:32:03 -070012 *
Ajit Khaparded2145cd2011-03-16 08:20:46 +000013 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
Sathya Perla6b7c5b92009-03-11 23:32:03 -070016 */
17
18#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000019#include "be_cmds.h"
Sathya Perla6b7c5b92009-03-11 23:32:03 -070020#include <linux/ethtool.h>
21
22struct be_ethtool_stat {
23 char desc[ETH_GSTRING_LEN];
24 int type;
25 int size;
26 int offset;
27};
28
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000029enum {NETSTAT, DRVSTAT_TX, DRVSTAT_RX, ERXSTAT,
30 DRVSTAT};
Sathya Perla6b7c5b92009-03-11 23:32:03 -070031#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 Perla3abcded2010-10-03 22:12:27 -070036#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 Khaparde89a88ab2011-05-16 07:36:18 +000040#define ERXSTAT_INFO(field) #field, ERXSTAT,\
41 FIELDINFO(struct be_erx_stats_v1, field)
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000042#define DRVSTAT_INFO(field) #field, DRVSTAT,\
43 FIELDINFO(struct be_drv_stats, \
44 field)
Sathya Perla6b7c5b92009-03-11 23:32:03 -070045
46static 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 Perla3c8def92011-06-12 20:01:58 +000055 {DRVSTAT_INFO(be_tx_events)},
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000056 {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 Khaparde609ff3b2011-02-20 11:42:07 +000091 {DRVSTAT_INFO(be_on_die_temperature)}
Sathya Perla6b7c5b92009-03-11 23:32:03 -070092};
93#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
94
Sathya Perla3abcded2010-10-03 22:12:27 -070095/* Stats related to multi RX queues */
96static 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 Perla3c8def92011-06-12 20:01:58 +0000109/* Stats related to multi TX queues */
110static 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 Rff33a6e2009-12-03 16:15:52 -0800119static const char et_self_tests[][ETH_GSTRING_LEN] = {
120 "MAC Loopback test",
121 "PHY Loopback test",
122 "External Loopback test",
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000123 "DDR DMA test",
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000124 "Link test"
Suresh Rff33a6e2009-12-03 16:15:52 -0800125};
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 Bandifced9992009-12-23 04:41:44 +0000131#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800132
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700133static void
134be_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
147static int
Somnath Kotur311fddc2011-03-16 21:22:43 +0000148be_get_reg_len(struct net_device *netdev)
149{
150 struct be_adapter *adapter = netdev_priv(netdev);
151 u32 log_size = 0;
152
Ajit Khaparde16a871e2011-04-19 12:10:43 +0000153 if (be_physfn(adapter))
154 be_cmd_get_reg_len(adapter, &log_size);
155
Somnath Kotur311fddc2011-03-16 21:22:43 +0000156 return log_size;
157}
158
159static void
160be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
161{
162 struct be_adapter *adapter = netdev_priv(netdev);
163
Ajit Khaparde16a871e2011-04-19 12:10:43 +0000164 if (be_physfn(adapter)) {
165 memset(buf, 0, regs->len);
166 be_cmd_get_regs(adapter, regs->len, buf);
167 }
Somnath Kotur311fddc2011-03-16 21:22:43 +0000168}
169
170static int
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700171be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
172{
173 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700174 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700175 struct be_eq_obj *tx_eq = &adapter->tx_eq;
176
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700177 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 Khaparde5be93b92009-07-21 12:36:19 -0700192 * This routine is used to set interrup coalescing delay
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700193 */
194static int
195be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
196{
197 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700198 struct be_rx_obj *rxo;
199 struct be_eq_obj *rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700200 struct be_eq_obj *tx_eq = &adapter->tx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700201 u32 rx_max, rx_min, rx_cur;
Sathya Perla3abcded2010-10-03 22:12:27 -0700202 int status = 0, i;
David S. Miller03746b02011-04-17 17:08:41 -0700203 u32 tx_cur;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700204
205 if (coalesce->use_adaptive_tx_coalesce == 1)
206 return -EINVAL;
207
Sathya Perla3abcded2010-10-03 22:12:27 -0700208 for_all_rx_queues(adapter, rxo, i) {
209 rx_eq = &rxo->rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700210
Sathya Perla3abcded2010-10-03 22:12:27 -0700211 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 Perla6b7c5b92009-03-11 23:32:03 -0700241
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700242 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 Perla8788fdc2009-07-27 22:52:03 +0000247 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700248 if (!status)
249 tx_eq->cur_eqd = tx_cur;
250 }
251
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700252 return 0;
253}
254
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700255static void
256be_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 Perla3abcded2010-10-03 22:12:27 -0700260 struct be_rx_obj *rxo;
Sathya Perla3c8def92011-06-12 20:01:58 +0000261 struct be_tx_obj *txo;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700262 void *p = NULL;
Sathya Perla3c8def92011-06-12 20:01:58 +0000263 int i, j, base;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700264
265 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
266 switch (et_stats[i].type) {
267 case NETSTAT:
Sathya Perla3abcded2010-10-03 22:12:27 -0700268 p = &netdev->stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700269 break;
Ajit Khaparde609ff3b2011-02-20 11:42:07 +0000270 case DRVSTAT:
271 p = &adapter->drv_stats;
272 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700273 }
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 Perla3abcded2010-10-03 22:12:27 -0700279
Sathya Perla3c8def92011-06-12 20:01:58 +0000280 base = ETHTOOL_STATS_NUM;
Sathya Perla3abcded2010-10-03 22:12:27 -0700281 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 Khaparde89a88ab2011-05-16 07:36:18 +0000288 p = (u32 *)be_erx_stats_from_cmd(adapter) +
289 rxo->q.id;
Sathya Perla3abcded2010-10-03 22:12:27 -0700290 break;
291 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000292 data[base + j * ETHTOOL_RXSTATS_NUM + i] =
Sathya Perla3abcded2010-10-03 22:12:27 -0700293 (et_rx_stats[i].size == sizeof(u64)) ?
294 *(u64 *)p: *(u32 *)p;
295 }
296 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000297
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 Perla6b7c5b92009-03-11 23:32:03 -0700307}
308
309static void
310be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
311 uint8_t *data)
312{
Sathya Perla3abcded2010-10-03 22:12:27 -0700313 struct be_adapter *adapter = netdev_priv(netdev);
314 int i, j;
315
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700316 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 Perla3abcded2010-10-03 22:12:27 -0700322 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 Perla3c8def92011-06-12 20:01:58 +0000329 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 Perla6b7c5b92009-03-11 23:32:03 -0700336 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800337 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 Perla6b7c5b92009-03-11 23:32:03 -0700343 }
344}
345
Ben Hutchings15f0a392009-10-01 11:58:24 +0000346static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700347{
Sathya Perla3abcded2010-10-03 22:12:27 -0700348 struct be_adapter *adapter = netdev_priv(netdev);
349
Ben Hutchings15f0a392009-10-01 11:58:24 +0000350 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800351 case ETH_SS_TEST:
352 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000353 case ETH_SS_STATS:
Sathya Perla3abcded2010-10-03 22:12:27 -0700354 return ETHTOOL_STATS_NUM +
Sathya Perla3c8def92011-06-12 20:01:58 +0000355 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
356 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000357 default:
358 return -EINVAL;
359 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700360}
361
362static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
363{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700364 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000365 struct be_dma_mem phy_cmd;
366 struct be_cmd_resp_get_phy_info *resp;
367 u8 mac_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700368 u16 link_speed = 0;
369 bool link_up = false;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000370 int status;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000371 u16 intf_type;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700372
Ajit Khaparde48e99892010-07-29 06:17:17 +0000373 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000374 status = be_cmd_link_status_query(adapter, &link_up,
Ajit Khaparde187e8752011-04-19 12:11:46 +0000375 &mac_speed, &link_speed, 0);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700376
Ajit Khaparde48e99892010-07-29 06:17:17 +0000377 be_link_status_update(adapter, link_up);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000378 /* link_speed is in units of 10 Mbps */
379 if (link_speed) {
David Decotigny70739492011-04-27 18:32:40 +0000380 ethtool_cmd_speed_set(ecmd, link_speed*10);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000381 } else {
382 switch (mac_speed) {
Ajit Khaparde4fa9ed02011-04-19 12:10:53 +0000383 case PHY_LINK_SPEED_10MBPS:
David Decotigny70739492011-04-27 18:32:40 +0000384 ethtool_cmd_speed_set(ecmd, SPEED_10);
Ajit Khaparde4fa9ed02011-04-19 12:10:53 +0000385 break;
386 case PHY_LINK_SPEED_100MBPS:
David Decotigny70739492011-04-27 18:32:40 +0000387 ethtool_cmd_speed_set(ecmd, SPEED_100);
Ajit Khaparde4fa9ed02011-04-19 12:10:53 +0000388 break;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000389 case PHY_LINK_SPEED_1GBPS:
David Decotigny70739492011-04-27 18:32:40 +0000390 ethtool_cmd_speed_set(ecmd, SPEED_1000);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000391 break;
392 case PHY_LINK_SPEED_10GBPS:
David Decotigny70739492011-04-27 18:32:40 +0000393 ethtool_cmd_speed_set(ecmd, SPEED_10000);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000394 break;
Ajit Khaparde4fa9ed02011-04-19 12:10:53 +0000395 case PHY_LINK_SPEED_ZERO:
David Decotigny70739492011-04-27 18:32:40 +0000396 ethtool_cmd_speed_set(ecmd, 0);
Ajit Khaparde4fa9ed02011-04-19 12:10:53 +0000397 break;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000398 }
399 }
400
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000401 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000402 phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
403 phy_cmd.size, &phy_cmd.dma,
404 GFP_KERNEL);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000405 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 Bandi16c02142009-12-23 04:42:51 +0000410 if (!status) {
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000411 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 Bandi16c02142009-12-23 04:42:51 +0000418 ecmd->port = PORT_FIBRE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000419 break;
420 default:
421 ecmd->port = PORT_TP;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000422 break;
423 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000424
425 switch (intf_type) {
426 case PHY_TYPE_KR_10GB:
427 case PHY_TYPE_KX4_10GB:
428 ecmd->autoneg = AUTONEG_ENABLE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000429 ecmd->transceiver = XCVR_INTERNAL;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000430 break;
431 default:
432 ecmd->autoneg = AUTONEG_DISABLE;
433 ecmd->transceiver = XCVR_EXTERNAL;
434 break;
435 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700436 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000437
438 /* Save for future use */
David Decotigny70739492011-04-27 18:32:40 +0000439 adapter->link_speed = ethtool_cmd_speed(ecmd);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000440 adapter->port_type = ecmd->port;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000441 adapter->transceiver = ecmd->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000442 adapter->autoneg = ecmd->autoneg;
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000443 dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va,
444 phy_cmd.dma);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000445 } else {
David Decotigny70739492011-04-27 18:32:40 +0000446 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000447 ecmd->port = adapter->port_type;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000448 ecmd->transceiver = adapter->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000449 ecmd->autoneg = adapter->autoneg;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700450 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000451
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700452 ecmd->duplex = DUPLEX_FULL;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700453 ecmd->phy_address = adapter->port_num;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000454 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 Bandi0388f252009-10-28 04:15:20 -0700465
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000466 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 Perla6b7c5b92009-03-11 23:32:03 -0700473 return 0;
474}
475
476static void
477be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
478{
479 struct be_adapter *adapter = netdev_priv(netdev);
480
Sathya Perla3abcded2010-10-03 22:12:27 -0700481 ring->rx_max_pending = adapter->rx_obj[0].q.len;
Sathya Perla3c8def92011-06-12 20:01:58 +0000482 ring->tx_max_pending = adapter->tx_obj[0].q.len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700483
Sathya Perla3abcded2010-10-03 22:12:27 -0700484 ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
Sathya Perla3c8def92011-06-12 20:01:58 +0000485 ring->tx_pending = atomic_read(&adapter->tx_obj[0].q.used);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700486}
487
488static void
489be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
490{
491 struct be_adapter *adapter = netdev_priv(netdev);
492
Sathya Perla8788fdc2009-07-27 22:52:03 +0000493 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700494 ecmd->autoneg = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700495}
496
497static int
498be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
499{
500 struct be_adapter *adapter = netdev_priv(netdev);
501 int status;
502
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700503 if (ecmd->autoneg != 0)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700504 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000505 adapter->tx_fc = ecmd->tx_pause;
506 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700507
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000508 status = be_cmd_set_flow_control(adapter,
509 adapter->tx_fc, adapter->rx_fc);
510 if (status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700511 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
512
513 return status;
514}
515
Ajit Khaparde84517482009-09-04 03:12:16 +0000516static int
stephen hemminger1a642462011-04-04 11:06:40 +0000517be_set_phys_id(struct net_device *netdev,
518 enum ethtool_phys_id_state state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700519{
520 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700521
stephen hemminger1a642462011-04-04 11:06:40 +0000522 switch (state) {
523 case ETHTOOL_ID_ACTIVE:
524 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
525 &adapter->beacon_state);
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000526 return 1; /* cycle on/off once per second */
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700527
stephen hemminger1a642462011-04-04 11:06:40 +0000528 case ETHTOOL_ID_ON:
529 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
530 BEACON_STATE_ENABLED);
531 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700532
stephen hemminger1a642462011-04-04 11:06:40 +0000533 case ETHTOOL_ID_OFF:
534 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
535 BEACON_STATE_DISABLED);
536 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700537
stephen hemminger1a642462011-04-04 11:06:40 +0000538 case ETHTOOL_ID_INACTIVE:
539 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
540 adapter->beacon_state);
541 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700542
stephen hemminger1a642462011-04-04 11:06:40 +0000543 return 0;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700544}
545
Ajit Khapardedcf96f12011-02-11 13:39:30 +0000546static bool
547be_is_wol_supported(struct be_adapter *adapter)
548{
549 if (!be_physfn(adapter))
550 return false;
551 else
552 return true;
553}
554
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000555static void
556be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
557{
558 struct be_adapter *adapter = netdev_priv(netdev);
559
Ajit Khapardedcf96f12011-02-11 13:39:30 +0000560 if (be_is_wol_supported(adapter))
561 wol->supported = WAKE_MAGIC;
562
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000563 if (adapter->wol)
564 wol->wolopts = WAKE_MAGIC;
565 else
566 wol->wolopts = 0;
567 memset(&wol->sopass, 0, sizeof(wol->sopass));
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000568}
569
570static int
571be_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 Khapardedcf96f12011-02-11 13:39:30 +0000578 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000579 adapter->wol = true;
580 else
581 adapter->wol = false;
582
583 return 0;
584}
585
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700586static int
Suresh Rff33a6e2009-12-03 16:15:52 -0800587be_test_ddr_dma(struct be_adapter *adapter)
588{
589 int ret, i;
590 struct be_dma_mem ddrdma_cmd;
Joe Perches215faf92010-12-21 02:16:10 -0800591 static const u64 pattern[2] = {
592 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
593 };
Suresh Rff33a6e2009-12-03 16:15:52 -0800594
595 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000596 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
597 &ddrdma_cmd.dma, GFP_KERNEL);
Suresh Rff33a6e2009-12-03 16:15:52 -0800598 if (!ddrdma_cmd.va) {
Frans Pop2381a552010-03-24 07:57:36 +0000599 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Rff33a6e2009-12-03 16:15:52 -0800600 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
610err:
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000611 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
612 ddrdma_cmd.dma);
Suresh Rff33a6e2009-12-03 16:15:52 -0800613 return ret;
614}
615
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000616static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
617 u64 *status)
618{
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000619 be_cmd_set_loopback(adapter, adapter->hba_port_num,
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000620 loopback_type, 1);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000621 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000622 loopback_type, 1500,
623 2, 0xabc);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000624 be_cmd_set_loopback(adapter, adapter->hba_port_num,
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000625 BE_NO_LOOPBACK, 1);
626 return *status;
627}
628
Suresh Rff33a6e2009-12-03 16:15:52 -0800629static void
630be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
631{
632 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000633 bool link_up;
634 u8 mac_speed = 0;
635 u16 qos_link_speed = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800636
637 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
638
639 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000640 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
641 &data[0]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800642 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000643 }
644 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
645 &data[1]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800646 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000647 }
648 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
649 &data[2]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800650 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000651 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000652 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800653
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000654 if (be_test_ddr_dma(adapter) != 0) {
655 data[3] = 1;
656 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800657 }
658
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000659 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
Ajit Khaparde187e8752011-04-19 12:11:46 +0000660 &qos_link_speed, 0) != 0) {
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000661 test->flags |= ETH_TEST_FL_FAILED;
662 data[4] = -1;
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000663 } else if (!mac_speed) {
664 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000665 data[4] = 1;
666 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800667}
668
669static int
Ajit Khaparde84517482009-09-04 03:12:16 +0000670be_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 Khaparde84517482009-09-04 03:12:16 +0000674
675 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
676 strcpy(file_name, efl->data);
Ajit Khaparde84517482009-09-04 03:12:16 +0000677
678 return be_load_fw(adapter, file_name);
679}
680
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800681static int
682be_get_eeprom_len(struct net_device *netdev)
683{
684 return BE_READ_SEEPROM_LEN;
685}
686
687static int
688be_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 Vecera2b7bceb2011-02-02 08:05:12 +0000703 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
704 &eeprom_cmd.dma, GFP_KERNEL);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800705
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 Khapardec0ad9842010-02-08 17:51:26 +0000716 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800717 }
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000718 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
719 eeprom_cmd.dma);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800720
721 return status;
722}
723
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700724const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700725 .get_settings = be_get_settings,
726 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000727 .get_wol = be_get_wol,
728 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700729 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800730 .get_eeprom_len = be_get_eeprom_len,
731 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700732 .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 Perla6b7c5b92009-03-11 23:32:03 -0700737 .get_strings = be_get_stat_strings,
stephen hemminger1a642462011-04-04 11:06:40 +0000738 .set_phys_id = be_set_phys_id,
Ben Hutchings15f0a392009-10-01 11:58:24 +0000739 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700740 .get_ethtool_stats = be_get_ethtool_stats,
Somnath Kotur311fddc2011-03-16 21:22:43 +0000741 .get_regs_len = be_get_reg_len,
742 .get_regs = be_get_regs,
Ajit Khaparde84517482009-09-04 03:12:16 +0000743 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -0800744 .self_test = be_self_test,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700745};