blob: 51e1065e78977df6f27a06eaf58dcdba64da5502 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Ajit Khaparde294aedc2010-02-19 13:54:58 +00002 * Copyright (C) 2005 - 2010 ServerEngines
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:
11 * linux-drivers@serverengines.com
12 *
13 * ServerEngines
14 * 209 N. Fair Oaks Ave
15 * Sunnyvale, CA 94085
16 */
17
18#include "be.h"
Sathya 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
29enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT, ERXSTAT};
30#define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
31 offsetof(_struct, field)
32#define NETSTAT_INFO(field) #field, NETSTAT,\
33 FIELDINFO(struct net_device_stats,\
34 field)
35#define DRVSTAT_INFO(field) #field, DRVSTAT,\
36 FIELDINFO(struct be_drvr_stats, field)
37#define MISCSTAT_INFO(field) #field, MISCSTAT,\
38 FIELDINFO(struct be_rxf_stats, field)
39#define PORTSTAT_INFO(field) #field, PORTSTAT,\
40 FIELDINFO(struct be_port_rxf_stats, \
41 field)
42#define ERXSTAT_INFO(field) #field, ERXSTAT,\
43 FIELDINFO(struct be_erx_stats, field)
44
45static const struct be_ethtool_stat et_stats[] = {
46 {NETSTAT_INFO(rx_packets)},
47 {NETSTAT_INFO(tx_packets)},
48 {NETSTAT_INFO(rx_bytes)},
49 {NETSTAT_INFO(tx_bytes)},
50 {NETSTAT_INFO(rx_errors)},
51 {NETSTAT_INFO(tx_errors)},
52 {NETSTAT_INFO(rx_dropped)},
53 {NETSTAT_INFO(tx_dropped)},
54 {DRVSTAT_INFO(be_tx_reqs)},
55 {DRVSTAT_INFO(be_tx_stops)},
56 {DRVSTAT_INFO(be_fwd_reqs)},
57 {DRVSTAT_INFO(be_tx_wrbs)},
Ajit Khapardeb7b83ac2009-11-29 17:57:22 +000058 {DRVSTAT_INFO(be_rx_polls)},
Sathya Perla6b7c5b92009-03-11 23:32:03 -070059 {DRVSTAT_INFO(be_tx_events)},
60 {DRVSTAT_INFO(be_rx_events)},
61 {DRVSTAT_INFO(be_tx_compl)},
62 {DRVSTAT_INFO(be_rx_compl)},
63 {DRVSTAT_INFO(be_ethrx_post_fail)},
64 {DRVSTAT_INFO(be_802_3_dropped_frames)},
65 {DRVSTAT_INFO(be_802_3_malformed_frames)},
66 {DRVSTAT_INFO(be_tx_rate)},
67 {DRVSTAT_INFO(be_rx_rate)},
68 {PORTSTAT_INFO(rx_unicast_frames)},
69 {PORTSTAT_INFO(rx_multicast_frames)},
70 {PORTSTAT_INFO(rx_broadcast_frames)},
71 {PORTSTAT_INFO(rx_crc_errors)},
72 {PORTSTAT_INFO(rx_alignment_symbol_errors)},
73 {PORTSTAT_INFO(rx_pause_frames)},
74 {PORTSTAT_INFO(rx_control_frames)},
75 {PORTSTAT_INFO(rx_in_range_errors)},
76 {PORTSTAT_INFO(rx_out_range_errors)},
77 {PORTSTAT_INFO(rx_frame_too_long)},
78 {PORTSTAT_INFO(rx_address_match_errors)},
79 {PORTSTAT_INFO(rx_vlan_mismatch)},
80 {PORTSTAT_INFO(rx_dropped_too_small)},
81 {PORTSTAT_INFO(rx_dropped_too_short)},
82 {PORTSTAT_INFO(rx_dropped_header_too_small)},
83 {PORTSTAT_INFO(rx_dropped_tcp_length)},
84 {PORTSTAT_INFO(rx_dropped_runt)},
85 {PORTSTAT_INFO(rx_fifo_overflow)},
86 {PORTSTAT_INFO(rx_input_fifo_overflow)},
87 {PORTSTAT_INFO(rx_ip_checksum_errs)},
88 {PORTSTAT_INFO(rx_tcp_checksum_errs)},
89 {PORTSTAT_INFO(rx_udp_checksum_errs)},
90 {PORTSTAT_INFO(rx_non_rss_packets)},
91 {PORTSTAT_INFO(rx_ipv4_packets)},
92 {PORTSTAT_INFO(rx_ipv6_packets)},
93 {PORTSTAT_INFO(tx_unicastframes)},
94 {PORTSTAT_INFO(tx_multicastframes)},
95 {PORTSTAT_INFO(tx_broadcastframes)},
96 {PORTSTAT_INFO(tx_pauseframes)},
97 {PORTSTAT_INFO(tx_controlframes)},
98 {MISCSTAT_INFO(rx_drops_no_pbuf)},
99 {MISCSTAT_INFO(rx_drops_no_txpb)},
100 {MISCSTAT_INFO(rx_drops_no_erx_descr)},
101 {MISCSTAT_INFO(rx_drops_no_tpre_descr)},
102 {MISCSTAT_INFO(rx_drops_too_many_frags)},
103 {MISCSTAT_INFO(rx_drops_invalid_ring)},
104 {MISCSTAT_INFO(forwarded_packets)},
105 {MISCSTAT_INFO(rx_drops_mtu)},
106 {ERXSTAT_INFO(rx_drops_no_fragments)},
107};
108#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
109
Suresh Rff33a6e2009-12-03 16:15:52 -0800110static const char et_self_tests[][ETH_GSTRING_LEN] = {
111 "MAC Loopback test",
112 "PHY Loopback test",
113 "External Loopback test",
114 "DDR DMA test"
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000115 "Link test"
Suresh Rff33a6e2009-12-03 16:15:52 -0800116};
117
118#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
119#define BE_MAC_LOOPBACK 0x0
120#define BE_PHY_LOOPBACK 0x1
121#define BE_ONE_PORT_EXT_LOOPBACK 0x2
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000122#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800123
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700124static void
125be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
126{
127 struct be_adapter *adapter = netdev_priv(netdev);
128
129 strcpy(drvinfo->driver, DRV_NAME);
130 strcpy(drvinfo->version, DRV_VER);
131 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
132 strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
133 drvinfo->testinfo_len = 0;
134 drvinfo->regdump_len = 0;
135 drvinfo->eedump_len = 0;
136}
137
138static int
139be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
140{
141 struct be_adapter *adapter = netdev_priv(netdev);
142 struct be_eq_obj *rx_eq = &adapter->rx_eq;
143 struct be_eq_obj *tx_eq = &adapter->tx_eq;
144
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700145 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
146 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
147 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
148
149 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
150 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
151 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
152
153 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
154 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
155
156 return 0;
157}
158
159/*
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700160 * This routine is used to set interrup coalescing delay
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700161 */
162static int
163be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
164{
165 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700166 struct be_eq_obj *rx_eq = &adapter->rx_eq;
167 struct be_eq_obj *tx_eq = &adapter->tx_eq;
168 u32 tx_max, tx_min, tx_cur;
169 u32 rx_max, rx_min, rx_cur;
170 int status = 0;
171
172 if (coalesce->use_adaptive_tx_coalesce == 1)
173 return -EINVAL;
174
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700175 /* if AIC is being turned on now, start with an EQD of 0 */
176 if (rx_eq->enable_aic == 0 &&
177 coalesce->use_adaptive_rx_coalesce == 1) {
178 rx_eq->cur_eqd = 0;
179 }
180 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
181
182 rx_max = coalesce->rx_coalesce_usecs_high;
183 rx_min = coalesce->rx_coalesce_usecs_low;
184 rx_cur = coalesce->rx_coalesce_usecs;
185
186 tx_max = coalesce->tx_coalesce_usecs_high;
187 tx_min = coalesce->tx_coalesce_usecs_low;
188 tx_cur = coalesce->tx_coalesce_usecs;
189
190 if (tx_cur > BE_MAX_EQD)
191 tx_cur = BE_MAX_EQD;
192 if (tx_eq->cur_eqd != tx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000193 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700194 if (!status)
195 tx_eq->cur_eqd = tx_cur;
196 }
197
198 if (rx_eq->enable_aic) {
199 if (rx_max > BE_MAX_EQD)
200 rx_max = BE_MAX_EQD;
201 if (rx_min > rx_max)
202 rx_min = rx_max;
203 rx_eq->max_eqd = rx_max;
204 rx_eq->min_eqd = rx_min;
205 if (rx_eq->cur_eqd > rx_max)
206 rx_eq->cur_eqd = rx_max;
207 if (rx_eq->cur_eqd < rx_min)
208 rx_eq->cur_eqd = rx_min;
209 } else {
210 if (rx_cur > BE_MAX_EQD)
211 rx_cur = BE_MAX_EQD;
212 if (rx_eq->cur_eqd != rx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000213 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
214 rx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700215 if (!status)
216 rx_eq->cur_eqd = rx_cur;
217 }
218 }
219 return 0;
220}
221
222static u32 be_get_rx_csum(struct net_device *netdev)
223{
224 struct be_adapter *adapter = netdev_priv(netdev);
225
226 return adapter->rx_csum;
227}
228
229static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
230{
231 struct be_adapter *adapter = netdev_priv(netdev);
232
233 if (data)
234 adapter->rx_csum = true;
235 else
236 adapter->rx_csum = false;
237
238 return 0;
239}
240
241static void
242be_get_ethtool_stats(struct net_device *netdev,
243 struct ethtool_stats *stats, uint64_t *data)
244{
245 struct be_adapter *adapter = netdev_priv(netdev);
246 struct be_drvr_stats *drvr_stats = &adapter->stats.drvr_stats;
247 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va);
248 struct be_rxf_stats *rxf_stats = &hw_stats->rxf;
249 struct be_port_rxf_stats *port_stats =
250 &rxf_stats->port[adapter->port_num];
Ajit Khaparde78122a52009-10-07 03:11:20 -0700251 struct net_device_stats *net_stats = &netdev->stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700252 struct be_erx_stats *erx_stats = &hw_stats->erx;
253 void *p = NULL;
254 int i;
255
256 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
257 switch (et_stats[i].type) {
258 case NETSTAT:
259 p = net_stats;
260 break;
261 case DRVSTAT:
262 p = drvr_stats;
263 break;
264 case PORTSTAT:
265 p = port_stats;
266 break;
267 case MISCSTAT:
268 p = rxf_stats;
269 break;
270 case ERXSTAT: /* Currently only one ERX stat is provided */
271 p = (u32 *)erx_stats + adapter->rx_obj.q.id;
272 break;
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 }
279
280 return;
281}
282
283static void
284be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
285 uint8_t *data)
286{
287 int i;
288 switch (stringset) {
289 case ETH_SS_STATS:
290 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
291 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
292 data += ETH_GSTRING_LEN;
293 }
294 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800295 case ETH_SS_TEST:
296 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
297 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
298 data += ETH_GSTRING_LEN;
299 }
300 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700301 }
302}
303
Ben Hutchings15f0a392009-10-01 11:58:24 +0000304static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700305{
Ben Hutchings15f0a392009-10-01 11:58:24 +0000306 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800307 case ETH_SS_TEST:
308 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000309 case ETH_SS_STATS:
310 return ETHTOOL_STATS_NUM;
311 default:
312 return -EINVAL;
313 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700314}
315
316static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
317{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700318 struct be_adapter *adapter = netdev_priv(netdev);
319 u8 mac_speed = 0, connector = 0;
320 u16 link_speed = 0;
321 bool link_up = false;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000322 int status;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700323
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000324 if (adapter->link_speed < 0) {
325 status = be_cmd_link_status_query(adapter, &link_up,
326 &mac_speed, &link_speed);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700327
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000328 /* link_speed is in units of 10 Mbps */
329 if (link_speed) {
330 ecmd->speed = link_speed*10;
331 } else {
332 switch (mac_speed) {
333 case PHY_LINK_SPEED_1GBPS:
334 ecmd->speed = SPEED_1000;
335 break;
336 case PHY_LINK_SPEED_10GBPS:
337 ecmd->speed = SPEED_10000;
338 break;
339 }
340 }
341
342 status = be_cmd_read_port_type(adapter, adapter->port_num,
343 &connector);
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000344 if (!status) {
345 switch (connector) {
346 case 7:
347 ecmd->port = PORT_FIBRE;
348 ecmd->transceiver = XCVR_EXTERNAL;
349 break;
350 case 0:
351 ecmd->port = PORT_TP;
352 ecmd->transceiver = XCVR_EXTERNAL;
353 break;
354 default:
355 ecmd->port = PORT_TP;
356 ecmd->transceiver = XCVR_INTERNAL;
357 break;
358 }
359 } else {
360 ecmd->port = PORT_AUI;
361 ecmd->transceiver = XCVR_INTERNAL;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700362 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000363
364 /* Save for future use */
365 adapter->link_speed = ecmd->speed;
366 adapter->port_type = ecmd->port;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000367 adapter->transceiver = ecmd->transceiver;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000368 } else {
369 ecmd->speed = adapter->link_speed;
370 ecmd->port = adapter->port_type;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000371 ecmd->transceiver = adapter->transceiver;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700372 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000373
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700374 ecmd->duplex = DUPLEX_FULL;
375 ecmd->autoneg = AUTONEG_DISABLE;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700376 ecmd->phy_address = adapter->port_num;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000377 switch (ecmd->port) {
378 case PORT_FIBRE:
379 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
380 break;
381 case PORT_TP:
382 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
383 break;
384 case PORT_AUI:
385 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
386 break;
387 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700388
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700389 return 0;
390}
391
392static void
393be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
394{
395 struct be_adapter *adapter = netdev_priv(netdev);
396
397 ring->rx_max_pending = adapter->rx_obj.q.len;
398 ring->tx_max_pending = adapter->tx_obj.q.len;
399
400 ring->rx_pending = atomic_read(&adapter->rx_obj.q.used);
401 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
402}
403
404static void
405be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
406{
407 struct be_adapter *adapter = netdev_priv(netdev);
408
Sathya Perla8788fdc2009-07-27 22:52:03 +0000409 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700410 ecmd->autoneg = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700411}
412
413static int
414be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
415{
416 struct be_adapter *adapter = netdev_priv(netdev);
417 int status;
418
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700419 if (ecmd->autoneg != 0)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700420 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000421 adapter->tx_fc = ecmd->tx_pause;
422 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700423
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000424 status = be_cmd_set_flow_control(adapter,
425 adapter->tx_fc, adapter->rx_fc);
426 if (status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700427 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
428
429 return status;
430}
431
Ajit Khaparde84517482009-09-04 03:12:16 +0000432static int
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700433be_phys_id(struct net_device *netdev, u32 data)
434{
435 struct be_adapter *adapter = netdev_priv(netdev);
436 int status;
437 u32 cur;
438
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700439 be_cmd_get_beacon_state(adapter, adapter->port_num, &cur);
440
441 if (cur == BEACON_STATE_ENABLED)
442 return 0;
443
444 if (data < 2)
445 data = 2;
446
447 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
448 BEACON_STATE_ENABLED);
449 set_current_state(TASK_INTERRUPTIBLE);
450 schedule_timeout(data*HZ);
451
452 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
453 BEACON_STATE_DISABLED);
454
455 return status;
456}
457
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000458static void
459be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
460{
461 struct be_adapter *adapter = netdev_priv(netdev);
462
463 wol->supported = WAKE_MAGIC;
464 if (adapter->wol)
465 wol->wolopts = WAKE_MAGIC;
466 else
467 wol->wolopts = 0;
468 memset(&wol->sopass, 0, sizeof(wol->sopass));
469 return;
470}
471
472static int
473be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
474{
475 struct be_adapter *adapter = netdev_priv(netdev);
476
477 if (wol->wolopts & ~WAKE_MAGIC)
478 return -EINVAL;
479
480 if (wol->wolopts & WAKE_MAGIC)
481 adapter->wol = true;
482 else
483 adapter->wol = false;
484
485 return 0;
486}
487
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700488static int
Suresh Rff33a6e2009-12-03 16:15:52 -0800489be_test_ddr_dma(struct be_adapter *adapter)
490{
491 int ret, i;
492 struct be_dma_mem ddrdma_cmd;
wzt wztc0e4d4b2010-03-25 20:12:59 +0000493 u64 pattern[2] = {0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL};
Suresh Rff33a6e2009-12-03 16:15:52 -0800494
495 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
496 ddrdma_cmd.va = pci_alloc_consistent(adapter->pdev, ddrdma_cmd.size,
497 &ddrdma_cmd.dma);
498 if (!ddrdma_cmd.va) {
499 dev_err(&adapter->pdev->dev, "Memory allocation failure \n");
500 return -ENOMEM;
501 }
502
503 for (i = 0; i < 2; i++) {
504 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
505 4096, &ddrdma_cmd);
506 if (ret != 0)
507 goto err;
508 }
509
510err:
511 pci_free_consistent(adapter->pdev, ddrdma_cmd.size,
512 ddrdma_cmd.va, ddrdma_cmd.dma);
513 return ret;
514}
515
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000516static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
517 u64 *status)
518{
519 be_cmd_set_loopback(adapter, adapter->port_num,
520 loopback_type, 1);
521 *status = be_cmd_loopback_test(adapter, adapter->port_num,
522 loopback_type, 1500,
523 2, 0xabc);
524 be_cmd_set_loopback(adapter, adapter->port_num,
525 BE_NO_LOOPBACK, 1);
526 return *status;
527}
528
Suresh Rff33a6e2009-12-03 16:15:52 -0800529static void
530be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
531{
532 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000533 bool link_up;
534 u8 mac_speed = 0;
535 u16 qos_link_speed = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800536
537 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
538
539 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000540 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
541 &data[0]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800542 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000543 }
544 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
545 &data[1]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800546 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000547 }
548 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
549 &data[2]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800550 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000551 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000552 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800553
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000554 if (be_test_ddr_dma(adapter) != 0) {
555 data[3] = 1;
556 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800557 }
558
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000559 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
560 &qos_link_speed) != 0) {
561 test->flags |= ETH_TEST_FL_FAILED;
562 data[4] = -1;
563 } else if (mac_speed) {
564 data[4] = 1;
565 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800566}
567
568static int
Ajit Khaparde84517482009-09-04 03:12:16 +0000569be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
570{
571 struct be_adapter *adapter = netdev_priv(netdev);
572 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
573 u32 region;
574
575 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
576 strcpy(file_name, efl->data);
577 region = efl->region;
578
579 return be_load_fw(adapter, file_name);
580}
581
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800582static int
583be_get_eeprom_len(struct net_device *netdev)
584{
585 return BE_READ_SEEPROM_LEN;
586}
587
588static int
589be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
590 uint8_t *data)
591{
592 struct be_adapter *adapter = netdev_priv(netdev);
593 struct be_dma_mem eeprom_cmd;
594 struct be_cmd_resp_seeprom_read *resp;
595 int status;
596
597 if (!eeprom->len)
598 return -EINVAL;
599
600 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
601
602 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
603 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
604 eeprom_cmd.va = pci_alloc_consistent(adapter->pdev, eeprom_cmd.size,
605 &eeprom_cmd.dma);
606
607 if (!eeprom_cmd.va) {
608 dev_err(&adapter->pdev->dev,
609 "Memory allocation failure. Could not read eeprom\n");
610 return -ENOMEM;
611 }
612
613 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
614
615 if (!status) {
616 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
Ajit Khapardec0ad9842010-02-08 17:51:26 +0000617 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800618 }
619 pci_free_consistent(adapter->pdev, eeprom_cmd.size, eeprom_cmd.va,
620 eeprom_cmd.dma);
621
622 return status;
623}
624
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700625const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700626 .get_settings = be_get_settings,
627 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000628 .get_wol = be_get_wol,
629 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700630 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800631 .get_eeprom_len = be_get_eeprom_len,
632 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700633 .get_coalesce = be_get_coalesce,
634 .set_coalesce = be_set_coalesce,
635 .get_ringparam = be_get_ringparam,
636 .get_pauseparam = be_get_pauseparam,
637 .set_pauseparam = be_set_pauseparam,
638 .get_rx_csum = be_get_rx_csum,
639 .set_rx_csum = be_set_rx_csum,
640 .get_tx_csum = ethtool_op_get_tx_csum,
Ajit Khaparde583e3f32009-10-05 02:22:19 +0000641 .set_tx_csum = ethtool_op_set_tx_hw_csum,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700642 .get_sg = ethtool_op_get_sg,
643 .set_sg = ethtool_op_set_sg,
644 .get_tso = ethtool_op_get_tso,
645 .set_tso = ethtool_op_set_tso,
646 .get_strings = be_get_stat_strings,
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700647 .phys_id = be_phys_id,
Ben Hutchings15f0a392009-10-01 11:58:24 +0000648 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700649 .get_ethtool_stats = be_get_ethtool_stats,
Ajit Khaparde84517482009-09-04 03:12:16 +0000650 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -0800651 .self_test = be_self_test,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700652};