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