blob: d92063420c25f2cdb7b3cc81633f20113852d248 [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)},
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +000063 {DRVSTAT_INFO(be_rx_mcast_pkt)},
Sathya Perla6b7c5b92009-03-11 23:32:03 -070064 {DRVSTAT_INFO(be_ethrx_post_fail)},
65 {DRVSTAT_INFO(be_802_3_dropped_frames)},
66 {DRVSTAT_INFO(be_802_3_malformed_frames)},
67 {DRVSTAT_INFO(be_tx_rate)},
68 {DRVSTAT_INFO(be_rx_rate)},
69 {PORTSTAT_INFO(rx_unicast_frames)},
70 {PORTSTAT_INFO(rx_multicast_frames)},
71 {PORTSTAT_INFO(rx_broadcast_frames)},
72 {PORTSTAT_INFO(rx_crc_errors)},
73 {PORTSTAT_INFO(rx_alignment_symbol_errors)},
74 {PORTSTAT_INFO(rx_pause_frames)},
75 {PORTSTAT_INFO(rx_control_frames)},
76 {PORTSTAT_INFO(rx_in_range_errors)},
77 {PORTSTAT_INFO(rx_out_range_errors)},
78 {PORTSTAT_INFO(rx_frame_too_long)},
79 {PORTSTAT_INFO(rx_address_match_errors)},
80 {PORTSTAT_INFO(rx_vlan_mismatch)},
81 {PORTSTAT_INFO(rx_dropped_too_small)},
82 {PORTSTAT_INFO(rx_dropped_too_short)},
83 {PORTSTAT_INFO(rx_dropped_header_too_small)},
84 {PORTSTAT_INFO(rx_dropped_tcp_length)},
85 {PORTSTAT_INFO(rx_dropped_runt)},
86 {PORTSTAT_INFO(rx_fifo_overflow)},
87 {PORTSTAT_INFO(rx_input_fifo_overflow)},
88 {PORTSTAT_INFO(rx_ip_checksum_errs)},
89 {PORTSTAT_INFO(rx_tcp_checksum_errs)},
90 {PORTSTAT_INFO(rx_udp_checksum_errs)},
91 {PORTSTAT_INFO(rx_non_rss_packets)},
92 {PORTSTAT_INFO(rx_ipv4_packets)},
93 {PORTSTAT_INFO(rx_ipv6_packets)},
Ajit Khapardedef824c2010-08-25 00:32:56 +000094 {PORTSTAT_INFO(rx_switched_unicast_packets)},
95 {PORTSTAT_INFO(rx_switched_multicast_packets)},
96 {PORTSTAT_INFO(rx_switched_broadcast_packets)},
Sathya Perla6b7c5b92009-03-11 23:32:03 -070097 {PORTSTAT_INFO(tx_unicastframes)},
98 {PORTSTAT_INFO(tx_multicastframes)},
99 {PORTSTAT_INFO(tx_broadcastframes)},
100 {PORTSTAT_INFO(tx_pauseframes)},
101 {PORTSTAT_INFO(tx_controlframes)},
102 {MISCSTAT_INFO(rx_drops_no_pbuf)},
103 {MISCSTAT_INFO(rx_drops_no_txpb)},
104 {MISCSTAT_INFO(rx_drops_no_erx_descr)},
105 {MISCSTAT_INFO(rx_drops_no_tpre_descr)},
106 {MISCSTAT_INFO(rx_drops_too_many_frags)},
107 {MISCSTAT_INFO(rx_drops_invalid_ring)},
108 {MISCSTAT_INFO(forwarded_packets)},
109 {MISCSTAT_INFO(rx_drops_mtu)},
110 {ERXSTAT_INFO(rx_drops_no_fragments)},
111};
112#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
113
Suresh Rff33a6e2009-12-03 16:15:52 -0800114static const char et_self_tests[][ETH_GSTRING_LEN] = {
115 "MAC Loopback test",
116 "PHY Loopback test",
117 "External Loopback test",
118 "DDR DMA test"
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000119 "Link test"
Suresh Rff33a6e2009-12-03 16:15:52 -0800120};
121
122#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
123#define BE_MAC_LOOPBACK 0x0
124#define BE_PHY_LOOPBACK 0x1
125#define BE_ONE_PORT_EXT_LOOPBACK 0x2
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000126#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800127
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700128static void
129be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
130{
131 struct be_adapter *adapter = netdev_priv(netdev);
132
133 strcpy(drvinfo->driver, DRV_NAME);
134 strcpy(drvinfo->version, DRV_VER);
135 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
136 strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
137 drvinfo->testinfo_len = 0;
138 drvinfo->regdump_len = 0;
139 drvinfo->eedump_len = 0;
140}
141
142static int
143be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
144{
145 struct be_adapter *adapter = netdev_priv(netdev);
146 struct be_eq_obj *rx_eq = &adapter->rx_eq;
147 struct be_eq_obj *tx_eq = &adapter->tx_eq;
148
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700149 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
150 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
151 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
152
153 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
154 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
155 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
156
157 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
158 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
159
160 return 0;
161}
162
163/*
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700164 * This routine is used to set interrup coalescing delay
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700165 */
166static int
167be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
168{
169 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700170 struct be_eq_obj *rx_eq = &adapter->rx_eq;
171 struct be_eq_obj *tx_eq = &adapter->tx_eq;
172 u32 tx_max, tx_min, tx_cur;
173 u32 rx_max, rx_min, rx_cur;
174 int status = 0;
175
176 if (coalesce->use_adaptive_tx_coalesce == 1)
177 return -EINVAL;
178
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700179 /* if AIC is being turned on now, start with an EQD of 0 */
180 if (rx_eq->enable_aic == 0 &&
181 coalesce->use_adaptive_rx_coalesce == 1) {
182 rx_eq->cur_eqd = 0;
183 }
184 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
185
186 rx_max = coalesce->rx_coalesce_usecs_high;
187 rx_min = coalesce->rx_coalesce_usecs_low;
188 rx_cur = coalesce->rx_coalesce_usecs;
189
190 tx_max = coalesce->tx_coalesce_usecs_high;
191 tx_min = coalesce->tx_coalesce_usecs_low;
192 tx_cur = coalesce->tx_coalesce_usecs;
193
194 if (tx_cur > BE_MAX_EQD)
195 tx_cur = BE_MAX_EQD;
196 if (tx_eq->cur_eqd != tx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000197 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700198 if (!status)
199 tx_eq->cur_eqd = tx_cur;
200 }
201
202 if (rx_eq->enable_aic) {
203 if (rx_max > BE_MAX_EQD)
204 rx_max = BE_MAX_EQD;
205 if (rx_min > rx_max)
206 rx_min = rx_max;
207 rx_eq->max_eqd = rx_max;
208 rx_eq->min_eqd = rx_min;
209 if (rx_eq->cur_eqd > rx_max)
210 rx_eq->cur_eqd = rx_max;
211 if (rx_eq->cur_eqd < rx_min)
212 rx_eq->cur_eqd = rx_min;
213 } else {
214 if (rx_cur > BE_MAX_EQD)
215 rx_cur = BE_MAX_EQD;
216 if (rx_eq->cur_eqd != rx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000217 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
218 rx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700219 if (!status)
220 rx_eq->cur_eqd = rx_cur;
221 }
222 }
223 return 0;
224}
225
226static u32 be_get_rx_csum(struct net_device *netdev)
227{
228 struct be_adapter *adapter = netdev_priv(netdev);
229
230 return adapter->rx_csum;
231}
232
233static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
234{
235 struct be_adapter *adapter = netdev_priv(netdev);
236
237 if (data)
238 adapter->rx_csum = true;
239 else
240 adapter->rx_csum = false;
241
242 return 0;
243}
244
245static void
246be_get_ethtool_stats(struct net_device *netdev,
247 struct ethtool_stats *stats, uint64_t *data)
248{
249 struct be_adapter *adapter = netdev_priv(netdev);
250 struct be_drvr_stats *drvr_stats = &adapter->stats.drvr_stats;
251 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va);
252 struct be_rxf_stats *rxf_stats = &hw_stats->rxf;
253 struct be_port_rxf_stats *port_stats =
254 &rxf_stats->port[adapter->port_num];
Ajit Khaparde78122a52009-10-07 03:11:20 -0700255 struct net_device_stats *net_stats = &netdev->stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700256 struct be_erx_stats *erx_stats = &hw_stats->erx;
257 void *p = NULL;
258 int i;
259
260 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
261 switch (et_stats[i].type) {
262 case NETSTAT:
263 p = net_stats;
264 break;
265 case DRVSTAT:
266 p = drvr_stats;
267 break;
268 case PORTSTAT:
269 p = port_stats;
270 break;
271 case MISCSTAT:
272 p = rxf_stats;
273 break;
274 case ERXSTAT: /* Currently only one ERX stat is provided */
275 p = (u32 *)erx_stats + adapter->rx_obj.q.id;
276 break;
277 }
278
279 p = (u8 *)p + et_stats[i].offset;
280 data[i] = (et_stats[i].size == sizeof(u64)) ?
281 *(u64 *)p: *(u32 *)p;
282 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700283}
284
285static void
286be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
287 uint8_t *data)
288{
289 int i;
290 switch (stringset) {
291 case ETH_SS_STATS:
292 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
293 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
294 data += ETH_GSTRING_LEN;
295 }
296 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800297 case ETH_SS_TEST:
298 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
299 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
300 data += ETH_GSTRING_LEN;
301 }
302 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700303 }
304}
305
Ben Hutchings15f0a392009-10-01 11:58:24 +0000306static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700307{
Ben Hutchings15f0a392009-10-01 11:58:24 +0000308 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800309 case ETH_SS_TEST:
310 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000311 case ETH_SS_STATS:
312 return ETHTOOL_STATS_NUM;
313 default:
314 return -EINVAL;
315 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700316}
317
318static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
319{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700320 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000321 struct be_dma_mem phy_cmd;
322 struct be_cmd_resp_get_phy_info *resp;
323 u8 mac_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700324 u16 link_speed = 0;
325 bool link_up = false;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000326 int status;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000327 u16 intf_type;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700328
Ajit Khaparde48e99892010-07-29 06:17:17 +0000329 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000330 status = be_cmd_link_status_query(adapter, &link_up,
331 &mac_speed, &link_speed);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700332
Ajit Khaparde48e99892010-07-29 06:17:17 +0000333 be_link_status_update(adapter, link_up);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000334 /* link_speed is in units of 10 Mbps */
335 if (link_speed) {
336 ecmd->speed = link_speed*10;
337 } else {
338 switch (mac_speed) {
339 case PHY_LINK_SPEED_1GBPS:
340 ecmd->speed = SPEED_1000;
341 break;
342 case PHY_LINK_SPEED_10GBPS:
343 ecmd->speed = SPEED_10000;
344 break;
345 }
346 }
347
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000348 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
349 phy_cmd.va = pci_alloc_consistent(adapter->pdev, phy_cmd.size,
350 &phy_cmd.dma);
351 if (!phy_cmd.va) {
352 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
353 return -ENOMEM;
354 }
355 status = be_cmd_get_phy_info(adapter, &phy_cmd);
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000356 if (!status) {
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000357 resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
358 intf_type = le16_to_cpu(resp->interface_type);
359
360 switch (intf_type) {
361 case PHY_TYPE_XFP_10GB:
362 case PHY_TYPE_SFP_1GB:
363 case PHY_TYPE_SFP_PLUS_10GB:
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000364 ecmd->port = PORT_FIBRE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000365 break;
366 default:
367 ecmd->port = PORT_TP;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000368 break;
369 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000370
371 switch (intf_type) {
372 case PHY_TYPE_KR_10GB:
373 case PHY_TYPE_KX4_10GB:
374 ecmd->autoneg = AUTONEG_ENABLE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000375 ecmd->transceiver = XCVR_INTERNAL;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000376 break;
377 default:
378 ecmd->autoneg = AUTONEG_DISABLE;
379 ecmd->transceiver = XCVR_EXTERNAL;
380 break;
381 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700382 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000383
384 /* Save for future use */
385 adapter->link_speed = ecmd->speed;
386 adapter->port_type = ecmd->port;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000387 adapter->transceiver = ecmd->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000388 adapter->autoneg = ecmd->autoneg;
389 pci_free_consistent(adapter->pdev, phy_cmd.size,
390 phy_cmd.va, phy_cmd.dma);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000391 } else {
392 ecmd->speed = adapter->link_speed;
393 ecmd->port = adapter->port_type;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000394 ecmd->transceiver = adapter->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000395 ecmd->autoneg = adapter->autoneg;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700396 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000397
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700398 ecmd->duplex = DUPLEX_FULL;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700399 ecmd->phy_address = adapter->port_num;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000400 switch (ecmd->port) {
401 case PORT_FIBRE:
402 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
403 break;
404 case PORT_TP:
405 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
406 break;
407 case PORT_AUI:
408 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
409 break;
410 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700411
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000412 if (ecmd->autoneg) {
413 ecmd->supported |= SUPPORTED_1000baseT_Full;
414 ecmd->supported |= SUPPORTED_Autoneg;
415 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
416 ADVERTISED_1000baseT_Full);
417 }
418
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700419 return 0;
420}
421
422static void
423be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
424{
425 struct be_adapter *adapter = netdev_priv(netdev);
426
427 ring->rx_max_pending = adapter->rx_obj.q.len;
428 ring->tx_max_pending = adapter->tx_obj.q.len;
429
430 ring->rx_pending = atomic_read(&adapter->rx_obj.q.used);
431 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
432}
433
434static void
435be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
436{
437 struct be_adapter *adapter = netdev_priv(netdev);
438
Sathya Perla8788fdc2009-07-27 22:52:03 +0000439 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700440 ecmd->autoneg = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700441}
442
443static int
444be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
445{
446 struct be_adapter *adapter = netdev_priv(netdev);
447 int status;
448
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700449 if (ecmd->autoneg != 0)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700450 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000451 adapter->tx_fc = ecmd->tx_pause;
452 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700453
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000454 status = be_cmd_set_flow_control(adapter,
455 adapter->tx_fc, adapter->rx_fc);
456 if (status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700457 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
458
459 return status;
460}
461
Ajit Khaparde84517482009-09-04 03:12:16 +0000462static int
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700463be_phys_id(struct net_device *netdev, u32 data)
464{
465 struct be_adapter *adapter = netdev_priv(netdev);
466 int status;
467 u32 cur;
468
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700469 be_cmd_get_beacon_state(adapter, adapter->port_num, &cur);
470
471 if (cur == BEACON_STATE_ENABLED)
472 return 0;
473
474 if (data < 2)
475 data = 2;
476
477 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
478 BEACON_STATE_ENABLED);
479 set_current_state(TASK_INTERRUPTIBLE);
480 schedule_timeout(data*HZ);
481
482 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
483 BEACON_STATE_DISABLED);
484
485 return status;
486}
487
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000488static void
489be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
490{
491 struct be_adapter *adapter = netdev_priv(netdev);
492
493 wol->supported = WAKE_MAGIC;
494 if (adapter->wol)
495 wol->wolopts = WAKE_MAGIC;
496 else
497 wol->wolopts = 0;
498 memset(&wol->sopass, 0, sizeof(wol->sopass));
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000499}
500
501static int
502be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
503{
504 struct be_adapter *adapter = netdev_priv(netdev);
505
506 if (wol->wolopts & ~WAKE_MAGIC)
507 return -EINVAL;
508
509 if (wol->wolopts & WAKE_MAGIC)
510 adapter->wol = true;
511 else
512 adapter->wol = false;
513
514 return 0;
515}
516
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700517static int
Suresh Rff33a6e2009-12-03 16:15:52 -0800518be_test_ddr_dma(struct be_adapter *adapter)
519{
520 int ret, i;
521 struct be_dma_mem ddrdma_cmd;
wzt wztc0e4d4b2010-03-25 20:12:59 +0000522 u64 pattern[2] = {0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL};
Suresh Rff33a6e2009-12-03 16:15:52 -0800523
524 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
525 ddrdma_cmd.va = pci_alloc_consistent(adapter->pdev, ddrdma_cmd.size,
526 &ddrdma_cmd.dma);
527 if (!ddrdma_cmd.va) {
Frans Pop2381a552010-03-24 07:57:36 +0000528 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Rff33a6e2009-12-03 16:15:52 -0800529 return -ENOMEM;
530 }
531
532 for (i = 0; i < 2; i++) {
533 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
534 4096, &ddrdma_cmd);
535 if (ret != 0)
536 goto err;
537 }
538
539err:
540 pci_free_consistent(adapter->pdev, ddrdma_cmd.size,
541 ddrdma_cmd.va, ddrdma_cmd.dma);
542 return ret;
543}
544
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000545static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
546 u64 *status)
547{
548 be_cmd_set_loopback(adapter, adapter->port_num,
549 loopback_type, 1);
550 *status = be_cmd_loopback_test(adapter, adapter->port_num,
551 loopback_type, 1500,
552 2, 0xabc);
553 be_cmd_set_loopback(adapter, adapter->port_num,
554 BE_NO_LOOPBACK, 1);
555 return *status;
556}
557
Suresh Rff33a6e2009-12-03 16:15:52 -0800558static void
559be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
560{
561 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000562 bool link_up;
563 u8 mac_speed = 0;
564 u16 qos_link_speed = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800565
566 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
567
568 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000569 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
570 &data[0]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800571 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000572 }
573 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
574 &data[1]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800575 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000576 }
577 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
578 &data[2]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800579 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000580 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000581 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800582
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000583 if (be_test_ddr_dma(adapter) != 0) {
584 data[3] = 1;
585 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800586 }
587
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000588 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
589 &qos_link_speed) != 0) {
590 test->flags |= ETH_TEST_FL_FAILED;
591 data[4] = -1;
592 } else if (mac_speed) {
593 data[4] = 1;
594 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800595}
596
597static int
Ajit Khaparde84517482009-09-04 03:12:16 +0000598be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
599{
600 struct be_adapter *adapter = netdev_priv(netdev);
601 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
602 u32 region;
603
604 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
605 strcpy(file_name, efl->data);
606 region = efl->region;
607
608 return be_load_fw(adapter, file_name);
609}
610
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800611static int
612be_get_eeprom_len(struct net_device *netdev)
613{
614 return BE_READ_SEEPROM_LEN;
615}
616
617static int
618be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
619 uint8_t *data)
620{
621 struct be_adapter *adapter = netdev_priv(netdev);
622 struct be_dma_mem eeprom_cmd;
623 struct be_cmd_resp_seeprom_read *resp;
624 int status;
625
626 if (!eeprom->len)
627 return -EINVAL;
628
629 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
630
631 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
632 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
633 eeprom_cmd.va = pci_alloc_consistent(adapter->pdev, eeprom_cmd.size,
634 &eeprom_cmd.dma);
635
636 if (!eeprom_cmd.va) {
637 dev_err(&adapter->pdev->dev,
638 "Memory allocation failure. Could not read eeprom\n");
639 return -ENOMEM;
640 }
641
642 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
643
644 if (!status) {
645 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
Ajit Khapardec0ad9842010-02-08 17:51:26 +0000646 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800647 }
648 pci_free_consistent(adapter->pdev, eeprom_cmd.size, eeprom_cmd.va,
649 eeprom_cmd.dma);
650
651 return status;
652}
653
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700654const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700655 .get_settings = be_get_settings,
656 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000657 .get_wol = be_get_wol,
658 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700659 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800660 .get_eeprom_len = be_get_eeprom_len,
661 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700662 .get_coalesce = be_get_coalesce,
663 .set_coalesce = be_set_coalesce,
664 .get_ringparam = be_get_ringparam,
665 .get_pauseparam = be_get_pauseparam,
666 .set_pauseparam = be_set_pauseparam,
667 .get_rx_csum = be_get_rx_csum,
668 .set_rx_csum = be_set_rx_csum,
669 .get_tx_csum = ethtool_op_get_tx_csum,
Ajit Khaparde583e3f32009-10-05 02:22:19 +0000670 .set_tx_csum = ethtool_op_set_tx_hw_csum,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700671 .get_sg = ethtool_op_get_sg,
672 .set_sg = ethtool_op_set_sg,
673 .get_tso = ethtool_op_get_tso,
674 .set_tso = ethtool_op_set_tso,
675 .get_strings = be_get_stat_strings,
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700676 .phys_id = be_phys_id,
Ben Hutchings15f0a392009-10-01 11:58:24 +0000677 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700678 .get_ethtool_stats = be_get_ethtool_stats,
Ajit Khaparde84517482009-09-04 03:12:16 +0000679 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -0800680 .self_test = be_self_test,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700681};