blob: 0833cbdb9b5304d9beaea7546c7933a36bff1e10 [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
Ajit Khapardef6c4bf32011-02-20 11:41:04 +000029enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT_TX, DRVSTAT_RX, ERXSTAT,
30 PMEMSTAT};
Sathya Perla6b7c5b92009-03-11 23:32:03 -070031#define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
32 offsetof(_struct, field)
33#define NETSTAT_INFO(field) #field, NETSTAT,\
34 FIELDINFO(struct net_device_stats,\
35 field)
Sathya Perla3abcded2010-10-03 22:12:27 -070036#define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\
37 FIELDINFO(struct be_tx_stats, field)
38#define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\
39 FIELDINFO(struct be_rx_stats, field)
Sathya Perla6b7c5b92009-03-11 23:32:03 -070040#define MISCSTAT_INFO(field) #field, MISCSTAT,\
41 FIELDINFO(struct be_rxf_stats, field)
42#define PORTSTAT_INFO(field) #field, PORTSTAT,\
43 FIELDINFO(struct be_port_rxf_stats, \
44 field)
45#define ERXSTAT_INFO(field) #field, ERXSTAT,\
46 FIELDINFO(struct be_erx_stats, field)
Ajit Khapardef6c4bf32011-02-20 11:41:04 +000047#define PMEMSTAT_INFO(field) #field, PMEMSTAT,\
48 FIELDINFO(struct be_pmem_stats, field)
Sathya Perla6b7c5b92009-03-11 23:32:03 -070049
50static const struct be_ethtool_stat et_stats[] = {
51 {NETSTAT_INFO(rx_packets)},
52 {NETSTAT_INFO(tx_packets)},
53 {NETSTAT_INFO(rx_bytes)},
54 {NETSTAT_INFO(tx_bytes)},
55 {NETSTAT_INFO(rx_errors)},
56 {NETSTAT_INFO(tx_errors)},
57 {NETSTAT_INFO(rx_dropped)},
58 {NETSTAT_INFO(tx_dropped)},
Sathya Perla3abcded2010-10-03 22:12:27 -070059 {DRVSTAT_TX_INFO(be_tx_rate)},
60 {DRVSTAT_TX_INFO(be_tx_reqs)},
61 {DRVSTAT_TX_INFO(be_tx_wrbs)},
62 {DRVSTAT_TX_INFO(be_tx_stops)},
63 {DRVSTAT_TX_INFO(be_tx_events)},
64 {DRVSTAT_TX_INFO(be_tx_compl)},
Sathya Perla6b7c5b92009-03-11 23:32:03 -070065 {PORTSTAT_INFO(rx_unicast_frames)},
66 {PORTSTAT_INFO(rx_multicast_frames)},
67 {PORTSTAT_INFO(rx_broadcast_frames)},
68 {PORTSTAT_INFO(rx_crc_errors)},
69 {PORTSTAT_INFO(rx_alignment_symbol_errors)},
70 {PORTSTAT_INFO(rx_pause_frames)},
71 {PORTSTAT_INFO(rx_control_frames)},
72 {PORTSTAT_INFO(rx_in_range_errors)},
73 {PORTSTAT_INFO(rx_out_range_errors)},
74 {PORTSTAT_INFO(rx_frame_too_long)},
75 {PORTSTAT_INFO(rx_address_match_errors)},
76 {PORTSTAT_INFO(rx_vlan_mismatch)},
77 {PORTSTAT_INFO(rx_dropped_too_small)},
78 {PORTSTAT_INFO(rx_dropped_too_short)},
79 {PORTSTAT_INFO(rx_dropped_header_too_small)},
80 {PORTSTAT_INFO(rx_dropped_tcp_length)},
81 {PORTSTAT_INFO(rx_dropped_runt)},
82 {PORTSTAT_INFO(rx_fifo_overflow)},
83 {PORTSTAT_INFO(rx_input_fifo_overflow)},
84 {PORTSTAT_INFO(rx_ip_checksum_errs)},
85 {PORTSTAT_INFO(rx_tcp_checksum_errs)},
86 {PORTSTAT_INFO(rx_udp_checksum_errs)},
87 {PORTSTAT_INFO(rx_non_rss_packets)},
88 {PORTSTAT_INFO(rx_ipv4_packets)},
89 {PORTSTAT_INFO(rx_ipv6_packets)},
Ajit Khapardedef824c2010-08-25 00:32:56 +000090 {PORTSTAT_INFO(rx_switched_unicast_packets)},
91 {PORTSTAT_INFO(rx_switched_multicast_packets)},
92 {PORTSTAT_INFO(rx_switched_broadcast_packets)},
Sathya Perla6b7c5b92009-03-11 23:32:03 -070093 {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)},
Ajit Khapardef6c4bf32011-02-20 11:41:04 +0000105 {MISCSTAT_INFO(rx_drops_mtu)},
106 {MISCSTAT_INFO(port0_jabber_events)},
107 {MISCSTAT_INFO(port1_jabber_events)},
108 {PMEMSTAT_INFO(eth_red_drops)}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700109};
110#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
111
Sathya Perla3abcded2010-10-03 22:12:27 -0700112/* Stats related to multi RX queues */
113static const struct be_ethtool_stat et_rx_stats[] = {
114 {DRVSTAT_RX_INFO(rx_bytes)},
115 {DRVSTAT_RX_INFO(rx_pkts)},
116 {DRVSTAT_RX_INFO(rx_rate)},
117 {DRVSTAT_RX_INFO(rx_polls)},
118 {DRVSTAT_RX_INFO(rx_events)},
119 {DRVSTAT_RX_INFO(rx_compl)},
120 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
121 {DRVSTAT_RX_INFO(rx_post_fail)},
122 {ERXSTAT_INFO(rx_drops_no_fragments)}
123};
124#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
125
Suresh Rff33a6e2009-12-03 16:15:52 -0800126static const char et_self_tests[][ETH_GSTRING_LEN] = {
127 "MAC Loopback test",
128 "PHY Loopback test",
129 "External Loopback test",
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000130 "DDR DMA test",
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000131 "Link test"
Suresh Rff33a6e2009-12-03 16:15:52 -0800132};
133
134#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
135#define BE_MAC_LOOPBACK 0x0
136#define BE_PHY_LOOPBACK 0x1
137#define BE_ONE_PORT_EXT_LOOPBACK 0x2
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000138#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800139
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700140static void
141be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
142{
143 struct be_adapter *adapter = netdev_priv(netdev);
144
145 strcpy(drvinfo->driver, DRV_NAME);
146 strcpy(drvinfo->version, DRV_VER);
147 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
148 strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
149 drvinfo->testinfo_len = 0;
150 drvinfo->regdump_len = 0;
151 drvinfo->eedump_len = 0;
152}
153
154static int
155be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
156{
157 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700158 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700159 struct be_eq_obj *tx_eq = &adapter->tx_eq;
160
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700161 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
162 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
163 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
164
165 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
166 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
167 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
168
169 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
170 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
171
172 return 0;
173}
174
175/*
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700176 * This routine is used to set interrup coalescing delay
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700177 */
178static int
179be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
180{
181 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700182 struct be_rx_obj *rxo;
183 struct be_eq_obj *rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700184 struct be_eq_obj *tx_eq = &adapter->tx_eq;
185 u32 tx_max, tx_min, tx_cur;
186 u32 rx_max, rx_min, rx_cur;
Sathya Perla3abcded2010-10-03 22:12:27 -0700187 int status = 0, i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700188
189 if (coalesce->use_adaptive_tx_coalesce == 1)
190 return -EINVAL;
191
Sathya Perla3abcded2010-10-03 22:12:27 -0700192 for_all_rx_queues(adapter, rxo, i) {
193 rx_eq = &rxo->rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700194
Sathya Perla3abcded2010-10-03 22:12:27 -0700195 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
196 rx_eq->cur_eqd = 0;
197 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
198
199 rx_max = coalesce->rx_coalesce_usecs_high;
200 rx_min = coalesce->rx_coalesce_usecs_low;
201 rx_cur = coalesce->rx_coalesce_usecs;
202
203 if (rx_eq->enable_aic) {
204 if (rx_max > BE_MAX_EQD)
205 rx_max = BE_MAX_EQD;
206 if (rx_min > rx_max)
207 rx_min = rx_max;
208 rx_eq->max_eqd = rx_max;
209 rx_eq->min_eqd = rx_min;
210 if (rx_eq->cur_eqd > rx_max)
211 rx_eq->cur_eqd = rx_max;
212 if (rx_eq->cur_eqd < rx_min)
213 rx_eq->cur_eqd = rx_min;
214 } else {
215 if (rx_cur > BE_MAX_EQD)
216 rx_cur = BE_MAX_EQD;
217 if (rx_eq->cur_eqd != rx_cur) {
218 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
219 rx_cur);
220 if (!status)
221 rx_eq->cur_eqd = rx_cur;
222 }
223 }
224 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700225
226 tx_max = coalesce->tx_coalesce_usecs_high;
227 tx_min = coalesce->tx_coalesce_usecs_low;
228 tx_cur = coalesce->tx_coalesce_usecs;
229
230 if (tx_cur > BE_MAX_EQD)
231 tx_cur = BE_MAX_EQD;
232 if (tx_eq->cur_eqd != tx_cur) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000233 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700234 if (!status)
235 tx_eq->cur_eqd = tx_cur;
236 }
237
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700238 return 0;
239}
240
241static u32 be_get_rx_csum(struct net_device *netdev)
242{
243 struct be_adapter *adapter = netdev_priv(netdev);
244
245 return adapter->rx_csum;
246}
247
248static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
249{
250 struct be_adapter *adapter = netdev_priv(netdev);
251
252 if (data)
253 adapter->rx_csum = true;
254 else
255 adapter->rx_csum = false;
256
257 return 0;
258}
259
260static void
261be_get_ethtool_stats(struct net_device *netdev,
262 struct ethtool_stats *stats, uint64_t *data)
263{
264 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700265 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700266 struct be_erx_stats *erx_stats = &hw_stats->erx;
Sathya Perla3abcded2010-10-03 22:12:27 -0700267 struct be_rx_obj *rxo;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700268 void *p = NULL;
Sathya Perla3abcded2010-10-03 22:12:27 -0700269 int i, j;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700270
271 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
272 switch (et_stats[i].type) {
273 case NETSTAT:
Sathya Perla3abcded2010-10-03 22:12:27 -0700274 p = &netdev->stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700275 break;
Sathya Perla3abcded2010-10-03 22:12:27 -0700276 case DRVSTAT_TX:
277 p = &adapter->tx_stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700278 break;
279 case PORTSTAT:
Sathya Perla3abcded2010-10-03 22:12:27 -0700280 p = &hw_stats->rxf.port[adapter->port_num];
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700281 break;
282 case MISCSTAT:
Sathya Perla3abcded2010-10-03 22:12:27 -0700283 p = &hw_stats->rxf;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700284 break;
Ajit Khapardef6c4bf32011-02-20 11:41:04 +0000285 case PMEMSTAT:
286 p = &hw_stats->pmem;
287 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700288 }
289
290 p = (u8 *)p + et_stats[i].offset;
291 data[i] = (et_stats[i].size == sizeof(u64)) ?
292 *(u64 *)p: *(u32 *)p;
293 }
Sathya Perla3abcded2010-10-03 22:12:27 -0700294
295 for_all_rx_queues(adapter, rxo, j) {
296 for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) {
297 switch (et_rx_stats[i].type) {
298 case DRVSTAT_RX:
299 p = (u8 *)&rxo->stats + et_rx_stats[i].offset;
300 break;
301 case ERXSTAT:
302 p = (u32 *)erx_stats + rxo->q.id;
303 break;
304 }
305 data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] =
306 (et_rx_stats[i].size == sizeof(u64)) ?
307 *(u64 *)p: *(u32 *)p;
308 }
309 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700310}
311
312static void
313be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
314 uint8_t *data)
315{
Sathya Perla3abcded2010-10-03 22:12:27 -0700316 struct be_adapter *adapter = netdev_priv(netdev);
317 int i, j;
318
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700319 switch (stringset) {
320 case ETH_SS_STATS:
321 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
322 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
323 data += ETH_GSTRING_LEN;
324 }
Sathya Perla3abcded2010-10-03 22:12:27 -0700325 for (i = 0; i < adapter->num_rx_qs; i++) {
326 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
327 sprintf(data, "rxq%d: %s", i,
328 et_rx_stats[j].desc);
329 data += ETH_GSTRING_LEN;
330 }
331 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700332 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800333 case ETH_SS_TEST:
334 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
335 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
336 data += ETH_GSTRING_LEN;
337 }
338 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700339 }
340}
341
Ben Hutchings15f0a392009-10-01 11:58:24 +0000342static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700343{
Sathya Perla3abcded2010-10-03 22:12:27 -0700344 struct be_adapter *adapter = netdev_priv(netdev);
345
Ben Hutchings15f0a392009-10-01 11:58:24 +0000346 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800347 case ETH_SS_TEST:
348 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000349 case ETH_SS_STATS:
Sathya Perla3abcded2010-10-03 22:12:27 -0700350 return ETHTOOL_STATS_NUM +
351 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000352 default:
353 return -EINVAL;
354 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700355}
356
357static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
358{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700359 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000360 struct be_dma_mem phy_cmd;
361 struct be_cmd_resp_get_phy_info *resp;
362 u8 mac_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700363 u16 link_speed = 0;
364 bool link_up = false;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000365 int status;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000366 u16 intf_type;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700367
Ajit Khaparde48e99892010-07-29 06:17:17 +0000368 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000369 status = be_cmd_link_status_query(adapter, &link_up,
370 &mac_speed, &link_speed);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700371
Ajit Khaparde48e99892010-07-29 06:17:17 +0000372 be_link_status_update(adapter, link_up);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000373 /* link_speed is in units of 10 Mbps */
374 if (link_speed) {
375 ecmd->speed = link_speed*10;
376 } else {
377 switch (mac_speed) {
378 case PHY_LINK_SPEED_1GBPS:
379 ecmd->speed = SPEED_1000;
380 break;
381 case PHY_LINK_SPEED_10GBPS:
382 ecmd->speed = SPEED_10000;
383 break;
384 }
385 }
386
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000387 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000388 phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
389 phy_cmd.size, &phy_cmd.dma,
390 GFP_KERNEL);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000391 if (!phy_cmd.va) {
392 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
393 return -ENOMEM;
394 }
395 status = be_cmd_get_phy_info(adapter, &phy_cmd);
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000396 if (!status) {
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000397 resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
398 intf_type = le16_to_cpu(resp->interface_type);
399
400 switch (intf_type) {
401 case PHY_TYPE_XFP_10GB:
402 case PHY_TYPE_SFP_1GB:
403 case PHY_TYPE_SFP_PLUS_10GB:
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000404 ecmd->port = PORT_FIBRE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000405 break;
406 default:
407 ecmd->port = PORT_TP;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000408 break;
409 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000410
411 switch (intf_type) {
412 case PHY_TYPE_KR_10GB:
413 case PHY_TYPE_KX4_10GB:
414 ecmd->autoneg = AUTONEG_ENABLE;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000415 ecmd->transceiver = XCVR_INTERNAL;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000416 break;
417 default:
418 ecmd->autoneg = AUTONEG_DISABLE;
419 ecmd->transceiver = XCVR_EXTERNAL;
420 break;
421 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700422 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000423
424 /* Save for future use */
425 adapter->link_speed = ecmd->speed;
426 adapter->port_type = ecmd->port;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000427 adapter->transceiver = ecmd->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000428 adapter->autoneg = ecmd->autoneg;
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000429 dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va,
430 phy_cmd.dma);
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000431 } else {
432 ecmd->speed = adapter->link_speed;
433 ecmd->port = adapter->port_type;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000434 ecmd->transceiver = adapter->transceiver;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000435 ecmd->autoneg = adapter->autoneg;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700436 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000437
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700438 ecmd->duplex = DUPLEX_FULL;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700439 ecmd->phy_address = adapter->port_num;
Sarveshwar Bandi16c02142009-12-23 04:42:51 +0000440 switch (ecmd->port) {
441 case PORT_FIBRE:
442 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
443 break;
444 case PORT_TP:
445 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
446 break;
447 case PORT_AUI:
448 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
449 break;
450 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700451
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000452 if (ecmd->autoneg) {
453 ecmd->supported |= SUPPORTED_1000baseT_Full;
454 ecmd->supported |= SUPPORTED_Autoneg;
455 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
456 ADVERTISED_1000baseT_Full);
457 }
458
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700459 return 0;
460}
461
462static void
463be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
464{
465 struct be_adapter *adapter = netdev_priv(netdev);
466
Sathya Perla3abcded2010-10-03 22:12:27 -0700467 ring->rx_max_pending = adapter->rx_obj[0].q.len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700468 ring->tx_max_pending = adapter->tx_obj.q.len;
469
Sathya Perla3abcded2010-10-03 22:12:27 -0700470 ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700471 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
472}
473
474static void
475be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
476{
477 struct be_adapter *adapter = netdev_priv(netdev);
478
Sathya Perla8788fdc2009-07-27 22:52:03 +0000479 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700480 ecmd->autoneg = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700481}
482
483static int
484be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
485{
486 struct be_adapter *adapter = netdev_priv(netdev);
487 int status;
488
Ajit Khaparde03a980d2009-04-13 15:41:50 -0700489 if (ecmd->autoneg != 0)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700490 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000491 adapter->tx_fc = ecmd->tx_pause;
492 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700493
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000494 status = be_cmd_set_flow_control(adapter,
495 adapter->tx_fc, adapter->rx_fc);
496 if (status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700497 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
498
499 return status;
500}
501
Ajit Khaparde84517482009-09-04 03:12:16 +0000502static int
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700503be_phys_id(struct net_device *netdev, u32 data)
504{
505 struct be_adapter *adapter = netdev_priv(netdev);
506 int status;
507 u32 cur;
508
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700509 be_cmd_get_beacon_state(adapter, adapter->port_num, &cur);
510
511 if (cur == BEACON_STATE_ENABLED)
512 return 0;
513
514 if (data < 2)
515 data = 2;
516
517 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
518 BEACON_STATE_ENABLED);
519 set_current_state(TASK_INTERRUPTIBLE);
520 schedule_timeout(data*HZ);
521
522 status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
523 BEACON_STATE_DISABLED);
524
525 return status;
526}
527
Ajit Khapardedcf96f12011-02-11 13:39:30 +0000528static bool
529be_is_wol_supported(struct be_adapter *adapter)
530{
531 if (!be_physfn(adapter))
532 return false;
533 else
534 return true;
535}
536
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000537static void
538be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
539{
540 struct be_adapter *adapter = netdev_priv(netdev);
541
Ajit Khapardedcf96f12011-02-11 13:39:30 +0000542 if (be_is_wol_supported(adapter))
543 wol->supported = WAKE_MAGIC;
544
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000545 if (adapter->wol)
546 wol->wolopts = WAKE_MAGIC;
547 else
548 wol->wolopts = 0;
549 memset(&wol->sopass, 0, sizeof(wol->sopass));
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000550}
551
552static int
553be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
554{
555 struct be_adapter *adapter = netdev_priv(netdev);
556
557 if (wol->wolopts & ~WAKE_MAGIC)
558 return -EINVAL;
559
Ajit Khapardedcf96f12011-02-11 13:39:30 +0000560 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000561 adapter->wol = true;
562 else
563 adapter->wol = false;
564
565 return 0;
566}
567
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700568static int
Suresh Rff33a6e2009-12-03 16:15:52 -0800569be_test_ddr_dma(struct be_adapter *adapter)
570{
571 int ret, i;
572 struct be_dma_mem ddrdma_cmd;
Joe Perches215faf92010-12-21 02:16:10 -0800573 static const u64 pattern[2] = {
574 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
575 };
Suresh Rff33a6e2009-12-03 16:15:52 -0800576
577 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000578 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
579 &ddrdma_cmd.dma, GFP_KERNEL);
Suresh Rff33a6e2009-12-03 16:15:52 -0800580 if (!ddrdma_cmd.va) {
Frans Pop2381a552010-03-24 07:57:36 +0000581 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Rff33a6e2009-12-03 16:15:52 -0800582 return -ENOMEM;
583 }
584
585 for (i = 0; i < 2; i++) {
586 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
587 4096, &ddrdma_cmd);
588 if (ret != 0)
589 goto err;
590 }
591
592err:
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000593 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
594 ddrdma_cmd.dma);
Suresh Rff33a6e2009-12-03 16:15:52 -0800595 return ret;
596}
597
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000598static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
599 u64 *status)
600{
601 be_cmd_set_loopback(adapter, adapter->port_num,
602 loopback_type, 1);
603 *status = be_cmd_loopback_test(adapter, adapter->port_num,
604 loopback_type, 1500,
605 2, 0xabc);
606 be_cmd_set_loopback(adapter, adapter->port_num,
607 BE_NO_LOOPBACK, 1);
608 return *status;
609}
610
Suresh Rff33a6e2009-12-03 16:15:52 -0800611static void
612be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
613{
614 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000615 bool link_up;
616 u8 mac_speed = 0;
617 u16 qos_link_speed = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800618
619 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
620
621 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000622 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
623 &data[0]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800624 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000625 }
626 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
627 &data[1]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800628 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000629 }
630 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
631 &data[2]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800632 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000633 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000634 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800635
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000636 if (be_test_ddr_dma(adapter) != 0) {
637 data[3] = 1;
638 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800639 }
640
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000641 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
642 &qos_link_speed) != 0) {
643 test->flags |= ETH_TEST_FL_FAILED;
644 data[4] = -1;
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000645 } else if (!mac_speed) {
646 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000647 data[4] = 1;
648 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800649}
650
651static int
Ajit Khaparde84517482009-09-04 03:12:16 +0000652be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
653{
654 struct be_adapter *adapter = netdev_priv(netdev);
655 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
656 u32 region;
657
658 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
659 strcpy(file_name, efl->data);
660 region = efl->region;
661
662 return be_load_fw(adapter, file_name);
663}
664
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800665static int
666be_get_eeprom_len(struct net_device *netdev)
667{
668 return BE_READ_SEEPROM_LEN;
669}
670
671static int
672be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
673 uint8_t *data)
674{
675 struct be_adapter *adapter = netdev_priv(netdev);
676 struct be_dma_mem eeprom_cmd;
677 struct be_cmd_resp_seeprom_read *resp;
678 int status;
679
680 if (!eeprom->len)
681 return -EINVAL;
682
683 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
684
685 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
686 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000687 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
688 &eeprom_cmd.dma, GFP_KERNEL);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800689
690 if (!eeprom_cmd.va) {
691 dev_err(&adapter->pdev->dev,
692 "Memory allocation failure. Could not read eeprom\n");
693 return -ENOMEM;
694 }
695
696 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
697
698 if (!status) {
699 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
Ajit Khapardec0ad9842010-02-08 17:51:26 +0000700 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800701 }
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000702 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
703 eeprom_cmd.dma);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800704
705 return status;
706}
707
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700708const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700709 .get_settings = be_get_settings,
710 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000711 .get_wol = be_get_wol,
712 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700713 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800714 .get_eeprom_len = be_get_eeprom_len,
715 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700716 .get_coalesce = be_get_coalesce,
717 .set_coalesce = be_set_coalesce,
718 .get_ringparam = be_get_ringparam,
719 .get_pauseparam = be_get_pauseparam,
720 .set_pauseparam = be_set_pauseparam,
721 .get_rx_csum = be_get_rx_csum,
722 .set_rx_csum = be_set_rx_csum,
723 .get_tx_csum = ethtool_op_get_tx_csum,
Ajit Khaparde583e3f32009-10-05 02:22:19 +0000724 .set_tx_csum = ethtool_op_set_tx_hw_csum,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700725 .get_sg = ethtool_op_get_sg,
726 .set_sg = ethtool_op_set_sg,
727 .get_tso = ethtool_op_get_tso,
728 .set_tso = ethtool_op_set_tso,
729 .get_strings = be_get_stat_strings,
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700730 .phys_id = be_phys_id,
Ben Hutchings15f0a392009-10-01 11:58:24 +0000731 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700732 .get_ethtool_stats = be_get_ethtool_stats,
Ajit Khaparde84517482009-09-04 03:12:16 +0000733 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -0800734 .self_test = be_self_test,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700735};