Staging: hv: mousevsc: Cleanup and properly implement reportdesc_callback()
[zen-stable.git] / drivers / net / benet / be_ethtool.c
blob7fd8130d86ea7b51b076fda3f293df467bd26548
1 /*
2 * Copyright (C) 2005 - 2011 Emulex
3 * All rights reserved.
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.
10 * Contact Information:
11 * linux-drivers@emulex.com
13 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
18 #include "be.h"
19 #include "be_cmds.h"
20 #include <linux/ethtool.h>
22 struct be_ethtool_stat {
23 char desc[ETH_GSTRING_LEN];
24 int type;
25 int size;
26 int offset;
29 enum {NETSTAT, DRVSTAT_TX, DRVSTAT_RX, ERXSTAT,
30 DRVSTAT};
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)
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)
40 #define ERXSTAT_INFO(field) #field, ERXSTAT,\
41 FIELDINFO(struct be_erx_stats_v1, field)
42 #define DRVSTAT_INFO(field) #field, DRVSTAT,\
43 FIELDINFO(struct be_drv_stats, \
44 field)
46 static const struct be_ethtool_stat et_stats[] = {
47 {NETSTAT_INFO(rx_packets)},
48 {NETSTAT_INFO(tx_packets)},
49 {NETSTAT_INFO(rx_bytes)},
50 {NETSTAT_INFO(tx_bytes)},
51 {NETSTAT_INFO(rx_errors)},
52 {NETSTAT_INFO(tx_errors)},
53 {NETSTAT_INFO(rx_dropped)},
54 {NETSTAT_INFO(tx_dropped)},
55 {DRVSTAT_INFO(be_tx_events)},
56 {DRVSTAT_INFO(rx_crc_errors)},
57 {DRVSTAT_INFO(rx_alignment_symbol_errors)},
58 {DRVSTAT_INFO(rx_pause_frames)},
59 {DRVSTAT_INFO(rx_control_frames)},
60 {DRVSTAT_INFO(rx_in_range_errors)},
61 {DRVSTAT_INFO(rx_out_range_errors)},
62 {DRVSTAT_INFO(rx_frame_too_long)},
63 {DRVSTAT_INFO(rx_address_match_errors)},
64 {DRVSTAT_INFO(rx_dropped_too_small)},
65 {DRVSTAT_INFO(rx_dropped_too_short)},
66 {DRVSTAT_INFO(rx_dropped_header_too_small)},
67 {DRVSTAT_INFO(rx_dropped_tcp_length)},
68 {DRVSTAT_INFO(rx_dropped_runt)},
69 {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
70 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
71 {DRVSTAT_INFO(rx_ip_checksum_errs)},
72 {DRVSTAT_INFO(rx_tcp_checksum_errs)},
73 {DRVSTAT_INFO(rx_udp_checksum_errs)},
74 {DRVSTAT_INFO(rx_switched_unicast_packets)},
75 {DRVSTAT_INFO(rx_switched_multicast_packets)},
76 {DRVSTAT_INFO(rx_switched_broadcast_packets)},
77 {DRVSTAT_INFO(tx_pauseframes)},
78 {DRVSTAT_INFO(tx_controlframes)},
79 {DRVSTAT_INFO(rx_priority_pause_frames)},
80 {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
81 {DRVSTAT_INFO(jabber_events)},
82 {DRVSTAT_INFO(rx_drops_no_pbuf)},
83 {DRVSTAT_INFO(rx_drops_no_txpb)},
84 {DRVSTAT_INFO(rx_drops_no_erx_descr)},
85 {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
86 {DRVSTAT_INFO(rx_drops_too_many_frags)},
87 {DRVSTAT_INFO(rx_drops_invalid_ring)},
88 {DRVSTAT_INFO(forwarded_packets)},
89 {DRVSTAT_INFO(rx_drops_mtu)},
90 {DRVSTAT_INFO(eth_red_drops)},
91 {DRVSTAT_INFO(be_on_die_temperature)}
93 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
95 /* Stats related to multi RX queues */
96 static const struct be_ethtool_stat et_rx_stats[] = {
97 {DRVSTAT_RX_INFO(rx_bytes)},
98 {DRVSTAT_RX_INFO(rx_pkts)},
99 {DRVSTAT_RX_INFO(rx_rate)},
100 {DRVSTAT_RX_INFO(rx_polls)},
101 {DRVSTAT_RX_INFO(rx_events)},
102 {DRVSTAT_RX_INFO(rx_compl)},
103 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
104 {DRVSTAT_RX_INFO(rx_post_fail)},
105 {DRVSTAT_RX_INFO(rx_dropped)},
106 {ERXSTAT_INFO(rx_drops_no_fragments)}
108 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
110 /* Stats related to multi TX queues */
111 static const struct be_ethtool_stat et_tx_stats[] = {
112 {DRVSTAT_TX_INFO(be_tx_rate)},
113 {DRVSTAT_TX_INFO(be_tx_reqs)},
114 {DRVSTAT_TX_INFO(be_tx_wrbs)},
115 {DRVSTAT_TX_INFO(be_tx_stops)},
116 {DRVSTAT_TX_INFO(be_tx_compl)}
118 #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
120 static const char et_self_tests[][ETH_GSTRING_LEN] = {
121 "MAC Loopback test",
122 "PHY Loopback test",
123 "External Loopback test",
124 "DDR DMA test",
125 "Link test"
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
132 #define BE_NO_LOOPBACK 0xff
134 static void
135 be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
137 struct be_adapter *adapter = netdev_priv(netdev);
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;
148 static int
149 be_get_reg_len(struct net_device *netdev)
151 struct be_adapter *adapter = netdev_priv(netdev);
152 u32 log_size = 0;
154 if (be_physfn(adapter))
155 be_cmd_get_reg_len(adapter, &log_size);
157 return log_size;
160 static void
161 be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
163 struct be_adapter *adapter = netdev_priv(netdev);
165 if (be_physfn(adapter)) {
166 memset(buf, 0, regs->len);
167 be_cmd_get_regs(adapter, regs->len, buf);
171 static int
172 be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
174 struct be_adapter *adapter = netdev_priv(netdev);
175 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
176 struct be_eq_obj *tx_eq = &adapter->tx_eq;
178 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
179 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
180 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
182 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
183 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
184 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
186 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
187 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
189 return 0;
193 * This routine is used to set interrup coalescing delay
195 static int
196 be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
198 struct be_adapter *adapter = netdev_priv(netdev);
199 struct be_rx_obj *rxo;
200 struct be_eq_obj *rx_eq;
201 struct be_eq_obj *tx_eq = &adapter->tx_eq;
202 u32 rx_max, rx_min, rx_cur;
203 int status = 0, i;
204 u32 tx_cur;
206 if (coalesce->use_adaptive_tx_coalesce == 1)
207 return -EINVAL;
209 for_all_rx_queues(adapter, rxo, i) {
210 rx_eq = &rxo->rx_eq;
212 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
213 rx_eq->cur_eqd = 0;
214 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
216 rx_max = coalesce->rx_coalesce_usecs_high;
217 rx_min = coalesce->rx_coalesce_usecs_low;
218 rx_cur = coalesce->rx_coalesce_usecs;
220 if (rx_eq->enable_aic) {
221 if (rx_max > BE_MAX_EQD)
222 rx_max = BE_MAX_EQD;
223 if (rx_min > rx_max)
224 rx_min = rx_max;
225 rx_eq->max_eqd = rx_max;
226 rx_eq->min_eqd = rx_min;
227 if (rx_eq->cur_eqd > rx_max)
228 rx_eq->cur_eqd = rx_max;
229 if (rx_eq->cur_eqd < rx_min)
230 rx_eq->cur_eqd = rx_min;
231 } else {
232 if (rx_cur > BE_MAX_EQD)
233 rx_cur = BE_MAX_EQD;
234 if (rx_eq->cur_eqd != rx_cur) {
235 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
236 rx_cur);
237 if (!status)
238 rx_eq->cur_eqd = rx_cur;
243 tx_cur = coalesce->tx_coalesce_usecs;
245 if (tx_cur > BE_MAX_EQD)
246 tx_cur = BE_MAX_EQD;
247 if (tx_eq->cur_eqd != tx_cur) {
248 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
249 if (!status)
250 tx_eq->cur_eqd = tx_cur;
253 return 0;
256 static void
257 be_get_ethtool_stats(struct net_device *netdev,
258 struct ethtool_stats *stats, uint64_t *data)
260 struct be_adapter *adapter = netdev_priv(netdev);
261 struct be_rx_obj *rxo;
262 struct be_tx_obj *txo;
263 void *p = NULL;
264 int i, j, base;
266 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
267 switch (et_stats[i].type) {
268 case NETSTAT:
269 p = &netdev->stats;
270 break;
271 case DRVSTAT:
272 p = &adapter->drv_stats;
273 break;
276 p = (u8 *)p + et_stats[i].offset;
277 data[i] = (et_stats[i].size == sizeof(u64)) ?
278 *(u64 *)p: *(u32 *)p;
281 base = ETHTOOL_STATS_NUM;
282 for_all_rx_queues(adapter, rxo, j) {
283 for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) {
284 switch (et_rx_stats[i].type) {
285 case DRVSTAT_RX:
286 p = (u8 *)&rxo->stats + et_rx_stats[i].offset;
287 break;
288 case ERXSTAT:
289 p = (u32 *)be_erx_stats_from_cmd(adapter) +
290 rxo->q.id;
291 break;
293 data[base + j * ETHTOOL_RXSTATS_NUM + i] =
294 (et_rx_stats[i].size == sizeof(u64)) ?
295 *(u64 *)p: *(u32 *)p;
299 base = ETHTOOL_STATS_NUM + adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
300 for_all_tx_queues(adapter, txo, j) {
301 for (i = 0; i < ETHTOOL_TXSTATS_NUM; i++) {
302 p = (u8 *)&txo->stats + et_tx_stats[i].offset;
303 data[base + j * ETHTOOL_TXSTATS_NUM + i] =
304 (et_tx_stats[i].size == sizeof(u64)) ?
305 *(u64 *)p: *(u32 *)p;
310 static void
311 be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
312 uint8_t *data)
314 struct be_adapter *adapter = netdev_priv(netdev);
315 int i, j;
317 switch (stringset) {
318 case ETH_SS_STATS:
319 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
320 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
321 data += ETH_GSTRING_LEN;
323 for (i = 0; i < adapter->num_rx_qs; i++) {
324 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
325 sprintf(data, "rxq%d: %s", i,
326 et_rx_stats[j].desc);
327 data += ETH_GSTRING_LEN;
330 for (i = 0; i < adapter->num_tx_qs; i++) {
331 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
332 sprintf(data, "txq%d: %s", i,
333 et_tx_stats[j].desc);
334 data += ETH_GSTRING_LEN;
337 break;
338 case ETH_SS_TEST:
339 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
340 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
341 data += ETH_GSTRING_LEN;
343 break;
347 static int be_get_sset_count(struct net_device *netdev, int stringset)
349 struct be_adapter *adapter = netdev_priv(netdev);
351 switch (stringset) {
352 case ETH_SS_TEST:
353 return ETHTOOL_TESTS_NUM;
354 case ETH_SS_STATS:
355 return ETHTOOL_STATS_NUM +
356 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
357 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
358 default:
359 return -EINVAL;
363 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
365 struct be_adapter *adapter = netdev_priv(netdev);
366 struct be_dma_mem phy_cmd;
367 struct be_cmd_resp_get_phy_info *resp;
368 u8 mac_speed = 0;
369 u16 link_speed = 0;
370 bool link_up = false;
371 int status;
372 u16 intf_type;
374 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
375 status = be_cmd_link_status_query(adapter, &link_up,
376 &mac_speed, &link_speed, 0);
378 be_link_status_update(adapter, link_up);
379 /* link_speed is in units of 10 Mbps */
380 if (link_speed) {
381 ethtool_cmd_speed_set(ecmd, link_speed*10);
382 } else {
383 switch (mac_speed) {
384 case PHY_LINK_SPEED_10MBPS:
385 ethtool_cmd_speed_set(ecmd, SPEED_10);
386 break;
387 case PHY_LINK_SPEED_100MBPS:
388 ethtool_cmd_speed_set(ecmd, SPEED_100);
389 break;
390 case PHY_LINK_SPEED_1GBPS:
391 ethtool_cmd_speed_set(ecmd, SPEED_1000);
392 break;
393 case PHY_LINK_SPEED_10GBPS:
394 ethtool_cmd_speed_set(ecmd, SPEED_10000);
395 break;
396 case PHY_LINK_SPEED_ZERO:
397 ethtool_cmd_speed_set(ecmd, 0);
398 break;
402 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
403 phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
404 phy_cmd.size, &phy_cmd.dma,
405 GFP_KERNEL);
406 if (!phy_cmd.va) {
407 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
408 return -ENOMEM;
410 status = be_cmd_get_phy_info(adapter, &phy_cmd);
411 if (!status) {
412 resp = phy_cmd.va;
413 intf_type = le16_to_cpu(resp->interface_type);
415 switch (intf_type) {
416 case PHY_TYPE_XFP_10GB:
417 case PHY_TYPE_SFP_1GB:
418 case PHY_TYPE_SFP_PLUS_10GB:
419 ecmd->port = PORT_FIBRE;
420 break;
421 default:
422 ecmd->port = PORT_TP;
423 break;
426 switch (intf_type) {
427 case PHY_TYPE_KR_10GB:
428 case PHY_TYPE_KX4_10GB:
429 ecmd->autoneg = AUTONEG_ENABLE;
430 ecmd->transceiver = XCVR_INTERNAL;
431 break;
432 default:
433 ecmd->autoneg = AUTONEG_DISABLE;
434 ecmd->transceiver = XCVR_EXTERNAL;
435 break;
439 /* Save for future use */
440 adapter->link_speed = ethtool_cmd_speed(ecmd);
441 adapter->port_type = ecmd->port;
442 adapter->transceiver = ecmd->transceiver;
443 adapter->autoneg = ecmd->autoneg;
444 dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va,
445 phy_cmd.dma);
446 } else {
447 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
448 ecmd->port = adapter->port_type;
449 ecmd->transceiver = adapter->transceiver;
450 ecmd->autoneg = adapter->autoneg;
453 ecmd->duplex = DUPLEX_FULL;
454 ecmd->phy_address = adapter->port_num;
455 switch (ecmd->port) {
456 case PORT_FIBRE:
457 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
458 break;
459 case PORT_TP:
460 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
461 break;
462 case PORT_AUI:
463 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
464 break;
467 if (ecmd->autoneg) {
468 ecmd->supported |= SUPPORTED_1000baseT_Full;
469 ecmd->supported |= SUPPORTED_Autoneg;
470 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
471 ADVERTISED_1000baseT_Full);
474 return 0;
477 static void
478 be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
480 struct be_adapter *adapter = netdev_priv(netdev);
482 ring->rx_max_pending = adapter->rx_obj[0].q.len;
483 ring->tx_max_pending = adapter->tx_obj[0].q.len;
485 ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
486 ring->tx_pending = atomic_read(&adapter->tx_obj[0].q.used);
489 static void
490 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
492 struct be_adapter *adapter = netdev_priv(netdev);
494 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
495 ecmd->autoneg = 0;
498 static int
499 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
501 struct be_adapter *adapter = netdev_priv(netdev);
502 int status;
504 if (ecmd->autoneg != 0)
505 return -EINVAL;
506 adapter->tx_fc = ecmd->tx_pause;
507 adapter->rx_fc = ecmd->rx_pause;
509 status = be_cmd_set_flow_control(adapter,
510 adapter->tx_fc, adapter->rx_fc);
511 if (status)
512 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
514 return status;
517 static int
518 be_set_phys_id(struct net_device *netdev,
519 enum ethtool_phys_id_state state)
521 struct be_adapter *adapter = netdev_priv(netdev);
523 switch (state) {
524 case ETHTOOL_ID_ACTIVE:
525 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
526 &adapter->beacon_state);
527 return 1; /* cycle on/off once per second */
529 case ETHTOOL_ID_ON:
530 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
531 BEACON_STATE_ENABLED);
532 break;
534 case ETHTOOL_ID_OFF:
535 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
536 BEACON_STATE_DISABLED);
537 break;
539 case ETHTOOL_ID_INACTIVE:
540 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
541 adapter->beacon_state);
544 return 0;
547 static bool
548 be_is_wol_supported(struct be_adapter *adapter)
550 if (!be_physfn(adapter))
551 return false;
552 else
553 return true;
556 static void
557 be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
559 struct be_adapter *adapter = netdev_priv(netdev);
561 if (be_is_wol_supported(adapter))
562 wol->supported = WAKE_MAGIC;
564 if (adapter->wol)
565 wol->wolopts = WAKE_MAGIC;
566 else
567 wol->wolopts = 0;
568 memset(&wol->sopass, 0, sizeof(wol->sopass));
571 static int
572 be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
574 struct be_adapter *adapter = netdev_priv(netdev);
576 if (wol->wolopts & ~WAKE_MAGIC)
577 return -EINVAL;
579 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
580 adapter->wol = true;
581 else
582 adapter->wol = false;
584 return 0;
587 static int
588 be_test_ddr_dma(struct be_adapter *adapter)
590 int ret, i;
591 struct be_dma_mem ddrdma_cmd;
592 static const u64 pattern[2] = {
593 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
596 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
597 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
598 &ddrdma_cmd.dma, GFP_KERNEL);
599 if (!ddrdma_cmd.va) {
600 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
601 return -ENOMEM;
604 for (i = 0; i < 2; i++) {
605 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
606 4096, &ddrdma_cmd);
607 if (ret != 0)
608 goto err;
611 err:
612 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
613 ddrdma_cmd.dma);
614 return ret;
617 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
618 u64 *status)
620 be_cmd_set_loopback(adapter, adapter->hba_port_num,
621 loopback_type, 1);
622 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
623 loopback_type, 1500,
624 2, 0xabc);
625 be_cmd_set_loopback(adapter, adapter->hba_port_num,
626 BE_NO_LOOPBACK, 1);
627 return *status;
630 static void
631 be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
633 struct be_adapter *adapter = netdev_priv(netdev);
634 bool link_up;
635 u8 mac_speed = 0;
636 u16 qos_link_speed = 0;
638 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
640 if (test->flags & ETH_TEST_FL_OFFLINE) {
641 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
642 &data[0]) != 0) {
643 test->flags |= ETH_TEST_FL_FAILED;
645 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
646 &data[1]) != 0) {
647 test->flags |= ETH_TEST_FL_FAILED;
649 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
650 &data[2]) != 0) {
651 test->flags |= ETH_TEST_FL_FAILED;
655 if (be_test_ddr_dma(adapter) != 0) {
656 data[3] = 1;
657 test->flags |= ETH_TEST_FL_FAILED;
660 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
661 &qos_link_speed, 0) != 0) {
662 test->flags |= ETH_TEST_FL_FAILED;
663 data[4] = -1;
664 } else if (!mac_speed) {
665 test->flags |= ETH_TEST_FL_FAILED;
666 data[4] = 1;
670 static int
671 be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
673 struct be_adapter *adapter = netdev_priv(netdev);
674 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
676 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
677 strcpy(file_name, efl->data);
679 return be_load_fw(adapter, file_name);
682 static int
683 be_get_eeprom_len(struct net_device *netdev)
685 return BE_READ_SEEPROM_LEN;
688 static int
689 be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
690 uint8_t *data)
692 struct be_adapter *adapter = netdev_priv(netdev);
693 struct be_dma_mem eeprom_cmd;
694 struct be_cmd_resp_seeprom_read *resp;
695 int status;
697 if (!eeprom->len)
698 return -EINVAL;
700 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
702 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
703 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
704 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
705 &eeprom_cmd.dma, GFP_KERNEL);
707 if (!eeprom_cmd.va) {
708 dev_err(&adapter->pdev->dev,
709 "Memory allocation failure. Could not read eeprom\n");
710 return -ENOMEM;
713 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
715 if (!status) {
716 resp = eeprom_cmd.va;
717 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
719 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
720 eeprom_cmd.dma);
722 return status;
725 const struct ethtool_ops be_ethtool_ops = {
726 .get_settings = be_get_settings,
727 .get_drvinfo = be_get_drvinfo,
728 .get_wol = be_get_wol,
729 .set_wol = be_set_wol,
730 .get_link = ethtool_op_get_link,
731 .get_eeprom_len = be_get_eeprom_len,
732 .get_eeprom = be_read_eeprom,
733 .get_coalesce = be_get_coalesce,
734 .set_coalesce = be_set_coalesce,
735 .get_ringparam = be_get_ringparam,
736 .get_pauseparam = be_get_pauseparam,
737 .set_pauseparam = be_set_pauseparam,
738 .get_strings = be_get_stat_strings,
739 .set_phys_id = be_set_phys_id,
740 .get_sset_count = be_get_sset_count,
741 .get_ethtool_stats = be_get_ethtool_stats,
742 .get_regs_len = be_get_reg_len,
743 .get_regs = be_get_regs,
744 .flash_device = be_do_flash,
745 .self_test = be_self_test,