blob: 0f46366ecc48eee1c7a7999db0a067fead28c37f [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
Sathya Perla3abcded2010-10-03 22:12:27 -070029enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT_TX, DRVSTAT_RX, ERXSTAT};
Sathya Perla6b7c5b92009-03-11 23:32:03 -070030#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)
Sathya Perla3abcded2010-10-03 22:12:27 -070035#define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\
36 FIELDINFO(struct be_tx_stats, field)
37#define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\
38 FIELDINFO(struct be_rx_stats, field)
Sathya Perla6b7c5b92009-03-11 23:32:03 -070039#define MISCSTAT_INFO(field) #field, MISCSTAT,\
40 FIELDINFO(struct be_rxf_stats, field)
41#define PORTSTAT_INFO(field) #field, PORTSTAT,\
42 FIELDINFO(struct be_port_rxf_stats, \
43 field)
44#define ERXSTAT_INFO(field) #field, ERXSTAT,\
45 FIELDINFO(struct be_erx_stats, field)
46
47static const struct be_ethtool_stat et_stats[] = {
48 {NETSTAT_INFO(rx_packets)},
49 {NETSTAT_INFO(tx_packets)},
50 {NETSTAT_INFO(rx_bytes)},
51 {NETSTAT_INFO(tx_bytes)},
52 {NETSTAT_INFO(rx_errors)},
53 {NETSTAT_INFO(tx_errors)},
54 {NETSTAT_INFO(rx_dropped)},
55 {NETSTAT_INFO(tx_dropped)},
Sathya Perla3abcded2010-10-03 22:12:27 -070056 {DRVSTAT_TX_INFO(be_tx_rate)},
57 {DRVSTAT_TX_INFO(be_tx_reqs)},
58 {DRVSTAT_TX_INFO(be_tx_wrbs)},
59 {DRVSTAT_TX_INFO(be_tx_stops)},
60 {DRVSTAT_TX_INFO(be_tx_events)},
61 {DRVSTAT_TX_INFO(be_tx_compl)},
Sathya Perla6b7c5b92009-03-11 23:32:03 -070062 {PORTSTAT_INFO(rx_unicast_frames)},
63 {PORTSTAT_INFO(rx_multicast_frames)},
64 {PORTSTAT_INFO(rx_broadcast_frames)},
65 {PORTSTAT_INFO(rx_crc_errors)},
66 {PORTSTAT_INFO(rx_alignment_symbol_errors)},
67 {PORTSTAT_INFO(rx_pause_frames)},
68 {PORTSTAT_INFO(rx_control_frames)},
69 {PORTSTAT_INFO(rx_in_range_errors)},
70 {PORTSTAT_INFO(rx_out_range_errors)},
71 {PORTSTAT_INFO(rx_frame_too_long)},
72 {PORTSTAT_INFO(rx_address_match_errors)},
73 {PORTSTAT_INFO(rx_vlan_mismatch)},
74 {PORTSTAT_INFO(rx_dropped_too_small)},
75 {PORTSTAT_INFO(rx_dropped_too_short)},
76 {PORTSTAT_INFO(rx_dropped_header_too_small)},
77 {PORTSTAT_INFO(rx_dropped_tcp_length)},
78 {PORTSTAT_INFO(rx_dropped_runt)},
79 {PORTSTAT_INFO(rx_fifo_overflow)},
80 {PORTSTAT_INFO(rx_input_fifo_overflow)},
81 {PORTSTAT_INFO(rx_ip_checksum_errs)},
82 {PORTSTAT_INFO(rx_tcp_checksum_errs)},
83 {PORTSTAT_INFO(rx_udp_checksum_errs)},
84 {PORTSTAT_INFO(rx_non_rss_packets)},
85 {PORTSTAT_INFO(rx_ipv4_packets)},
86 {PORTSTAT_INFO(rx_ipv6_packets)},
Ajit Khapardedef824c2010-08-25 00:32:56 +000087 {PORTSTAT_INFO(rx_switched_unicast_packets)},
88 {PORTSTAT_INFO(rx_switched_multicast_packets)},
89 {PORTSTAT_INFO(rx_switched_broadcast_packets)},
Sathya Perla6b7c5b92009-03-11 23:32:03 -070090 {PORTSTAT_INFO(tx_unicastframes)},
91 {PORTSTAT_INFO(tx_multicastframes)},
92 {PORTSTAT_INFO(tx_broadcastframes)},
93 {PORTSTAT_INFO(tx_pauseframes)},
94 {PORTSTAT_INFO(tx_controlframes)},
95 {MISCSTAT_INFO(rx_drops_no_pbuf)},
96 {MISCSTAT_INFO(rx_drops_no_txpb)},
97 {MISCSTAT_INFO(rx_drops_no_erx_descr)},
98 {MISCSTAT_INFO(rx_drops_no_tpre_descr)},
99 {MISCSTAT_INFO(rx_drops_too_many_frags)},
100 {MISCSTAT_INFO(rx_drops_invalid_ring)},
101 {MISCSTAT_INFO(forwarded_packets)},
Sathya Perla3abcded2010-10-03 22:12:27 -0700102 {MISCSTAT_INFO(rx_drops_mtu)}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700103};
104#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
105
Sathya Perla3abcded2010-10-03 22:12:27 -0700106/* Stats related to multi RX queues */
107static const struct be_ethtool_stat et_rx_stats[] = {
108 {DRVSTAT_RX_INFO(rx_bytes)},
109 {DRVSTAT_RX_INFO(rx_pkts)},
110 {DRVSTAT_RX_INFO(rx_rate)},
111 {DRVSTAT_RX_INFO(rx_polls)},
112 {DRVSTAT_RX_INFO(rx_events)},
113 {DRVSTAT_RX_INFO(rx_compl)},
114 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
115 {DRVSTAT_RX_INFO(rx_post_fail)},
116 {ERXSTAT_INFO(rx_drops_no_fragments)}
117};
118#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
119
Suresh Rff33a6e2009-12-03 16:15:52 -0800120static const char et_self_tests[][ETH_GSTRING_LEN] = {
121 "MAC Loopback test",
122 "PHY Loopback test",
123 "External Loopback test",
124 "DDR DMA test"
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000125 "Link test"
Suresh Rff33a6e2009-12-03 16:15:52 -0800126};
127
128#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
129#define BE_MAC_LOOPBACK 0x0
130#define BE_PHY_LOOPBACK 0x1
131#define BE_ONE_PORT_EXT_LOOPBACK 0x2
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000132#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800133
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700134static void
135be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
136{
137 struct be_adapter *adapter = netdev_priv(netdev);
138
139 strcpy(drvinfo->driver, DRV_NAME);
140 strcpy(drvinfo->version, DRV_VER);
141 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
142 strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
143 drvinfo->testinfo_len = 0;
144 drvinfo->regdump_len = 0;
145 drvinfo->eedump_len = 0;
146}
147
148static int
149be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
150{
151 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700152 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700153 struct be_eq_obj *tx_eq = &adapter->tx_eq;
154
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700155 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
156 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
157 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
158
159 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
160 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
161 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
162
163 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
164 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
165
166 return 0;
167}
168
169/*
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700170 * This routine is used to set interrup coalescing delay
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700171 */
172static int
173be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
174{
175 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700176 struct be_rx_obj *rxo;
177 struct be_eq_obj *rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700178 struct be_eq_obj *tx_eq = &adapter->tx_eq;
179 u32 tx_max, tx_min, tx_cur;
180 u32 rx_max, rx_min, rx_cur;
Sathya Perla3abcded2010-10-03 22:12:27 -0700181 int status = 0, i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700182
183 if (coalesce->use_adaptive_tx_coalesce == 1)
184 return -EINVAL;
185
Sathya Perla3abcded2010-10-03 22:12:27 -0700186 for_all_rx_queues(adapter, rxo, i) {
187 rx_eq = &rxo->rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700188
Sathya Perla3abcded2010-10-03 22:12:27 -0700189 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
190 rx_eq->cur_eqd = 0;
191 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
192
193 rx_max = coalesce->rx_coalesce_usecs_high;
194 rx_min = coalesce->rx_coalesce_usecs_low;
195 rx_cur = coalesce->rx_coalesce_usecs;
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) {
212 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
213 rx_cur);
214 if (!status)
215 rx_eq->cur_eqd = rx_cur;
216 }
217 }
218 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700219
220 tx_max = coalesce->tx_coalesce_usecs_high;
221 tx_min = coalesce->tx_coalesce_usecs_low;
222 tx_cur = coalesce->tx_coalesce_usecs;
223
224 if (tx_cur > BE_MAX_EQD)
225 tx_cur = BE_MAX_EQD;
226 if (tx_eq->cur_eqd != tx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000227 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700228 if (!status)
229 tx_eq->cur_eqd = tx_cur;
230 }
231
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700232 return 0;
233}
234
235static u32 be_get_rx_csum(struct net_device *netdev)
236{
237 struct be_adapter *adapter = netdev_priv(netdev);
238
239 return adapter->rx_csum;
240}
241
242static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
243{
244 struct be_adapter *adapter = netdev_priv(netdev);
245
246 if (data)
247 adapter->rx_csum = true;
248 else
249 adapter->rx_csum = false;
250
251 return 0;
252}
253
254static void
255be_get_ethtool_stats(struct net_device *netdev,
256 struct ethtool_stats *stats, uint64_t *data)
257{
258 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700259 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700260 struct be_erx_stats *erx_stats = &hw_stats->erx;
Sathya Perla3abcded2010-10-03 22:12:27 -0700261 struct be_rx_obj *rxo;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700262 void *p = NULL;
Sathya Perla3abcded2010-10-03 22:12:27 -0700263 int i, j;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700264
265 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
266 switch (et_stats[i].type) {
267 case NETSTAT:
Sathya Perla3abcded2010-10-03 22:12:27 -0700268 p = &netdev->stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700269 break;
Sathya Perla3abcded2010-10-03 22:12:27 -0700270 case DRVSTAT_TX:
271 p = &adapter->tx_stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700272 break;
273 case PORTSTAT:
Sathya Perla3abcded2010-10-03 22:12:27 -0700274 p = &hw_stats->rxf.port[adapter->port_num];
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700275 break;
276 case MISCSTAT:
Sathya Perla3abcded2010-10-03 22:12:27 -0700277 p = &hw_stats->rxf;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700278 break;
279 }
280
281 p = (u8 *)p + et_stats[i].offset;
282 data[i] = (et_stats[i].size == sizeof(u64)) ?
283 *(u64 *)p: *(u32 *)p;
284 }
Sathya Perla3abcded2010-10-03 22:12:27 -0700285
286 for_all_rx_queues(adapter, rxo, j) {
287 for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) {
288 switch (et_rx_stats[i].type) {
289 case DRVSTAT_RX:
290 p = (u8 *)&rxo->stats + et_rx_stats[i].offset;
291 break;
292 case ERXSTAT:
293 p = (u32 *)erx_stats + rxo->q.id;
294 break;
295 }
296 data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] =
297 (et_rx_stats[i].size == sizeof(u64)) ?
298 *(u64 *)p: *(u32 *)p;
299 }
300 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700301}
302
303static void
304be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
305 uint8_t *data)
306{
Sathya Perla3abcded2010-10-03 22:12:27 -0700307 struct be_adapter *adapter = netdev_priv(netdev);
308 int i, j;
309
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700310 switch (stringset) {
311 case ETH_SS_STATS:
312 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
313 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
314 data += ETH_GSTRING_LEN;
315 }
Sathya Perla3abcded2010-10-03 22:12:27 -0700316 for (i = 0; i < adapter->num_rx_qs; i++) {
317 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
318 sprintf(data, "rxq%d: %s", i,
319 et_rx_stats[j].desc);
320 data += ETH_GSTRING_LEN;
321 }
322 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700323 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800324 case ETH_SS_TEST:
325 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
326 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
327 data += ETH_GSTRING_LEN;
328 }
329 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700330 }
331}
332
Ben Hutchings15f0a392009-10-01 11:58:24 +0000333static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700334{
Sathya Perla3abcded2010-10-03 22:12:27 -0700335 struct be_adapter *adapter = netdev_priv(netdev);
336
Ben Hutchings15f0a392009-10-01 11:58:24 +0000337 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800338 case ETH_SS_TEST:
339 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000340 case ETH_SS_STATS:
Sathya Perla3abcded2010-10-03 22:12:27 -0700341 return ETHTOOL_STATS_NUM +
342 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000343 default:
344 return -EINVAL;
345 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700346}
347
348static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
349{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700350 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000351 struct be_dma_mem phy_cmd;
352 struct be_cmd_resp_get_phy_info *resp;
353 u8 mac_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700354 u16 link_speed = 0;
355 bool link_up = false;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000356 int status;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000357 u16 intf_type;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700358
Ajit Khaparde48e99892010-07-29 06:17:17 +0000359 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000360 status = be_cmd_link_status_query(adapter, &link_up,
361 &mac_speed, &link_speed);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700362
Ajit Khaparde48e99892010-07-29 06:17:17 +0000363 be_link_status_update(adapter, link_up);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000364 /* link_speed is in units of 10 Mbps */
365 if (link_speed) {
366 ecmd->speed = link_speed*10;
367 } else {
368 switch (mac_speed) {
369 case PHY_LINK_SPEED_1GBPS:
370 ecmd->speed = SPEED_1000;
371 break;
372 case PHY_LINK_SPEED_10GBPS:
373 ecmd->speed = SPEED_10000;
374 break;
375 }
376 }
377
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000378 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
379 phy_cmd.va = pci_alloc_consistent(adapter->pdev, phy_cmd.size,
380 &phy_cmd.dma);
381 if (!phy_cmd.va) {
382 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
383 return -ENOMEM;
384 }
385 status = be_cmd_get_phy_info(adapter, &phy_cmd);
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000386 if (!status) {
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000387 resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
388 intf_type = le16_to_cpu(resp->interface_type);
389
390 switch (intf_type) {
391 case PHY_TYPE_XFP_10GB:
392 case PHY_TYPE_SFP_1GB:
393 case PHY_TYPE_SFP_PLUS_10GB:
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000394 ecmd->port = PORT_FIBRE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000395 break;
396 default:
397 ecmd->port = PORT_TP;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000398 break;
399 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000400
401 switch (intf_type) {
402 case PHY_TYPE_KR_10GB:
403 case PHY_TYPE_KX4_10GB:
404 ecmd->autoneg = AUTONEG_ENABLE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000405 ecmd->transceiver = XCVR_INTERNAL;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000406 break;
407 default:
408 ecmd->autoneg = AUTONEG_DISABLE;
409 ecmd->transceiver = XCVR_EXTERNAL;
410 break;
411 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700412 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000413
414 /* Save for future use */
415 adapter->link_speed = ecmd->speed;
416 adapter->port_type = ecmd->port;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000417 adapter->transceiver = ecmd->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000418 adapter->autoneg = ecmd->autoneg;
419 pci_free_consistent(adapter->pdev, phy_cmd.size,
420 phy_cmd.va, phy_cmd.dma);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000421 } else {
422 ecmd->speed = adapter->link_speed;
423 ecmd->port = adapter->port_type;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000424 ecmd->transceiver = adapter->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000425 ecmd->autoneg = adapter->autoneg;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700426 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000427
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700428 ecmd->duplex = DUPLEX_FULL;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700429 ecmd->phy_address = adapter->port_num;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000430 switch (ecmd->port) {
431 case PORT_FIBRE:
432 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
433 break;
434 case PORT_TP:
435 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
436 break;
437 case PORT_AUI:
438 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
439 break;
440 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700441
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000442 if (ecmd->autoneg) {
443 ecmd->supported |= SUPPORTED_1000baseT_Full;
444 ecmd->supported |= SUPPORTED_Autoneg;
445 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
446 ADVERTISED_1000baseT_Full);
447 }
448
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700449 return 0;
450}
451
452static void
453be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
454{
455 struct be_adapter *adapter = netdev_priv(netdev);
456
Sathya Perla3abcded2010-10-03 22:12:27 -0700457 ring->rx_max_pending = adapter->rx_obj[0].q.len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700458 ring->tx_max_pending = adapter->tx_obj.q.len;
459
Sathya Perla3abcded2010-10-03 22:12:27 -0700460 ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700461 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
462}
463
464static void
465be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
466{
467 struct be_adapter *adapter = netdev_priv(netdev);
468
Sathya Perla8788fdc2009-07-27 22:52:03 +0000469 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700470 ecmd->autoneg = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700471}
472
473static int
474be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
475{
476 struct be_adapter *adapter = netdev_priv(netdev);
477 int status;
478
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700479 if (ecmd->autoneg != 0)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700480 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000481 adapter->tx_fc = ecmd->tx_pause;
482 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700483
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000484 status = be_cmd_set_flow_control(adapter,
485 adapter->tx_fc, adapter->rx_fc);
486 if (status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700487 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
488
489 return status;
490}
491
Ajit Khaparde84517482009-09-04 03:12:16 +0000492static int
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700493be_phys_id(struct net_device *netdev, u32 data)
494{
495 struct be_adapter *adapter = netdev_priv(netdev);
496 int status;
497 u32 cur;
498
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700499 be_cmd_get_beacon_state(adapter, adapter->port_num, &cur);
500
501 if (cur == BEACON_STATE_ENABLED)
502 return 0;
503
504 if (data < 2)
505 data = 2;
506
507 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
508 BEACON_STATE_ENABLED);
509 set_current_state(TASK_INTERRUPTIBLE);
510 schedule_timeout(data*HZ);
511
512 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
513 BEACON_STATE_DISABLED);
514
515 return status;
516}
517
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000518static void
519be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
520{
521 struct be_adapter *adapter = netdev_priv(netdev);
522
523 wol->supported = WAKE_MAGIC;
524 if (adapter->wol)
525 wol->wolopts = WAKE_MAGIC;
526 else
527 wol->wolopts = 0;
528 memset(&wol->sopass, 0, sizeof(wol->sopass));
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000529}
530
531static int
532be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
533{
534 struct be_adapter *adapter = netdev_priv(netdev);
535
536 if (wol->wolopts & ~WAKE_MAGIC)
537 return -EINVAL;
538
539 if (wol->wolopts & WAKE_MAGIC)
540 adapter->wol = true;
541 else
542 adapter->wol = false;
543
544 return 0;
545}
546
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700547static int
Suresh Rff33a6e2009-12-03 16:15:52 -0800548be_test_ddr_dma(struct be_adapter *adapter)
549{
550 int ret, i;
551 struct be_dma_mem ddrdma_cmd;
wzt wztc0e4d4b2010-03-25 20:12:59 +0000552 u64 pattern[2] = {0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL};
Suresh Rff33a6e2009-12-03 16:15:52 -0800553
554 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
555 ddrdma_cmd.va = pci_alloc_consistent(adapter->pdev, ddrdma_cmd.size,
556 &ddrdma_cmd.dma);
557 if (!ddrdma_cmd.va) {
Frans Pop2381a552010-03-24 07:57:36 +0000558 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Rff33a6e2009-12-03 16:15:52 -0800559 return -ENOMEM;
560 }
561
562 for (i = 0; i < 2; i++) {
563 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
564 4096, &ddrdma_cmd);
565 if (ret != 0)
566 goto err;
567 }
568
569err:
570 pci_free_consistent(adapter->pdev, ddrdma_cmd.size,
571 ddrdma_cmd.va, ddrdma_cmd.dma);
572 return ret;
573}
574
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000575static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
576 u64 *status)
577{
578 be_cmd_set_loopback(adapter, adapter->port_num,
579 loopback_type, 1);
580 *status = be_cmd_loopback_test(adapter, adapter->port_num,
581 loopback_type, 1500,
582 2, 0xabc);
583 be_cmd_set_loopback(adapter, adapter->port_num,
584 BE_NO_LOOPBACK, 1);
585 return *status;
586}
587
Suresh Rff33a6e2009-12-03 16:15:52 -0800588static void
589be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
590{
591 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000592 bool link_up;
593 u8 mac_speed = 0;
594 u16 qos_link_speed = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800595
596 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
597
598 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000599 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
600 &data[0]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800601 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000602 }
603 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
604 &data[1]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800605 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000606 }
607 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
608 &data[2]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800609 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000610 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000611 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800612
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000613 if (be_test_ddr_dma(adapter) != 0) {
614 data[3] = 1;
615 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800616 }
617
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000618 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
619 &qos_link_speed) != 0) {
620 test->flags |= ETH_TEST_FL_FAILED;
621 data[4] = -1;
622 } else if (mac_speed) {
623 data[4] = 1;
624 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800625}
626
627static int
Ajit Khaparde84517482009-09-04 03:12:16 +0000628be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
629{
630 struct be_adapter *adapter = netdev_priv(netdev);
631 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
632 u32 region;
633
634 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
635 strcpy(file_name, efl->data);
636 region = efl->region;
637
638 return be_load_fw(adapter, file_name);
639}
640
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800641static int
642be_get_eeprom_len(struct net_device *netdev)
643{
644 return BE_READ_SEEPROM_LEN;
645}
646
647static int
648be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
649 uint8_t *data)
650{
651 struct be_adapter *adapter = netdev_priv(netdev);
652 struct be_dma_mem eeprom_cmd;
653 struct be_cmd_resp_seeprom_read *resp;
654 int status;
655
656 if (!eeprom->len)
657 return -EINVAL;
658
659 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
660
661 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
662 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
663 eeprom_cmd.va = pci_alloc_consistent(adapter->pdev, eeprom_cmd.size,
664 &eeprom_cmd.dma);
665
666 if (!eeprom_cmd.va) {
667 dev_err(&adapter->pdev->dev,
668 "Memory allocation failure. Could not read eeprom\n");
669 return -ENOMEM;
670 }
671
672 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
673
674 if (!status) {
675 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
Ajit Khapardec0ad9842010-02-08 17:51:26 +0000676 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800677 }
678 pci_free_consistent(adapter->pdev, eeprom_cmd.size, eeprom_cmd.va,
679 eeprom_cmd.dma);
680
681 return status;
682}
683
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700684const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700685 .get_settings = be_get_settings,
686 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000687 .get_wol = be_get_wol,
688 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700689 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800690 .get_eeprom_len = be_get_eeprom_len,
691 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700692 .get_coalesce = be_get_coalesce,
693 .set_coalesce = be_set_coalesce,
694 .get_ringparam = be_get_ringparam,
695 .get_pauseparam = be_get_pauseparam,
696 .set_pauseparam = be_set_pauseparam,
697 .get_rx_csum = be_get_rx_csum,
698 .set_rx_csum = be_set_rx_csum,
699 .get_tx_csum = ethtool_op_get_tx_csum,
Ajit Khaparde583e3f32009-10-05 02:22:19 +0000700 .set_tx_csum = ethtool_op_set_tx_hw_csum,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700701 .get_sg = ethtool_op_get_sg,
702 .set_sg = ethtool_op_set_sg,
703 .get_tso = ethtool_op_get_tso,
704 .set_tso = ethtool_op_set_tso,
705 .get_strings = be_get_stat_strings,
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700706 .phys_id = be_phys_id,
Ben Hutchings15f0a392009-10-01 11:58:24 +0000707 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700708 .get_ethtool_stats = be_get_ethtool_stats,
Ajit Khaparde84517482009-09-04 03:12:16 +0000709 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -0800710 .self_test = be_self_test,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700711};