OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / drivers / net / ethernet / emulex / benet / be_ethtool.c
blob802e5ddef8a8c48aa48ad4ae2adafc35ff8b5f84
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 {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
30 #define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
31 offsetof(_struct, field)
32 #define DRVSTAT_TX_INFO(field) #field, DRVSTAT_TX,\
33 FIELDINFO(struct be_tx_stats, field)
34 #define DRVSTAT_RX_INFO(field) #field, DRVSTAT_RX,\
35 FIELDINFO(struct be_rx_stats, field)
36 #define DRVSTAT_INFO(field) #field, DRVSTAT,\
37 FIELDINFO(struct be_drv_stats, field)
39 static const struct be_ethtool_stat et_stats[] = {
40 {DRVSTAT_INFO(tx_events)},
41 {DRVSTAT_INFO(rx_crc_errors)},
42 {DRVSTAT_INFO(rx_alignment_symbol_errors)},
43 {DRVSTAT_INFO(rx_pause_frames)},
44 {DRVSTAT_INFO(rx_control_frames)},
45 {DRVSTAT_INFO(rx_in_range_errors)},
46 {DRVSTAT_INFO(rx_out_range_errors)},
47 {DRVSTAT_INFO(rx_frame_too_long)},
48 {DRVSTAT_INFO(rx_address_match_errors)},
49 {DRVSTAT_INFO(rx_dropped_too_small)},
50 {DRVSTAT_INFO(rx_dropped_too_short)},
51 {DRVSTAT_INFO(rx_dropped_header_too_small)},
52 {DRVSTAT_INFO(rx_dropped_tcp_length)},
53 {DRVSTAT_INFO(rx_dropped_runt)},
54 {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
55 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
56 {DRVSTAT_INFO(rx_ip_checksum_errs)},
57 {DRVSTAT_INFO(rx_tcp_checksum_errs)},
58 {DRVSTAT_INFO(rx_udp_checksum_errs)},
59 {DRVSTAT_INFO(tx_pauseframes)},
60 {DRVSTAT_INFO(tx_controlframes)},
61 {DRVSTAT_INFO(rx_priority_pause_frames)},
62 {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
63 {DRVSTAT_INFO(jabber_events)},
64 {DRVSTAT_INFO(rx_drops_no_pbuf)},
65 {DRVSTAT_INFO(rx_drops_no_txpb)},
66 {DRVSTAT_INFO(rx_drops_no_erx_descr)},
67 {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
68 {DRVSTAT_INFO(rx_drops_too_many_frags)},
69 {DRVSTAT_INFO(rx_drops_invalid_ring)},
70 {DRVSTAT_INFO(forwarded_packets)},
71 {DRVSTAT_INFO(rx_drops_mtu)},
72 {DRVSTAT_INFO(eth_red_drops)},
73 {DRVSTAT_INFO(be_on_die_temperature)}
75 #define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
77 /* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
78 * are first and second members respectively.
80 static const struct be_ethtool_stat et_rx_stats[] = {
81 {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
82 {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
83 {DRVSTAT_RX_INFO(rx_polls)},
84 {DRVSTAT_RX_INFO(rx_events)},
85 {DRVSTAT_RX_INFO(rx_compl)},
86 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
87 {DRVSTAT_RX_INFO(rx_post_fail)},
88 {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
89 {DRVSTAT_RX_INFO(rx_drops_no_frags)}
91 #define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
93 /* Stats related to multi TX queues: get_stats routine assumes compl is the
94 * first member
96 static const struct be_ethtool_stat et_tx_stats[] = {
97 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
98 {DRVSTAT_TX_INFO(tx_bytes)},
99 {DRVSTAT_TX_INFO(tx_pkts)},
100 {DRVSTAT_TX_INFO(tx_reqs)},
101 {DRVSTAT_TX_INFO(tx_wrbs)},
102 {DRVSTAT_TX_INFO(tx_compl)},
103 {DRVSTAT_TX_INFO(tx_stops)}
105 #define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
107 static const char et_self_tests[][ETH_GSTRING_LEN] = {
108 "MAC Loopback test",
109 "PHY Loopback test",
110 "External Loopback test",
111 "DDR DMA test",
112 "Link test"
115 #define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
116 #define BE_MAC_LOOPBACK 0x0
117 #define BE_PHY_LOOPBACK 0x1
118 #define BE_ONE_PORT_EXT_LOOPBACK 0x2
119 #define BE_NO_LOOPBACK 0xff
121 static void be_get_drvinfo(struct net_device *netdev,
122 struct ethtool_drvinfo *drvinfo)
124 struct be_adapter *adapter = netdev_priv(netdev);
125 char fw_on_flash[FW_VER_LEN];
127 memset(fw_on_flash, 0 , sizeof(fw_on_flash));
128 be_cmd_get_fw_ver(adapter, adapter->fw_ver, fw_on_flash);
130 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
131 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
132 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
133 if (memcmp(adapter->fw_ver, fw_on_flash, FW_VER_LEN) != 0) {
134 strcat(drvinfo->fw_version, " [");
135 strcat(drvinfo->fw_version, fw_on_flash);
136 strcat(drvinfo->fw_version, "]");
139 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
140 sizeof(drvinfo->bus_info));
141 drvinfo->testinfo_len = 0;
142 drvinfo->regdump_len = 0;
143 drvinfo->eedump_len = 0;
146 static u32
147 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
149 u32 data_read = 0, eof;
150 u8 addn_status;
151 struct be_dma_mem data_len_cmd;
152 int status;
154 memset(&data_len_cmd, 0, sizeof(data_len_cmd));
155 /* data_offset and data_size should be 0 to get reg len */
156 status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
157 file_name, &data_read, &eof, &addn_status);
159 return data_read;
162 static int
163 lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
164 u32 buf_len, void *buf)
166 struct be_dma_mem read_cmd;
167 u32 read_len = 0, total_read_len = 0, chunk_size;
168 u32 eof = 0;
169 u8 addn_status;
170 int status = 0;
172 read_cmd.size = LANCER_READ_FILE_CHUNK;
173 read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
174 &read_cmd.dma);
176 if (!read_cmd.va) {
177 dev_err(&adapter->pdev->dev,
178 "Memory allocation failure while reading dump\n");
179 return -ENOMEM;
182 while ((total_read_len < buf_len) && !eof) {
183 chunk_size = min_t(u32, (buf_len - total_read_len),
184 LANCER_READ_FILE_CHUNK);
185 chunk_size = ALIGN(chunk_size, 4);
186 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
187 total_read_len, file_name, &read_len,
188 &eof, &addn_status);
189 if (!status) {
190 memcpy(buf + total_read_len, read_cmd.va, read_len);
191 total_read_len += read_len;
192 eof &= LANCER_READ_FILE_EOF_MASK;
193 } else {
194 status = -EIO;
195 break;
198 pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
199 read_cmd.dma);
201 return status;
204 static int
205 be_get_reg_len(struct net_device *netdev)
207 struct be_adapter *adapter = netdev_priv(netdev);
208 u32 log_size = 0;
210 if (be_physfn(adapter)) {
211 if (lancer_chip(adapter))
212 log_size = lancer_cmd_get_file_len(adapter,
213 LANCER_FW_DUMP_FILE);
214 else
215 be_cmd_get_reg_len(adapter, &log_size);
217 return log_size;
220 static void
221 be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
223 struct be_adapter *adapter = netdev_priv(netdev);
225 if (be_physfn(adapter)) {
226 memset(buf, 0, regs->len);
227 if (lancer_chip(adapter))
228 lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
229 regs->len, buf);
230 else
231 be_cmd_get_regs(adapter, regs->len, buf);
235 static int
236 be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
238 struct be_adapter *adapter = netdev_priv(netdev);
239 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
240 struct be_eq_obj *tx_eq = &adapter->tx_eq;
242 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
243 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
244 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
246 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
247 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
248 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
250 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
251 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
253 return 0;
257 * This routine is used to set interrup coalescing delay
259 static int
260 be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
262 struct be_adapter *adapter = netdev_priv(netdev);
263 struct be_rx_obj *rxo;
264 struct be_eq_obj *rx_eq;
265 struct be_eq_obj *tx_eq = &adapter->tx_eq;
266 u32 rx_max, rx_min, rx_cur;
267 int status = 0, i;
268 u32 tx_cur;
270 if (coalesce->use_adaptive_tx_coalesce == 1)
271 return -EINVAL;
273 for_all_rx_queues(adapter, rxo, i) {
274 rx_eq = &rxo->rx_eq;
276 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
277 rx_eq->cur_eqd = 0;
278 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
280 rx_max = coalesce->rx_coalesce_usecs_high;
281 rx_min = coalesce->rx_coalesce_usecs_low;
282 rx_cur = coalesce->rx_coalesce_usecs;
284 if (rx_eq->enable_aic) {
285 if (rx_max > BE_MAX_EQD)
286 rx_max = BE_MAX_EQD;
287 if (rx_min > rx_max)
288 rx_min = rx_max;
289 rx_eq->max_eqd = rx_max;
290 rx_eq->min_eqd = rx_min;
291 if (rx_eq->cur_eqd > rx_max)
292 rx_eq->cur_eqd = rx_max;
293 if (rx_eq->cur_eqd < rx_min)
294 rx_eq->cur_eqd = rx_min;
295 } else {
296 if (rx_cur > BE_MAX_EQD)
297 rx_cur = BE_MAX_EQD;
298 if (rx_eq->cur_eqd != rx_cur) {
299 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
300 rx_cur);
301 if (!status)
302 rx_eq->cur_eqd = rx_cur;
307 tx_cur = coalesce->tx_coalesce_usecs;
309 if (tx_cur > BE_MAX_EQD)
310 tx_cur = BE_MAX_EQD;
311 if (tx_eq->cur_eqd != tx_cur) {
312 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
313 if (!status)
314 tx_eq->cur_eqd = tx_cur;
317 return 0;
320 static void
321 be_get_ethtool_stats(struct net_device *netdev,
322 struct ethtool_stats *stats, uint64_t *data)
324 struct be_adapter *adapter = netdev_priv(netdev);
325 struct be_rx_obj *rxo;
326 struct be_tx_obj *txo;
327 void *p;
328 unsigned int i, j, base = 0, start;
330 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
331 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
332 data[i] = *(u32 *)p;
334 base += ETHTOOL_STATS_NUM;
336 for_all_rx_queues(adapter, rxo, j) {
337 struct be_rx_stats *stats = rx_stats(rxo);
339 do {
340 start = u64_stats_fetch_begin_bh(&stats->sync);
341 data[base] = stats->rx_bytes;
342 data[base + 1] = stats->rx_pkts;
343 } while (u64_stats_fetch_retry_bh(&stats->sync, start));
345 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
346 p = (u8 *)stats + et_rx_stats[i].offset;
347 data[base + i] = *(u32 *)p;
349 base += ETHTOOL_RXSTATS_NUM;
352 for_all_tx_queues(adapter, txo, j) {
353 struct be_tx_stats *stats = tx_stats(txo);
355 do {
356 start = u64_stats_fetch_begin_bh(&stats->sync_compl);
357 data[base] = stats->tx_compl;
358 } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start));
360 do {
361 start = u64_stats_fetch_begin_bh(&stats->sync);
362 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
363 p = (u8 *)stats + et_tx_stats[i].offset;
364 data[base + i] =
365 (et_tx_stats[i].size == sizeof(u64)) ?
366 *(u64 *)p : *(u32 *)p;
368 } while (u64_stats_fetch_retry_bh(&stats->sync, start));
369 base += ETHTOOL_TXSTATS_NUM;
373 static void
374 be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
375 uint8_t *data)
377 struct be_adapter *adapter = netdev_priv(netdev);
378 int i, j;
380 switch (stringset) {
381 case ETH_SS_STATS:
382 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
383 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
384 data += ETH_GSTRING_LEN;
386 for (i = 0; i < adapter->num_rx_qs; i++) {
387 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
388 sprintf(data, "rxq%d: %s", i,
389 et_rx_stats[j].desc);
390 data += ETH_GSTRING_LEN;
393 for (i = 0; i < adapter->num_tx_qs; i++) {
394 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
395 sprintf(data, "txq%d: %s", i,
396 et_tx_stats[j].desc);
397 data += ETH_GSTRING_LEN;
400 break;
401 case ETH_SS_TEST:
402 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
403 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
404 data += ETH_GSTRING_LEN;
406 break;
410 static int be_get_sset_count(struct net_device *netdev, int stringset)
412 struct be_adapter *adapter = netdev_priv(netdev);
414 switch (stringset) {
415 case ETH_SS_TEST:
416 return ETHTOOL_TESTS_NUM;
417 case ETH_SS_STATS:
418 return ETHTOOL_STATS_NUM +
419 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
420 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
421 default:
422 return -EINVAL;
426 static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
428 struct be_adapter *adapter = netdev_priv(netdev);
429 struct be_phy_info phy_info;
430 u8 mac_speed = 0;
431 u16 link_speed = 0;
432 u8 link_status;
433 int status;
435 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
436 status = be_cmd_link_status_query(adapter, &mac_speed,
437 &link_speed, &link_status, 0);
438 if (!status)
439 be_link_status_update(adapter, link_status);
441 /* link_speed is in units of 10 Mbps */
442 if (link_speed) {
443 ethtool_cmd_speed_set(ecmd, link_speed*10);
444 } else {
445 switch (mac_speed) {
446 case PHY_LINK_SPEED_10MBPS:
447 ethtool_cmd_speed_set(ecmd, SPEED_10);
448 break;
449 case PHY_LINK_SPEED_100MBPS:
450 ethtool_cmd_speed_set(ecmd, SPEED_100);
451 break;
452 case PHY_LINK_SPEED_1GBPS:
453 ethtool_cmd_speed_set(ecmd, SPEED_1000);
454 break;
455 case PHY_LINK_SPEED_10GBPS:
456 ethtool_cmd_speed_set(ecmd, SPEED_10000);
457 break;
458 case PHY_LINK_SPEED_ZERO:
459 ethtool_cmd_speed_set(ecmd, 0);
460 break;
464 status = be_cmd_get_phy_info(adapter, &phy_info);
465 if (!status) {
466 switch (phy_info.interface_type) {
467 case PHY_TYPE_XFP_10GB:
468 case PHY_TYPE_SFP_1GB:
469 case PHY_TYPE_SFP_PLUS_10GB:
470 ecmd->port = PORT_FIBRE;
471 break;
472 default:
473 ecmd->port = PORT_TP;
474 break;
477 switch (phy_info.interface_type) {
478 case PHY_TYPE_KR_10GB:
479 case PHY_TYPE_KX4_10GB:
480 ecmd->autoneg = AUTONEG_ENABLE;
481 ecmd->transceiver = XCVR_INTERNAL;
482 break;
483 default:
484 ecmd->autoneg = AUTONEG_DISABLE;
485 ecmd->transceiver = XCVR_EXTERNAL;
486 break;
490 /* Save for future use */
491 adapter->link_speed = ethtool_cmd_speed(ecmd);
492 adapter->port_type = ecmd->port;
493 adapter->transceiver = ecmd->transceiver;
494 adapter->autoneg = ecmd->autoneg;
495 } else {
496 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
497 ecmd->port = adapter->port_type;
498 ecmd->transceiver = adapter->transceiver;
499 ecmd->autoneg = adapter->autoneg;
502 ecmd->duplex = DUPLEX_FULL;
503 ecmd->phy_address = adapter->port_num;
504 switch (ecmd->port) {
505 case PORT_FIBRE:
506 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
507 break;
508 case PORT_TP:
509 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
510 break;
511 case PORT_AUI:
512 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
513 break;
516 if (ecmd->autoneg) {
517 ecmd->supported |= SUPPORTED_1000baseT_Full;
518 ecmd->supported |= SUPPORTED_Autoneg;
519 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
520 ADVERTISED_1000baseT_Full);
523 return 0;
526 static void be_get_ringparam(struct net_device *netdev,
527 struct ethtool_ringparam *ring)
529 struct be_adapter *adapter = netdev_priv(netdev);
531 ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len;
532 ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len;
535 static void
536 be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
538 struct be_adapter *adapter = netdev_priv(netdev);
540 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
541 ecmd->autoneg = 0;
544 static int
545 be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
547 struct be_adapter *adapter = netdev_priv(netdev);
548 int status;
550 if (ecmd->autoneg != 0)
551 return -EINVAL;
552 adapter->tx_fc = ecmd->tx_pause;
553 adapter->rx_fc = ecmd->rx_pause;
555 status = be_cmd_set_flow_control(adapter,
556 adapter->tx_fc, adapter->rx_fc);
557 if (status)
558 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
560 return status;
563 static int
564 be_set_phys_id(struct net_device *netdev,
565 enum ethtool_phys_id_state state)
567 struct be_adapter *adapter = netdev_priv(netdev);
569 switch (state) {
570 case ETHTOOL_ID_ACTIVE:
571 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
572 &adapter->beacon_state);
573 return 1; /* cycle on/off once per second */
575 case ETHTOOL_ID_ON:
576 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
577 BEACON_STATE_ENABLED);
578 break;
580 case ETHTOOL_ID_OFF:
581 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
582 BEACON_STATE_DISABLED);
583 break;
585 case ETHTOOL_ID_INACTIVE:
586 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
587 adapter->beacon_state);
590 return 0;
593 static bool
594 be_is_wol_supported(struct be_adapter *adapter)
596 if (!be_physfn(adapter))
597 return false;
598 else
599 return true;
602 static void
603 be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
605 struct be_adapter *adapter = netdev_priv(netdev);
607 if (be_is_wol_supported(adapter))
608 wol->supported = WAKE_MAGIC;
610 if (adapter->wol)
611 wol->wolopts = WAKE_MAGIC;
612 else
613 wol->wolopts = 0;
614 memset(&wol->sopass, 0, sizeof(wol->sopass));
617 static int
618 be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
620 struct be_adapter *adapter = netdev_priv(netdev);
622 if (wol->wolopts & ~WAKE_MAGIC)
623 return -EINVAL;
625 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
626 adapter->wol = true;
627 else
628 adapter->wol = false;
630 return 0;
633 static int
634 be_test_ddr_dma(struct be_adapter *adapter)
636 int ret, i;
637 struct be_dma_mem ddrdma_cmd;
638 static const u64 pattern[2] = {
639 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
642 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
643 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
644 &ddrdma_cmd.dma, GFP_KERNEL);
645 if (!ddrdma_cmd.va) {
646 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
647 return -ENOMEM;
650 for (i = 0; i < 2; i++) {
651 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
652 4096, &ddrdma_cmd);
653 if (ret != 0)
654 goto err;
657 err:
658 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
659 ddrdma_cmd.dma);
660 return ret;
663 static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
664 u64 *status)
666 be_cmd_set_loopback(adapter, adapter->hba_port_num,
667 loopback_type, 1);
668 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
669 loopback_type, 1500,
670 2, 0xabc);
671 be_cmd_set_loopback(adapter, adapter->hba_port_num,
672 BE_NO_LOOPBACK, 1);
673 return *status;
676 static void
677 be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
679 struct be_adapter *adapter = netdev_priv(netdev);
680 u8 mac_speed = 0;
681 u16 qos_link_speed = 0;
683 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
685 if (test->flags & ETH_TEST_FL_OFFLINE) {
686 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
687 &data[0]) != 0) {
688 test->flags |= ETH_TEST_FL_FAILED;
690 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
691 &data[1]) != 0) {
692 test->flags |= ETH_TEST_FL_FAILED;
694 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
695 &data[2]) != 0) {
696 test->flags |= ETH_TEST_FL_FAILED;
700 if (be_test_ddr_dma(adapter) != 0) {
701 data[3] = 1;
702 test->flags |= ETH_TEST_FL_FAILED;
705 if (be_cmd_link_status_query(adapter, &mac_speed,
706 &qos_link_speed, NULL, 0) != 0) {
707 test->flags |= ETH_TEST_FL_FAILED;
708 data[4] = -1;
709 } else if (!mac_speed) {
710 test->flags |= ETH_TEST_FL_FAILED;
711 data[4] = 1;
715 static int
716 be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
718 struct be_adapter *adapter = netdev_priv(netdev);
720 return be_load_fw(adapter, efl->data);
723 static int
724 be_get_eeprom_len(struct net_device *netdev)
726 struct be_adapter *adapter = netdev_priv(netdev);
727 if (lancer_chip(adapter)) {
728 if (be_physfn(adapter))
729 return lancer_cmd_get_file_len(adapter,
730 LANCER_VPD_PF_FILE);
731 else
732 return lancer_cmd_get_file_len(adapter,
733 LANCER_VPD_VF_FILE);
734 } else {
735 return BE_READ_SEEPROM_LEN;
739 static int
740 be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
741 uint8_t *data)
743 struct be_adapter *adapter = netdev_priv(netdev);
744 struct be_dma_mem eeprom_cmd;
745 struct be_cmd_resp_seeprom_read *resp;
746 int status;
748 if (!eeprom->len)
749 return -EINVAL;
751 if (lancer_chip(adapter)) {
752 if (be_physfn(adapter))
753 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
754 eeprom->len, data);
755 else
756 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
757 eeprom->len, data);
760 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
762 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
763 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
764 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
765 &eeprom_cmd.dma, GFP_KERNEL);
767 if (!eeprom_cmd.va) {
768 dev_err(&adapter->pdev->dev,
769 "Memory allocation failure. Could not read eeprom\n");
770 return -ENOMEM;
773 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
775 if (!status) {
776 resp = eeprom_cmd.va;
777 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
779 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
780 eeprom_cmd.dma);
782 return status;
785 const struct ethtool_ops be_ethtool_ops = {
786 .get_settings = be_get_settings,
787 .get_drvinfo = be_get_drvinfo,
788 .get_wol = be_get_wol,
789 .set_wol = be_set_wol,
790 .get_link = ethtool_op_get_link,
791 .get_eeprom_len = be_get_eeprom_len,
792 .get_eeprom = be_read_eeprom,
793 .get_coalesce = be_get_coalesce,
794 .set_coalesce = be_set_coalesce,
795 .get_ringparam = be_get_ringparam,
796 .get_pauseparam = be_get_pauseparam,
797 .set_pauseparam = be_set_pauseparam,
798 .get_strings = be_get_stat_strings,
799 .set_phys_id = be_set_phys_id,
800 .get_sset_count = be_get_sset_count,
801 .get_ethtool_stats = be_get_ethtool_stats,
802 .get_regs_len = be_get_reg_len,
803 .get_regs = be_get_regs,
804 .flash_device = be_do_flash,
805 .self_test = be_self_test,