be2net: use device model DMA API
[cascardo/linux.git] / drivers / net / benet / be_ethtool.c
1 /*
2  * Copyright (C) 2005 - 2010 ServerEngines
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@serverengines.com
12  *
13  * ServerEngines
14  * 209 N. Fair Oaks Ave
15  * Sunnyvale, CA 94085
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 #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
31                                         offsetof(_struct, field)
32 #define NETSTAT_INFO(field)     #field, NETSTAT,\
33                                         FIELDINFO(struct net_device_stats,\
34                                                 field)
35 #define DRVSTAT_TX_INFO(field)  #field, DRVSTAT_TX,\
36                                         FIELDINFO(struct be_tx_stats, field)
37 #define DRVSTAT_RX_INFO(field)  #field, DRVSTAT_RX,\
38                                         FIELDINFO(struct be_rx_stats, field)
39 #define MISCSTAT_INFO(field)    #field, MISCSTAT,\
40                                         FIELDINFO(struct be_rxf_stats, field)
41 #define PORTSTAT_INFO(field)    #field, PORTSTAT,\
42                                         FIELDINFO(struct be_port_rxf_stats, \
43                                                 field)
44 #define ERXSTAT_INFO(field)     #field, ERXSTAT,\
45                                         FIELDINFO(struct be_erx_stats, field)
46
47 static const struct be_ethtool_stat et_stats[] = {
48         {NETSTAT_INFO(rx_packets)},
49         {NETSTAT_INFO(tx_packets)},
50         {NETSTAT_INFO(rx_bytes)},
51         {NETSTAT_INFO(tx_bytes)},
52         {NETSTAT_INFO(rx_errors)},
53         {NETSTAT_INFO(tx_errors)},
54         {NETSTAT_INFO(rx_dropped)},
55         {NETSTAT_INFO(tx_dropped)},
56         {DRVSTAT_TX_INFO(be_tx_rate)},
57         {DRVSTAT_TX_INFO(be_tx_reqs)},
58         {DRVSTAT_TX_INFO(be_tx_wrbs)},
59         {DRVSTAT_TX_INFO(be_tx_stops)},
60         {DRVSTAT_TX_INFO(be_tx_events)},
61         {DRVSTAT_TX_INFO(be_tx_compl)},
62         {PORTSTAT_INFO(rx_unicast_frames)},
63         {PORTSTAT_INFO(rx_multicast_frames)},
64         {PORTSTAT_INFO(rx_broadcast_frames)},
65         {PORTSTAT_INFO(rx_crc_errors)},
66         {PORTSTAT_INFO(rx_alignment_symbol_errors)},
67         {PORTSTAT_INFO(rx_pause_frames)},
68         {PORTSTAT_INFO(rx_control_frames)},
69         {PORTSTAT_INFO(rx_in_range_errors)},
70         {PORTSTAT_INFO(rx_out_range_errors)},
71         {PORTSTAT_INFO(rx_frame_too_long)},
72         {PORTSTAT_INFO(rx_address_match_errors)},
73         {PORTSTAT_INFO(rx_vlan_mismatch)},
74         {PORTSTAT_INFO(rx_dropped_too_small)},
75         {PORTSTAT_INFO(rx_dropped_too_short)},
76         {PORTSTAT_INFO(rx_dropped_header_too_small)},
77         {PORTSTAT_INFO(rx_dropped_tcp_length)},
78         {PORTSTAT_INFO(rx_dropped_runt)},
79         {PORTSTAT_INFO(rx_fifo_overflow)},
80         {PORTSTAT_INFO(rx_input_fifo_overflow)},
81         {PORTSTAT_INFO(rx_ip_checksum_errs)},
82         {PORTSTAT_INFO(rx_tcp_checksum_errs)},
83         {PORTSTAT_INFO(rx_udp_checksum_errs)},
84         {PORTSTAT_INFO(rx_non_rss_packets)},
85         {PORTSTAT_INFO(rx_ipv4_packets)},
86         {PORTSTAT_INFO(rx_ipv6_packets)},
87         {PORTSTAT_INFO(rx_switched_unicast_packets)},
88         {PORTSTAT_INFO(rx_switched_multicast_packets)},
89         {PORTSTAT_INFO(rx_switched_broadcast_packets)},
90         {PORTSTAT_INFO(tx_unicastframes)},
91         {PORTSTAT_INFO(tx_multicastframes)},
92         {PORTSTAT_INFO(tx_broadcastframes)},
93         {PORTSTAT_INFO(tx_pauseframes)},
94         {PORTSTAT_INFO(tx_controlframes)},
95         {MISCSTAT_INFO(rx_drops_no_pbuf)},
96         {MISCSTAT_INFO(rx_drops_no_txpb)},
97         {MISCSTAT_INFO(rx_drops_no_erx_descr)},
98         {MISCSTAT_INFO(rx_drops_no_tpre_descr)},
99         {MISCSTAT_INFO(rx_drops_too_many_frags)},
100         {MISCSTAT_INFO(rx_drops_invalid_ring)},
101         {MISCSTAT_INFO(forwarded_packets)},
102         {MISCSTAT_INFO(rx_drops_mtu)}
103 };
104 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
105
106 /* Stats related to multi RX queues */
107 static const struct be_ethtool_stat et_rx_stats[] = {
108         {DRVSTAT_RX_INFO(rx_bytes)},
109         {DRVSTAT_RX_INFO(rx_pkts)},
110         {DRVSTAT_RX_INFO(rx_rate)},
111         {DRVSTAT_RX_INFO(rx_polls)},
112         {DRVSTAT_RX_INFO(rx_events)},
113         {DRVSTAT_RX_INFO(rx_compl)},
114         {DRVSTAT_RX_INFO(rx_mcast_pkts)},
115         {DRVSTAT_RX_INFO(rx_post_fail)},
116         {ERXSTAT_INFO(rx_drops_no_fragments)}
117 };
118 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
119
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"
126 };
127
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
133
134 static void
135 be_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
136 {
137         struct be_adapter *adapter = netdev_priv(netdev);
138
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;
146 }
147
148 static int
149 be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
150 {
151         struct be_adapter *adapter = netdev_priv(netdev);
152         struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
153         struct be_eq_obj *tx_eq = &adapter->tx_eq;
154
155         coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
156         coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
157         coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
158
159         coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
160         coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
161         coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
162
163         coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
164         coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
165
166         return 0;
167 }
168
169 /*
170  * This routine is used to set interrup coalescing delay
171  */
172 static int
173 be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
174 {
175         struct be_adapter *adapter = netdev_priv(netdev);
176         struct be_rx_obj *rxo;
177         struct be_eq_obj *rx_eq;
178         struct be_eq_obj *tx_eq = &adapter->tx_eq;
179         u32 tx_max, tx_min, tx_cur;
180         u32 rx_max, rx_min, rx_cur;
181         int status = 0, i;
182
183         if (coalesce->use_adaptive_tx_coalesce == 1)
184                 return -EINVAL;
185
186         for_all_rx_queues(adapter, rxo, i) {
187                 rx_eq = &rxo->rx_eq;
188
189                 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
190                         rx_eq->cur_eqd = 0;
191                 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
192
193                 rx_max = coalesce->rx_coalesce_usecs_high;
194                 rx_min = coalesce->rx_coalesce_usecs_low;
195                 rx_cur = coalesce->rx_coalesce_usecs;
196
197                 if (rx_eq->enable_aic) {
198                         if (rx_max > BE_MAX_EQD)
199                                 rx_max = BE_MAX_EQD;
200                         if (rx_min > rx_max)
201                                 rx_min = rx_max;
202                         rx_eq->max_eqd = rx_max;
203                         rx_eq->min_eqd = rx_min;
204                         if (rx_eq->cur_eqd > rx_max)
205                                 rx_eq->cur_eqd = rx_max;
206                         if (rx_eq->cur_eqd < rx_min)
207                                 rx_eq->cur_eqd = rx_min;
208                 } else {
209                         if (rx_cur > BE_MAX_EQD)
210                                 rx_cur = BE_MAX_EQD;
211                         if (rx_eq->cur_eqd != rx_cur) {
212                                 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
213                                                 rx_cur);
214                                 if (!status)
215                                         rx_eq->cur_eqd = rx_cur;
216                         }
217                 }
218         }
219
220         tx_max = coalesce->tx_coalesce_usecs_high;
221         tx_min = coalesce->tx_coalesce_usecs_low;
222         tx_cur = coalesce->tx_coalesce_usecs;
223
224         if (tx_cur > BE_MAX_EQD)
225                 tx_cur = BE_MAX_EQD;
226         if (tx_eq->cur_eqd != tx_cur) {
227                 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
228                 if (!status)
229                         tx_eq->cur_eqd = tx_cur;
230         }
231
232         return 0;
233 }
234
235 static u32 be_get_rx_csum(struct net_device *netdev)
236 {
237         struct be_adapter *adapter = netdev_priv(netdev);
238
239         return adapter->rx_csum;
240 }
241
242 static int be_set_rx_csum(struct net_device *netdev, uint32_t data)
243 {
244         struct be_adapter *adapter = netdev_priv(netdev);
245
246         if (data)
247                 adapter->rx_csum = true;
248         else
249                 adapter->rx_csum = false;
250
251         return 0;
252 }
253
254 static void
255 be_get_ethtool_stats(struct net_device *netdev,
256                 struct ethtool_stats *stats, uint64_t *data)
257 {
258         struct be_adapter *adapter = netdev_priv(netdev);
259         struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats_cmd.va);
260         struct be_erx_stats *erx_stats = &hw_stats->erx;
261         struct be_rx_obj *rxo;
262         void *p = NULL;
263         int i, j;
264
265         for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
266                 switch (et_stats[i].type) {
267                 case NETSTAT:
268                         p = &netdev->stats;
269                         break;
270                 case DRVSTAT_TX:
271                         p = &adapter->tx_stats;
272                         break;
273                 case PORTSTAT:
274                         p = &hw_stats->rxf.port[adapter->port_num];
275                         break;
276                 case MISCSTAT:
277                         p = &hw_stats->rxf;
278                         break;
279                 }
280
281                 p = (u8 *)p + et_stats[i].offset;
282                 data[i] = (et_stats[i].size == sizeof(u64)) ?
283                                 *(u64 *)p: *(u32 *)p;
284         }
285
286         for_all_rx_queues(adapter, rxo, j) {
287                 for (i = 0; i < ETHTOOL_RXSTATS_NUM; i++) {
288                         switch (et_rx_stats[i].type) {
289                         case DRVSTAT_RX:
290                                 p = (u8 *)&rxo->stats + et_rx_stats[i].offset;
291                                 break;
292                         case ERXSTAT:
293                                 p = (u32 *)erx_stats + rxo->q.id;
294                                 break;
295                         }
296                         data[ETHTOOL_STATS_NUM + j * ETHTOOL_RXSTATS_NUM + i] =
297                                 (et_rx_stats[i].size == sizeof(u64)) ?
298                                         *(u64 *)p: *(u32 *)p;
299                 }
300         }
301 }
302
303 static void
304 be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
305                 uint8_t *data)
306 {
307         struct be_adapter *adapter = netdev_priv(netdev);
308         int i, j;
309
310         switch (stringset) {
311         case ETH_SS_STATS:
312                 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
313                         memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
314                         data += ETH_GSTRING_LEN;
315                 }
316                 for (i = 0; i < adapter->num_rx_qs; i++) {
317                         for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
318                                 sprintf(data, "rxq%d: %s", i,
319                                         et_rx_stats[j].desc);
320                                 data += ETH_GSTRING_LEN;
321                         }
322                 }
323                 break;
324         case ETH_SS_TEST:
325                 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
326                         memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
327                         data += ETH_GSTRING_LEN;
328                 }
329                 break;
330         }
331 }
332
333 static int be_get_sset_count(struct net_device *netdev, int stringset)
334 {
335         struct be_adapter *adapter = netdev_priv(netdev);
336
337         switch (stringset) {
338         case ETH_SS_TEST:
339                 return ETHTOOL_TESTS_NUM;
340         case ETH_SS_STATS:
341                 return ETHTOOL_STATS_NUM +
342                         adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM;
343         default:
344                 return -EINVAL;
345         }
346 }
347
348 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
349 {
350         struct be_adapter *adapter = netdev_priv(netdev);
351         struct be_dma_mem phy_cmd;
352         struct be_cmd_resp_get_phy_info *resp;
353         u8 mac_speed = 0;
354         u16 link_speed = 0;
355         bool link_up = false;
356         int status;
357         u16 intf_type;
358
359         if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
360                 status = be_cmd_link_status_query(adapter, &link_up,
361                                                 &mac_speed, &link_speed);
362
363                 be_link_status_update(adapter, link_up);
364                 /* link_speed is in units of 10 Mbps */
365                 if (link_speed) {
366                         ecmd->speed = link_speed*10;
367                 } else {
368                         switch (mac_speed) {
369                         case PHY_LINK_SPEED_1GBPS:
370                                 ecmd->speed = SPEED_1000;
371                                 break;
372                         case PHY_LINK_SPEED_10GBPS:
373                                 ecmd->speed = SPEED_10000;
374                                 break;
375                         }
376                 }
377
378                 phy_cmd.size = sizeof(struct be_cmd_req_get_phy_info);
379                 phy_cmd.va = dma_alloc_coherent(&adapter->pdev->dev,
380                                                 phy_cmd.size, &phy_cmd.dma,
381                                                 GFP_KERNEL);
382                 if (!phy_cmd.va) {
383                         dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
384                         return -ENOMEM;
385                 }
386                 status = be_cmd_get_phy_info(adapter, &phy_cmd);
387                 if (!status) {
388                         resp = (struct be_cmd_resp_get_phy_info *) phy_cmd.va;
389                         intf_type = le16_to_cpu(resp->interface_type);
390
391                         switch (intf_type) {
392                         case PHY_TYPE_XFP_10GB:
393                         case PHY_TYPE_SFP_1GB:
394                         case PHY_TYPE_SFP_PLUS_10GB:
395                                 ecmd->port = PORT_FIBRE;
396                                 break;
397                         default:
398                                 ecmd->port = PORT_TP;
399                                 break;
400                         }
401
402                         switch (intf_type) {
403                         case PHY_TYPE_KR_10GB:
404                         case PHY_TYPE_KX4_10GB:
405                                 ecmd->autoneg = AUTONEG_ENABLE;
406                         ecmd->transceiver = XCVR_INTERNAL;
407                                 break;
408                         default:
409                                 ecmd->autoneg = AUTONEG_DISABLE;
410                                 ecmd->transceiver = XCVR_EXTERNAL;
411                                 break;
412                         }
413                 }
414
415                 /* Save for future use */
416                 adapter->link_speed = ecmd->speed;
417                 adapter->port_type = ecmd->port;
418                 adapter->transceiver = ecmd->transceiver;
419                 adapter->autoneg = ecmd->autoneg;
420                 dma_free_coherent(&adapter->pdev->dev, phy_cmd.size, phy_cmd.va,
421                                   phy_cmd.dma);
422         } else {
423                 ecmd->speed = adapter->link_speed;
424                 ecmd->port = adapter->port_type;
425                 ecmd->transceiver = adapter->transceiver;
426                 ecmd->autoneg = adapter->autoneg;
427         }
428
429         ecmd->duplex = DUPLEX_FULL;
430         ecmd->phy_address = adapter->port_num;
431         switch (ecmd->port) {
432         case PORT_FIBRE:
433                 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
434                 break;
435         case PORT_TP:
436                 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
437                 break;
438         case PORT_AUI:
439                 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
440                 break;
441         }
442
443         if (ecmd->autoneg) {
444                 ecmd->supported |= SUPPORTED_1000baseT_Full;
445                 ecmd->supported |= SUPPORTED_Autoneg;
446                 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
447                                 ADVERTISED_1000baseT_Full);
448         }
449
450         return 0;
451 }
452
453 static void
454 be_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
455 {
456         struct be_adapter *adapter = netdev_priv(netdev);
457
458         ring->rx_max_pending = adapter->rx_obj[0].q.len;
459         ring->tx_max_pending = adapter->tx_obj.q.len;
460
461         ring->rx_pending = atomic_read(&adapter->rx_obj[0].q.used);
462         ring->tx_pending = atomic_read(&adapter->tx_obj.q.used);
463 }
464
465 static void
466 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
467 {
468         struct be_adapter *adapter = netdev_priv(netdev);
469
470         be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
471         ecmd->autoneg = 0;
472 }
473
474 static int
475 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
476 {
477         struct be_adapter *adapter = netdev_priv(netdev);
478         int status;
479
480         if (ecmd->autoneg != 0)
481                 return -EINVAL;
482         adapter->tx_fc = ecmd->tx_pause;
483         adapter->rx_fc = ecmd->rx_pause;
484
485         status = be_cmd_set_flow_control(adapter,
486                                         adapter->tx_fc, adapter->rx_fc);
487         if (status)
488                 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
489
490         return status;
491 }
492
493 static int
494 be_phys_id(struct net_device *netdev, u32 data)
495 {
496         struct be_adapter *adapter = netdev_priv(netdev);
497         int status;
498         u32 cur;
499
500         be_cmd_get_beacon_state(adapter, adapter->port_num, &cur);
501
502         if (cur == BEACON_STATE_ENABLED)
503                 return 0;
504
505         if (data < 2)
506                 data = 2;
507
508         status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
509                         BEACON_STATE_ENABLED);
510         set_current_state(TASK_INTERRUPTIBLE);
511         schedule_timeout(data*HZ);
512
513         status = be_cmd_set_beacon_state(adapter, adapter->port_num, 0, 0,
514                         BEACON_STATE_DISABLED);
515
516         return status;
517 }
518
519 static void
520 be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
521 {
522         struct be_adapter *adapter = netdev_priv(netdev);
523
524         wol->supported = WAKE_MAGIC;
525         if (adapter->wol)
526                 wol->wolopts = WAKE_MAGIC;
527         else
528                 wol->wolopts = 0;
529         memset(&wol->sopass, 0, sizeof(wol->sopass));
530 }
531
532 static int
533 be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
534 {
535         struct be_adapter *adapter = netdev_priv(netdev);
536
537         if (wol->wolopts & ~WAKE_MAGIC)
538                 return -EINVAL;
539
540         if (wol->wolopts & WAKE_MAGIC)
541                 adapter->wol = true;
542         else
543                 adapter->wol = false;
544
545         return 0;
546 }
547
548 static int
549 be_test_ddr_dma(struct be_adapter *adapter)
550 {
551         int ret, i;
552         struct be_dma_mem ddrdma_cmd;
553         static const u64 pattern[2] = {
554                 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
555         };
556
557         ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
558         ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
559                                            &ddrdma_cmd.dma, GFP_KERNEL);
560         if (!ddrdma_cmd.va) {
561                 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
562                 return -ENOMEM;
563         }
564
565         for (i = 0; i < 2; i++) {
566                 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
567                                         4096, &ddrdma_cmd);
568                 if (ret != 0)
569                         goto err;
570         }
571
572 err:
573         dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
574                           ddrdma_cmd.dma);
575         return ret;
576 }
577
578 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
579                                 u64 *status)
580 {
581         be_cmd_set_loopback(adapter, adapter->port_num,
582                                 loopback_type, 1);
583         *status = be_cmd_loopback_test(adapter, adapter->port_num,
584                                 loopback_type, 1500,
585                                 2, 0xabc);
586         be_cmd_set_loopback(adapter, adapter->port_num,
587                                 BE_NO_LOOPBACK, 1);
588         return *status;
589 }
590
591 static void
592 be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
593 {
594         struct be_adapter *adapter = netdev_priv(netdev);
595         bool link_up;
596         u8 mac_speed = 0;
597         u16 qos_link_speed = 0;
598
599         memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
600
601         if (test->flags & ETH_TEST_FL_OFFLINE) {
602                 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
603                                                 &data[0]) != 0) {
604                         test->flags |= ETH_TEST_FL_FAILED;
605                 }
606                 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
607                                                 &data[1]) != 0) {
608                         test->flags |= ETH_TEST_FL_FAILED;
609                 }
610                 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
611                                                 &data[2]) != 0) {
612                         test->flags |= ETH_TEST_FL_FAILED;
613                 }
614         }
615
616         if (be_test_ddr_dma(adapter) != 0) {
617                 data[3] = 1;
618                 test->flags |= ETH_TEST_FL_FAILED;
619         }
620
621         if (be_cmd_link_status_query(adapter, &link_up, &mac_speed,
622                                 &qos_link_speed) != 0) {
623                 test->flags |= ETH_TEST_FL_FAILED;
624                 data[4] = -1;
625         } else if (mac_speed) {
626                 data[4] = 1;
627         }
628 }
629
630 static int
631 be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
632 {
633         struct be_adapter *adapter = netdev_priv(netdev);
634         char file_name[ETHTOOL_FLASH_MAX_FILENAME];
635         u32 region;
636
637         file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
638         strcpy(file_name, efl->data);
639         region = efl->region;
640
641         return be_load_fw(adapter, file_name);
642 }
643
644 static int
645 be_get_eeprom_len(struct net_device *netdev)
646 {
647         return BE_READ_SEEPROM_LEN;
648 }
649
650 static int
651 be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
652                         uint8_t *data)
653 {
654         struct be_adapter *adapter = netdev_priv(netdev);
655         struct be_dma_mem eeprom_cmd;
656         struct be_cmd_resp_seeprom_read *resp;
657         int status;
658
659         if (!eeprom->len)
660                 return -EINVAL;
661
662         eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
663
664         memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
665         eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
666         eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
667                                            &eeprom_cmd.dma, GFP_KERNEL);
668
669         if (!eeprom_cmd.va) {
670                 dev_err(&adapter->pdev->dev,
671                         "Memory allocation failure. Could not read eeprom\n");
672                 return -ENOMEM;
673         }
674
675         status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
676
677         if (!status) {
678                 resp = (struct be_cmd_resp_seeprom_read *) eeprom_cmd.va;
679                 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
680         }
681         dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
682                           eeprom_cmd.dma);
683
684         return status;
685 }
686
687 const struct ethtool_ops be_ethtool_ops = {
688         .get_settings = be_get_settings,
689         .get_drvinfo = be_get_drvinfo,
690         .get_wol = be_get_wol,
691         .set_wol = be_set_wol,
692         .get_link = ethtool_op_get_link,
693         .get_eeprom_len = be_get_eeprom_len,
694         .get_eeprom = be_read_eeprom,
695         .get_coalesce = be_get_coalesce,
696         .set_coalesce = be_set_coalesce,
697         .get_ringparam = be_get_ringparam,
698         .get_pauseparam = be_get_pauseparam,
699         .set_pauseparam = be_set_pauseparam,
700         .get_rx_csum = be_get_rx_csum,
701         .set_rx_csum = be_set_rx_csum,
702         .get_tx_csum = ethtool_op_get_tx_csum,
703         .set_tx_csum = ethtool_op_set_tx_hw_csum,
704         .get_sg = ethtool_op_get_sg,
705         .set_sg = ethtool_op_set_sg,
706         .get_tso = ethtool_op_get_tso,
707         .set_tso = ethtool_op_set_tso,
708         .get_strings = be_get_stat_strings,
709         .phys_id = be_phys_id,
710         .get_sset_count = be_get_sset_count,
711         .get_ethtool_stats = be_get_ethtool_stats,
712         .flash_device = be_do_flash,
713         .self_test = be_self_test,
714 };