ipv4: Call fib_select_default() only when actually necessary.
[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
164 be_cmd_get_reg_len(adapter, &log_size);
165 return log_size;
166}
167
168static void
169be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
170{
171 struct be_adapter *adapter = netdev_priv(netdev);
172
173 memset(buf, 0, regs->len);
174 be_cmd_get_regs(adapter, regs->len, buf);
175}
176
6b7c5b94
SP
177static int
178be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
179{
180 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda 181 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
6b7c5b94
SP
182 struct be_eq_obj *tx_eq = &adapter->tx_eq;
183
6b7c5b94
SP
184 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
185 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
186 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
187
188 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
189 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
190 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
191
192 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
193 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
194
195 return 0;
196}
197
198/*
5be93b9a 199 * This routine is used to set interrup coalescing delay
6b7c5b94
SP
200 */
201static int
202be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
203{
204 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda
SP
205 struct be_rx_obj *rxo;
206 struct be_eq_obj *rx_eq;
6b7c5b94
SP
207 struct be_eq_obj *tx_eq = &adapter->tx_eq;
208 u32 tx_max, tx_min, tx_cur;
209 u32 rx_max, rx_min, rx_cur;
3abcdeda 210 int status = 0, i;
6b7c5b94
SP
211
212 if (coalesce->use_adaptive_tx_coalesce == 1)
213 return -EINVAL;
214
3abcdeda
SP
215 for_all_rx_queues(adapter, rxo, i) {
216 rx_eq = &rxo->rx_eq;
217
218 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
219 rx_eq->cur_eqd = 0;
220 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
221
222 rx_max = coalesce->rx_coalesce_usecs_high;
223 rx_min = coalesce->rx_coalesce_usecs_low;
224 rx_cur = coalesce->rx_coalesce_usecs;
225
226 if (rx_eq->enable_aic) {
227 if (rx_max > BE_MAX_EQD)
228 rx_max = BE_MAX_EQD;
229 if (rx_min > rx_max)
230 rx_min = rx_max;
231 rx_eq->max_eqd = rx_max;
232 rx_eq->min_eqd = rx_min;
233 if (rx_eq->cur_eqd > rx_max)
234 rx_eq->cur_eqd = rx_max;
235 if (rx_eq->cur_eqd < rx_min)
236 rx_eq->cur_eqd = rx_min;
237 } else {
238 if (rx_cur > BE_MAX_EQD)
239 rx_cur = BE_MAX_EQD;
240 if (rx_eq->cur_eqd != rx_cur) {
241 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
242 rx_cur);
243 if (!status)
244 rx_eq->cur_eqd = rx_cur;
245 }
246 }
6b7c5b94 247 }
6b7c5b94
SP
248
249 tx_max = coalesce->tx_coalesce_usecs_high;
250 tx_min = coalesce->tx_coalesce_usecs_low;
251 tx_cur = coalesce->tx_coalesce_usecs;
252
253 if (tx_cur > BE_MAX_EQD)
254 tx_cur = BE_MAX_EQD;
255 if (tx_eq->cur_eqd != tx_cur) {
8788fdc2 256 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
6b7c5b94
SP
257 if (!status)
258 tx_eq->cur_eqd = tx_cur;
259 }
260
6b7c5b94
SP
261 return 0;
262}
263
6b7c5b94
SP
264static void
265be_get_ethtool_stats(struct net_device *netdev,
266 struct ethtool_stats *stats, uint64_t *data)
267{
268 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda 269 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va);
6b7c5b94 270 struct be_erx_stats *erx_stats = &hw_stats->erx;
3abcdeda 271 struct be_rx_obj *rxo;
6b7c5b94 272 void *p = NULL;
3abcdeda 273 int i, j;
6b7c5b94
SP
274
275 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
276 switch (et_stats[i].type) {
277 case NETSTAT:
3abcdeda 278 p = &netdev->stats;
6b7c5b94 279 break;
3abcdeda
SP
280 case DRVSTAT_TX:
281 p = &adapter->tx_stats;
6b7c5b94
SP
282 break;
283 case PORTSTAT:
3abcdeda 284 p = &hw_stats->rxf.port[adapter->port_num];
6b7c5b94
SP
285 break;
286 case MISCSTAT:
3abcdeda 287 p = &hw_stats->rxf;
6b7c5b94 288 break;
f6c4bf3e
AK
289 case PMEMSTAT:
290 p = &hw_stats->pmem;
291 break;
609ff3bb
AK
292 case DRVSTAT:
293 p = &adapter->drv_stats;
294 break;
6b7c5b94
SP
295 }
296
297 p = (u8 *)p + et_stats[i].offset;
298 data[i] = (et_stats[i].size == sizeof(u64)) ?
299 *(u64 *)p: *(u32 *)p;
300 }
3abcdeda
SP
301
302 for_all_rx_queues(adapter, rxo, j) {
303 for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) {
304 switch (et_rx_stats[i].type) {
305 case DRVSTAT_RX:
306 p = (u8 *)&rxo->stats + et_rx_stats[i].offset;
307 break;
308 case ERXSTAT:
309 p = (u32 *)erx_stats + rxo->q.id;
310 break;
311 }
312 data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] =
313 (et_rx_stats[i].size == sizeof(u64)) ?
314 *(u64 *)p: *(u32 *)p;
315 }
316 }
6b7c5b94
SP
317}
318
319static void
320be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
321 uint8_t *data)
322{
3abcdeda
SP
323 struct be_adapter *adapter = netdev_priv(netdev);
324 int i, j;
325
6b7c5b94
SP
326 switch (stringset) {
327 case ETH_SS_STATS:
328 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
329 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
330 data += ETH_GSTRING_LEN;
331 }
3abcdeda
SP
332 for (i = 0; i < adapter->num_rx_qs; i++) {
333 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
334 sprintf(data, "rxq%d: %s", i,
335 et_rx_stats[j].desc);
336 data += ETH_GSTRING_LEN;
337 }
338 }
6b7c5b94 339 break;
ff33a6e2
S
340 case ETH_SS_TEST:
341 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
342 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
343 data += ETH_GSTRING_LEN;
344 }
345 break;
6b7c5b94
SP
346 }
347}
348
15f0a394 349static int be_get_sset_count(struct net_device *netdev, int stringset)
6b7c5b94 350{
3abcdeda
SP
351 struct be_adapter *adapter = netdev_priv(netdev);
352
15f0a394 353 switch (stringset) {
ff33a6e2
S
354 case ETH_SS_TEST:
355 return ETHTOOL_TESTS_NUM;
15f0a394 356 case ETH_SS_STATS:
3abcdeda
SP
357 return ETHTOOL_STATS_NUM +
358 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
15f0a394
BH
359 default:
360 return -EINVAL;
361 }
6b7c5b94
SP
362}
363
364static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
365{
0388f251 366 struct be_adapter *adapter = netdev_priv(netdev);
ee3cb629
AK
367 struct be_dma_mem phy_cmd;
368 struct be_cmd_resp_get_phy_info *resp;
369 u8 mac_speed = 0;
0388f251
SB
370 u16 link_speed = 0;
371 bool link_up = false;
0dffc83e 372 int status;
ee3cb629 373 u16 intf_type;
0dffc83e 374
48e9989e 375 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
0dffc83e
AK
376 status = be_cmd_link_status_query(adapter, &link_up,
377 &mac_speed, &link_speed);
378
48e9989e 379 be_link_status_update(adapter, link_up);
0dffc83e
AK
380 /* link_speed is in units of 10 Mbps */
381 if (link_speed) {
382 ecmd->speed = link_speed*10;
383 } else {
384 switch (mac_speed) {
385 case PHY_LINK_SPEED_1GBPS:
386 ecmd->speed = SPEED_1000;
387 break;
388 case PHY_LINK_SPEED_10GBPS:
389 ecmd->speed = SPEED_10000;
390 break;
391 }
392 }
0388f251 393
ee3cb629 394 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2b7bcebf
IV
395 phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
396 phy_cmd.size, &phy_cmd.dma,
397 GFP_KERNEL);
ee3cb629
AK
398 if (!phy_cmd.va) {
399 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
400 return -ENOMEM;
401 }
402 status = be_cmd_get_phy_info(adapter, &phy_cmd);
16c02145 403 if (!status) {
ee3cb629
AK
404 resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
405 intf_type = le16_to_cpu(resp->interface_type);
406
407 switch (intf_type) {
408 case PHY_TYPE_XFP_10GB:
409 case PHY_TYPE_SFP_1GB:
410 case PHY_TYPE_SFP_PLUS_10GB:
16c02145 411 ecmd->port = PORT_FIBRE;
16c02145
SB
412 break;
413 default:
414 ecmd->port = PORT_TP;
16c02145
SB
415 break;
416 }
ee3cb629
AK
417
418 switch (intf_type) {
419 case PHY_TYPE_KR_10GB:
420 case PHY_TYPE_KX4_10GB:
421 ecmd->autoneg = AUTONEG_ENABLE;
16c02145 422 ecmd->transceiver = XCVR_INTERNAL;
ee3cb629
AK
423 break;
424 default:
425 ecmd->autoneg = AUTONEG_DISABLE;
426 ecmd->transceiver = XCVR_EXTERNAL;
427 break;
428 }
0388f251 429 }
0dffc83e
AK
430
431 /* Save for future use */
432 adapter->link_speed = ecmd->speed;
433 adapter->port_type = ecmd->port;
16c02145 434 adapter->transceiver = ecmd->transceiver;
ee3cb629 435 adapter->autoneg = ecmd->autoneg;
2b7bcebf
IV
436 dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va,
437 phy_cmd.dma);
0dffc83e
AK
438 } else {
439 ecmd->speed = adapter->link_speed;
440 ecmd->port = adapter->port_type;
16c02145 441 ecmd->transceiver = adapter->transceiver;
ee3cb629 442 ecmd->autoneg = adapter->autoneg;
0388f251 443 }
0dffc83e 444
6b7c5b94 445 ecmd->duplex = DUPLEX_FULL;
0388f251 446 ecmd->phy_address = adapter->port_num;
16c02145
SB
447 switch (ecmd->port) {
448 case PORT_FIBRE:
449 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
450 break;
451 case PORT_TP:
452 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
453 break;
454 case PORT_AUI:
455 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
456 break;
457 }
0388f251 458
ee3cb629
AK
459 if (ecmd->autoneg) {
460 ecmd->supported |= SUPPORTED_1000baseT_Full;
461 ecmd->supported |= SUPPORTED_Autoneg;
462 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
463 ADVERTISED_1000baseT_Full);
464 }
465
6b7c5b94
SP
466 return 0;
467}
468
469static void
470be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
471{
472 struct be_adapter *adapter = netdev_priv(netdev);
473
3abcdeda 474 ring->rx_max_pending = adapter->rx_obj[0].q.len;
6b7c5b94
SP
475 ring->tx_max_pending = adapter->tx_obj.q.len;
476
3abcdeda 477 ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
6b7c5b94
SP
478 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
479}
480
481static void
482be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
483{
484 struct be_adapter *adapter = netdev_priv(netdev);
485
8788fdc2 486 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
03a980d1 487 ecmd->autoneg = 0;
6b7c5b94
SP
488}
489
490static int
491be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
492{
493 struct be_adapter *adapter = netdev_priv(netdev);
494 int status;
495
03a980d1 496 if (ecmd->autoneg != 0)
6b7c5b94 497 return -EINVAL;
9e90c961
AK
498 adapter->tx_fc = ecmd->tx_pause;
499 adapter->rx_fc = ecmd->rx_pause;
6b7c5b94 500
9e90c961
AK
501 status = be_cmd_set_flow_control(adapter,
502 adapter->tx_fc, adapter->rx_fc);
503 if (status)
6b7c5b94
SP
504 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
505
506 return status;
507}
508
fad9ab2c 509static int
1a642469 510be_set_phys_id(struct net_device *netdev,
511 enum ethtool_phys_id_state state)
fad9ab2c
SB
512{
513 struct be_adapter *adapter = netdev_priv(netdev);
fad9ab2c 514
1a642469 515 switch (state) {
516 case ETHTOOL_ID_ACTIVE:
517 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
518 &adapter->beacon_state);
519 return -EINVAL;
fad9ab2c 520
1a642469 521 case ETHTOOL_ID_ON:
522 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
523 BEACON_STATE_ENABLED);
524 break;
fad9ab2c 525
1a642469 526 case ETHTOOL_ID_OFF:
527 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
528 BEACON_STATE_DISABLED);
529 break;
fad9ab2c 530
1a642469 531 case ETHTOOL_ID_INACTIVE:
532 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
533 adapter->beacon_state);
534 }
fad9ab2c 535
1a642469 536 return 0;
fad9ab2c
SB
537}
538
dcf96f1f
AK
539static bool
540be_is_wol_supported(struct be_adapter *adapter)
541{
542 if (!be_physfn(adapter))
543 return false;
544 else
545 return true;
546}
547
71d8d1b5
AK
548static void
549be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
550{
551 struct be_adapter *adapter = netdev_priv(netdev);
552
dcf96f1f
AK
553 if (be_is_wol_supported(adapter))
554 wol->supported = WAKE_MAGIC;
555
71d8d1b5
AK
556 if (adapter->wol)
557 wol->wolopts = WAKE_MAGIC;
558 else
559 wol->wolopts = 0;
560 memset(&wol->sopass, 0, sizeof(wol->sopass));
71d8d1b5
AK
561}
562
563static int
564be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
565{
566 struct be_adapter *adapter = netdev_priv(netdev);
567
568 if (wol->wolopts & ~WAKE_MAGIC)
569 return -EINVAL;
570
dcf96f1f 571 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
71d8d1b5
AK
572 adapter->wol = true;
573 else
574 adapter->wol = false;
575
576 return 0;
577}
578
ff33a6e2
S
579static int
580be_test_ddr_dma(struct be_adapter *adapter)
581{
582 int ret, i;
583 struct be_dma_mem ddrdma_cmd;
215faf9c
JP
584 static const u64 pattern[2] = {
585 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
586 };
ff33a6e2
S
587
588 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
2b7bcebf
IV
589 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
590 &ddrdma_cmd.dma, GFP_KERNEL);
ff33a6e2 591 if (!ddrdma_cmd.va) {
2381a55c 592 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
ff33a6e2
S
593 return -ENOMEM;
594 }
595
596 for (i = 0; i < 2; i++) {
597 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
598 4096, &ddrdma_cmd);
599 if (ret != 0)
600 goto err;
601 }
602
603err:
2b7bcebf
IV
604 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
605 ddrdma_cmd.dma);
ff33a6e2
S
606 return ret;
607}
608
fced9999
SB
609static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
610 u64 *status)
611{
9e1453c5 612 be_cmd_set_loopback(adapter, adapter->hba_port_num,
fced9999 613 loopback_type, 1);
9e1453c5 614 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
fced9999
SB
615 loopback_type, 1500,
616 2, 0xabc);
9e1453c5 617 be_cmd_set_loopback(adapter, adapter->hba_port_num,
fced9999
SB
618 BE_NO_LOOPBACK, 1);
619 return *status;
620}
621
ff33a6e2
S
622static void
623be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
624{
625 struct be_adapter *adapter = netdev_priv(netdev);
4276e47e
SB
626 bool link_up;
627 u8 mac_speed = 0;
628 u16 qos_link_speed = 0;
ff33a6e2
S
629
630 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
631
632 if (test->flags & ETH_TEST_FL_OFFLINE) {
fced9999
SB
633 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
634 &data[0]) != 0) {
ff33a6e2 635 test->flags |= ETH_TEST_FL_FAILED;
fced9999
SB
636 }
637 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
638 &data[1]) != 0) {
ff33a6e2 639 test->flags |= ETH_TEST_FL_FAILED;
fced9999
SB
640 }
641 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
642 &data[2]) != 0) {
ff33a6e2 643 test->flags |= ETH_TEST_FL_FAILED;
fced9999 644 }
8f47afe0 645 }
ff33a6e2 646
8f47afe0
SB
647 if (be_test_ddr_dma(adapter) != 0) {
648 data[3] = 1;
649 test->flags |= ETH_TEST_FL_FAILED;
ff33a6e2
S
650 }
651
4276e47e
SB
652 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
653 &qos_link_speed) != 0) {
654 test->flags |= ETH_TEST_FL_FAILED;
655 data[4] = -1;
4ee77214
AK
656 } else if (!mac_speed) {
657 test->flags |= ETH_TEST_FL_FAILED;
4276e47e
SB
658 data[4] = 1;
659 }
ff33a6e2
S
660}
661
84517482
AK
662static int
663be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
664{
665 struct be_adapter *adapter = netdev_priv(netdev);
666 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
667 u32 region;
668
669 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
670 strcpy(file_name, efl->data);
671 region = efl->region;
672
673 return be_load_fw(adapter, file_name);
674}
675
368c0ca2
SB
676static int
677be_get_eeprom_len(struct net_device *netdev)
678{
679 return BE_READ_SEEPROM_LEN;
680}
681
682static int
683be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
684 uint8_t *data)
685{
686 struct be_adapter *adapter = netdev_priv(netdev);
687 struct be_dma_mem eeprom_cmd;
688 struct be_cmd_resp_seeprom_read *resp;
689 int status;
690
691 if (!eeprom->len)
692 return -EINVAL;
693
694 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
695
696 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
697 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
2b7bcebf
IV
698 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
699 &eeprom_cmd.dma, GFP_KERNEL);
368c0ca2
SB
700
701 if (!eeprom_cmd.va) {
702 dev_err(&adapter->pdev->dev,
703 "Memory allocation failure. Could not read eeprom\n");
704 return -ENOMEM;
705 }
706
707 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
708
709 if (!status) {
710 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
c0ad9845 711 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
368c0ca2 712 }
2b7bcebf
IV
713 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
714 eeprom_cmd.dma);
368c0ca2
SB
715
716 return status;
717}
718
4b972914
AK
719static int be_set_flags(struct net_device *netdev, u32 data)
720{
721 struct be_adapter *adapter = netdev_priv(netdev);
722 int rc = -1;
723
724 if (be_multi_rxq(adapter))
725 rc = ethtool_op_set_flags(netdev, data, ETH_FLAG_RXHASH |
726 ETH_FLAG_TXVLAN | ETH_FLAG_RXVLAN);
727
728 return rc;
729}
730
0fc0b732 731const struct ethtool_ops be_ethtool_ops = {
6b7c5b94
SP
732 .get_settings = be_get_settings,
733 .get_drvinfo = be_get_drvinfo,
71d8d1b5
AK
734 .get_wol = be_get_wol,
735 .set_wol = be_set_wol,
6b7c5b94 736 .get_link = ethtool_op_get_link,
368c0ca2
SB
737 .get_eeprom_len = be_get_eeprom_len,
738 .get_eeprom = be_read_eeprom,
6b7c5b94
SP
739 .get_coalesce = be_get_coalesce,
740 .set_coalesce = be_set_coalesce,
741 .get_ringparam = be_get_ringparam,
742 .get_pauseparam = be_get_pauseparam,
743 .set_pauseparam = be_set_pauseparam,
6b7c5b94 744 .get_strings = be_get_stat_strings,
1a642469 745 .set_phys_id = be_set_phys_id,
15f0a394 746 .get_sset_count = be_get_sset_count,
6b7c5b94 747 .get_ethtool_stats = be_get_ethtool_stats,
311fddc7
SK
748 .get_regs_len = be_get_reg_len,
749 .get_regs = be_get_regs,
84517482 750 .flash_device = be_do_flash,
ff33a6e2 751 .self_test = be_self_test,
4b972914 752 .set_flags = be_set_flags,
6b7c5b94 753};
This page took 0.273076 seconds and 5 git commands to generate.