sfc: Don't use enums as a bitmask.
[zen-stable.git] / drivers / net / benet / be_ethtool.c
blobfacfe3ca5c40788907a6c68d1618616022434a88
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_TX_INFO(be_tx_rate)},
56 {DRVSTAT_TX_INFO(be_tx_reqs)},
57 {DRVSTAT_TX_INFO(be_tx_wrbs)},
58 {DRVSTAT_TX_INFO(be_tx_stops)},
59 {DRVSTAT_TX_INFO(be_tx_events)},
60 {DRVSTAT_TX_INFO(be_tx_compl)},
61 {DRVSTAT_INFO(rx_crc_errors)},
62 {DRVSTAT_INFO(rx_alignment_symbol_errors)},
63 {DRVSTAT_INFO(rx_pause_frames)},
64 {DRVSTAT_INFO(rx_control_frames)},
65 {DRVSTAT_INFO(rx_in_range_errors)},
66 {DRVSTAT_INFO(rx_out_range_errors)},
67 {DRVSTAT_INFO(rx_frame_too_long)},
68 {DRVSTAT_INFO(rx_address_match_errors)},
69 {DRVSTAT_INFO(rx_dropped_too_small)},
70 {DRVSTAT_INFO(rx_dropped_too_short)},
71 {DRVSTAT_INFO(rx_dropped_header_too_small)},
72 {DRVSTAT_INFO(rx_dropped_tcp_length)},
73 {DRVSTAT_INFO(rx_dropped_runt)},
74 {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
75 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
76 {DRVSTAT_INFO(rx_ip_checksum_errs)},
77 {DRVSTAT_INFO(rx_tcp_checksum_errs)},
78 {DRVSTAT_INFO(rx_udp_checksum_errs)},
79 {DRVSTAT_INFO(rx_switched_unicast_packets)},
80 {DRVSTAT_INFO(rx_switched_multicast_packets)},
81 {DRVSTAT_INFO(rx_switched_broadcast_packets)},
82 {DRVSTAT_INFO(tx_pauseframes)},
83 {DRVSTAT_INFO(tx_controlframes)},
84 {DRVSTAT_INFO(rx_priority_pause_frames)},
85 {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
86 {DRVSTAT_INFO(jabber_events)},
87 {DRVSTAT_INFO(rx_drops_no_pbuf)},
88 {DRVSTAT_INFO(rx_drops_no_txpb)},
89 {DRVSTAT_INFO(rx_drops_no_erx_descr)},
90 {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
91 {DRVSTAT_INFO(rx_drops_too_many_frags)},
92 {DRVSTAT_INFO(rx_drops_invalid_ring)},
93 {DRVSTAT_INFO(forwarded_packets)},
94 {DRVSTAT_INFO(rx_drops_mtu)},
95 {DRVSTAT_INFO(eth_red_drops)},
96 {DRVSTAT_INFO(be_on_die_temperature)}
98 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
100 /* Stats related to multi RX queues */
101 static const struct be_ethtool_stat et_rx_stats[] = {
102 {DRVSTAT_RX_INFO(rx_bytes)},
103 {DRVSTAT_RX_INFO(rx_pkts)},
104 {DRVSTAT_RX_INFO(rx_rate)},
105 {DRVSTAT_RX_INFO(rx_polls)},
106 {DRVSTAT_RX_INFO(rx_events)},
107 {DRVSTAT_RX_INFO(rx_compl)},
108 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
109 {DRVSTAT_RX_INFO(rx_post_fail)},
110 {ERXSTAT_INFO(rx_drops_no_fragments)}
112 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
114 static const char et_self_tests[][ETH_GSTRING_LEN] = {
115 "MAC Loopback test",
116 "PHY Loopback test",
117 "External Loopback test",
118 "DDR DMA test",
119 "Link test"
122 #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
123 #define BE_MAC_LOOPBACK 0x0
124 #define BE_PHY_LOOPBACK 0x1
125 #define BE_ONE_PORT_EXT_LOOPBACK 0x2
126 #define BE_NO_LOOPBACK 0xff
128 static void
129 be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
131 struct be_adapter *adapter = netdev_priv(netdev);
133 strcpy(drvinfo->driver, DRV_NAME);
134 strcpy(drvinfo->version, DRV_VER);
135 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
136 strcpy(drvinfo->bus_info, pci_name(adapter->pdev));
137 drvinfo->testinfo_len = 0;
138 drvinfo->regdump_len = 0;
139 drvinfo->eedump_len = 0;
142 static int
143 be_get_reg_len(struct net_device *netdev)
145 struct be_adapter *adapter = netdev_priv(netdev);
146 u32 log_size = 0;
148 if (be_physfn(adapter))
149 be_cmd_get_reg_len(adapter, &log_size);
151 return log_size;
154 static void
155 be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
157 struct be_adapter *adapter = netdev_priv(netdev);
159 if (be_physfn(adapter)) {
160 memset(buf, 0, regs->len);
161 be_cmd_get_regs(adapter, regs->len, buf);
165 static int
166 be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
168 struct be_adapter *adapter = netdev_priv(netdev);
169 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
170 struct be_eq_obj *tx_eq = &adapter->tx_eq;
172 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
173 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
174 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
176 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
177 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
178 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
180 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
181 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
183 return 0;
187 * This routine is used to set interrup coalescing delay
189 static int
190 be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
192 struct be_adapter *adapter = netdev_priv(netdev);
193 struct be_rx_obj *rxo;
194 struct be_eq_obj *rx_eq;
195 struct be_eq_obj *tx_eq = &adapter->tx_eq;
196 u32 rx_max, rx_min, rx_cur;
197 int status = 0, i;
198 u32 tx_cur;
200 if (coalesce->use_adaptive_tx_coalesce == 1)
201 return -EINVAL;
203 for_all_rx_queues(adapter, rxo, i) {
204 rx_eq = &rxo->rx_eq;
206 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
207 rx_eq->cur_eqd = 0;
208 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
210 rx_max = coalesce->rx_coalesce_usecs_high;
211 rx_min = coalesce->rx_coalesce_usecs_low;
212 rx_cur = coalesce->rx_coalesce_usecs;
214 if (rx_eq->enable_aic) {
215 if (rx_max > BE_MAX_EQD)
216 rx_max = BE_MAX_EQD;
217 if (rx_min > rx_max)
218 rx_min = rx_max;
219 rx_eq->max_eqd = rx_max;
220 rx_eq->min_eqd = rx_min;
221 if (rx_eq->cur_eqd > rx_max)
222 rx_eq->cur_eqd = rx_max;
223 if (rx_eq->cur_eqd < rx_min)
224 rx_eq->cur_eqd = rx_min;
225 } else {
226 if (rx_cur > BE_MAX_EQD)
227 rx_cur = BE_MAX_EQD;
228 if (rx_eq->cur_eqd != rx_cur) {
229 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
230 rx_cur);
231 if (!status)
232 rx_eq->cur_eqd = rx_cur;
237 tx_cur = coalesce->tx_coalesce_usecs;
239 if (tx_cur > BE_MAX_EQD)
240 tx_cur = BE_MAX_EQD;
241 if (tx_eq->cur_eqd != tx_cur) {
242 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
243 if (!status)
244 tx_eq->cur_eqd = tx_cur;
247 return 0;
250 static void
251 be_get_ethtool_stats(struct net_device *netdev,
252 struct ethtool_stats *stats, uint64_t *data)
254 struct be_adapter *adapter = netdev_priv(netdev);
255 struct be_rx_obj *rxo;
256 void *p = NULL;
257 int i, j;
259 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
260 switch (et_stats[i].type) {
261 case NETSTAT:
262 p = &netdev->stats;
263 break;
264 case DRVSTAT_TX:
265 p = &adapter->tx_stats;
266 break;
267 case DRVSTAT:
268 p = &adapter->drv_stats;
269 break;
272 p = (u8 *)p + et_stats[i].offset;
273 data[i] = (et_stats[i].size == sizeof(u64)) ?
274 *(u64 *)p: *(u32 *)p;
277 for_all_rx_queues(adapter, rxo, j) {
278 for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) {
279 switch (et_rx_stats[i].type) {
280 case DRVSTAT_RX:
281 p = (u8 *)&rxo->stats + et_rx_stats[i].offset;
282 break;
283 case ERXSTAT:
284 p = (u32 *)be_erx_stats_from_cmd(adapter) +
285 rxo->q.id;
286 break;
288 data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] =
289 (et_rx_stats[i].size == sizeof(u64)) ?
290 *(u64 *)p: *(u32 *)p;
295 static void
296 be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
297 uint8_t *data)
299 struct be_adapter *adapter = netdev_priv(netdev);
300 int i, j;
302 switch (stringset) {
303 case ETH_SS_STATS:
304 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
305 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
306 data += ETH_GSTRING_LEN;
308 for (i = 0; i < adapter->num_rx_qs; i++) {
309 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
310 sprintf(data, "rxq%d: %s", i,
311 et_rx_stats[j].desc);
312 data += ETH_GSTRING_LEN;
315 break;
316 case ETH_SS_TEST:
317 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
318 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
319 data += ETH_GSTRING_LEN;
321 break;
325 static int be_get_sset_count(struct net_device *netdev, int stringset)
327 struct be_adapter *adapter = netdev_priv(netdev);
329 switch (stringset) {
330 case ETH_SS_TEST:
331 return ETHTOOL_TESTS_NUM;
332 case ETH_SS_STATS:
333 return ETHTOOL_STATS_NUM +
334 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
335 default:
336 return -EINVAL;
340 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
342 struct be_adapter *adapter = netdev_priv(netdev);
343 struct be_dma_mem phy_cmd;
344 struct be_cmd_resp_get_phy_info *resp;
345 u8 mac_speed = 0;
346 u16 link_speed = 0;
347 bool link_up = false;
348 int status;
349 u16 intf_type;
351 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
352 status = be_cmd_link_status_query(adapter, &link_up,
353 &mac_speed, &link_speed, 0);
355 be_link_status_update(adapter, link_up);
356 /* link_speed is in units of 10 Mbps */
357 if (link_speed) {
358 ethtool_cmd_speed_set(ecmd, link_speed*10);
359 } else {
360 switch (mac_speed) {
361 case PHY_LINK_SPEED_10MBPS:
362 ethtool_cmd_speed_set(ecmd, SPEED_10);
363 break;
364 case PHY_LINK_SPEED_100MBPS:
365 ethtool_cmd_speed_set(ecmd, SPEED_100);
366 break;
367 case PHY_LINK_SPEED_1GBPS:
368 ethtool_cmd_speed_set(ecmd, SPEED_1000);
369 break;
370 case PHY_LINK_SPEED_10GBPS:
371 ethtool_cmd_speed_set(ecmd, SPEED_10000);
372 break;
373 case PHY_LINK_SPEED_ZERO:
374 ethtool_cmd_speed_set(ecmd, 0);
375 break;
379 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
380 phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
381 phy_cmd.size, &phy_cmd.dma,
382 GFP_KERNEL);
383 if (!phy_cmd.va) {
384 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
385 return -ENOMEM;
387 status = be_cmd_get_phy_info(adapter, &phy_cmd);
388 if (!status) {
389 resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
390 intf_type = le16_to_cpu(resp->interface_type);
392 switch (intf_type) {
393 case PHY_TYPE_XFP_10GB:
394 case PHY_TYPE_SFP_1GB:
395 case PHY_TYPE_SFP_PLUS_10GB:
396 ecmd->port = PORT_FIBRE;
397 break;
398 default:
399 ecmd->port = PORT_TP;
400 break;
403 switch (intf_type) {
404 case PHY_TYPE_KR_10GB:
405 case PHY_TYPE_KX4_10GB:
406 ecmd->autoneg = AUTONEG_ENABLE;
407 ecmd->transceiver = XCVR_INTERNAL;
408 break;
409 default:
410 ecmd->autoneg = AUTONEG_DISABLE;
411 ecmd->transceiver = XCVR_EXTERNAL;
412 break;
416 /* Save for future use */
417 adapter->link_speed = ethtool_cmd_speed(ecmd);
418 adapter->port_type = ecmd->port;
419 adapter->transceiver = ecmd->transceiver;
420 adapter->autoneg = ecmd->autoneg;
421 dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va,
422 phy_cmd.dma);
423 } else {
424 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
425 ecmd->port = adapter->port_type;
426 ecmd->transceiver = adapter->transceiver;
427 ecmd->autoneg = adapter->autoneg;
430 ecmd->duplex = DUPLEX_FULL;
431 ecmd->phy_address = adapter->port_num;
432 switch (ecmd->port) {
433 case PORT_FIBRE:
434 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
435 break;
436 case PORT_TP:
437 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
438 break;
439 case PORT_AUI:
440 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
441 break;
444 if (ecmd->autoneg) {
445 ecmd->supported |= SUPPORTED_1000baseT_Full;
446 ecmd->supported |= SUPPORTED_Autoneg;
447 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
448 ADVERTISED_1000baseT_Full);
451 return 0;
454 static void
455 be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
457 struct be_adapter *adapter = netdev_priv(netdev);
459 ring->rx_max_pending = adapter->rx_obj[0].q.len;
460 ring->tx_max_pending = adapter->tx_obj.q.len;
462 ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
463 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
466 static void
467 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
469 struct be_adapter *adapter = netdev_priv(netdev);
471 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
472 ecmd->autoneg = 0;
475 static int
476 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
478 struct be_adapter *adapter = netdev_priv(netdev);
479 int status;
481 if (ecmd->autoneg != 0)
482 return -EINVAL;
483 adapter->tx_fc = ecmd->tx_pause;
484 adapter->rx_fc = ecmd->rx_pause;
486 status = be_cmd_set_flow_control(adapter,
487 adapter->tx_fc, adapter->rx_fc);
488 if (status)
489 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
491 return status;
494 static int
495 be_set_phys_id(struct net_device *netdev,
496 enum ethtool_phys_id_state state)
498 struct be_adapter *adapter = netdev_priv(netdev);
500 switch (state) {
501 case ETHTOOL_ID_ACTIVE:
502 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
503 &adapter->beacon_state);
504 return 1; /* cycle on/off once per second */
506 case ETHTOOL_ID_ON:
507 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
508 BEACON_STATE_ENABLED);
509 break;
511 case ETHTOOL_ID_OFF:
512 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
513 BEACON_STATE_DISABLED);
514 break;
516 case ETHTOOL_ID_INACTIVE:
517 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
518 adapter->beacon_state);
521 return 0;
524 static bool
525 be_is_wol_supported(struct be_adapter *adapter)
527 if (!be_physfn(adapter))
528 return false;
529 else
530 return true;
533 static void
534 be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
536 struct be_adapter *adapter = netdev_priv(netdev);
538 if (be_is_wol_supported(adapter))
539 wol->supported = WAKE_MAGIC;
541 if (adapter->wol)
542 wol->wolopts = WAKE_MAGIC;
543 else
544 wol->wolopts = 0;
545 memset(&wol->sopass, 0, sizeof(wol->sopass));
548 static int
549 be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
551 struct be_adapter *adapter = netdev_priv(netdev);
553 if (wol->wolopts & ~WAKE_MAGIC)
554 return -EINVAL;
556 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
557 adapter->wol = true;
558 else
559 adapter->wol = false;
561 return 0;
564 static int
565 be_test_ddr_dma(struct be_adapter *adapter)
567 int ret, i;
568 struct be_dma_mem ddrdma_cmd;
569 static const u64 pattern[2] = {
570 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
573 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
574 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
575 &ddrdma_cmd.dma, GFP_KERNEL);
576 if (!ddrdma_cmd.va) {
577 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
578 return -ENOMEM;
581 for (i = 0; i < 2; i++) {
582 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
583 4096, &ddrdma_cmd);
584 if (ret != 0)
585 goto err;
588 err:
589 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
590 ddrdma_cmd.dma);
591 return ret;
594 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
595 u64 *status)
597 be_cmd_set_loopback(adapter, adapter->hba_port_num,
598 loopback_type, 1);
599 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
600 loopback_type, 1500,
601 2, 0xabc);
602 be_cmd_set_loopback(adapter, adapter->hba_port_num,
603 BE_NO_LOOPBACK, 1);
604 return *status;
607 static void
608 be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
610 struct be_adapter *adapter = netdev_priv(netdev);
611 bool link_up;
612 u8 mac_speed = 0;
613 u16 qos_link_speed = 0;
615 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
617 if (test->flags & ETH_TEST_FL_OFFLINE) {
618 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
619 &data[0]) != 0) {
620 test->flags |= ETH_TEST_FL_FAILED;
622 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
623 &data[1]) != 0) {
624 test->flags |= ETH_TEST_FL_FAILED;
626 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
627 &data[2]) != 0) {
628 test->flags |= ETH_TEST_FL_FAILED;
632 if (be_test_ddr_dma(adapter) != 0) {
633 data[3] = 1;
634 test->flags |= ETH_TEST_FL_FAILED;
637 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
638 &qos_link_speed, 0) != 0) {
639 test->flags |= ETH_TEST_FL_FAILED;
640 data[4] = -1;
641 } else if (!mac_speed) {
642 test->flags |= ETH_TEST_FL_FAILED;
643 data[4] = 1;
647 static int
648 be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
650 struct be_adapter *adapter = netdev_priv(netdev);
651 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
653 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
654 strcpy(file_name, efl->data);
656 return be_load_fw(adapter, file_name);
659 static int
660 be_get_eeprom_len(struct net_device *netdev)
662 return BE_READ_SEEPROM_LEN;
665 static int
666 be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
667 uint8_t *data)
669 struct be_adapter *adapter = netdev_priv(netdev);
670 struct be_dma_mem eeprom_cmd;
671 struct be_cmd_resp_seeprom_read *resp;
672 int status;
674 if (!eeprom->len)
675 return -EINVAL;
677 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
679 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
680 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
681 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
682 &eeprom_cmd.dma, GFP_KERNEL);
684 if (!eeprom_cmd.va) {
685 dev_err(&adapter->pdev->dev,
686 "Memory allocation failure. Could not read eeprom\n");
687 return -ENOMEM;
690 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
692 if (!status) {
693 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
694 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
696 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
697 eeprom_cmd.dma);
699 return status;
702 const struct ethtool_ops be_ethtool_ops = {
703 .get_settings = be_get_settings,
704 .get_drvinfo = be_get_drvinfo,
705 .get_wol = be_get_wol,
706 .set_wol = be_set_wol,
707 .get_link = ethtool_op_get_link,
708 .get_eeprom_len = be_get_eeprom_len,
709 .get_eeprom = be_read_eeprom,
710 .get_coalesce = be_get_coalesce,
711 .set_coalesce = be_set_coalesce,
712 .get_ringparam = be_get_ringparam,
713 .get_pauseparam = be_get_pauseparam,
714 .set_pauseparam = be_set_pauseparam,
715 .get_strings = be_get_stat_strings,
716 .set_phys_id = be_set_phys_id,
717 .get_sset_count = be_get_sset_count,
718 .get_ethtool_stats = be_get_ethtool_stats,
719 .get_regs_len = be_get_reg_len,
720 .get_regs = be_get_regs,
721 .flash_device = be_do_flash,
722 .self_test = be_self_test,