blob: 9bedb9ff6e12327b877912abcc75d9b0a9f59f44 [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)},
Ajit Khapardedef824c2010-08-25 00:32:56 +000093 {PORTSTAT_INFO(rx_switched_unicast_packets)},
94 {PORTSTAT_INFO(rx_switched_multicast_packets)},
95 {PORTSTAT_INFO(rx_switched_broadcast_packets)},
Sathya Perla6b7c5b92009-03-11 23:32:03 -070096 {PORTSTAT_INFO(tx_unicastframes)},
97 {PORTSTAT_INFO(tx_multicastframes)},
98 {PORTSTAT_INFO(tx_broadcastframes)},
99 {PORTSTAT_INFO(tx_pauseframes)},
100 {PORTSTAT_INFO(tx_controlframes)},
101 {MISCSTAT_INFO(rx_drops_no_pbuf)},
102 {MISCSTAT_INFO(rx_drops_no_txpb)},
103 {MISCSTAT_INFO(rx_drops_no_erx_descr)},
104 {MISCSTAT_INFO(rx_drops_no_tpre_descr)},
105 {MISCSTAT_INFO(rx_drops_too_many_frags)},
106 {MISCSTAT_INFO(rx_drops_invalid_ring)},
107 {MISCSTAT_INFO(forwarded_packets)},
108 {MISCSTAT_INFO(rx_drops_mtu)},
109 {ERXSTAT_INFO(rx_drops_no_fragments)},
110};
111#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
112
Suresh Rff33a6e2009-12-03 16:15:52 -0800113static const char et_self_tests[][ETH_GSTRING_LEN] = {
114 "MAC Loopback test",
115 "PHY Loopback test",
116 "External Loopback test",
117 "DDR DMA test"
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000118 "Link test"
Suresh Rff33a6e2009-12-03 16:15:52 -0800119};
120
121#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
122#define BE_MAC_LOOPBACK 0x0
123#define BE_PHY_LOOPBACK 0x1
124#define BE_ONE_PORT_EXT_LOOPBACK 0x2
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000125#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800126
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700127static void
128be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
129{
130 struct be_adapter *adapter = netdev_priv(netdev);
131
132 strcpy(drvinfo->driver, DRV_NAME);
133 strcpy(drvinfo->version, DRV_VER);
134 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
135 strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
136 drvinfo->testinfo_len = 0;
137 drvinfo->regdump_len = 0;
138 drvinfo->eedump_len = 0;
139}
140
141static int
142be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
143{
144 struct be_adapter *adapter = netdev_priv(netdev);
145 struct be_eq_obj *rx_eq = &adapter->rx_eq;
146 struct be_eq_obj *tx_eq = &adapter->tx_eq;
147
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700148 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
149 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
150 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
151
152 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
153 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
154 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
155
156 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
157 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
158
159 return 0;
160}
161
162/*
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700163 * This routine is used to set interrup coalescing delay
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700164 */
165static int
166be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
167{
168 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700169 struct be_eq_obj *rx_eq = &adapter->rx_eq;
170 struct be_eq_obj *tx_eq = &adapter->tx_eq;
171 u32 tx_max, tx_min, tx_cur;
172 u32 rx_max, rx_min, rx_cur;
173 int status = 0;
174
175 if (coalesce->use_adaptive_tx_coalesce == 1)
176 return -EINVAL;
177
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700178 /* if AIC is being turned on now, start with an EQD of 0 */
179 if (rx_eq->enable_aic == 0 &&
180 coalesce->use_adaptive_rx_coalesce == 1) {
181 rx_eq->cur_eqd = 0;
182 }
183 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
184
185 rx_max = coalesce->rx_coalesce_usecs_high;
186 rx_min = coalesce->rx_coalesce_usecs_low;
187 rx_cur = coalesce->rx_coalesce_usecs;
188
189 tx_max = coalesce->tx_coalesce_usecs_high;
190 tx_min = coalesce->tx_coalesce_usecs_low;
191 tx_cur = coalesce->tx_coalesce_usecs;
192
193 if (tx_cur > BE_MAX_EQD)
194 tx_cur = BE_MAX_EQD;
195 if (tx_eq->cur_eqd != tx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000196 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700197 if (!status)
198 tx_eq->cur_eqd = tx_cur;
199 }
200
201 if (rx_eq->enable_aic) {
202 if (rx_max > BE_MAX_EQD)
203 rx_max = BE_MAX_EQD;
204 if (rx_min > rx_max)
205 rx_min = rx_max;
206 rx_eq->max_eqd = rx_max;
207 rx_eq->min_eqd = rx_min;
208 if (rx_eq->cur_eqd > rx_max)
209 rx_eq->cur_eqd = rx_max;
210 if (rx_eq->cur_eqd < rx_min)
211 rx_eq->cur_eqd = rx_min;
212 } else {
213 if (rx_cur > BE_MAX_EQD)
214 rx_cur = BE_MAX_EQD;
215 if (rx_eq->cur_eqd != rx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000216 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
217 rx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700218 if (!status)
219 rx_eq->cur_eqd = rx_cur;
220 }
221 }
222 return 0;
223}
224
225static u32 be_get_rx_csum(struct net_device *netdev)
226{
227 struct be_adapter *adapter = netdev_priv(netdev);
228
229 return adapter->rx_csum;
230}
231
232static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
233{
234 struct be_adapter *adapter = netdev_priv(netdev);
235
236 if (data)
237 adapter->rx_csum = true;
238 else
239 adapter->rx_csum = false;
240
241 return 0;
242}
243
244static void
245be_get_ethtool_stats(struct net_device *netdev,
246 struct ethtool_stats *stats, uint64_t *data)
247{
248 struct be_adapter *adapter = netdev_priv(netdev);
249 struct be_drvr_stats *drvr_stats = &adapter->stats.drvr_stats;
250 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va);
251 struct be_rxf_stats *rxf_stats = &hw_stats->rxf;
252 struct be_port_rxf_stats *port_stats =
253 &rxf_stats->port[adapter->port_num];
Ajit Khaparde78122a52009-10-07 03:11:20 -0700254 struct net_device_stats *net_stats = &netdev->stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700255 struct be_erx_stats *erx_stats = &hw_stats->erx;
256 void *p = NULL;
257 int i;
258
259 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
260 switch (et_stats[i].type) {
261 case NETSTAT:
262 p = net_stats;
263 break;
264 case DRVSTAT:
265 p = drvr_stats;
266 break;
267 case PORTSTAT:
268 p = port_stats;
269 break;
270 case MISCSTAT:
271 p = rxf_stats;
272 break;
273 case ERXSTAT: /* Currently only one ERX stat is provided */
274 p = (u32 *)erx_stats + adapter->rx_obj.q.id;
275 break;
276 }
277
278 p = (u8 *)p + et_stats[i].offset;
279 data[i] = (et_stats[i].size == sizeof(u64)) ?
280 *(u64 *)p: *(u32 *)p;
281 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700282}
283
284static void
285be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
286 uint8_t *data)
287{
288 int i;
289 switch (stringset) {
290 case ETH_SS_STATS:
291 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
292 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
293 data += ETH_GSTRING_LEN;
294 }
295 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800296 case ETH_SS_TEST:
297 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
298 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
299 data += ETH_GSTRING_LEN;
300 }
301 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700302 }
303}
304
Ben Hutchings15f0a392009-10-01 11:58:24 +0000305static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700306{
Ben Hutchings15f0a392009-10-01 11:58:24 +0000307 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800308 case ETH_SS_TEST:
309 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000310 case ETH_SS_STATS:
311 return ETHTOOL_STATS_NUM;
312 default:
313 return -EINVAL;
314 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700315}
316
317static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
318{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700319 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000320 struct be_dma_mem phy_cmd;
321 struct be_cmd_resp_get_phy_info *resp;
322 u8 mac_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700323 u16 link_speed = 0;
324 bool link_up = false;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000325 int status;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000326 u16 intf_type;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700327
Ajit Khaparde48e99892010-07-29 06:17:17 +0000328 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000329 status = be_cmd_link_status_query(adapter, &link_up,
330 &mac_speed, &link_speed);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700331
Ajit Khaparde48e99892010-07-29 06:17:17 +0000332 be_link_status_update(adapter, link_up);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000333 /* link_speed is in units of 10 Mbps */
334 if (link_speed) {
335 ecmd->speed = link_speed*10;
336 } else {
337 switch (mac_speed) {
338 case PHY_LINK_SPEED_1GBPS:
339 ecmd->speed = SPEED_1000;
340 break;
341 case PHY_LINK_SPEED_10GBPS:
342 ecmd->speed = SPEED_10000;
343 break;
344 }
345 }
346
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000347 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
348 phy_cmd.va = pci_alloc_consistent(adapter->pdev, phy_cmd.size,
349 &phy_cmd.dma);
350 if (!phy_cmd.va) {
351 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
352 return -ENOMEM;
353 }
354 status = be_cmd_get_phy_info(adapter, &phy_cmd);
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000355 if (!status) {
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000356 resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
357 intf_type = le16_to_cpu(resp->interface_type);
358
359 switch (intf_type) {
360 case PHY_TYPE_XFP_10GB:
361 case PHY_TYPE_SFP_1GB:
362 case PHY_TYPE_SFP_PLUS_10GB:
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000363 ecmd->port = PORT_FIBRE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000364 break;
365 default:
366 ecmd->port = PORT_TP;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000367 break;
368 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000369
370 switch (intf_type) {
371 case PHY_TYPE_KR_10GB:
372 case PHY_TYPE_KX4_10GB:
373 ecmd->autoneg = AUTONEG_ENABLE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000374 ecmd->transceiver = XCVR_INTERNAL;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000375 break;
376 default:
377 ecmd->autoneg = AUTONEG_DISABLE;
378 ecmd->transceiver = XCVR_EXTERNAL;
379 break;
380 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700381 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000382
383 /* Save for future use */
384 adapter->link_speed = ecmd->speed;
385 adapter->port_type = ecmd->port;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000386 adapter->transceiver = ecmd->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000387 adapter->autoneg = ecmd->autoneg;
388 pci_free_consistent(adapter->pdev, phy_cmd.size,
389 phy_cmd.va, phy_cmd.dma);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000390 } else {
391 ecmd->speed = adapter->link_speed;
392 ecmd->port = adapter->port_type;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000393 ecmd->transceiver = adapter->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000394 ecmd->autoneg = adapter->autoneg;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700395 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000396
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700397 ecmd->duplex = DUPLEX_FULL;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700398 ecmd->phy_address = adapter->port_num;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000399 switch (ecmd->port) {
400 case PORT_FIBRE:
401 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
402 break;
403 case PORT_TP:
404 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
405 break;
406 case PORT_AUI:
407 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
408 break;
409 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700410
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000411 if (ecmd->autoneg) {
412 ecmd->supported |= SUPPORTED_1000baseT_Full;
413 ecmd->supported |= SUPPORTED_Autoneg;
414 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
415 ADVERTISED_1000baseT_Full);
416 }
417
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700418 return 0;
419}
420
421static void
422be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
423{
424 struct be_adapter *adapter = netdev_priv(netdev);
425
426 ring->rx_max_pending = adapter->rx_obj.q.len;
427 ring->tx_max_pending = adapter->tx_obj.q.len;
428
429 ring->rx_pending = atomic_read(&adapter->rx_obj.q.used);
430 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
431}
432
433static void
434be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
435{
436 struct be_adapter *adapter = netdev_priv(netdev);
437
Sathya Perla8788fdc2009-07-27 22:52:03 +0000438 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700439 ecmd->autoneg = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700440}
441
442static int
443be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
444{
445 struct be_adapter *adapter = netdev_priv(netdev);
446 int status;
447
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700448 if (ecmd->autoneg != 0)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700449 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000450 adapter->tx_fc = ecmd->tx_pause;
451 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700452
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000453 status = be_cmd_set_flow_control(adapter,
454 adapter->tx_fc, adapter->rx_fc);
455 if (status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700456 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
457
458 return status;
459}
460
Ajit Khaparde84517482009-09-04 03:12:16 +0000461static int
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700462be_phys_id(struct net_device *netdev, u32 data)
463{
464 struct be_adapter *adapter = netdev_priv(netdev);
465 int status;
466 u32 cur;
467
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700468 be_cmd_get_beacon_state(adapter, adapter->port_num, &cur);
469
470 if (cur == BEACON_STATE_ENABLED)
471 return 0;
472
473 if (data < 2)
474 data = 2;
475
476 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
477 BEACON_STATE_ENABLED);
478 set_current_state(TASK_INTERRUPTIBLE);
479 schedule_timeout(data*HZ);
480
481 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
482 BEACON_STATE_DISABLED);
483
484 return status;
485}
486
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000487static void
488be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
489{
490 struct be_adapter *adapter = netdev_priv(netdev);
491
492 wol->supported = WAKE_MAGIC;
493 if (adapter->wol)
494 wol->wolopts = WAKE_MAGIC;
495 else
496 wol->wolopts = 0;
497 memset(&wol->sopass, 0, sizeof(wol->sopass));
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000498}
499
500static int
501be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
502{
503 struct be_adapter *adapter = netdev_priv(netdev);
504
505 if (wol->wolopts & ~WAKE_MAGIC)
506 return -EINVAL;
507
508 if (wol->wolopts & WAKE_MAGIC)
509 adapter->wol = true;
510 else
511 adapter->wol = false;
512
513 return 0;
514}
515
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700516static int
Suresh Rff33a6e2009-12-03 16:15:52 -0800517be_test_ddr_dma(struct be_adapter *adapter)
518{
519 int ret, i;
520 struct be_dma_mem ddrdma_cmd;
wzt wztc0e4d4b2010-03-25 20:12:59 +0000521 u64 pattern[2] = {0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL};
Suresh Rff33a6e2009-12-03 16:15:52 -0800522
523 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
524 ddrdma_cmd.va = pci_alloc_consistent(adapter->pdev, ddrdma_cmd.size,
525 &ddrdma_cmd.dma);
526 if (!ddrdma_cmd.va) {
Frans Pop2381a552010-03-24 07:57:36 +0000527 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Rff33a6e2009-12-03 16:15:52 -0800528 return -ENOMEM;
529 }
530
531 for (i = 0; i < 2; i++) {
532 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
533 4096, &ddrdma_cmd);
534 if (ret != 0)
535 goto err;
536 }
537
538err:
539 pci_free_consistent(adapter->pdev, ddrdma_cmd.size,
540 ddrdma_cmd.va, ddrdma_cmd.dma);
541 return ret;
542}
543
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000544static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
545 u64 *status)
546{
547 be_cmd_set_loopback(adapter, adapter->port_num,
548 loopback_type, 1);
549 *status = be_cmd_loopback_test(adapter, adapter->port_num,
550 loopback_type, 1500,
551 2, 0xabc);
552 be_cmd_set_loopback(adapter, adapter->port_num,
553 BE_NO_LOOPBACK, 1);
554 return *status;
555}
556
Suresh Rff33a6e2009-12-03 16:15:52 -0800557static void
558be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
559{
560 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000561 bool link_up;
562 u8 mac_speed = 0;
563 u16 qos_link_speed = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800564
565 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
566
567 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000568 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
569 &data[0]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800570 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000571 }
572 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
573 &data[1]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800574 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000575 }
576 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
577 &data[2]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800578 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000579 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000580 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800581
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000582 if (be_test_ddr_dma(adapter) != 0) {
583 data[3] = 1;
584 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800585 }
586
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000587 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
588 &qos_link_speed) != 0) {
589 test->flags |= ETH_TEST_FL_FAILED;
590 data[4] = -1;
591 } else if (mac_speed) {
592 data[4] = 1;
593 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800594}
595
596static int
Ajit Khaparde84517482009-09-04 03:12:16 +0000597be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
598{
599 struct be_adapter *adapter = netdev_priv(netdev);
600 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
601 u32 region;
602
603 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
604 strcpy(file_name, efl->data);
605 region = efl->region;
606
607 return be_load_fw(adapter, file_name);
608}
609
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800610static int
611be_get_eeprom_len(struct net_device *netdev)
612{
613 return BE_READ_SEEPROM_LEN;
614}
615
616static int
617be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
618 uint8_t *data)
619{
620 struct be_adapter *adapter = netdev_priv(netdev);
621 struct be_dma_mem eeprom_cmd;
622 struct be_cmd_resp_seeprom_read *resp;
623 int status;
624
625 if (!eeprom->len)
626 return -EINVAL;
627
628 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
629
630 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
631 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
632 eeprom_cmd.va = pci_alloc_consistent(adapter->pdev, eeprom_cmd.size,
633 &eeprom_cmd.dma);
634
635 if (!eeprom_cmd.va) {
636 dev_err(&adapter->pdev->dev,
637 "Memory allocation failure. Could not read eeprom\n");
638 return -ENOMEM;
639 }
640
641 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
642
643 if (!status) {
644 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
Ajit Khapardec0ad9842010-02-08 17:51:26 +0000645 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800646 }
647 pci_free_consistent(adapter->pdev, eeprom_cmd.size, eeprom_cmd.va,
648 eeprom_cmd.dma);
649
650 return status;
651}
652
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700653const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700654 .get_settings = be_get_settings,
655 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000656 .get_wol = be_get_wol,
657 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700658 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800659 .get_eeprom_len = be_get_eeprom_len,
660 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700661 .get_coalesce = be_get_coalesce,
662 .set_coalesce = be_set_coalesce,
663 .get_ringparam = be_get_ringparam,
664 .get_pauseparam = be_get_pauseparam,
665 .set_pauseparam = be_set_pauseparam,
666 .get_rx_csum = be_get_rx_csum,
667 .set_rx_csum = be_set_rx_csum,
668 .get_tx_csum = ethtool_op_get_tx_csum,
Ajit Khaparde583e3f32009-10-05 02:22:19 +0000669 .set_tx_csum = ethtool_op_set_tx_hw_csum,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700670 .get_sg = ethtool_op_get_sg,
671 .set_sg = ethtool_op_set_sg,
672 .get_tso = ethtool_op_get_tso,
673 .set_tso = ethtool_op_set_tso,
674 .get_strings = be_get_stat_strings,
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700675 .phys_id = be_phys_id,
Ben Hutchings15f0a392009-10-01 11:58:24 +0000676 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700677 .get_ethtool_stats = be_get_ethtool_stats,
Ajit Khaparde84517482009-09-04 03:12:16 +0000678 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -0800679 .self_test = be_self_test,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700680};