Merge branch 'omap-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / drivers / net / benet / be_ethtool.c
1 /*
2 * Copyright (C) 2005 - 2011 Emulex
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:
11 * linux-drivers@emulex.com
12 *
13 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
16 */
17
18 #include "be.h"
19 #include "be_cmds.h"
20 #include <linux/ethtool.h>
21
22 struct be_ethtool_stat {
23 char desc[ETH_GSTRING_LEN];
24 int type;
25 int size;
26 int offset;
27 };
28
29 enum {NETSTAT, PORTSTAT, MISCSTAT, DRVSTAT_TX, DRVSTAT_RX, ERXSTAT,
30 PMEMSTAT, 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 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)
47 #define PMEMSTAT_INFO(field) #field, PMEMSTAT,\
48 FIELDINFO(struct be_pmem_stats, field)
49 #define DRVSTAT_INFO(field) #field, DRVSTAT,\
50 FIELDINFO(struct be_drv_stats, \
51 field)
52
53 static 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)},
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)},
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)},
93 {PORTSTAT_INFO(rx_switched_unicast_packets)},
94 {PORTSTAT_INFO(rx_switched_multicast_packets)},
95 {PORTSTAT_INFO(rx_switched_broadcast_packets)},
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)},
108 {MISCSTAT_INFO(rx_drops_mtu)},
109 {MISCSTAT_INFO(port0_jabber_events)},
110 {MISCSTAT_INFO(port1_jabber_events)},
111 {PMEMSTAT_INFO(eth_red_drops)},
112 {DRVSTAT_INFO(be_on_die_temperature)}
113 };
114 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
115
116 /* Stats related to multi RX queues */
117 static 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
130 static const char et_self_tests[][ETH_GSTRING_LEN] = {
131 "MAC Loopback test",
132 "PHY Loopback test",
133 "External Loopback test",
134 "DDR DMA test",
135 "Link test"
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
142 #define BE_NO_LOOPBACK 0xff
143
144 static void
145 be_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
158 static int
159 be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
160 {
161 struct be_adapter *adapter = netdev_priv(netdev);
162 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
163 struct be_eq_obj *tx_eq = &adapter->tx_eq;
164
165 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
166 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
167 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
168
169 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
170 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
171 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
172
173 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
174 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
175
176 return 0;
177 }
178
179 /*
180 * This routine is used to set interrup coalescing delay
181 */
182 static int
183 be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
184 {
185 struct be_adapter *adapter = netdev_priv(netdev);
186 struct be_rx_obj *rxo;
187 struct be_eq_obj *rx_eq;
188 struct be_eq_obj *tx_eq = &adapter->tx_eq;
189 u32 tx_max, tx_min, tx_cur;
190 u32 rx_max, rx_min, rx_cur;
191 int status = 0, i;
192
193 if (coalesce->use_adaptive_tx_coalesce == 1)
194 return -EINVAL;
195
196 for_all_rx_queues(adapter, rxo, i) {
197 rx_eq = &rxo->rx_eq;
198
199 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
200 rx_eq->cur_eqd = 0;
201 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
202
203 rx_max = coalesce->rx_coalesce_usecs_high;
204 rx_min = coalesce->rx_coalesce_usecs_low;
205 rx_cur = coalesce->rx_coalesce_usecs;
206
207 if (rx_eq->enable_aic) {
208 if (rx_max > BE_MAX_EQD)
209 rx_max = BE_MAX_EQD;
210 if (rx_min > rx_max)
211 rx_min = rx_max;
212 rx_eq->max_eqd = rx_max;
213 rx_eq->min_eqd = rx_min;
214 if (rx_eq->cur_eqd > rx_max)
215 rx_eq->cur_eqd = rx_max;
216 if (rx_eq->cur_eqd < rx_min)
217 rx_eq->cur_eqd = rx_min;
218 } else {
219 if (rx_cur > BE_MAX_EQD)
220 rx_cur = BE_MAX_EQD;
221 if (rx_eq->cur_eqd != rx_cur) {
222 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
223 rx_cur);
224 if (!status)
225 rx_eq->cur_eqd = rx_cur;
226 }
227 }
228 }
229
230 tx_max = coalesce->tx_coalesce_usecs_high;
231 tx_min = coalesce->tx_coalesce_usecs_low;
232 tx_cur = coalesce->tx_coalesce_usecs;
233
234 if (tx_cur > BE_MAX_EQD)
235 tx_cur = BE_MAX_EQD;
236 if (tx_eq->cur_eqd != tx_cur) {
237 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
238 if (!status)
239 tx_eq->cur_eqd = tx_cur;
240 }
241
242 return 0;
243 }
244
245 static u32 be_get_rx_csum(struct net_device *netdev)
246 {
247 struct be_adapter *adapter = netdev_priv(netdev);
248
249 return adapter->rx_csum;
250 }
251
252 static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
253 {
254 struct be_adapter *adapter = netdev_priv(netdev);
255
256 if (data)
257 adapter->rx_csum = true;
258 else
259 adapter->rx_csum = false;
260
261 return 0;
262 }
263
264 static void
265 be_get_ethtool_stats(struct net_device *netdev,
266 struct ethtool_stats *stats, uint64_t *data)
267 {
268 struct be_adapter *adapter = netdev_priv(netdev);
269 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va);
270 struct be_erx_stats *erx_stats = &hw_stats->erx;
271 struct be_rx_obj *rxo;
272 void *p = NULL;
273 int i, j;
274
275 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
276 switch (et_stats[i].type) {
277 case NETSTAT:
278 p = &netdev->stats;
279 break;
280 case DRVSTAT_TX:
281 p = &adapter->tx_stats;
282 break;
283 case PORTSTAT:
284 p = &hw_stats->rxf.port[adapter->port_num];
285 break;
286 case MISCSTAT:
287 p = &hw_stats->rxf;
288 break;
289 case PMEMSTAT:
290 p = &hw_stats->pmem;
291 break;
292 case DRVSTAT:
293 p = &adapter->drv_stats;
294 break;
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 }
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 }
317 }
318
319 static void
320 be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
321 uint8_t *data)
322 {
323 struct be_adapter *adapter = netdev_priv(netdev);
324 int i, j;
325
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 }
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 }
339 break;
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;
346 }
347 }
348
349 static int be_get_sset_count(struct net_device *netdev, int stringset)
350 {
351 struct be_adapter *adapter = netdev_priv(netdev);
352
353 switch (stringset) {
354 case ETH_SS_TEST:
355 return ETHTOOL_TESTS_NUM;
356 case ETH_SS_STATS:
357 return ETHTOOL_STATS_NUM +
358 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
359 default:
360 return -EINVAL;
361 }
362 }
363
364 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
365 {
366 struct be_adapter *adapter = netdev_priv(netdev);
367 struct be_dma_mem phy_cmd;
368 struct be_cmd_resp_get_phy_info *resp;
369 u8 mac_speed = 0;
370 u16 link_speed = 0;
371 bool link_up = false;
372 int status;
373 u16 intf_type;
374
375 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
376 status = be_cmd_link_status_query(adapter, &link_up,
377 &mac_speed, &link_speed);
378
379 be_link_status_update(adapter, link_up);
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 }
393
394 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
395 phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
396 phy_cmd.size, &phy_cmd.dma,
397 GFP_KERNEL);
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);
403 if (!status) {
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:
411 ecmd->port = PORT_FIBRE;
412 break;
413 default:
414 ecmd->port = PORT_TP;
415 break;
416 }
417
418 switch (intf_type) {
419 case PHY_TYPE_KR_10GB:
420 case PHY_TYPE_KX4_10GB:
421 ecmd->autoneg = AUTONEG_ENABLE;
422 ecmd->transceiver = XCVR_INTERNAL;
423 break;
424 default:
425 ecmd->autoneg = AUTONEG_DISABLE;
426 ecmd->transceiver = XCVR_EXTERNAL;
427 break;
428 }
429 }
430
431 /* Save for future use */
432 adapter->link_speed = ecmd->speed;
433 adapter->port_type = ecmd->port;
434 adapter->transceiver = ecmd->transceiver;
435 adapter->autoneg = ecmd->autoneg;
436 dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va,
437 phy_cmd.dma);
438 } else {
439 ecmd->speed = adapter->link_speed;
440 ecmd->port = adapter->port_type;
441 ecmd->transceiver = adapter->transceiver;
442 ecmd->autoneg = adapter->autoneg;
443 }
444
445 ecmd->duplex = DUPLEX_FULL;
446 ecmd->phy_address = adapter->port_num;
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 }
458
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
466 return 0;
467 }
468
469 static void
470 be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
471 {
472 struct be_adapter *adapter = netdev_priv(netdev);
473
474 ring->rx_max_pending = adapter->rx_obj[0].q.len;
475 ring->tx_max_pending = adapter->tx_obj.q.len;
476
477 ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
478 ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
479 }
480
481 static void
482 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
483 {
484 struct be_adapter *adapter = netdev_priv(netdev);
485
486 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
487 ecmd->autoneg = 0;
488 }
489
490 static int
491 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
492 {
493 struct be_adapter *adapter = netdev_priv(netdev);
494 int status;
495
496 if (ecmd->autoneg != 0)
497 return -EINVAL;
498 adapter->tx_fc = ecmd->tx_pause;
499 adapter->rx_fc = ecmd->rx_pause;
500
501 status = be_cmd_set_flow_control(adapter,
502 adapter->tx_fc, adapter->rx_fc);
503 if (status)
504 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
505
506 return status;
507 }
508
509 static int
510 be_phys_id(struct net_device *netdev, u32 data)
511 {
512 struct be_adapter *adapter = netdev_priv(netdev);
513 int status;
514 u32 cur;
515
516 be_cmd_get_beacon_state(adapter, adapter->hba_port_num, &cur);
517
518 if (cur == BEACON_STATE_ENABLED)
519 return 0;
520
521 if (data < 2)
522 data = 2;
523
524 status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
525 BEACON_STATE_ENABLED);
526 set_current_state(TASK_INTERRUPTIBLE);
527 schedule_timeout(data*HZ);
528
529 status = be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
530 BEACON_STATE_DISABLED);
531
532 return status;
533 }
534
535 static bool
536 be_is_wol_supported(struct be_adapter *adapter)
537 {
538 if (!be_physfn(adapter))
539 return false;
540 else
541 return true;
542 }
543
544 static void
545 be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
546 {
547 struct be_adapter *adapter = netdev_priv(netdev);
548
549 if (be_is_wol_supported(adapter))
550 wol->supported = WAKE_MAGIC;
551
552 if (adapter->wol)
553 wol->wolopts = WAKE_MAGIC;
554 else
555 wol->wolopts = 0;
556 memset(&wol->sopass, 0, sizeof(wol->sopass));
557 }
558
559 static int
560 be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
561 {
562 struct be_adapter *adapter = netdev_priv(netdev);
563
564 if (wol->wolopts & ~WAKE_MAGIC)
565 return -EINVAL;
566
567 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
568 adapter->wol = true;
569 else
570 adapter->wol = false;
571
572 return 0;
573 }
574
575 static int
576 be_test_ddr_dma(struct be_adapter *adapter)
577 {
578 int ret, i;
579 struct be_dma_mem ddrdma_cmd;
580 static const u64 pattern[2] = {
581 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
582 };
583
584 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
585 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
586 &ddrdma_cmd.dma, GFP_KERNEL);
587 if (!ddrdma_cmd.va) {
588 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
589 return -ENOMEM;
590 }
591
592 for (i = 0; i < 2; i++) {
593 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
594 4096, &ddrdma_cmd);
595 if (ret != 0)
596 goto err;
597 }
598
599 err:
600 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
601 ddrdma_cmd.dma);
602 return ret;
603 }
604
605 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
606 u64 *status)
607 {
608 be_cmd_set_loopback(adapter, adapter->hba_port_num,
609 loopback_type, 1);
610 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
611 loopback_type, 1500,
612 2, 0xabc);
613 be_cmd_set_loopback(adapter, adapter->hba_port_num,
614 BE_NO_LOOPBACK, 1);
615 return *status;
616 }
617
618 static void
619 be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
620 {
621 struct be_adapter *adapter = netdev_priv(netdev);
622 bool link_up;
623 u8 mac_speed = 0;
624 u16 qos_link_speed = 0;
625
626 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
627
628 if (test->flags & ETH_TEST_FL_OFFLINE) {
629 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
630 &data[0]) != 0) {
631 test->flags |= ETH_TEST_FL_FAILED;
632 }
633 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
634 &data[1]) != 0) {
635 test->flags |= ETH_TEST_FL_FAILED;
636 }
637 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
638 &data[2]) != 0) {
639 test->flags |= ETH_TEST_FL_FAILED;
640 }
641 }
642
643 if (be_test_ddr_dma(adapter) != 0) {
644 data[3] = 1;
645 test->flags |= ETH_TEST_FL_FAILED;
646 }
647
648 if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
649 &qos_link_speed) != 0) {
650 test->flags |= ETH_TEST_FL_FAILED;
651 data[4] = -1;
652 } else if (!mac_speed) {
653 test->flags |= ETH_TEST_FL_FAILED;
654 data[4] = 1;
655 }
656 }
657
658 static int
659 be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
660 {
661 struct be_adapter *adapter = netdev_priv(netdev);
662 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
663 u32 region;
664
665 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
666 strcpy(file_name, efl->data);
667 region = efl->region;
668
669 return be_load_fw(adapter, file_name);
670 }
671
672 static int
673 be_get_eeprom_len(struct net_device *netdev)
674 {
675 return BE_READ_SEEPROM_LEN;
676 }
677
678 static int
679 be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
680 uint8_t *data)
681 {
682 struct be_adapter *adapter = netdev_priv(netdev);
683 struct be_dma_mem eeprom_cmd;
684 struct be_cmd_resp_seeprom_read *resp;
685 int status;
686
687 if (!eeprom->len)
688 return -EINVAL;
689
690 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
691
692 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
693 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
694 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
695 &eeprom_cmd.dma, GFP_KERNEL);
696
697 if (!eeprom_cmd.va) {
698 dev_err(&adapter->pdev->dev,
699 "Memory allocation failure. Could not read eeprom\n");
700 return -ENOMEM;
701 }
702
703 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
704
705 if (!status) {
706 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
707 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
708 }
709 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
710 eeprom_cmd.dma);
711
712 return status;
713 }
714
715 const struct ethtool_ops be_ethtool_ops = {
716 .get_settings = be_get_settings,
717 .get_drvinfo = be_get_drvinfo,
718 .get_wol = be_get_wol,
719 .set_wol = be_set_wol,
720 .get_link = ethtool_op_get_link,
721 .get_eeprom_len = be_get_eeprom_len,
722 .get_eeprom = be_read_eeprom,
723 .get_coalesce = be_get_coalesce,
724 .set_coalesce = be_set_coalesce,
725 .get_ringparam = be_get_ringparam,
726 .get_pauseparam = be_get_pauseparam,
727 .set_pauseparam = be_set_pauseparam,
728 .get_rx_csum = be_get_rx_csum,
729 .set_rx_csum = be_set_rx_csum,
730 .get_tx_csum = ethtool_op_get_tx_csum,
731 .set_tx_csum = ethtool_op_set_tx_hw_csum,
732 .get_sg = ethtool_op_get_sg,
733 .set_sg = ethtool_op_set_sg,
734 .get_tso = ethtool_op_get_tso,
735 .set_tso = ethtool_op_set_tso,
736 .get_strings = be_get_stat_strings,
737 .phys_id = be_phys_id,
738 .get_sset_count = be_get_sset_count,
739 .get_ethtool_stats = be_get_ethtool_stats,
740 .flash_device = be_do_flash,
741 .self_test = be_self_test,
742 };
This page took 0.047822 seconds and 6 git commands to generate.