drivers/net: Remove boolean comparisons to true/false
[deliverable/linux.git] / drivers / net / ethernet / emulex / benet / be_ethtool.c
CommitLineData
6b7c5b94 1/*
d2145cde 2 * Copyright (C) 2005 - 2011 Emulex
6b7c5b94
SP
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:
d2145cde 11 * linux-drivers@emulex.com
6b7c5b94 12 *
d2145cde
AK
13 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
6b7c5b94
SP
16 */
17
18#include "be.h"
8788fdc2 19#include "be_cmds.h"
6b7c5b94
SP
20#include <linux/ethtool.h>
21
22struct be_ethtool_stat {
23 char desc[ETH_GSTRING_LEN];
24 int type;
25 int size;
26 int offset;
27};
28
ac124ff9 29enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
6b7c5b94
SP
30#define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
31 offsetof(_struct, field)
3abcdeda
SP
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)
609ff3bb 36#define DRVSTAT_INFO(field) #field, DRVSTAT,\
ac124ff9 37 FIELDINFO(struct be_drv_stats, field)
6b7c5b94
SP
38
39static const struct be_ethtool_stat et_stats[] = {
ac124ff9 40 {DRVSTAT_INFO(tx_events)},
89a88ab8
AK
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)},
d45b9d39
SP
45 /* Received packets dropped when the Ethernet length field
46 * is not equal to the actual Ethernet data length.
47 */
89a88ab8 48 {DRVSTAT_INFO(rx_in_range_errors)},
d45b9d39
SP
49 /* Received packets dropped when their length field is >= 1501 bytes
50 * and <= 1535 bytes.
51 */
89a88ab8 52 {DRVSTAT_INFO(rx_out_range_errors)},
d45b9d39 53 /* Received packets dropped when they are longer than 9216 bytes */
89a88ab8 54 {DRVSTAT_INFO(rx_frame_too_long)},
d45b9d39
SP
55 /* Received packets dropped when they don't pass the unicast or
56 * multicast address filtering.
57 */
58 {DRVSTAT_INFO(rx_address_mismatch_drops)},
59 /* Received packets dropped when IP packet length field is less than
60 * the IP header length field.
61 */
89a88ab8 62 {DRVSTAT_INFO(rx_dropped_too_small)},
d45b9d39
SP
63 /* Received packets dropped when IP length field is greater than
64 * the actual packet length.
65 */
89a88ab8 66 {DRVSTAT_INFO(rx_dropped_too_short)},
d45b9d39
SP
67 /* Received packets dropped when the IP header length field is less
68 * than 5.
69 */
89a88ab8 70 {DRVSTAT_INFO(rx_dropped_header_too_small)},
d45b9d39
SP
71 /* Received packets dropped when the TCP header length field is less
72 * than 5 or the TCP header length + IP header length is more
73 * than IP packet length.
74 */
89a88ab8
AK
75 {DRVSTAT_INFO(rx_dropped_tcp_length)},
76 {DRVSTAT_INFO(rx_dropped_runt)},
d45b9d39
SP
77 /* Number of received packets dropped when a fifo for descriptors going
78 * into the packet demux block overflows. In normal operation, this
79 * fifo must never overflow.
80 */
89a88ab8
AK
81 {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
82 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
83 {DRVSTAT_INFO(rx_ip_checksum_errs)},
84 {DRVSTAT_INFO(rx_tcp_checksum_errs)},
85 {DRVSTAT_INFO(rx_udp_checksum_errs)},
89a88ab8
AK
86 {DRVSTAT_INFO(tx_pauseframes)},
87 {DRVSTAT_INFO(tx_controlframes)},
88 {DRVSTAT_INFO(rx_priority_pause_frames)},
d45b9d39
SP
89 /* Received packets dropped when an internal fifo going into
90 * main packet buffer tank (PMEM) overflows.
91 */
89a88ab8
AK
92 {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
93 {DRVSTAT_INFO(jabber_events)},
d45b9d39
SP
94 /* Received packets dropped due to lack of available HW packet buffers
95 * used to temporarily hold the received packets.
96 */
89a88ab8 97 {DRVSTAT_INFO(rx_drops_no_pbuf)},
d45b9d39
SP
98 /* Received packets dropped due to input receive buffer
99 * descriptor fifo overflowing.
100 */
89a88ab8 101 {DRVSTAT_INFO(rx_drops_no_erx_descr)},
d45b9d39
SP
102 /* Packets dropped because the internal FIFO to the offloaded TCP
103 * receive processing block is full. This could happen only for
104 * offloaded iSCSI or FCoE trarffic.
105 */
89a88ab8 106 {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
d45b9d39
SP
107 /* Received packets dropped when they need more than 8
108 * receive buffers. This cannot happen as the driver configures
109 * 2048 byte receive buffers.
110 */
89a88ab8 111 {DRVSTAT_INFO(rx_drops_too_many_frags)},
89a88ab8 112 {DRVSTAT_INFO(forwarded_packets)},
d45b9d39
SP
113 /* Received packets dropped when the frame length
114 * is more than 9018 bytes
115 */
89a88ab8 116 {DRVSTAT_INFO(rx_drops_mtu)},
d45b9d39 117 /* Number of packets dropped due to random early drop function */
89a88ab8 118 {DRVSTAT_INFO(eth_red_drops)},
609ff3bb 119 {DRVSTAT_INFO(be_on_die_temperature)}
6b7c5b94
SP
120};
121#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
122
ab1594e9
SP
123/* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
124 * are first and second members respectively.
125 */
3abcdeda 126static const struct be_ethtool_stat et_rx_stats[] = {
ab1594e9
SP
127 {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
128 {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
3abcdeda
SP
129 {DRVSTAT_RX_INFO(rx_polls)},
130 {DRVSTAT_RX_INFO(rx_events)},
131 {DRVSTAT_RX_INFO(rx_compl)},
132 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
d45b9d39
SP
133 /* Number of page allocation failures while posting receive buffers
134 * to HW.
135 */
3abcdeda 136 {DRVSTAT_RX_INFO(rx_post_fail)},
d45b9d39 137 /* Recevied packets dropped due to skb allocation failure */
ac124ff9 138 {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
d45b9d39
SP
139 /* Received packets dropped due to lack of available fetched buffers
140 * posted by the driver.
141 */
ac124ff9 142 {DRVSTAT_RX_INFO(rx_drops_no_frags)}
3abcdeda
SP
143};
144#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
145
ab1594e9
SP
146/* Stats related to multi TX queues: get_stats routine assumes compl is the
147 * first member
148 */
3c8def97 149static const struct be_ethtool_stat et_tx_stats[] = {
ab1594e9 150 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
ac124ff9
SP
151 {DRVSTAT_TX_INFO(tx_bytes)},
152 {DRVSTAT_TX_INFO(tx_pkts)},
d45b9d39 153 /* Number of skbs queued for trasmission by the driver */
ac124ff9 154 {DRVSTAT_TX_INFO(tx_reqs)},
d45b9d39 155 /* Number of TX work request blocks DMAed to HW */
ac124ff9
SP
156 {DRVSTAT_TX_INFO(tx_wrbs)},
157 {DRVSTAT_TX_INFO(tx_compl)},
d45b9d39
SP
158 /* Number of times the TX queue was stopped due to lack
159 * of spaces in the TXQ.
160 */
ac124ff9 161 {DRVSTAT_TX_INFO(tx_stops)}
3c8def97
SP
162};
163#define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
164
ff33a6e2
S
165static const char et_self_tests[][ETH_GSTRING_LEN] = {
166 "MAC Loopback test",
167 "PHY Loopback test",
168 "External Loopback test",
4ee77214 169 "DDR DMA test",
4276e47e 170 "Link test"
ff33a6e2
S
171};
172
173#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
174#define BE_MAC_LOOPBACK 0x0
175#define BE_PHY_LOOPBACK 0x1
176#define BE_ONE_PORT_EXT_LOOPBACK 0x2
fced9999 177#define BE_NO_LOOPBACK 0xff
ff33a6e2 178
04b71175
SP
179static void be_get_drvinfo(struct net_device *netdev,
180 struct ethtool_drvinfo *drvinfo)
6b7c5b94
SP
181{
182 struct be_adapter *adapter = netdev_priv(netdev);
04b71175
SP
183 char fw_on_flash[FW_VER_LEN];
184
185 memset(fw_on_flash, 0 , sizeof(fw_on_flash));
186 be_cmd_get_fw_ver(adapter, adapter->fw_ver, fw_on_flash);
6b7c5b94 187
68aad78c
RJ
188 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
189 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
6b7c5b94 190 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
04b71175
SP
191 if (memcmp(adapter->fw_ver, fw_on_flash, FW_VER_LEN) != 0) {
192 strcat(drvinfo->fw_version, " [");
193 strcat(drvinfo->fw_version, fw_on_flash);
194 strcat(drvinfo->fw_version, "]");
195 }
196
68aad78c
RJ
197 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
198 sizeof(drvinfo->bus_info));
6b7c5b94
SP
199 drvinfo->testinfo_len = 0;
200 drvinfo->regdump_len = 0;
201 drvinfo->eedump_len = 0;
202}
203
de49bd5a
PR
204static u32
205lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
206{
207 u32 data_read = 0, eof;
208 u8 addn_status;
209 struct be_dma_mem data_len_cmd;
210 int status;
211
212 memset(&data_len_cmd, 0, sizeof(data_len_cmd));
213 /* data_offset and data_size should be 0 to get reg len */
214 status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
215 file_name, &data_read, &eof, &addn_status);
216
217 return data_read;
218}
219
220static int
221lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
222 u32 buf_len, void *buf)
223{
224 struct be_dma_mem read_cmd;
225 u32 read_len = 0, total_read_len = 0, chunk_size;
226 u32 eof = 0;
227 u8 addn_status;
228 int status = 0;
229
230 read_cmd.size = LANCER_READ_FILE_CHUNK;
231 read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
232 &read_cmd.dma);
233
234 if (!read_cmd.va) {
235 dev_err(&adapter->pdev->dev,
236 "Memory allocation failure while reading dump\n");
237 return -ENOMEM;
238 }
239
240 while ((total_read_len < buf_len) && !eof) {
241 chunk_size = min_t(u32, (buf_len - total_read_len),
242 LANCER_READ_FILE_CHUNK);
243 chunk_size = ALIGN(chunk_size, 4);
244 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
245 total_read_len, file_name, &read_len,
246 &eof, &addn_status);
247 if (!status) {
248 memcpy(buf + total_read_len, read_cmd.va, read_len);
249 total_read_len += read_len;
250 eof &= LANCER_READ_FILE_EOF_MASK;
251 } else {
252 status = -EIO;
253 break;
254 }
255 }
256 pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
257 read_cmd.dma);
258
259 return status;
260}
261
311fddc7
SK
262static int
263be_get_reg_len(struct net_device *netdev)
264{
265 struct be_adapter *adapter = netdev_priv(netdev);
266 u32 log_size = 0;
267
de49bd5a
PR
268 if (be_physfn(adapter)) {
269 if (lancer_chip(adapter))
270 log_size = lancer_cmd_get_file_len(adapter,
271 LANCER_FW_DUMP_FILE);
272 else
273 be_cmd_get_reg_len(adapter, &log_size);
274 }
311fddc7
SK
275 return log_size;
276}
277
278static void
279be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
280{
281 struct be_adapter *adapter = netdev_priv(netdev);
282
16a871ef
AK
283 if (be_physfn(adapter)) {
284 memset(buf, 0, regs->len);
de49bd5a
PR
285 if (lancer_chip(adapter))
286 lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
287 regs->len, buf);
288 else
289 be_cmd_get_regs(adapter, regs->len, buf);
16a871ef 290 }
311fddc7
SK
291}
292
6b7c5b94
SP
293static int
294be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
295{
296 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda 297 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
6b7c5b94
SP
298 struct be_eq_obj *tx_eq = &adapter->tx_eq;
299
6b7c5b94
SP
300 coalesce->rx_coalesce_usecs = rx_eq->cur_eqd;
301 coalesce->rx_coalesce_usecs_high = rx_eq->max_eqd;
302 coalesce->rx_coalesce_usecs_low = rx_eq->min_eqd;
303
304 coalesce->tx_coalesce_usecs = tx_eq->cur_eqd;
305 coalesce->tx_coalesce_usecs_high = tx_eq->max_eqd;
306 coalesce->tx_coalesce_usecs_low = tx_eq->min_eqd;
307
308 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
309 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
310
311 return 0;
312}
313
314/*
5be93b9a 315 * This routine is used to set interrup coalescing delay
6b7c5b94
SP
316 */
317static int
318be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
319{
320 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda
SP
321 struct be_rx_obj *rxo;
322 struct be_eq_obj *rx_eq;
6b7c5b94 323 struct be_eq_obj *tx_eq = &adapter->tx_eq;
6b7c5b94 324 u32 rx_max, rx_min, rx_cur;
3abcdeda 325 int status = 0, i;
03746b0a 326 u32 tx_cur;
6b7c5b94
SP
327
328 if (coalesce->use_adaptive_tx_coalesce == 1)
329 return -EINVAL;
330
3abcdeda
SP
331 for_all_rx_queues(adapter, rxo, i) {
332 rx_eq = &rxo->rx_eq;
333
334 if (!rx_eq->enable_aic && coalesce->use_adaptive_rx_coalesce)
335 rx_eq->cur_eqd = 0;
336 rx_eq->enable_aic = coalesce->use_adaptive_rx_coalesce;
337
338 rx_max = coalesce->rx_coalesce_usecs_high;
339 rx_min = coalesce->rx_coalesce_usecs_low;
340 rx_cur = coalesce->rx_coalesce_usecs;
341
342 if (rx_eq->enable_aic) {
343 if (rx_max > BE_MAX_EQD)
344 rx_max = BE_MAX_EQD;
345 if (rx_min > rx_max)
346 rx_min = rx_max;
347 rx_eq->max_eqd = rx_max;
348 rx_eq->min_eqd = rx_min;
349 if (rx_eq->cur_eqd > rx_max)
350 rx_eq->cur_eqd = rx_max;
351 if (rx_eq->cur_eqd < rx_min)
352 rx_eq->cur_eqd = rx_min;
353 } else {
354 if (rx_cur > BE_MAX_EQD)
355 rx_cur = BE_MAX_EQD;
356 if (rx_eq->cur_eqd != rx_cur) {
357 status = be_cmd_modify_eqd(adapter, rx_eq->q.id,
358 rx_cur);
359 if (!status)
360 rx_eq->cur_eqd = rx_cur;
361 }
362 }
6b7c5b94 363 }
6b7c5b94 364
6b7c5b94
SP
365 tx_cur = coalesce->tx_coalesce_usecs;
366
367 if (tx_cur > BE_MAX_EQD)
368 tx_cur = BE_MAX_EQD;
369 if (tx_eq->cur_eqd != tx_cur) {
8788fdc2 370 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
6b7c5b94
SP
371 if (!status)
372 tx_eq->cur_eqd = tx_cur;
373 }
374
6b7c5b94
SP
375 return 0;
376}
377
6b7c5b94
SP
378static void
379be_get_ethtool_stats(struct net_device *netdev,
380 struct ethtool_stats *stats, uint64_t *data)
381{
382 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda 383 struct be_rx_obj *rxo;
3c8def97 384 struct be_tx_obj *txo;
ac124ff9 385 void *p;
ab1594e9 386 unsigned int i, j, base = 0, start;
6b7c5b94
SP
387
388 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
ac124ff9 389 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
ab1594e9 390 data[i] = *(u32 *)p;
6b7c5b94 391 }
ab1594e9 392 base += ETHTOOL_STATS_NUM;
3abcdeda
SP
393
394 for_all_rx_queues(adapter, rxo, j) {
ab1594e9
SP
395 struct be_rx_stats *stats = rx_stats(rxo);
396
397 do {
398 start = u64_stats_fetch_begin_bh(&stats->sync);
399 data[base] = stats->rx_bytes;
400 data[base + 1] = stats->rx_pkts;
401 } while (u64_stats_fetch_retry_bh(&stats->sync, start));
402
403 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
404 p = (u8 *)stats + et_rx_stats[i].offset;
405 data[base + i] = *(u32 *)p;
3abcdeda 406 }
ab1594e9 407 base += ETHTOOL_RXSTATS_NUM;
3abcdeda 408 }
3c8def97 409
3c8def97 410 for_all_tx_queues(adapter, txo, j) {
ab1594e9
SP
411 struct be_tx_stats *stats = tx_stats(txo);
412
413 do {
414 start = u64_stats_fetch_begin_bh(&stats->sync_compl);
415 data[base] = stats->tx_compl;
416 } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start));
417
418 do {
419 start = u64_stats_fetch_begin_bh(&stats->sync);
420 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
421 p = (u8 *)stats + et_tx_stats[i].offset;
422 data[base + i] =
423 (et_tx_stats[i].size == sizeof(u64)) ?
424 *(u64 *)p : *(u32 *)p;
425 }
426 } while (u64_stats_fetch_retry_bh(&stats->sync, start));
427 base += ETHTOOL_TXSTATS_NUM;
3c8def97 428 }
6b7c5b94
SP
429}
430
431static void
432be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
433 uint8_t *data)
434{
3abcdeda
SP
435 struct be_adapter *adapter = netdev_priv(netdev);
436 int i, j;
437
6b7c5b94
SP
438 switch (stringset) {
439 case ETH_SS_STATS:
440 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
441 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
442 data += ETH_GSTRING_LEN;
443 }
3abcdeda
SP
444 for (i = 0; i < adapter->num_rx_qs; i++) {
445 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
446 sprintf(data, "rxq%d: %s", i,
447 et_rx_stats[j].desc);
448 data += ETH_GSTRING_LEN;
449 }
450 }
3c8def97
SP
451 for (i = 0; i < adapter->num_tx_qs; i++) {
452 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
453 sprintf(data, "txq%d: %s", i,
454 et_tx_stats[j].desc);
455 data += ETH_GSTRING_LEN;
456 }
457 }
6b7c5b94 458 break;
ff33a6e2
S
459 case ETH_SS_TEST:
460 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
461 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
462 data += ETH_GSTRING_LEN;
463 }
464 break;
6b7c5b94
SP
465 }
466}
467
15f0a394 468static int be_get_sset_count(struct net_device *netdev, int stringset)
6b7c5b94 469{
3abcdeda
SP
470 struct be_adapter *adapter = netdev_priv(netdev);
471
15f0a394 472 switch (stringset) {
ff33a6e2
S
473 case ETH_SS_TEST:
474 return ETHTOOL_TESTS_NUM;
15f0a394 475 case ETH_SS_STATS:
3abcdeda 476 return ETHTOOL_STATS_NUM +
3c8def97
SP
477 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
478 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
15f0a394
BH
479 default:
480 return -EINVAL;
481 }
6b7c5b94
SP
482}
483
484static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
485{
0388f251 486 struct be_adapter *adapter = netdev_priv(netdev);
306f1348 487 struct be_phy_info phy_info;
ee3cb629 488 u8 mac_speed = 0;
0388f251 489 u16 link_speed = 0;
b236916a 490 u8 link_status;
0dffc83e
AK
491 int status;
492
48e9989e 493 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
ea172a01 494 status = be_cmd_link_status_query(adapter, &mac_speed,
b236916a
AK
495 &link_speed, &link_status, 0);
496 if (!status)
497 be_link_status_update(adapter, link_status);
0dffc83e
AK
498
499 /* link_speed is in units of 10 Mbps */
500 if (link_speed) {
70739497 501 ethtool_cmd_speed_set(ecmd, link_speed*10);
0dffc83e
AK
502 } else {
503 switch (mac_speed) {
4fa9ed07 504 case PHY_LINK_SPEED_10MBPS:
70739497 505 ethtool_cmd_speed_set(ecmd, SPEED_10);
4fa9ed07
AK
506 break;
507 case PHY_LINK_SPEED_100MBPS:
70739497 508 ethtool_cmd_speed_set(ecmd, SPEED_100);
4fa9ed07 509 break;
0dffc83e 510 case PHY_LINK_SPEED_1GBPS:
70739497 511 ethtool_cmd_speed_set(ecmd, SPEED_1000);
0dffc83e
AK
512 break;
513 case PHY_LINK_SPEED_10GBPS:
70739497 514 ethtool_cmd_speed_set(ecmd, SPEED_10000);
0dffc83e 515 break;
4fa9ed07 516 case PHY_LINK_SPEED_ZERO:
70739497 517 ethtool_cmd_speed_set(ecmd, 0);
4fa9ed07 518 break;
0dffc83e
AK
519 }
520 }
0388f251 521
306f1348 522 status = be_cmd_get_phy_info(adapter, &phy_info);
16c02145 523 if (!status) {
306f1348 524 switch (phy_info.interface_type) {
ee3cb629
AK
525 case PHY_TYPE_XFP_10GB:
526 case PHY_TYPE_SFP_1GB:
527 case PHY_TYPE_SFP_PLUS_10GB:
16c02145 528 ecmd->port = PORT_FIBRE;
16c02145
SB
529 break;
530 default:
531 ecmd->port = PORT_TP;
16c02145
SB
532 break;
533 }
ee3cb629 534
306f1348 535 switch (phy_info.interface_type) {
ee3cb629
AK
536 case PHY_TYPE_KR_10GB:
537 case PHY_TYPE_KX4_10GB:
538 ecmd->autoneg = AUTONEG_ENABLE;
16c02145 539 ecmd->transceiver = XCVR_INTERNAL;
ee3cb629
AK
540 break;
541 default:
542 ecmd->autoneg = AUTONEG_DISABLE;
543 ecmd->transceiver = XCVR_EXTERNAL;
544 break;
545 }
0388f251 546 }
0dffc83e
AK
547
548 /* Save for future use */
70739497 549 adapter->link_speed = ethtool_cmd_speed(ecmd);
0dffc83e 550 adapter->port_type = ecmd->port;
16c02145 551 adapter->transceiver = ecmd->transceiver;
ee3cb629 552 adapter->autoneg = ecmd->autoneg;
0dffc83e 553 } else {
70739497 554 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
0dffc83e 555 ecmd->port = adapter->port_type;
16c02145 556 ecmd->transceiver = adapter->transceiver;
ee3cb629 557 ecmd->autoneg = adapter->autoneg;
0388f251 558 }
0dffc83e 559
6b7c5b94 560 ecmd->duplex = DUPLEX_FULL;
0388f251 561 ecmd->phy_address = adapter->port_num;
16c02145
SB
562 switch (ecmd->port) {
563 case PORT_FIBRE:
564 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
565 break;
566 case PORT_TP:
567 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
568 break;
569 case PORT_AUI:
570 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
571 break;
572 }
0388f251 573
ee3cb629
AK
574 if (ecmd->autoneg) {
575 ecmd->supported |= SUPPORTED_1000baseT_Full;
576 ecmd->supported |= SUPPORTED_Autoneg;
577 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
578 ADVERTISED_1000baseT_Full);
579 }
580
6b7c5b94
SP
581 return 0;
582}
583
110b82bc
SP
584static void be_get_ringparam(struct net_device *netdev,
585 struct ethtool_ringparam *ring)
6b7c5b94
SP
586{
587 struct be_adapter *adapter = netdev_priv(netdev);
588
110b82bc
SP
589 ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len;
590 ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len;
6b7c5b94
SP
591}
592
593static void
594be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
595{
596 struct be_adapter *adapter = netdev_priv(netdev);
597
8788fdc2 598 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
03a980d1 599 ecmd->autoneg = 0;
6b7c5b94
SP
600}
601
602static int
603be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
604{
605 struct be_adapter *adapter = netdev_priv(netdev);
606 int status;
607
03a980d1 608 if (ecmd->autoneg != 0)
6b7c5b94 609 return -EINVAL;
9e90c961
AK
610 adapter->tx_fc = ecmd->tx_pause;
611 adapter->rx_fc = ecmd->rx_pause;
6b7c5b94 612
9e90c961
AK
613 status = be_cmd_set_flow_control(adapter,
614 adapter->tx_fc, adapter->rx_fc);
615 if (status)
6b7c5b94
SP
616 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
617
618 return status;
619}
620
fad9ab2c 621static int
1a642469 622be_set_phys_id(struct net_device *netdev,
623 enum ethtool_phys_id_state state)
fad9ab2c
SB
624{
625 struct be_adapter *adapter = netdev_priv(netdev);
fad9ab2c 626
1a642469 627 switch (state) {
628 case ETHTOOL_ID_ACTIVE:
629 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
630 &adapter->beacon_state);
fce55922 631 return 1; /* cycle on/off once per second */
fad9ab2c 632
1a642469 633 case ETHTOOL_ID_ON:
634 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
635 BEACON_STATE_ENABLED);
636 break;
fad9ab2c 637
1a642469 638 case ETHTOOL_ID_OFF:
639 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
640 BEACON_STATE_DISABLED);
641 break;
fad9ab2c 642
1a642469 643 case ETHTOOL_ID_INACTIVE:
644 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
645 adapter->beacon_state);
646 }
fad9ab2c 647
1a642469 648 return 0;
fad9ab2c
SB
649}
650
dcf96f1f
AK
651static bool
652be_is_wol_supported(struct be_adapter *adapter)
653{
654 if (!be_physfn(adapter))
655 return false;
656 else
657 return true;
658}
659
71d8d1b5
AK
660static void
661be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
662{
663 struct be_adapter *adapter = netdev_priv(netdev);
664
dcf96f1f
AK
665 if (be_is_wol_supported(adapter))
666 wol->supported = WAKE_MAGIC;
667
71d8d1b5
AK
668 if (adapter->wol)
669 wol->wolopts = WAKE_MAGIC;
670 else
671 wol->wolopts = 0;
672 memset(&wol->sopass, 0, sizeof(wol->sopass));
71d8d1b5
AK
673}
674
675static int
676be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
677{
678 struct be_adapter *adapter = netdev_priv(netdev);
679
680 if (wol->wolopts & ~WAKE_MAGIC)
681 return -EINVAL;
682
dcf96f1f 683 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
71d8d1b5
AK
684 adapter->wol = true;
685 else
686 adapter->wol = false;
687
688 return 0;
689}
690
ff33a6e2
S
691static int
692be_test_ddr_dma(struct be_adapter *adapter)
693{
694 int ret, i;
695 struct be_dma_mem ddrdma_cmd;
215faf9c
JP
696 static const u64 pattern[2] = {
697 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
698 };
ff33a6e2
S
699
700 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
2b7bcebf
IV
701 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
702 &ddrdma_cmd.dma, GFP_KERNEL);
ff33a6e2 703 if (!ddrdma_cmd.va) {
2381a55c 704 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
ff33a6e2
S
705 return -ENOMEM;
706 }
707
708 for (i = 0; i < 2; i++) {
709 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
710 4096, &ddrdma_cmd);
711 if (ret != 0)
712 goto err;
713 }
714
715err:
2b7bcebf
IV
716 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
717 ddrdma_cmd.dma);
ff33a6e2
S
718 return ret;
719}
720
fced9999
SB
721static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
722 u64 *status)
723{
9e1453c5 724 be_cmd_set_loopback(adapter, adapter->hba_port_num,
fced9999 725 loopback_type, 1);
9e1453c5 726 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
fced9999
SB
727 loopback_type, 1500,
728 2, 0xabc);
9e1453c5 729 be_cmd_set_loopback(adapter, adapter->hba_port_num,
fced9999
SB
730 BE_NO_LOOPBACK, 1);
731 return *status;
732}
733
ff33a6e2
S
734static void
735be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
736{
737 struct be_adapter *adapter = netdev_priv(netdev);
4276e47e
SB
738 u8 mac_speed = 0;
739 u16 qos_link_speed = 0;
ff33a6e2
S
740
741 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
742
743 if (test->flags & ETH_TEST_FL_OFFLINE) {
fced9999
SB
744 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
745 &data[0]) != 0) {
ff33a6e2 746 test->flags |= ETH_TEST_FL_FAILED;
fced9999
SB
747 }
748 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
749 &data[1]) != 0) {
ff33a6e2 750 test->flags |= ETH_TEST_FL_FAILED;
fced9999
SB
751 }
752 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
753 &data[2]) != 0) {
ff33a6e2 754 test->flags |= ETH_TEST_FL_FAILED;
fced9999 755 }
8f47afe0 756 }
ff33a6e2 757
8f47afe0
SB
758 if (be_test_ddr_dma(adapter) != 0) {
759 data[3] = 1;
760 test->flags |= ETH_TEST_FL_FAILED;
ff33a6e2
S
761 }
762
ea172a01 763 if (be_cmd_link_status_query(adapter, &mac_speed,
b236916a 764 &qos_link_speed, NULL, 0) != 0) {
4276e47e
SB
765 test->flags |= ETH_TEST_FL_FAILED;
766 data[4] = -1;
4ee77214
AK
767 } else if (!mac_speed) {
768 test->flags |= ETH_TEST_FL_FAILED;
4276e47e
SB
769 data[4] = 1;
770 }
ff33a6e2
S
771}
772
84517482
AK
773static int
774be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
775{
776 struct be_adapter *adapter = netdev_priv(netdev);
84517482 777
786f5281 778 return be_load_fw(adapter, efl->data);
84517482
AK
779}
780
368c0ca2
SB
781static int
782be_get_eeprom_len(struct net_device *netdev)
783{
af5875bd
PR
784 struct be_adapter *adapter = netdev_priv(netdev);
785 if (lancer_chip(adapter)) {
786 if (be_physfn(adapter))
787 return lancer_cmd_get_file_len(adapter,
788 LANCER_VPD_PF_FILE);
789 else
790 return lancer_cmd_get_file_len(adapter,
791 LANCER_VPD_VF_FILE);
792 } else {
793 return BE_READ_SEEPROM_LEN;
794 }
368c0ca2
SB
795}
796
797static int
798be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
799 uint8_t *data)
800{
801 struct be_adapter *adapter = netdev_priv(netdev);
802 struct be_dma_mem eeprom_cmd;
803 struct be_cmd_resp_seeprom_read *resp;
804 int status;
805
806 if (!eeprom->len)
807 return -EINVAL;
808
af5875bd
PR
809 if (lancer_chip(adapter)) {
810 if (be_physfn(adapter))
811 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
812 eeprom->len, data);
813 else
814 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
815 eeprom->len, data);
816 }
817
368c0ca2
SB
818 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
819
820 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
821 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
2b7bcebf
IV
822 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
823 &eeprom_cmd.dma, GFP_KERNEL);
368c0ca2
SB
824
825 if (!eeprom_cmd.va) {
826 dev_err(&adapter->pdev->dev,
827 "Memory allocation failure. Could not read eeprom\n");
828 return -ENOMEM;
829 }
830
831 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
832
833 if (!status) {
43d620c8 834 resp = eeprom_cmd.va;
c0ad9845 835 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
368c0ca2 836 }
2b7bcebf
IV
837 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
838 eeprom_cmd.dma);
368c0ca2
SB
839
840 return status;
841}
842
0fc0b732 843const struct ethtool_ops be_ethtool_ops = {
6b7c5b94
SP
844 .get_settings = be_get_settings,
845 .get_drvinfo = be_get_drvinfo,
71d8d1b5
AK
846 .get_wol = be_get_wol,
847 .set_wol = be_set_wol,
6b7c5b94 848 .get_link = ethtool_op_get_link,
368c0ca2
SB
849 .get_eeprom_len = be_get_eeprom_len,
850 .get_eeprom = be_read_eeprom,
6b7c5b94
SP
851 .get_coalesce = be_get_coalesce,
852 .set_coalesce = be_set_coalesce,
853 .get_ringparam = be_get_ringparam,
854 .get_pauseparam = be_get_pauseparam,
855 .set_pauseparam = be_set_pauseparam,
6b7c5b94 856 .get_strings = be_get_stat_strings,
1a642469 857 .set_phys_id = be_set_phys_id,
15f0a394 858 .get_sset_count = be_get_sset_count,
6b7c5b94 859 .get_ethtool_stats = be_get_ethtool_stats,
311fddc7
SK
860 .get_regs_len = be_get_reg_len,
861 .get_regs = be_get_regs,
84517482 862 .flash_device = be_do_flash,
ff33a6e2 863 .self_test = be_self_test,
6b7c5b94 864};
This page took 0.360042 seconds and 5 git commands to generate.