be2net: fix range check for set_qos for a VF
[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)},
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)},
89a88ab8
AK
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)},
609ff3bb 73 {DRVSTAT_INFO(be_on_die_temperature)}
6b7c5b94
SP
74};
75#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
76
ab1594e9
SP
77/* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
78 * are first and second members respectively.
79 */
3abcdeda 80static const struct be_ethtool_stat et_rx_stats[] = {
ab1594e9
SP
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 */
3abcdeda
SP
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)},
ac124ff9
SP
88 {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
89 {DRVSTAT_RX_INFO(rx_drops_no_frags)}
3abcdeda
SP
90};
91#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
92
ab1594e9
SP
93/* Stats related to multi TX queues: get_stats routine assumes compl is the
94 * first member
95 */
3c8def97 96static const struct be_ethtool_stat et_tx_stats[] = {
ab1594e9 97 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
ac124ff9
SP
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)}
3c8def97
SP
104};
105#define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
106
ff33a6e2
S
107static const char et_self_tests[][ETH_GSTRING_LEN] = {
108 "MAC Loopback test",
109 "PHY Loopback test",
110 "External Loopback test",
4ee77214 111 "DDR DMA test",
4276e47e 112 "Link test"
ff33a6e2
S
113};
114
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
fced9999 119#define BE_NO_LOOPBACK 0xff
ff33a6e2 120
04b71175
SP
121static void be_get_drvinfo(struct net_device *netdev,
122 struct ethtool_drvinfo *drvinfo)
6b7c5b94
SP
123{
124 struct be_adapter *adapter = netdev_priv(netdev);
04b71175
SP
125 char fw_on_flash[FW_VER_LEN];
126
127 memset(fw_on_flash, 0 , sizeof(fw_on_flash));
128 be_cmd_get_fw_ver(adapter, adapter->fw_ver, fw_on_flash);
6b7c5b94 129
68aad78c
RJ
130 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
131 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
6b7c5b94 132 strncpy(drvinfo->fw_version, adapter->fw_ver, FW_VER_LEN);
04b71175
SP
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, "]");
137 }
138
68aad78c
RJ
139 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
140 sizeof(drvinfo->bus_info));
6b7c5b94
SP
141 drvinfo->testinfo_len = 0;
142 drvinfo->regdump_len = 0;
143 drvinfo->eedump_len = 0;
144}
145
de49bd5a
PR
146static u32
147lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
148{
149 u32 data_read = 0, eof;
150 u8 addn_status;
151 struct be_dma_mem data_len_cmd;
152 int status;
153
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);
158
159 return data_read;
160}
161
162static int
163lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
164 u32 buf_len, void *buf)
165{
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;
171
172 read_cmd.size = LANCER_READ_FILE_CHUNK;
173 read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
174 &read_cmd.dma);
175
176 if (!read_cmd.va) {
177 dev_err(&adapter->pdev->dev,
178 "Memory allocation failure while reading dump\n");
179 return -ENOMEM;
180 }
181
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;
196 }
197 }
198 pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
199 read_cmd.dma);
200
201 return status;
202}
203
311fddc7
SK
204static int
205be_get_reg_len(struct net_device *netdev)
206{
207 struct be_adapter *adapter = netdev_priv(netdev);
208 u32 log_size = 0;
209
de49bd5a
PR
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);
216 }
311fddc7
SK
217 return log_size;
218}
219
220static void
221be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
222{
223 struct be_adapter *adapter = netdev_priv(netdev);
224
16a871ef
AK
225 if (be_physfn(adapter)) {
226 memset(buf, 0, regs->len);
de49bd5a
PR
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);
16a871ef 232 }
311fddc7
SK
233}
234
6b7c5b94
SP
235static int
236be_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
237{
238 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda 239 struct be_eq_obj *rx_eq = &adapter->rx_obj[0].rx_eq;
6b7c5b94
SP
240 struct be_eq_obj *tx_eq = &adapter->tx_eq;
241
6b7c5b94
SP
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;
245
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;
249
250 coalesce->use_adaptive_rx_coalesce = rx_eq->enable_aic;
251 coalesce->use_adaptive_tx_coalesce = tx_eq->enable_aic;
252
253 return 0;
254}
255
256/*
5be93b9a 257 * This routine is used to set interrup coalescing delay
6b7c5b94
SP
258 */
259static int
260be_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *coalesce)
261{
262 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda
SP
263 struct be_rx_obj *rxo;
264 struct be_eq_obj *rx_eq;
6b7c5b94 265 struct be_eq_obj *tx_eq = &adapter->tx_eq;
6b7c5b94 266 u32 rx_max, rx_min, rx_cur;
3abcdeda 267 int status = 0, i;
03746b0a 268 u32 tx_cur;
6b7c5b94
SP
269
270 if (coalesce->use_adaptive_tx_coalesce == 1)
271 return -EINVAL;
272
3abcdeda
SP
273 for_all_rx_queues(adapter, rxo, i) {
274 rx_eq = &rxo->rx_eq;
275
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;
279
280 rx_max = coalesce->rx_coalesce_usecs_high;
281 rx_min = coalesce->rx_coalesce_usecs_low;
282 rx_cur = coalesce->rx_coalesce_usecs;
283
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;
303 }
304 }
6b7c5b94 305 }
6b7c5b94 306
6b7c5b94
SP
307 tx_cur = coalesce->tx_coalesce_usecs;
308
309 if (tx_cur > BE_MAX_EQD)
310 tx_cur = BE_MAX_EQD;
311 if (tx_eq->cur_eqd != tx_cur) {
8788fdc2 312 status = be_cmd_modify_eqd(adapter, tx_eq->q.id, tx_cur);
6b7c5b94
SP
313 if (!status)
314 tx_eq->cur_eqd = tx_cur;
315 }
316
6b7c5b94
SP
317 return 0;
318}
319
6b7c5b94
SP
320static void
321be_get_ethtool_stats(struct net_device *netdev,
322 struct ethtool_stats *stats, uint64_t *data)
323{
324 struct be_adapter *adapter = netdev_priv(netdev);
3abcdeda 325 struct be_rx_obj *rxo;
3c8def97 326 struct be_tx_obj *txo;
ac124ff9 327 void *p;
ab1594e9 328 unsigned int i, j, base = 0, start;
6b7c5b94
SP
329
330 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
ac124ff9 331 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
ab1594e9 332 data[i] = *(u32 *)p;
6b7c5b94 333 }
ab1594e9 334 base += ETHTOOL_STATS_NUM;
3abcdeda
SP
335
336 for_all_rx_queues(adapter, rxo, j) {
ab1594e9
SP
337 struct be_rx_stats *stats = rx_stats(rxo);
338
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));
344
345 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
346 p = (u8 *)stats + et_rx_stats[i].offset;
347 data[base + i] = *(u32 *)p;
3abcdeda 348 }
ab1594e9 349 base += ETHTOOL_RXSTATS_NUM;
3abcdeda 350 }
3c8def97 351
3c8def97 352 for_all_tx_queues(adapter, txo, j) {
ab1594e9
SP
353 struct be_tx_stats *stats = tx_stats(txo);
354
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));
359
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;
367 }
368 } while (u64_stats_fetch_retry_bh(&stats->sync, start));
369 base += ETHTOOL_TXSTATS_NUM;
3c8def97 370 }
6b7c5b94
SP
371}
372
373static void
374be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
375 uint8_t *data)
376{
3abcdeda
SP
377 struct be_adapter *adapter = netdev_priv(netdev);
378 int i, j;
379
6b7c5b94
SP
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;
385 }
3abcdeda
SP
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;
391 }
392 }
3c8def97
SP
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;
398 }
399 }
6b7c5b94 400 break;
ff33a6e2
S
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;
405 }
406 break;
6b7c5b94
SP
407 }
408}
409
15f0a394 410static int be_get_sset_count(struct net_device *netdev, int stringset)
6b7c5b94 411{
3abcdeda
SP
412 struct be_adapter *adapter = netdev_priv(netdev);
413
15f0a394 414 switch (stringset) {
ff33a6e2
S
415 case ETH_SS_TEST:
416 return ETHTOOL_TESTS_NUM;
15f0a394 417 case ETH_SS_STATS:
3abcdeda 418 return ETHTOOL_STATS_NUM +
3c8def97
SP
419 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
420 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
15f0a394
BH
421 default:
422 return -EINVAL;
423 }
6b7c5b94
SP
424}
425
426static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
427{
0388f251 428 struct be_adapter *adapter = netdev_priv(netdev);
306f1348 429 struct be_phy_info phy_info;
ee3cb629 430 u8 mac_speed = 0;
0388f251 431 u16 link_speed = 0;
0dffc83e
AK
432 int status;
433
48e9989e 434 if ((adapter->link_speed < 0) || (!(netdev->flags & IFF_UP))) {
ea172a01
SP
435 status = be_cmd_link_status_query(adapter, &mac_speed,
436 &link_speed, 0);
0dffc83e
AK
437
438 /* link_speed is in units of 10 Mbps */
439 if (link_speed) {
70739497 440 ethtool_cmd_speed_set(ecmd, link_speed*10);
0dffc83e
AK
441 } else {
442 switch (mac_speed) {
4fa9ed07 443 case PHY_LINK_SPEED_10MBPS:
70739497 444 ethtool_cmd_speed_set(ecmd, SPEED_10);
4fa9ed07
AK
445 break;
446 case PHY_LINK_SPEED_100MBPS:
70739497 447 ethtool_cmd_speed_set(ecmd, SPEED_100);
4fa9ed07 448 break;
0dffc83e 449 case PHY_LINK_SPEED_1GBPS:
70739497 450 ethtool_cmd_speed_set(ecmd, SPEED_1000);
0dffc83e
AK
451 break;
452 case PHY_LINK_SPEED_10GBPS:
70739497 453 ethtool_cmd_speed_set(ecmd, SPEED_10000);
0dffc83e 454 break;
4fa9ed07 455 case PHY_LINK_SPEED_ZERO:
70739497 456 ethtool_cmd_speed_set(ecmd, 0);
4fa9ed07 457 break;
0dffc83e
AK
458 }
459 }
0388f251 460
306f1348 461 status = be_cmd_get_phy_info(adapter, &phy_info);
16c02145 462 if (!status) {
306f1348 463 switch (phy_info.interface_type) {
ee3cb629
AK
464 case PHY_TYPE_XFP_10GB:
465 case PHY_TYPE_SFP_1GB:
466 case PHY_TYPE_SFP_PLUS_10GB:
16c02145 467 ecmd->port = PORT_FIBRE;
16c02145
SB
468 break;
469 default:
470 ecmd->port = PORT_TP;
16c02145
SB
471 break;
472 }
ee3cb629 473
306f1348 474 switch (phy_info.interface_type) {
ee3cb629
AK
475 case PHY_TYPE_KR_10GB:
476 case PHY_TYPE_KX4_10GB:
477 ecmd->autoneg = AUTONEG_ENABLE;
16c02145 478 ecmd->transceiver = XCVR_INTERNAL;
ee3cb629
AK
479 break;
480 default:
481 ecmd->autoneg = AUTONEG_DISABLE;
482 ecmd->transceiver = XCVR_EXTERNAL;
483 break;
484 }
0388f251 485 }
0dffc83e
AK
486
487 /* Save for future use */
70739497 488 adapter->link_speed = ethtool_cmd_speed(ecmd);
0dffc83e 489 adapter->port_type = ecmd->port;
16c02145 490 adapter->transceiver = ecmd->transceiver;
ee3cb629 491 adapter->autoneg = ecmd->autoneg;
0dffc83e 492 } else {
70739497 493 ethtool_cmd_speed_set(ecmd, adapter->link_speed);
0dffc83e 494 ecmd->port = adapter->port_type;
16c02145 495 ecmd->transceiver = adapter->transceiver;
ee3cb629 496 ecmd->autoneg = adapter->autoneg;
0388f251 497 }
0dffc83e 498
6b7c5b94 499 ecmd->duplex = DUPLEX_FULL;
0388f251 500 ecmd->phy_address = adapter->port_num;
16c02145
SB
501 switch (ecmd->port) {
502 case PORT_FIBRE:
503 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
504 break;
505 case PORT_TP:
506 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_TP);
507 break;
508 case PORT_AUI:
509 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_AUI);
510 break;
511 }
0388f251 512
ee3cb629
AK
513 if (ecmd->autoneg) {
514 ecmd->supported |= SUPPORTED_1000baseT_Full;
515 ecmd->supported |= SUPPORTED_Autoneg;
516 ecmd->advertising |= (ADVERTISED_10000baseT_Full |
517 ADVERTISED_1000baseT_Full);
518 }
519
6b7c5b94
SP
520 return 0;
521}
522
110b82bc
SP
523static void be_get_ringparam(struct net_device *netdev,
524 struct ethtool_ringparam *ring)
6b7c5b94
SP
525{
526 struct be_adapter *adapter = netdev_priv(netdev);
527
110b82bc
SP
528 ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len;
529 ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len;
6b7c5b94
SP
530}
531
532static void
533be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
534{
535 struct be_adapter *adapter = netdev_priv(netdev);
536
8788fdc2 537 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
03a980d1 538 ecmd->autoneg = 0;
6b7c5b94
SP
539}
540
541static int
542be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
543{
544 struct be_adapter *adapter = netdev_priv(netdev);
545 int status;
546
03a980d1 547 if (ecmd->autoneg != 0)
6b7c5b94 548 return -EINVAL;
9e90c961
AK
549 adapter->tx_fc = ecmd->tx_pause;
550 adapter->rx_fc = ecmd->rx_pause;
6b7c5b94 551
9e90c961
AK
552 status = be_cmd_set_flow_control(adapter,
553 adapter->tx_fc, adapter->rx_fc);
554 if (status)
6b7c5b94
SP
555 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
556
557 return status;
558}
559
fad9ab2c 560static int
1a642469 561be_set_phys_id(struct net_device *netdev,
562 enum ethtool_phys_id_state state)
fad9ab2c
SB
563{
564 struct be_adapter *adapter = netdev_priv(netdev);
fad9ab2c 565
1a642469 566 switch (state) {
567 case ETHTOOL_ID_ACTIVE:
568 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
569 &adapter->beacon_state);
fce55922 570 return 1; /* cycle on/off once per second */
fad9ab2c 571
1a642469 572 case ETHTOOL_ID_ON:
573 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
574 BEACON_STATE_ENABLED);
575 break;
fad9ab2c 576
1a642469 577 case ETHTOOL_ID_OFF:
578 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
579 BEACON_STATE_DISABLED);
580 break;
fad9ab2c 581
1a642469 582 case ETHTOOL_ID_INACTIVE:
583 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
584 adapter->beacon_state);
585 }
fad9ab2c 586
1a642469 587 return 0;
fad9ab2c
SB
588}
589
dcf96f1f
AK
590static bool
591be_is_wol_supported(struct be_adapter *adapter)
592{
593 if (!be_physfn(adapter))
594 return false;
595 else
596 return true;
597}
598
71d8d1b5
AK
599static void
600be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
601{
602 struct be_adapter *adapter = netdev_priv(netdev);
603
dcf96f1f
AK
604 if (be_is_wol_supported(adapter))
605 wol->supported = WAKE_MAGIC;
606
71d8d1b5
AK
607 if (adapter->wol)
608 wol->wolopts = WAKE_MAGIC;
609 else
610 wol->wolopts = 0;
611 memset(&wol->sopass, 0, sizeof(wol->sopass));
71d8d1b5
AK
612}
613
614static int
615be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
616{
617 struct be_adapter *adapter = netdev_priv(netdev);
618
619 if (wol->wolopts & ~WAKE_MAGIC)
620 return -EINVAL;
621
dcf96f1f 622 if ((wol->wolopts & WAKE_MAGIC) && be_is_wol_supported(adapter))
71d8d1b5
AK
623 adapter->wol = true;
624 else
625 adapter->wol = false;
626
627 return 0;
628}
629
ff33a6e2
S
630static int
631be_test_ddr_dma(struct be_adapter *adapter)
632{
633 int ret, i;
634 struct be_dma_mem ddrdma_cmd;
215faf9c
JP
635 static const u64 pattern[2] = {
636 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
637 };
ff33a6e2
S
638
639 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
2b7bcebf
IV
640 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
641 &ddrdma_cmd.dma, GFP_KERNEL);
ff33a6e2 642 if (!ddrdma_cmd.va) {
2381a55c 643 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
ff33a6e2
S
644 return -ENOMEM;
645 }
646
647 for (i = 0; i < 2; i++) {
648 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
649 4096, &ddrdma_cmd);
650 if (ret != 0)
651 goto err;
652 }
653
654err:
2b7bcebf
IV
655 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
656 ddrdma_cmd.dma);
ff33a6e2
S
657 return ret;
658}
659
fced9999
SB
660static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
661 u64 *status)
662{
9e1453c5 663 be_cmd_set_loopback(adapter, adapter->hba_port_num,
fced9999 664 loopback_type, 1);
9e1453c5 665 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
fced9999
SB
666 loopback_type, 1500,
667 2, 0xabc);
9e1453c5 668 be_cmd_set_loopback(adapter, adapter->hba_port_num,
fced9999
SB
669 BE_NO_LOOPBACK, 1);
670 return *status;
671}
672
ff33a6e2
S
673static void
674be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
675{
676 struct be_adapter *adapter = netdev_priv(netdev);
4276e47e
SB
677 u8 mac_speed = 0;
678 u16 qos_link_speed = 0;
ff33a6e2
S
679
680 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
681
682 if (test->flags & ETH_TEST_FL_OFFLINE) {
fced9999
SB
683 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
684 &data[0]) != 0) {
ff33a6e2 685 test->flags |= ETH_TEST_FL_FAILED;
fced9999
SB
686 }
687 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
688 &data[1]) != 0) {
ff33a6e2 689 test->flags |= ETH_TEST_FL_FAILED;
fced9999
SB
690 }
691 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
692 &data[2]) != 0) {
ff33a6e2 693 test->flags |= ETH_TEST_FL_FAILED;
fced9999 694 }
8f47afe0 695 }
ff33a6e2 696
8f47afe0
SB
697 if (be_test_ddr_dma(adapter) != 0) {
698 data[3] = 1;
699 test->flags |= ETH_TEST_FL_FAILED;
ff33a6e2
S
700 }
701
ea172a01 702 if (be_cmd_link_status_query(adapter, &mac_speed,
187e8756 703 &qos_link_speed, 0) != 0) {
4276e47e
SB
704 test->flags |= ETH_TEST_FL_FAILED;
705 data[4] = -1;
4ee77214
AK
706 } else if (!mac_speed) {
707 test->flags |= ETH_TEST_FL_FAILED;
4276e47e
SB
708 data[4] = 1;
709 }
ff33a6e2
S
710}
711
84517482
AK
712static int
713be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
714{
715 struct be_adapter *adapter = netdev_priv(netdev);
716 char file_name[ETHTOOL_FLASH_MAX_FILENAME];
84517482
AK
717
718 file_name[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
719 strcpy(file_name, efl->data);
84517482
AK
720
721 return be_load_fw(adapter, file_name);
722}
723
368c0ca2
SB
724static int
725be_get_eeprom_len(struct net_device *netdev)
726{
af5875bd
PR
727 struct be_adapter *adapter = netdev_priv(netdev);
728 if (lancer_chip(adapter)) {
729 if (be_physfn(adapter))
730 return lancer_cmd_get_file_len(adapter,
731 LANCER_VPD_PF_FILE);
732 else
733 return lancer_cmd_get_file_len(adapter,
734 LANCER_VPD_VF_FILE);
735 } else {
736 return BE_READ_SEEPROM_LEN;
737 }
368c0ca2
SB
738}
739
740static int
741be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
742 uint8_t *data)
743{
744 struct be_adapter *adapter = netdev_priv(netdev);
745 struct be_dma_mem eeprom_cmd;
746 struct be_cmd_resp_seeprom_read *resp;
747 int status;
748
749 if (!eeprom->len)
750 return -EINVAL;
751
af5875bd
PR
752 if (lancer_chip(adapter)) {
753 if (be_physfn(adapter))
754 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
755 eeprom->len, data);
756 else
757 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
758 eeprom->len, data);
759 }
760
368c0ca2
SB
761 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
762
763 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
764 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
2b7bcebf
IV
765 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
766 &eeprom_cmd.dma, GFP_KERNEL);
368c0ca2
SB
767
768 if (!eeprom_cmd.va) {
769 dev_err(&adapter->pdev->dev,
770 "Memory allocation failure. Could not read eeprom\n");
771 return -ENOMEM;
772 }
773
774 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
775
776 if (!status) {
43d620c8 777 resp = eeprom_cmd.va;
c0ad9845 778 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
368c0ca2 779 }
2b7bcebf
IV
780 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
781 eeprom_cmd.dma);
368c0ca2
SB
782
783 return status;
784}
785
0fc0b732 786const struct ethtool_ops be_ethtool_ops = {
6b7c5b94
SP
787 .get_settings = be_get_settings,
788 .get_drvinfo = be_get_drvinfo,
71d8d1b5
AK
789 .get_wol = be_get_wol,
790 .set_wol = be_set_wol,
6b7c5b94 791 .get_link = ethtool_op_get_link,
368c0ca2
SB
792 .get_eeprom_len = be_get_eeprom_len,
793 .get_eeprom = be_read_eeprom,
6b7c5b94
SP
794 .get_coalesce = be_get_coalesce,
795 .set_coalesce = be_set_coalesce,
796 .get_ringparam = be_get_ringparam,
797 .get_pauseparam = be_get_pauseparam,
798 .set_pauseparam = be_set_pauseparam,
6b7c5b94 799 .get_strings = be_get_stat_strings,
1a642469 800 .set_phys_id = be_set_phys_id,
15f0a394 801 .get_sset_count = be_get_sset_count,
6b7c5b94 802 .get_ethtool_stats = be_get_ethtool_stats,
311fddc7
SK
803 .get_regs_len = be_get_reg_len,
804 .get_regs = be_get_regs,
84517482 805 .flash_device = be_do_flash,
ff33a6e2 806 .self_test = be_self_test,
6b7c5b94 807};
This page took 0.353719 seconds and 5 git commands to generate.