be2net: Add code to display nic speeds other than 1Gbps/10Gbps
[deliverable/linux.git] / drivers / net / benet / be_ethtool.c
CommitLineData
6b7c5b94 1/*
d2145cde 2 * Copyright (C) 2005 - 2011 Emulex
6b7c5b94
SP
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
10 * Contact Information:
d2145cde 11 * linux-drivers@emulex.com
6b7c5b94 12 *
d2145cde
AK
13 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
6b7c5b94
SP
16 */
17
18#include "be.h"
8788fdc2 19#include "be_cmds.h"
6b7c5b94
SP
20#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
f6c4bf3e 29enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT_TX, DRVSTAT_RX, ERXSTAT,
609ff3bb 30 PMEMSTAT, DRVSTAT};
6b7c5b94
SP
31#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)
3abcdeda
SP
36#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)
6b7c5b94
SP
40#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)
f6c4bf3e
AK
47#define PMEMSTAT_INFO(field) #field, PMEMSTAT,\
48 FIELDINFO(struct be_pmem_stats, field)
609ff3bb
AK
49#define DRVSTAT_INFO(field) #field, DRVSTAT,\
50 FIELDINFO(struct be_drv_stats, \
51 field)
6b7c5b94
SP
52
53static const struct be_ethtool_stat et_stats[] = {
54 {NETSTAT_INFO(rx_packets)},
55 {NETSTAT_INFO(tx_packets)},
56 {NETSTAT_INFO(rx_bytes)},
57 {NETSTAT_INFO(tx_bytes)},
58 {NETSTAT_INFO(rx_errors)},
59 {NETSTAT_INFO(tx_errors)},
60 {NETSTAT_INFO(rx_dropped)},
61 {NETSTAT_INFO(tx_dropped)},
3abcdeda
SP
62 {DRVSTAT_TX_INFO(be_tx_rate)},
63 {DRVSTAT_TX_INFO(be_tx_reqs)},
64 {DRVSTAT_TX_INFO(be_tx_wrbs)},
65 {DRVSTAT_TX_INFO(be_tx_stops)},
66 {DRVSTAT_TX_INFO(be_tx_events)},
67 {DRVSTAT_TX_INFO(be_tx_compl)},
6b7c5b94
SP
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)},
def824c0
AK
93 {PORTSTAT_INFO(rx_switched_unicast_packets)},
94 {PORTSTAT_INFO(rx_switched_multicast_packets)},
95 {PORTSTAT_INFO(rx_switched_broadcast_packets)},
6b7c5b94
SP
96 {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)},
f6c4bf3e
AK
108 {MISCSTAT_INFO(rx_drops_mtu)},
109 {MISCSTAT_INFO(port0_jabber_events)},
110 {MISCSTAT_INFO(port1_jabber_events)},
609ff3bb
AK
111 {PMEMSTAT_INFO(eth_red_drops)},
112 {DRVSTAT_INFO(be_on_die_temperature)}
6b7c5b94
SP
113};
114#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
115
3abcdeda
SP
116/* Stats related to multi RX queues */
117static const struct be_ethtool_stat et_rx_stats[] = {
118 {DRVSTAT_RX_INFO(rx_bytes)},
119 {DRVSTAT_RX_INFO(rx_pkts)},
120 {DRVSTAT_RX_INFO(rx_rate)},
121 {DRVSTAT_RX_INFO(rx_polls)},
122 {DRVSTAT_RX_INFO(rx_events)},
123 {DRVSTAT_RX_INFO(rx_compl)},
124 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
125 {DRVSTAT_RX_INFO(rx_post_fail)},
126 {ERXSTAT_INFO(rx_drops_no_fragments)}
127};
128#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
129
ff33a6e2
S
130static const char et_self_tests[][ETH_GSTRING_LEN] = {
131 "MAC Loopback test",
132 "PHY Loopback test",
133 "External Loopback test",
4ee77214 134 "DDR DMA test",
4276e47e 135 "Link test"
ff33a6e2
S
136};
137
138#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
139#define BE_MAC_LOOPBACK 0x0
140#define BE_PHY_LOOPBACK 0x1
141#define BE_ONE_PORT_EXT_LOOPBACK 0x2
fced9999 142#define BE_NO_LOOPBACK 0xff
ff33a6e2 143
6b7c5b94
SP
144static void
145be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
146{
147 struct be_adapter *adapter = netdev_priv(netdev);
148
149 strcpy(drvinfo->driver, DRV_NAME);
150 strcpy(drvinfo->version, DRV_VER);
151 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
152 strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
153 drvinfo->testinfo_len = 0;
154 drvinfo->regdump_len = 0;
155 drvinfo->eedump_len = 0;
156}
157
311fddc7
SK
158static int
159be_get_reg_len(struct net_device *netdev)
160{
161 struct be_adapter *adapter = netdev_priv(netdev);
162 u32 log_size = 0;
163
16a871ef
AK
164 if (be_physfn(adapter))
165 be_cmd_get_reg_len(adapter, &log_size);
166
311fddc7
SK
167 return log_size;
168}
169
170static void
171be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
172{
173 struct be_adapter *adapter = netdev_priv(netdev);
174
16a871ef
AK
175 if (be_physfn(adapter)) {
176 memset(buf, 0, regs->len);
177 be_cmd_get_regs(adapter, regs->len, buf);
178 }
311fddc7
SK
179}
180
6b7c5b94
SP
181static int
182be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
183{
184 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda 185 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
6b7c5b94
SP
186 struct be_eq_obj *tx_eq = &adapter->tx_eq;
187
6b7c5b94
SP
188 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
189 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
190 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
191
192 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
193 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
194 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
195
196 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
197 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
198
199 return 0;
200}
201
202/*
5be93b9a 203 * This routine is used to set interrup coalescing delay
6b7c5b94
SP
204 */
205static int
206be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
207{
208 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda
SP
209 struct be_rx_obj *rxo;
210 struct be_eq_obj *rx_eq;
6b7c5b94 211 struct be_eq_obj *tx_eq = &adapter->tx_eq;
6b7c5b94 212 u32 rx_max, rx_min, rx_cur;
3abcdeda 213 int status = 0, i;
03746b0a 214 u32 tx_cur;
6b7c5b94
SP
215
216 if (coalesce->use_adaptive_tx_coalesce == 1)
217 return -EINVAL;
218
3abcdeda
SP
219 for_all_rx_queues(adapter, rxo, i) {
220 rx_eq = &rxo->rx_eq;
221
222 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
223 rx_eq->cur_eqd = 0;
224 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
225
226 rx_max = coalesce->rx_coalesce_usecs_high;
227 rx_min = coalesce->rx_coalesce_usecs_low;
228 rx_cur = coalesce->rx_coalesce_usecs;
229
230 if (rx_eq->enable_aic) {
231 if (rx_max > BE_MAX_EQD)
232 rx_max = BE_MAX_EQD;
233 if (rx_min > rx_max)
234 rx_min = rx_max;
235 rx_eq->max_eqd = rx_max;
236 rx_eq->min_eqd = rx_min;
237 if (rx_eq->cur_eqd > rx_max)
238 rx_eq->cur_eqd = rx_max;
239 if (rx_eq->cur_eqd < rx_min)
240 rx_eq->cur_eqd = rx_min;
241 } else {
242 if (rx_cur > BE_MAX_EQD)
243 rx_cur = BE_MAX_EQD;
244 if (rx_eq->cur_eqd != rx_cur) {
245 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
246 rx_cur);
247 if (!status)
248 rx_eq->cur_eqd = rx_cur;
249 }
250 }
6b7c5b94 251 }
6b7c5b94 252
6b7c5b94
SP
253 tx_cur = coalesce->tx_coalesce_usecs;
254
255 if (tx_cur > BE_MAX_EQD)
256 tx_cur = BE_MAX_EQD;
257 if (tx_eq->cur_eqd != tx_cur) {
8788fdc2 258 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
6b7c5b94
SP
259 if (!status)
260 tx_eq->cur_eqd = tx_cur;
261 }
262
6b7c5b94
SP
263 return 0;
264}
265
6b7c5b94
SP
266static void
267be_get_ethtool_stats(struct net_device *netdev,
268 struct ethtool_stats *stats, uint64_t *data)
269{
270 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda 271 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va);
6b7c5b94 272 struct be_erx_stats *erx_stats = &hw_stats->erx;
3abcdeda 273 struct be_rx_obj *rxo;
6b7c5b94 274 void *p = NULL;
3abcdeda 275 int i, j;
6b7c5b94
SP
276
277 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
278 switch (et_stats[i].type) {
279 case NETSTAT:
3abcdeda 280 p = &netdev->stats;
6b7c5b94 281 break;
3abcdeda
SP
282 case DRVSTAT_TX:
283 p = &adapter->tx_stats;
6b7c5b94
SP
284 break;
285 case PORTSTAT:
3abcdeda 286 p = &hw_stats->rxf.port[adapter->port_num];
6b7c5b94
SP
287 break;
288 case MISCSTAT:
3abcdeda 289 p = &hw_stats->rxf;
6b7c5b94 290 break;
f6c4bf3e
AK
291 case PMEMSTAT:
292 p = &hw_stats->pmem;
293 break;
609ff3bb
AK
294 case DRVSTAT:
295 p = &adapter->drv_stats;
296 break;
6b7c5b94
SP
297 }
298
299 p = (u8 *)p + et_stats[i].offset;
300 data[i] = (et_stats[i].size == sizeof(u64)) ?
301 *(u64 *)p: *(u32 *)p;
302 }
3abcdeda
SP
303
304 for_all_rx_queues(adapter, rxo, j) {
305 for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) {
306 switch (et_rx_stats[i].type) {
307 case DRVSTAT_RX:
308 p = (u8 *)&rxo->stats + et_rx_stats[i].offset;
309 break;
310 case ERXSTAT:
311 p = (u32 *)erx_stats + rxo->q.id;
312 break;
313 }
314 data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] =
315 (et_rx_stats[i].size == sizeof(u64)) ?
316 *(u64 *)p: *(u32 *)p;
317 }
318 }
6b7c5b94
SP
319}
320
321static void
322be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
323 uint8_t *data)
324{
3abcdeda
SP
325 struct be_adapter *adapter = netdev_priv(netdev);
326 int i, j;
327
6b7c5b94
SP
328 switch (stringset) {
329 case ETH_SS_STATS:
330 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
331 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
332 data += ETH_GSTRING_LEN;
333 }
3abcdeda
SP
334 for (i = 0; i < adapter->num_rx_qs; i++) {
335 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
336 sprintf(data, "rxq%d: %s", i,
337 et_rx_stats[j].desc);
338 data += ETH_GSTRING_LEN;
339 }
340 }
6b7c5b94 341 break;
ff33a6e2
S
342 case ETH_SS_TEST:
343 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
344 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
345 data += ETH_GSTRING_LEN;
346 }
347 break;
6b7c5b94
SP
348 }
349}
350
15f0a394 351static int be_get_sset_count(struct net_device *netdev, int stringset)
6b7c5b94 352{
3abcdeda
SP
353 struct be_adapter *adapter = netdev_priv(netdev);
354
15f0a394 355 switch (stringset) {
ff33a6e2
S
356 case ETH_SS_TEST:
357 return ETHTOOL_TESTS_NUM;
15f0a394 358 case ETH_SS_STATS:
3abcdeda
SP
359 return ETHTOOL_STATS_NUM +
360 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
15f0a394
BH
361 default:
362 return -EINVAL;
363 }
6b7c5b94
SP
364}
365
366static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
367{
0388f251 368 struct be_adapter *adapter = netdev_priv(netdev);
ee3cb629
AK
369 struct be_dma_mem phy_cmd;
370 struct be_cmd_resp_get_phy_info *resp;
371 u8 mac_speed = 0;
0388f251
SB
372 u16 link_speed = 0;
373 bool link_up = false;
0dffc83e 374 int status;
ee3cb629 375 u16 intf_type;
0dffc83e 376
48e9989e 377 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
0dffc83e
AK
378 status = be_cmd_link_status_query(adapter, &link_up,
379 &mac_speed, &link_speed);
380
48e9989e 381 be_link_status_update(adapter, link_up);
0dffc83e
AK
382 /* link_speed is in units of 10 Mbps */
383 if (link_speed) {
384 ecmd->speed = link_speed*10;
385 } else {
386 switch (mac_speed) {
4fa9ed07
AK
387 case PHY_LINK_SPEED_10MBPS:
388 ecmd->speed = SPEED_10;
389 break;
390 case PHY_LINK_SPEED_100MBPS:
391 ecmd->speed = SPEED_100;
392 break;
0dffc83e
AK
393 case PHY_LINK_SPEED_1GBPS:
394 ecmd->speed = SPEED_1000;
395 break;
396 case PHY_LINK_SPEED_10GBPS:
397 ecmd->speed = SPEED_10000;
398 break;
4fa9ed07
AK
399 case PHY_LINK_SPEED_ZERO:
400 ecmd->speed = 0;
401 break;
0dffc83e
AK
402 }
403 }
0388f251 404
ee3cb629 405 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2b7bcebf
IV
406 phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
407 phy_cmd.size, &phy_cmd.dma,
408 GFP_KERNEL);
ee3cb629
AK
409 if (!phy_cmd.va) {
410 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
411 return -ENOMEM;
412 }
413 status = be_cmd_get_phy_info(adapter, &phy_cmd);
16c02145 414 if (!status) {
ee3cb629
AK
415 resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
416 intf_type = le16_to_cpu(resp->interface_type);
417
418 switch (intf_type) {
419 case PHY_TYPE_XFP_10GB:
420 case PHY_TYPE_SFP_1GB:
421 case PHY_TYPE_SFP_PLUS_10GB:
16c02145 422 ecmd->port = PORT_FIBRE;
16c02145
SB
423 break;
424 default:
425 ecmd->port = PORT_TP;
16c02145
SB
426 break;
427 }
ee3cb629
AK
428
429 switch (intf_type) {
430 case PHY_TYPE_KR_10GB:
431 case PHY_TYPE_KX4_10GB:
432 ecmd->autoneg = AUTONEG_ENABLE;
16c02145 433 ecmd->transceiver = XCVR_INTERNAL;
ee3cb629
AK
434 break;
435 default:
436 ecmd->autoneg = AUTONEG_DISABLE;
437 ecmd->transceiver = XCVR_EXTERNAL;
438 break;
439 }
0388f251 440 }
0dffc83e
AK
441
442 /* Save for future use */
443 adapter->link_speed = ecmd->speed;
444 adapter->port_type = ecmd->port;
16c02145 445 adapter->transceiver = ecmd->transceiver;
ee3cb629 446 adapter->autoneg = ecmd->autoneg;
2b7bcebf
IV
447 dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va,
448 phy_cmd.dma);
0dffc83e
AK
449 } else {
450 ecmd->speed = adapter->link_speed;
451 ecmd->port = adapter->port_type;
16c02145 452 ecmd->transceiver = adapter->transceiver;
ee3cb629 453 ecmd->autoneg = adapter->autoneg;
0388f251 454 }
0dffc83e 455
6b7c5b94 456 ecmd->duplex = DUPLEX_FULL;
0388f251 457 ecmd->phy_address = adapter->port_num;
16c02145
SB
458 switch (ecmd->port) {
459 case PORT_FIBRE:
460 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
461 break;
462 case PORT_TP:
463 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
464 break;
465 case PORT_AUI:
466 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
467 break;
468 }
0388f251 469
ee3cb629
AK
470 if (ecmd->autoneg) {
471 ecmd->supported |= SUPPORTED_1000baseT_Full;
472 ecmd->supported |= SUPPORTED_Autoneg;
473 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
474 ADVERTISED_1000baseT_Full);
475 }
476
6b7c5b94
SP
477 return 0;
478}
479
480static void
481be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
482{
483 struct be_adapter *adapter = netdev_priv(netdev);
484
3abcdeda 485 ring->rx_max_pending = adapter->rx_obj[0].q.len;
6b7c5b94
SP
486 ring->tx_max_pending = adapter->tx_obj.q.len;
487
3abcdeda 488 ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
6b7c5b94
SP
489 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
490}
491
492static void
493be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
494{
495 struct be_adapter *adapter = netdev_priv(netdev);
496
8788fdc2 497 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
03a980d1 498 ecmd->autoneg = 0;
6b7c5b94
SP
499}
500
501static int
502be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
503{
504 struct be_adapter *adapter = netdev_priv(netdev);
505 int status;
506
03a980d1 507 if (ecmd->autoneg != 0)
6b7c5b94 508 return -EINVAL;
9e90c961
AK
509 adapter->tx_fc = ecmd->tx_pause;
510 adapter->rx_fc = ecmd->rx_pause;
6b7c5b94 511
9e90c961
AK
512 status = be_cmd_set_flow_control(adapter,
513 adapter->tx_fc, adapter->rx_fc);
514 if (status)
6b7c5b94
SP
515 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
516
517 return status;
518}
519
fad9ab2c 520static int
1a642469 521be_set_phys_id(struct net_device *netdev,
522 enum ethtool_phys_id_state state)
fad9ab2c
SB
523{
524 struct be_adapter *adapter = netdev_priv(netdev);
fad9ab2c 525
1a642469 526 switch (state) {
527 case ETHTOOL_ID_ACTIVE:
528 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
529 &adapter->beacon_state);
fce55922 530 return 1; /* cycle on/off once per second */
fad9ab2c 531
1a642469 532 case ETHTOOL_ID_ON:
533 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
534 BEACON_STATE_ENABLED);
535 break;
fad9ab2c 536
1a642469 537 case ETHTOOL_ID_OFF:
538 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
539 BEACON_STATE_DISABLED);
540 break;
fad9ab2c 541
1a642469 542 case ETHTOOL_ID_INACTIVE:
543 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
544 adapter->beacon_state);
545 }
fad9ab2c 546
1a642469 547 return 0;
fad9ab2c
SB
548}
549
dcf96f1f
AK
550static bool
551be_is_wol_supported(struct be_adapter *adapter)
552{
553 if (!be_physfn(adapter))
554 return false;
555 else
556 return true;
557}
558
71d8d1b5
AK
559static void
560be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
561{
562 struct be_adapter *adapter = netdev_priv(netdev);
563
dcf96f1f
AK
564 if (be_is_wol_supported(adapter))
565 wol->supported = WAKE_MAGIC;
566
71d8d1b5
AK
567 if (adapter->wol)
568 wol->wolopts = WAKE_MAGIC;
569 else
570 wol->wolopts = 0;
571 memset(&wol->sopass, 0, sizeof(wol->sopass));
71d8d1b5
AK
572}
573
574static int
575be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
576{
577 struct be_adapter *adapter = netdev_priv(netdev);
578
579 if (wol->wolopts & ~WAKE_MAGIC)
580 return -EINVAL;
581
dcf96f1f 582 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
71d8d1b5
AK
583 adapter->wol = true;
584 else
585 adapter->wol = false;
586
587 return 0;
588}
589
ff33a6e2
S
590static int
591be_test_ddr_dma(struct be_adapter *adapter)
592{
593 int ret, i;
594 struct be_dma_mem ddrdma_cmd;
215faf9c
JP
595 static const u64 pattern[2] = {
596 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
597 };
ff33a6e2
S
598
599 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
2b7bcebf
IV
600 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
601 &ddrdma_cmd.dma, GFP_KERNEL);
ff33a6e2 602 if (!ddrdma_cmd.va) {
2381a55c 603 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
ff33a6e2
S
604 return -ENOMEM;
605 }
606
607 for (i = 0; i < 2; i++) {
608 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
609 4096, &ddrdma_cmd);
610 if (ret != 0)
611 goto err;
612 }
613
614err:
2b7bcebf
IV
615 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
616 ddrdma_cmd.dma);
ff33a6e2
S
617 return ret;
618}
619
fced9999
SB
620static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
621 u64 *status)
622{
9e1453c5 623 be_cmd_set_loopback(adapter, adapter->hba_port_num,
fced9999 624 loopback_type, 1);
9e1453c5 625 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
fced9999
SB
626 loopback_type, 1500,
627 2, 0xabc);
9e1453c5 628 be_cmd_set_loopback(adapter, adapter->hba_port_num,
fced9999
SB
629 BE_NO_LOOPBACK, 1);
630 return *status;
631}
632
ff33a6e2
S
633static void
634be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
635{
636 struct be_adapter *adapter = netdev_priv(netdev);
4276e47e
SB
637 bool link_up;
638 u8 mac_speed = 0;
639 u16 qos_link_speed = 0;
ff33a6e2
S
640
641 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
642
643 if (test->flags & ETH_TEST_FL_OFFLINE) {
fced9999
SB
644 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
645 &data[0]) != 0) {
ff33a6e2 646 test->flags |= ETH_TEST_FL_FAILED;
fced9999
SB
647 }
648 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
649 &data[1]) != 0) {
ff33a6e2 650 test->flags |= ETH_TEST_FL_FAILED;
fced9999
SB
651 }
652 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
653 &data[2]) != 0) {
ff33a6e2 654 test->flags |= ETH_TEST_FL_FAILED;
fced9999 655 }
8f47afe0 656 }
ff33a6e2 657
8f47afe0
SB
658 if (be_test_ddr_dma(adapter) != 0) {
659 data[3] = 1;
660 test->flags |= ETH_TEST_FL_FAILED;
ff33a6e2
S
661 }
662
4276e47e
SB
663 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
664 &qos_link_speed) != 0) {
665 test->flags |= ETH_TEST_FL_FAILED;
666 data[4] = -1;
4ee77214
AK
667 } else if (!mac_speed) {
668 test->flags |= ETH_TEST_FL_FAILED;
4276e47e
SB
669 data[4] = 1;
670 }
ff33a6e2
S
671}
672
84517482
AK
673static int
674be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
675{
676 struct be_adapter *adapter = netdev_priv(netdev);
677 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
84517482
AK
678
679 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
680 strcpy(file_name, efl->data);
84517482
AK
681
682 return be_load_fw(adapter, file_name);
683}
684
368c0ca2
SB
685static int
686be_get_eeprom_len(struct net_device *netdev)
687{
688 return BE_READ_SEEPROM_LEN;
689}
690
691static int
692be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
693 uint8_t *data)
694{
695 struct be_adapter *adapter = netdev_priv(netdev);
696 struct be_dma_mem eeprom_cmd;
697 struct be_cmd_resp_seeprom_read *resp;
698 int status;
699
700 if (!eeprom->len)
701 return -EINVAL;
702
703 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
704
705 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
706 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
2b7bcebf
IV
707 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
708 &eeprom_cmd.dma, GFP_KERNEL);
368c0ca2
SB
709
710 if (!eeprom_cmd.va) {
711 dev_err(&adapter->pdev->dev,
712 "Memory allocation failure. Could not read eeprom\n");
713 return -ENOMEM;
714 }
715
716 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
717
718 if (!status) {
719 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
c0ad9845 720 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
368c0ca2 721 }
2b7bcebf
IV
722 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
723 eeprom_cmd.dma);
368c0ca2
SB
724
725 return status;
726}
727
0fc0b732 728const struct ethtool_ops be_ethtool_ops = {
6b7c5b94
SP
729 .get_settings = be_get_settings,
730 .get_drvinfo = be_get_drvinfo,
71d8d1b5
AK
731 .get_wol = be_get_wol,
732 .set_wol = be_set_wol,
6b7c5b94 733 .get_link = ethtool_op_get_link,
368c0ca2
SB
734 .get_eeprom_len = be_get_eeprom_len,
735 .get_eeprom = be_read_eeprom,
6b7c5b94
SP
736 .get_coalesce = be_get_coalesce,
737 .set_coalesce = be_set_coalesce,
738 .get_ringparam = be_get_ringparam,
739 .get_pauseparam = be_get_pauseparam,
740 .set_pauseparam = be_set_pauseparam,
6b7c5b94 741 .get_strings = be_get_stat_strings,
1a642469 742 .set_phys_id = be_set_phys_id,
15f0a394 743 .get_sset_count = be_get_sset_count,
6b7c5b94 744 .get_ethtool_stats = be_get_ethtool_stats,
311fddc7
SK
745 .get_regs_len = be_get_reg_len,
746 .get_regs = be_get_regs,
84517482 747 .flash_device = be_do_flash,
ff33a6e2 748 .self_test = be_self_test,
6b7c5b94 749};
This page took 0.294422 seconds and 5 git commands to generate.