blob: 2f2ebbd678f20b693a9687359fe4b6dc694a2c4c [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
2 * Copyright (C) 2005 - 2009 ServerEngines
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:
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"
115};
116
117#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
118#define BE_MAC_LOOPBACK 0x0
119#define BE_PHY_LOOPBACK 0x1
120#define BE_ONE_PORT_EXT_LOOPBACK 0x2
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000121#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800122
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700123static void
124be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
125{
126 struct be_adapter *adapter = netdev_priv(netdev);
127
128 strcpy(drvinfo->driver, DRV_NAME);
129 strcpy(drvinfo->version, DRV_VER);
130 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
131 strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
132 drvinfo->testinfo_len = 0;
133 drvinfo->regdump_len = 0;
134 drvinfo->eedump_len = 0;
135}
136
137static int
138be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
139{
140 struct be_adapter *adapter = netdev_priv(netdev);
141 struct be_eq_obj *rx_eq = &adapter->rx_eq;
142 struct be_eq_obj *tx_eq = &adapter->tx_eq;
143
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700144 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
145 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
146 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
147
148 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
149 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
150 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
151
152 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
153 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
154
155 return 0;
156}
157
158/*
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700159 * This routine is used to set interrup coalescing delay
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700160 */
161static int
162be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
163{
164 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700165 struct be_eq_obj *rx_eq = &adapter->rx_eq;
166 struct be_eq_obj *tx_eq = &adapter->tx_eq;
167 u32 tx_max, tx_min, tx_cur;
168 u32 rx_max, rx_min, rx_cur;
169 int status = 0;
170
171 if (coalesce->use_adaptive_tx_coalesce == 1)
172 return -EINVAL;
173
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700174 /* if AIC is being turned on now, start with an EQD of 0 */
175 if (rx_eq->enable_aic == 0 &&
176 coalesce->use_adaptive_rx_coalesce == 1) {
177 rx_eq->cur_eqd = 0;
178 }
179 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
180
181 rx_max = coalesce->rx_coalesce_usecs_high;
182 rx_min = coalesce->rx_coalesce_usecs_low;
183 rx_cur = coalesce->rx_coalesce_usecs;
184
185 tx_max = coalesce->tx_coalesce_usecs_high;
186 tx_min = coalesce->tx_coalesce_usecs_low;
187 tx_cur = coalesce->tx_coalesce_usecs;
188
189 if (tx_cur > BE_MAX_EQD)
190 tx_cur = BE_MAX_EQD;
191 if (tx_eq->cur_eqd != tx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000192 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700193 if (!status)
194 tx_eq->cur_eqd = tx_cur;
195 }
196
197 if (rx_eq->enable_aic) {
198 if (rx_max > BE_MAX_EQD)
199 rx_max = BE_MAX_EQD;
200 if (rx_min > rx_max)
201 rx_min = rx_max;
202 rx_eq->max_eqd = rx_max;
203 rx_eq->min_eqd = rx_min;
204 if (rx_eq->cur_eqd > rx_max)
205 rx_eq->cur_eqd = rx_max;
206 if (rx_eq->cur_eqd < rx_min)
207 rx_eq->cur_eqd = rx_min;
208 } else {
209 if (rx_cur > BE_MAX_EQD)
210 rx_cur = BE_MAX_EQD;
211 if (rx_eq->cur_eqd != rx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000212 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
213 rx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700214 if (!status)
215 rx_eq->cur_eqd = rx_cur;
216 }
217 }
218 return 0;
219}
220
221static u32 be_get_rx_csum(struct net_device *netdev)
222{
223 struct be_adapter *adapter = netdev_priv(netdev);
224
225 return adapter->rx_csum;
226}
227
228static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
229{
230 struct be_adapter *adapter = netdev_priv(netdev);
231
232 if (data)
233 adapter->rx_csum = true;
234 else
235 adapter->rx_csum = false;
236
237 return 0;
238}
239
240static void
241be_get_ethtool_stats(struct net_device *netdev,
242 struct ethtool_stats *stats, uint64_t *data)
243{
244 struct be_adapter *adapter = netdev_priv(netdev);
245 struct be_drvr_stats *drvr_stats = &adapter->stats.drvr_stats;
246 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va);
247 struct be_rxf_stats *rxf_stats = &hw_stats->rxf;
248 struct be_port_rxf_stats *port_stats =
249 &rxf_stats->port[adapter->port_num];
Ajit Khaparde78122a52009-10-07 03:11:20 -0700250 struct net_device_stats *net_stats = &netdev->stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700251 struct be_erx_stats *erx_stats = &hw_stats->erx;
252 void *p = NULL;
253 int i;
254
255 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
256 switch (et_stats[i].type) {
257 case NETSTAT:
258 p = net_stats;
259 break;
260 case DRVSTAT:
261 p = drvr_stats;
262 break;
263 case PORTSTAT:
264 p = port_stats;
265 break;
266 case MISCSTAT:
267 p = rxf_stats;
268 break;
269 case ERXSTAT: /* Currently only one ERX stat is provided */
270 p = (u32 *)erx_stats + adapter->rx_obj.q.id;
271 break;
272 }
273
274 p = (u8 *)p + et_stats[i].offset;
275 data[i] = (et_stats[i].size == sizeof(u64)) ?
276 *(u64 *)p: *(u32 *)p;
277 }
278
279 return;
280}
281
282static void
283be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
284 uint8_t *data)
285{
286 int i;
287 switch (stringset) {
288 case ETH_SS_STATS:
289 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
290 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
291 data += ETH_GSTRING_LEN;
292 }
293 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800294 case ETH_SS_TEST:
295 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
296 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
297 data += ETH_GSTRING_LEN;
298 }
299 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700300 }
301}
302
Ben Hutchings15f0a392009-10-01 11:58:24 +0000303static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700304{
Ben Hutchings15f0a392009-10-01 11:58:24 +0000305 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800306 case ETH_SS_TEST:
307 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000308 case ETH_SS_STATS:
309 return ETHTOOL_STATS_NUM;
310 default:
311 return -EINVAL;
312 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700313}
314
315static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
316{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700317 struct be_adapter *adapter = netdev_priv(netdev);
318 u8 mac_speed = 0, connector = 0;
319 u16 link_speed = 0;
320 bool link_up = false;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000321 int status;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700322
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000323 if (adapter->link_speed < 0) {
324 status = be_cmd_link_status_query(adapter, &link_up,
325 &mac_speed, &link_speed);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700326
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000327 /* link_speed is in units of 10 Mbps */
328 if (link_speed) {
329 ecmd->speed = link_speed*10;
330 } else {
331 switch (mac_speed) {
332 case PHY_LINK_SPEED_1GBPS:
333 ecmd->speed = SPEED_1000;
334 break;
335 case PHY_LINK_SPEED_10GBPS:
336 ecmd->speed = SPEED_10000;
337 break;
338 }
339 }
340
341 status = be_cmd_read_port_type(adapter, adapter->port_num,
342 &connector);
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000343 if (!status) {
344 switch (connector) {
345 case 7:
346 ecmd->port = PORT_FIBRE;
347 ecmd->transceiver = XCVR_EXTERNAL;
348 break;
349 case 0:
350 ecmd->port = PORT_TP;
351 ecmd->transceiver = XCVR_EXTERNAL;
352 break;
353 default:
354 ecmd->port = PORT_TP;
355 ecmd->transceiver = XCVR_INTERNAL;
356 break;
357 }
358 } else {
359 ecmd->port = PORT_AUI;
360 ecmd->transceiver = XCVR_INTERNAL;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700361 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000362
363 /* Save for future use */
364 adapter->link_speed = ecmd->speed;
365 adapter->port_type = ecmd->port;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000366 adapter->transceiver = ecmd->transceiver;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000367 } else {
368 ecmd->speed = adapter->link_speed;
369 ecmd->port = adapter->port_type;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000370 ecmd->transceiver = adapter->transceiver;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700371 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000372
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700373 ecmd->duplex = DUPLEX_FULL;
374 ecmd->autoneg = AUTONEG_DISABLE;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700375 ecmd->phy_address = adapter->port_num;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000376 switch (ecmd->port) {
377 case PORT_FIBRE:
378 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
379 break;
380 case PORT_TP:
381 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
382 break;
383 case PORT_AUI:
384 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
385 break;
386 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700387
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700388 return 0;
389}
390
391static void
392be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
393{
394 struct be_adapter *adapter = netdev_priv(netdev);
395
396 ring->rx_max_pending = adapter->rx_obj.q.len;
397 ring->tx_max_pending = adapter->tx_obj.q.len;
398
399 ring->rx_pending = atomic_read(&adapter->rx_obj.q.used);
400 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
401}
402
403static void
404be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
405{
406 struct be_adapter *adapter = netdev_priv(netdev);
407
Sathya Perla8788fdc2009-07-27 22:52:03 +0000408 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700409 ecmd->autoneg = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700410}
411
412static int
413be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
414{
415 struct be_adapter *adapter = netdev_priv(netdev);
416 int status;
417
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700418 if (ecmd->autoneg != 0)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700419 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000420 adapter->tx_fc = ecmd->tx_pause;
421 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700422
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000423 status = be_cmd_set_flow_control(adapter,
424 adapter->tx_fc, adapter->rx_fc);
425 if (status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700426 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
427
428 return status;
429}
430
Ajit Khaparde84517482009-09-04 03:12:16 +0000431static int
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700432be_phys_id(struct net_device *netdev, u32 data)
433{
434 struct be_adapter *adapter = netdev_priv(netdev);
435 int status;
436 u32 cur;
437
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700438 be_cmd_get_beacon_state(adapter, adapter->port_num, &cur);
439
440 if (cur == BEACON_STATE_ENABLED)
441 return 0;
442
443 if (data < 2)
444 data = 2;
445
446 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
447 BEACON_STATE_ENABLED);
448 set_current_state(TASK_INTERRUPTIBLE);
449 schedule_timeout(data*HZ);
450
451 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
452 BEACON_STATE_DISABLED);
453
454 return status;
455}
456
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000457static void
458be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
459{
460 struct be_adapter *adapter = netdev_priv(netdev);
461
462 wol->supported = WAKE_MAGIC;
463 if (adapter->wol)
464 wol->wolopts = WAKE_MAGIC;
465 else
466 wol->wolopts = 0;
467 memset(&wol->sopass, 0, sizeof(wol->sopass));
468 return;
469}
470
471static int
472be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
473{
474 struct be_adapter *adapter = netdev_priv(netdev);
475
476 if (wol->wolopts & ~WAKE_MAGIC)
477 return -EINVAL;
478
479 if (wol->wolopts & WAKE_MAGIC)
480 adapter->wol = true;
481 else
482 adapter->wol = false;
483
484 return 0;
485}
486
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700487static int
Suresh Rff33a6e2009-12-03 16:15:52 -0800488be_test_ddr_dma(struct be_adapter *adapter)
489{
490 int ret, i;
491 struct be_dma_mem ddrdma_cmd;
492 u64 pattern[2] = {0x5a5a5a5a5a5a5a5a, 0xa5a5a5a5a5a5a5a5};
493
494 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
495 ddrdma_cmd.va = pci_alloc_consistent(adapter->pdev, ddrdma_cmd.size,
496 &ddrdma_cmd.dma);
497 if (!ddrdma_cmd.va) {
498 dev_err(&adapter->pdev->dev, "Memory allocation failure \n");
499 return -ENOMEM;
500 }
501
502 for (i = 0; i < 2; i++) {
503 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
504 4096, &ddrdma_cmd);
505 if (ret != 0)
506 goto err;
507 }
508
509err:
510 pci_free_consistent(adapter->pdev, ddrdma_cmd.size,
511 ddrdma_cmd.va, ddrdma_cmd.dma);
512 return ret;
513}
514
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000515static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
516 u64 *status)
517{
518 be_cmd_set_loopback(adapter, adapter->port_num,
519 loopback_type, 1);
520 *status = be_cmd_loopback_test(adapter, adapter->port_num,
521 loopback_type, 1500,
522 2, 0xabc);
523 be_cmd_set_loopback(adapter, adapter->port_num,
524 BE_NO_LOOPBACK, 1);
525 return *status;
526}
527
Suresh Rff33a6e2009-12-03 16:15:52 -0800528static void
529be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
530{
531 struct be_adapter *adapter = netdev_priv(netdev);
532
533 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
534
535 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000536 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
537 &data[0]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800538 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000539 }
540 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
541 &data[1]) != 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_ONE_PORT_EXT_LOOPBACK,
545 &data[2]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800546 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000547 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000548 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800549
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000550 if (be_test_ddr_dma(adapter) != 0) {
551 data[3] = 1;
552 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800553 }
554
555}
556
557static int
Ajit Khaparde84517482009-09-04 03:12:16 +0000558be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
559{
560 struct be_adapter *adapter = netdev_priv(netdev);
561 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
562 u32 region;
563
564 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
565 strcpy(file_name, efl->data);
566 region = efl->region;
567
568 return be_load_fw(adapter, file_name);
569}
570
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800571static int
572be_get_eeprom_len(struct net_device *netdev)
573{
574 return BE_READ_SEEPROM_LEN;
575}
576
577static int
578be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
579 uint8_t *data)
580{
581 struct be_adapter *adapter = netdev_priv(netdev);
582 struct be_dma_mem eeprom_cmd;
583 struct be_cmd_resp_seeprom_read *resp;
584 int status;
585
586 if (!eeprom->len)
587 return -EINVAL;
588
589 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
590
591 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
592 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
593 eeprom_cmd.va = pci_alloc_consistent(adapter->pdev, eeprom_cmd.size,
594 &eeprom_cmd.dma);
595
596 if (!eeprom_cmd.va) {
597 dev_err(&adapter->pdev->dev,
598 "Memory allocation failure. Could not read eeprom\n");
599 return -ENOMEM;
600 }
601
602 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
603
604 if (!status) {
605 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
606 memcpy(data, resp->seeprom_data, eeprom->len);
607 }
608 pci_free_consistent(adapter->pdev, eeprom_cmd.size, eeprom_cmd.va,
609 eeprom_cmd.dma);
610
611 return status;
612}
613
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700614const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700615 .get_settings = be_get_settings,
616 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000617 .get_wol = be_get_wol,
618 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700619 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800620 .get_eeprom_len = be_get_eeprom_len,
621 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700622 .get_coalesce = be_get_coalesce,
623 .set_coalesce = be_set_coalesce,
624 .get_ringparam = be_get_ringparam,
625 .get_pauseparam = be_get_pauseparam,
626 .set_pauseparam = be_set_pauseparam,
627 .get_rx_csum = be_get_rx_csum,
628 .set_rx_csum = be_set_rx_csum,
629 .get_tx_csum = ethtool_op_get_tx_csum,
Ajit Khaparde583e3f32009-10-05 02:22:19 +0000630 .set_tx_csum = ethtool_op_set_tx_hw_csum,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700631 .get_sg = ethtool_op_get_sg,
632 .set_sg = ethtool_op_set_sg,
633 .get_tso = ethtool_op_get_tso,
634 .set_tso = ethtool_op_set_tso,
635 .get_strings = be_get_stat_strings,
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700636 .phys_id = be_phys_id,
Ben Hutchings15f0a392009-10-01 11:58:24 +0000637 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700638 .get_ethtool_stats = be_get_ethtool_stats,
Ajit Khaparde84517482009-09-04 03:12:16 +0000639 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -0800640 .self_test = be_self_test,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700641};