blob: 675cbacef772d20fea8e992e51dd134c06bff346 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Vasundhara Volamd19261b2015-05-06 05:30:39 -04002 * Copyright (C) 2005 - 2015 Emulex
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003 * 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:
Ajit Khaparded2145cd2011-03-16 08:20:46 +000011 * linux-drivers@emulex.com
Sathya Perla6b7c5b92009-03-11 23:32:03 -070012 *
Ajit Khaparded2145cd2011-03-16 08:20:46 +000013 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
Sathya Perla6b7c5b92009-03-11 23:32:03 -070016 */
17
18#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000019#include "be_cmds.h"
Sathya Perla6b7c5b92009-03-11 23:32:03 -070020#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
Sathya Perlaac124ff2011-07-25 19:10:14 +000029enum {DRVSTAT_TX, DRVSTAT_RX, DRVSTAT};
Sathya Perla6b7c5b92009-03-11 23:32:03 -070030#define FIELDINFO(_struct, field) FIELD_SIZEOF(_struct, field), \
31 offsetof(_struct, field)
Sathya Perla3abcded2010-10-03 22:12:27 -070032#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)
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000036#define DRVSTAT_INFO(field) #field, DRVSTAT,\
Sathya Perlaac124ff2011-07-25 19:10:14 +000037 FIELDINFO(struct be_drv_stats, field)
Sathya Perla6b7c5b92009-03-11 23:32:03 -070038
39static const struct be_ethtool_stat et_stats[] = {
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000040 {DRVSTAT_INFO(rx_crc_errors)},
41 {DRVSTAT_INFO(rx_alignment_symbol_errors)},
42 {DRVSTAT_INFO(rx_pause_frames)},
43 {DRVSTAT_INFO(rx_control_frames)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000044 /* Received packets dropped when the Ethernet length field
45 * is not equal to the actual Ethernet data length.
46 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000047 {DRVSTAT_INFO(rx_in_range_errors)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000048 /* Received packets dropped when their length field is >= 1501 bytes
49 * and <= 1535 bytes.
50 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000051 {DRVSTAT_INFO(rx_out_range_errors)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000052 /* Received packets dropped when they are longer than 9216 bytes */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000053 {DRVSTAT_INFO(rx_frame_too_long)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000054 /* Received packets dropped when they don't pass the unicast or
55 * multicast address filtering.
56 */
Suresh Reddy18fb06a2013-04-25 23:03:21 +000057 {DRVSTAT_INFO(rx_address_filtered)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000058 /* Received packets dropped when IP packet length field is less than
59 * the IP header length field.
60 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000061 {DRVSTAT_INFO(rx_dropped_too_small)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000062 /* Received packets dropped when IP length field is greater than
63 * the actual packet length.
64 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000065 {DRVSTAT_INFO(rx_dropped_too_short)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000066 /* Received packets dropped when the IP header length field is less
67 * than 5.
68 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000069 {DRVSTAT_INFO(rx_dropped_header_too_small)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000070 /* Received packets dropped when the TCP header length field is less
71 * than 5 or the TCP header length + IP header length is more
72 * than IP packet length.
73 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000074 {DRVSTAT_INFO(rx_dropped_tcp_length)},
75 {DRVSTAT_INFO(rx_dropped_runt)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000076 /* Number of received packets dropped when a fifo for descriptors going
77 * into the packet demux block overflows. In normal operation, this
78 * fifo must never overflow.
79 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000080 {DRVSTAT_INFO(rxpp_fifo_overflow_drop)},
Sathya Perlaacbd6ff82014-09-02 09:56:48 +053081 /* Received packets dropped when the RX block runs out of space in
82 * one of its input FIFOs. This could happen due a long burst of
83 * minimum-sized (64b) frames in the receive path.
84 * This counter may also be erroneously incremented rarely.
85 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000086 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
87 {DRVSTAT_INFO(rx_ip_checksum_errs)},
88 {DRVSTAT_INFO(rx_tcp_checksum_errs)},
89 {DRVSTAT_INFO(rx_udp_checksum_errs)},
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000090 {DRVSTAT_INFO(tx_pauseframes)},
91 {DRVSTAT_INFO(tx_controlframes)},
92 {DRVSTAT_INFO(rx_priority_pause_frames)},
Ajit Khapardeb5adffc42013-05-01 09:38:00 +000093 {DRVSTAT_INFO(tx_priority_pauseframes)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000094 /* Received packets dropped when an internal fifo going into
95 * main packet buffer tank (PMEM) overflows.
96 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000097 {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
98 {DRVSTAT_INFO(jabber_events)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000099 /* Received packets dropped due to lack of available HW packet buffers
100 * used to temporarily hold the received packets.
101 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000102 {DRVSTAT_INFO(rx_drops_no_pbuf)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000103 /* Received packets dropped due to input receive buffer
104 * descriptor fifo overflowing.
105 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000106 {DRVSTAT_INFO(rx_drops_no_erx_descr)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000107 /* Packets dropped because the internal FIFO to the offloaded TCP
108 * receive processing block is full. This could happen only for
109 * offloaded iSCSI or FCoE trarffic.
110 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000111 {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000112 /* Received packets dropped when they need more than 8
113 * receive buffers. This cannot happen as the driver configures
114 * 2048 byte receive buffers.
115 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000116 {DRVSTAT_INFO(rx_drops_too_many_frags)},
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000117 {DRVSTAT_INFO(forwarded_packets)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000118 /* Received packets dropped when the frame length
119 * is more than 9018 bytes
120 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000121 {DRVSTAT_INFO(rx_drops_mtu)},
Vasundhara Volamd3de1542014-09-02 09:56:50 +0530122 /* Number of dma mapping errors */
123 {DRVSTAT_INFO(dma_map_errors)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000124 /* Number of packets dropped due to random early drop function */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000125 {DRVSTAT_INFO(eth_red_drops)},
Ajit Khaparde461ae372013-10-03 16:16:50 -0500126 {DRVSTAT_INFO(rx_roce_bytes_lsd)},
127 {DRVSTAT_INFO(rx_roce_bytes_msd)},
128 {DRVSTAT_INFO(rx_roce_frames)},
129 {DRVSTAT_INFO(roce_drops_payload_len)},
130 {DRVSTAT_INFO(roce_drops_crc)}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700131};
Kalesh APe2fb1af2014-09-19 15:46:58 +0530132
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700133#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
134
Sathya Perlaab1594e2011-07-25 19:10:15 +0000135/* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
136 * are first and second members respectively.
137 */
Sathya Perla3abcded2010-10-03 22:12:27 -0700138static const struct be_ethtool_stat et_rx_stats[] = {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000139 {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
140 {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
Sathya Perla3abcded2010-10-03 22:12:27 -0700141 {DRVSTAT_RX_INFO(rx_compl)},
Kalesh AP5c29c092014-05-09 13:29:18 +0530142 {DRVSTAT_RX_INFO(rx_compl_err)},
Sathya Perla3abcded2010-10-03 22:12:27 -0700143 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000144 /* Number of page allocation failures while posting receive buffers
145 * to HW.
146 */
Sathya Perla3abcded2010-10-03 22:12:27 -0700147 {DRVSTAT_RX_INFO(rx_post_fail)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000148 /* Recevied packets dropped due to skb allocation failure */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000149 {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000150 /* Received packets dropped due to lack of available fetched buffers
151 * posted by the driver.
152 */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000153 {DRVSTAT_RX_INFO(rx_drops_no_frags)}
Sathya Perla3abcded2010-10-03 22:12:27 -0700154};
Kalesh APe2fb1af2014-09-19 15:46:58 +0530155
Sathya Perla3abcded2010-10-03 22:12:27 -0700156#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
157
Sathya Perlaab1594e2011-07-25 19:10:15 +0000158/* Stats related to multi TX queues: get_stats routine assumes compl is the
159 * first member
160 */
Sathya Perla3c8def92011-06-12 20:01:58 +0000161static const struct be_ethtool_stat et_tx_stats[] = {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000162 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
Kalesh AP512bb8a2014-09-02 09:56:49 +0530163 /* This counter is incremented when the HW encounters an error while
164 * parsing the packet header of an outgoing TX request. This counter is
165 * applicable only for BE2, BE3 and Skyhawk based adapters.
166 */
167 {DRVSTAT_TX_INFO(tx_hdr_parse_err)},
168 /* This counter is incremented when an error occurs in the DMA
169 * operation associated with the TX request from the host to the device.
170 */
171 {DRVSTAT_TX_INFO(tx_dma_err)},
172 /* This counter is incremented when MAC or VLAN spoof checking is
173 * enabled on the interface and the TX request fails the spoof check
174 * in HW.
175 */
176 {DRVSTAT_TX_INFO(tx_spoof_check_err)},
177 /* This counter is incremented when the HW encounters an error while
178 * performing TSO offload. This counter is applicable only for Lancer
179 * adapters.
180 */
181 {DRVSTAT_TX_INFO(tx_tso_err)},
182 /* This counter is incremented when the HW detects Q-in-Q style VLAN
183 * tagging in a packet and such tagging is not expected on the outgoing
184 * interface. This counter is applicable only for Lancer adapters.
185 */
186 {DRVSTAT_TX_INFO(tx_qinq_err)},
187 /* This counter is incremented when the HW detects parity errors in the
188 * packet data. This counter is applicable only for Lancer adapters.
189 */
190 {DRVSTAT_TX_INFO(tx_internal_parity_err)},
Sathya Perlaac124ff2011-07-25 19:10:14 +0000191 {DRVSTAT_TX_INFO(tx_bytes)},
192 {DRVSTAT_TX_INFO(tx_pkts)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000193 /* Number of skbs queued for trasmission by the driver */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000194 {DRVSTAT_TX_INFO(tx_reqs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000195 /* Number of times the TX queue was stopped due to lack
196 * of spaces in the TXQ.
197 */
Sathya Perlabc617522013-10-01 16:00:01 +0530198 {DRVSTAT_TX_INFO(tx_stops)},
199 /* Pkts dropped in the driver's transmit path */
200 {DRVSTAT_TX_INFO(tx_drv_drops)}
Sathya Perla3c8def92011-06-12 20:01:58 +0000201};
Kalesh APe2fb1af2014-09-19 15:46:58 +0530202
Sathya Perla3c8def92011-06-12 20:01:58 +0000203#define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
204
Suresh Rff33a6e2009-12-03 16:15:52 -0800205static const char et_self_tests[][ETH_GSTRING_LEN] = {
206 "MAC Loopback test",
207 "PHY Loopback test",
208 "External Loopback test",
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000209 "DDR DMA test",
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000210 "Link test"
Suresh Rff33a6e2009-12-03 16:15:52 -0800211};
212
213#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
214#define BE_MAC_LOOPBACK 0x0
215#define BE_PHY_LOOPBACK 0x1
216#define BE_ONE_PORT_EXT_LOOPBACK 0x2
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000217#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800218
Sathya Perla04b71172011-09-27 13:30:27 -0400219static void be_get_drvinfo(struct net_device *netdev,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530220 struct ethtool_drvinfo *drvinfo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700221{
222 struct be_adapter *adapter = netdev_priv(netdev);
223
Rick Jones68aad782011-11-07 13:29:27 +0000224 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
225 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
Somnath Kotureeb65ce2013-05-26 21:08:36 +0000226 if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN))
Jiri Pirko7826d432013-01-06 00:44:26 +0000227 strlcpy(drvinfo->fw_version, adapter->fw_ver,
228 sizeof(drvinfo->fw_version));
229 else
230 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
Somnath Kotureeb65ce2013-05-26 21:08:36 +0000231 "%s [%s]", adapter->fw_ver, adapter->fw_on_flash);
Sathya Perla04b71172011-09-27 13:30:27 -0400232
Rick Jones68aad782011-11-07 13:29:27 +0000233 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
234 sizeof(drvinfo->bus_info));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700235 drvinfo->testinfo_len = 0;
236 drvinfo->regdump_len = 0;
237 drvinfo->eedump_len = 0;
238}
239
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530240static u32 lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000241{
242 u32 data_read = 0, eof;
243 u8 addn_status;
244 struct be_dma_mem data_len_cmd;
245 int status;
246
247 memset(&data_len_cmd, 0, sizeof(data_len_cmd));
248 /* data_offset and data_size should be 0 to get reg len */
249 status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530250 file_name, &data_read, &eof,
251 &addn_status);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000252
253 return data_read;
254}
255
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530256static int lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
257 u32 buf_len, void *buf)
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000258{
259 struct be_dma_mem read_cmd;
260 u32 read_len = 0, total_read_len = 0, chunk_size;
261 u32 eof = 0;
262 u8 addn_status;
263 int status = 0;
264
265 read_cmd.size = LANCER_READ_FILE_CHUNK;
266 read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530267 &read_cmd.dma);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000268
269 if (!read_cmd.va) {
270 dev_err(&adapter->pdev->dev,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530271 "Memory allocation failure while reading dump\n");
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000272 return -ENOMEM;
273 }
274
275 while ((total_read_len < buf_len) && !eof) {
276 chunk_size = min_t(u32, (buf_len - total_read_len),
Kalesh APcd3307aa2014-09-19 15:47:02 +0530277 LANCER_READ_FILE_CHUNK);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000278 chunk_size = ALIGN(chunk_size, 4);
279 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530280 total_read_len, file_name,
281 &read_len, &eof, &addn_status);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000282 if (!status) {
283 memcpy(buf + total_read_len, read_cmd.va, read_len);
284 total_read_len += read_len;
285 eof &= LANCER_READ_FILE_EOF_MASK;
286 } else {
287 status = -EIO;
288 break;
289 }
290 }
291 pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530292 read_cmd.dma);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000293
294 return status;
295}
296
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530297static int be_get_reg_len(struct net_device *netdev)
Somnath Kotur311fddc2011-03-16 21:22:43 +0000298{
299 struct be_adapter *adapter = netdev_priv(netdev);
300 u32 log_size = 0;
301
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +0000302 if (!check_privilege(adapter, MAX_PRIVILEGES))
303 return 0;
304
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000305 if (be_physfn(adapter)) {
306 if (lancer_chip(adapter))
307 log_size = lancer_cmd_get_file_len(adapter,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530308 LANCER_FW_DUMP_FILE);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000309 else
310 be_cmd_get_reg_len(adapter, &log_size);
311 }
Somnath Kotur311fddc2011-03-16 21:22:43 +0000312 return log_size;
313}
314
315static void
316be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
317{
318 struct be_adapter *adapter = netdev_priv(netdev);
319
Ajit Khaparde16a871e2011-04-19 12:10:43 +0000320 if (be_physfn(adapter)) {
321 memset(buf, 0, regs->len);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000322 if (lancer_chip(adapter))
323 lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530324 regs->len, buf);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000325 else
326 be_cmd_get_regs(adapter, regs->len, buf);
Ajit Khaparde16a871e2011-04-19 12:10:43 +0000327 }
Somnath Kotur311fddc2011-03-16 21:22:43 +0000328}
329
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000330static int be_get_coalesce(struct net_device *netdev,
331 struct ethtool_coalesce *et)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700332{
333 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla2632baf2013-10-01 16:00:00 +0530334 struct be_aic_obj *aic = &adapter->aic_obj[0];
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700335
Sathya Perla2632baf2013-10-01 16:00:00 +0530336 et->rx_coalesce_usecs = aic->prev_eqd;
337 et->rx_coalesce_usecs_high = aic->max_eqd;
338 et->rx_coalesce_usecs_low = aic->min_eqd;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700339
Sathya Perla2632baf2013-10-01 16:00:00 +0530340 et->tx_coalesce_usecs = aic->prev_eqd;
341 et->tx_coalesce_usecs_high = aic->max_eqd;
342 et->tx_coalesce_usecs_low = aic->min_eqd;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000343
Sathya Perla2632baf2013-10-01 16:00:00 +0530344 et->use_adaptive_rx_coalesce = aic->enable;
345 et->use_adaptive_tx_coalesce = aic->enable;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700346
347 return 0;
348}
349
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000350/* TX attributes are ignored. Only RX attributes are considered
351 * eqd cmd is issued in the worker thread.
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700352 */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000353static int be_set_coalesce(struct net_device *netdev,
354 struct ethtool_coalesce *et)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700355{
356 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla2632baf2013-10-01 16:00:00 +0530357 struct be_aic_obj *aic = &adapter->aic_obj[0];
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000358 struct be_eq_obj *eqo;
359 int i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700360
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000361 for_all_evt_queues(adapter, eqo, i) {
Sathya Perla2632baf2013-10-01 16:00:00 +0530362 aic->enable = et->use_adaptive_rx_coalesce;
363 aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
364 aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd);
365 aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd);
366 aic->et_eqd = max(aic->et_eqd, aic->min_eqd);
367 aic++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700368 }
369
Padmanabh Ratnakar20947772015-05-06 05:30:33 -0400370 /* For Skyhawk, the EQD setting happens via EQ_DB when AIC is enabled.
371 * When AIC is disabled, persistently force set EQD value via the
372 * FW cmd, so that we don't have to calculate the delay multiplier
373 * encode value each time EQ_DB is rung
374 */
375 if (!et->use_adaptive_rx_coalesce && skyhawk_chip(adapter))
376 be_eqd_update(adapter, true);
377
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700378 return 0;
379}
380
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530381static void be_get_ethtool_stats(struct net_device *netdev,
382 struct ethtool_stats *stats, uint64_t *data)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700383{
384 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700385 struct be_rx_obj *rxo;
Sathya Perla3c8def92011-06-12 20:01:58 +0000386 struct be_tx_obj *txo;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000387 void *p;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000388 unsigned int i, j, base = 0, start;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700389
390 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
Sathya Perlaac124ff2011-07-25 19:10:14 +0000391 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000392 data[i] = *(u32 *)p;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700393 }
Sathya Perlaab1594e2011-07-25 19:10:15 +0000394 base += ETHTOOL_STATS_NUM;
Sathya Perla3abcded2010-10-03 22:12:27 -0700395
396 for_all_rx_queues(adapter, rxo, j) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000397 struct be_rx_stats *stats = rx_stats(rxo);
398
399 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700400 start = u64_stats_fetch_begin_irq(&stats->sync);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000401 data[base] = stats->rx_bytes;
402 data[base + 1] = stats->rx_pkts;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700403 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000404
405 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
406 p = (u8 *)stats + et_rx_stats[i].offset;
407 data[base + i] = *(u32 *)p;
Sathya Perla3abcded2010-10-03 22:12:27 -0700408 }
Sathya Perlaab1594e2011-07-25 19:10:15 +0000409 base += ETHTOOL_RXSTATS_NUM;
Sathya Perla3abcded2010-10-03 22:12:27 -0700410 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000411
Sathya Perla3c8def92011-06-12 20:01:58 +0000412 for_all_tx_queues(adapter, txo, j) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000413 struct be_tx_stats *stats = tx_stats(txo);
414
415 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700416 start = u64_stats_fetch_begin_irq(&stats->sync_compl);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000417 data[base] = stats->tx_compl;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700418 } while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000419
420 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700421 start = u64_stats_fetch_begin_irq(&stats->sync);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000422 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
423 p = (u8 *)stats + et_tx_stats[i].offset;
424 data[base + i] =
425 (et_tx_stats[i].size == sizeof(u64)) ?
426 *(u64 *)p : *(u32 *)p;
427 }
Eric W. Biederman57a77442014-03-13 21:26:42 -0700428 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000429 base += ETHTOOL_TXSTATS_NUM;
Sathya Perla3c8def92011-06-12 20:01:58 +0000430 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700431}
432
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530433static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
434 uint8_t *data)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700435{
Sathya Perla3abcded2010-10-03 22:12:27 -0700436 struct be_adapter *adapter = netdev_priv(netdev);
437 int i, j;
438
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700439 switch (stringset) {
440 case ETH_SS_STATS:
441 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
442 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
443 data += ETH_GSTRING_LEN;
444 }
Sathya Perla3abcded2010-10-03 22:12:27 -0700445 for (i = 0; i < adapter->num_rx_qs; i++) {
446 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
447 sprintf(data, "rxq%d: %s", i,
448 et_rx_stats[j].desc);
449 data += ETH_GSTRING_LEN;
450 }
451 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000452 for (i = 0; i < adapter->num_tx_qs; i++) {
453 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
454 sprintf(data, "txq%d: %s", i,
455 et_tx_stats[j].desc);
456 data += ETH_GSTRING_LEN;
457 }
458 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700459 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800460 case ETH_SS_TEST:
461 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
462 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
463 data += ETH_GSTRING_LEN;
464 }
465 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700466 }
467}
468
Ben Hutchings15f0a392009-10-01 11:58:24 +0000469static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700470{
Sathya Perla3abcded2010-10-03 22:12:27 -0700471 struct be_adapter *adapter = netdev_priv(netdev);
472
Ben Hutchings15f0a392009-10-01 11:58:24 +0000473 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800474 case ETH_SS_TEST:
475 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000476 case ETH_SS_STATS:
Sathya Perla3abcded2010-10-03 22:12:27 -0700477 return ETHTOOL_STATS_NUM +
Sathya Perla3c8def92011-06-12 20:01:58 +0000478 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
479 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000480 default:
481 return -EINVAL;
482 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700483}
484
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530485static u32 be_get_port_type(struct be_adapter *adapter)
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000486{
487 u32 port;
488
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530489 switch (adapter->phy.interface_type) {
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000490 case PHY_TYPE_BASET_1GB:
491 case PHY_TYPE_BASEX_1GB:
492 case PHY_TYPE_SGMII:
493 port = PORT_TP;
494 break;
495 case PHY_TYPE_SFP_PLUS_10GB:
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530496 if (adapter->phy.cable_type & SFP_PLUS_COPPER_CABLE)
497 port = PORT_DA;
498 else
499 port = PORT_FIBRE;
500 break;
501 case PHY_TYPE_QSFP:
502 if (adapter->phy.cable_type & QSFP_PLUS_CR4_CABLE)
503 port = PORT_DA;
504 else
505 port = PORT_FIBRE;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000506 break;
507 case PHY_TYPE_XFP_10GB:
508 case PHY_TYPE_SFP_1GB:
509 port = PORT_FIBRE;
510 break;
511 case PHY_TYPE_BASET_10GB:
512 port = PORT_TP;
513 break;
514 default:
515 port = PORT_OTHER;
516 }
517
518 return port;
519}
520
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530521static u32 convert_to_et_setting(struct be_adapter *adapter, u32 if_speeds)
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000522{
523 u32 val = 0;
524
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530525 switch (adapter->phy.interface_type) {
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000526 case PHY_TYPE_BASET_1GB:
527 case PHY_TYPE_BASEX_1GB:
528 case PHY_TYPE_SGMII:
529 val |= SUPPORTED_TP;
530 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
531 val |= SUPPORTED_1000baseT_Full;
532 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
533 val |= SUPPORTED_100baseT_Full;
534 if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
535 val |= SUPPORTED_10baseT_Full;
536 break;
537 case PHY_TYPE_KX4_10GB:
538 val |= SUPPORTED_Backplane;
539 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
540 val |= SUPPORTED_1000baseKX_Full;
541 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
542 val |= SUPPORTED_10000baseKX4_Full;
543 break;
Vasundhara Volamd6b7a9b2014-09-19 15:46:54 +0530544 case PHY_TYPE_KR2_20GB:
545 val |= SUPPORTED_Backplane;
546 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
547 val |= SUPPORTED_10000baseKR_Full;
548 if (if_speeds & BE_SUPPORTED_SPEED_20GBPS)
549 val |= SUPPORTED_20000baseKR2_Full;
550 break;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000551 case PHY_TYPE_KR_10GB:
552 val |= SUPPORTED_Backplane |
553 SUPPORTED_10000baseKR_Full;
554 break;
Kalesh APca390762014-09-19 15:46:53 +0530555 case PHY_TYPE_KR4_40GB:
556 val |= SUPPORTED_Backplane;
557 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
558 val |= SUPPORTED_10000baseKR_Full;
559 if (if_speeds & BE_SUPPORTED_SPEED_40GBPS)
560 val |= SUPPORTED_40000baseKR4_Full;
561 break;
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530562 case PHY_TYPE_QSFP:
563 if (if_speeds & BE_SUPPORTED_SPEED_40GBPS) {
564 switch (adapter->phy.cable_type) {
565 case QSFP_PLUS_CR4_CABLE:
566 val |= SUPPORTED_40000baseCR4_Full;
567 break;
568 case QSFP_PLUS_LR4_CABLE:
569 val |= SUPPORTED_40000baseLR4_Full;
570 break;
571 default:
572 val |= SUPPORTED_40000baseSR4_Full;
573 break;
574 }
575 }
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000576 case PHY_TYPE_SFP_PLUS_10GB:
577 case PHY_TYPE_XFP_10GB:
578 case PHY_TYPE_SFP_1GB:
579 val |= SUPPORTED_FIBRE;
580 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
581 val |= SUPPORTED_10000baseT_Full;
582 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
583 val |= SUPPORTED_1000baseT_Full;
584 break;
585 case PHY_TYPE_BASET_10GB:
586 val |= SUPPORTED_TP;
587 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
588 val |= SUPPORTED_10000baseT_Full;
589 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
590 val |= SUPPORTED_1000baseT_Full;
591 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
592 val |= SUPPORTED_100baseT_Full;
593 break;
594 default:
595 val |= SUPPORTED_TP;
596 }
597
598 return val;
599}
600
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000601bool be_pause_supported(struct be_adapter *adapter)
602{
603 return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
604 adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
605 false : true;
606}
607
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700608static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
609{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700610 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000611 u8 link_status;
Sathya Perla323ff712012-09-28 04:39:43 +0000612 u16 link_speed = 0;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000613 int status;
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000614 u32 auto_speeds;
615 u32 fixed_speeds;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700616
Sathya Perla323ff712012-09-28 04:39:43 +0000617 if (adapter->phy.link_speed < 0) {
618 status = be_cmd_link_status_query(adapter, &link_speed,
619 &link_status, 0);
620 if (!status)
621 be_link_status_update(adapter, link_status);
622 ethtool_cmd_speed_set(ecmd, link_speed);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000623
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000624 status = be_cmd_get_phy_info(adapter);
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000625 if (!status) {
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000626 auto_speeds = adapter->phy.auto_speeds_supported;
627 fixed_speeds = adapter->phy.fixed_speeds_supported;
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530628
629 be_cmd_query_cable_type(adapter);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000630
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000631 ecmd->supported =
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530632 convert_to_et_setting(adapter,
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000633 auto_speeds |
634 fixed_speeds);
635 ecmd->advertising =
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530636 convert_to_et_setting(adapter, auto_speeds);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000637
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +0530638 ecmd->port = be_get_port_type(adapter);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000639
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000640 if (adapter->phy.auto_speeds_supported) {
641 ecmd->supported |= SUPPORTED_Autoneg;
642 ecmd->autoneg = AUTONEG_ENABLE;
643 ecmd->advertising |= ADVERTISED_Autoneg;
644 }
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000645
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000646 ecmd->supported |= SUPPORTED_Pause;
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000647 if (be_pause_supported(adapter))
648 ecmd->advertising |= ADVERTISED_Pause;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000649
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000650 switch (adapter->phy.interface_type) {
651 case PHY_TYPE_KR_10GB:
652 case PHY_TYPE_KX4_10GB:
653 ecmd->transceiver = XCVR_INTERNAL;
654 break;
655 default:
656 ecmd->transceiver = XCVR_EXTERNAL;
657 break;
658 }
659 } else {
660 ecmd->port = PORT_OTHER;
661 ecmd->autoneg = AUTONEG_DISABLE;
662 ecmd->transceiver = XCVR_DUMMY1;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700663 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000664
665 /* Save for future use */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000666 adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
667 adapter->phy.port_type = ecmd->port;
668 adapter->phy.transceiver = ecmd->transceiver;
669 adapter->phy.autoneg = ecmd->autoneg;
670 adapter->phy.advertising = ecmd->advertising;
671 adapter->phy.supported = ecmd->supported;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000672 } else {
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000673 ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
674 ecmd->port = adapter->phy.port_type;
675 ecmd->transceiver = adapter->phy.transceiver;
676 ecmd->autoneg = adapter->phy.autoneg;
677 ecmd->advertising = adapter->phy.advertising;
678 ecmd->supported = adapter->phy.supported;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700679 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000680
Somnath Kotur682256d2012-05-02 03:40:32 +0000681 ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700682 ecmd->phy_address = adapter->port_num;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000683
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700684 return 0;
685}
686
Sathya Perla110b82b2011-12-13 00:58:49 +0000687static void be_get_ringparam(struct net_device *netdev,
688 struct ethtool_ringparam *ring)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700689{
690 struct be_adapter *adapter = netdev_priv(netdev);
691
Kalesh AP5f820b62014-09-19 15:47:01 +0530692 ring->rx_max_pending = adapter->rx_obj[0].q.len;
693 ring->rx_pending = adapter->rx_obj[0].q.len;
694 ring->tx_max_pending = adapter->tx_obj[0].q.len;
695 ring->tx_pending = adapter->tx_obj[0].q.len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700696}
697
698static void
699be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
700{
701 struct be_adapter *adapter = netdev_priv(netdev);
702
Sathya Perla8788fdc2009-07-27 22:52:03 +0000703 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000704 ecmd->autoneg = adapter->phy.fc_autoneg;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700705}
706
707static int
708be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
709{
710 struct be_adapter *adapter = netdev_priv(netdev);
711 int status;
712
Padmanabh Ratnakarc871c5f2012-07-12 03:56:11 +0000713 if (ecmd->autoneg != adapter->phy.fc_autoneg)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700714 return -EINVAL;
Kalesh AP00d594c2015-01-20 03:51:44 -0500715
716 status = be_cmd_set_flow_control(adapter, ecmd->tx_pause,
717 ecmd->rx_pause);
718 if (status) {
719 dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
720 return be_cmd_status(status);
721 }
722
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000723 adapter->tx_fc = ecmd->tx_pause;
724 adapter->rx_fc = ecmd->rx_pause;
Kalesh AP00d594c2015-01-20 03:51:44 -0500725 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700726}
727
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530728static int be_set_phys_id(struct net_device *netdev,
729 enum ethtool_phys_id_state state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700730{
731 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700732
stephen hemminger1a642462011-04-04 11:06:40 +0000733 switch (state) {
734 case ETHTOOL_ID_ACTIVE:
735 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
736 &adapter->beacon_state);
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000737 return 1; /* cycle on/off once per second */
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700738
stephen hemminger1a642462011-04-04 11:06:40 +0000739 case ETHTOOL_ID_ON:
740 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
741 BEACON_STATE_ENABLED);
742 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700743
stephen hemminger1a642462011-04-04 11:06:40 +0000744 case ETHTOOL_ID_OFF:
745 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
746 BEACON_STATE_DISABLED);
747 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700748
stephen hemminger1a642462011-04-04 11:06:40 +0000749 case ETHTOOL_ID_INACTIVE:
750 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
751 adapter->beacon_state);
752 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700753
stephen hemminger1a642462011-04-04 11:06:40 +0000754 return 0;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700755}
756
Somnath Kotur5c510812013-05-30 02:52:23 +0000757static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
758{
759 struct be_adapter *adapter = netdev_priv(netdev);
760 struct device *dev = &adapter->pdev->dev;
761 int status;
762
Kalesh APf0613382014-08-01 17:47:32 +0530763 if (!lancer_chip(adapter) ||
764 !check_privilege(adapter, MAX_PRIVILEGES))
Somnath Kotur5c510812013-05-30 02:52:23 +0000765 return -EOPNOTSUPP;
Somnath Kotur5c510812013-05-30 02:52:23 +0000766
767 switch (dump->flag) {
768 case LANCER_INITIATE_FW_DUMP:
769 status = lancer_initiate_dump(adapter);
770 if (!status)
Kalesh APf0613382014-08-01 17:47:32 +0530771 dev_info(dev, "FW dump initiated successfully\n");
Somnath Kotur5c510812013-05-30 02:52:23 +0000772 break;
Kalesh APf0613382014-08-01 17:47:32 +0530773 case LANCER_DELETE_FW_DUMP:
774 status = lancer_delete_dump(adapter);
775 if (!status)
776 dev_info(dev, "FW dump deleted successfully\n");
777 break;
Somnath Kotur5c510812013-05-30 02:52:23 +0000778 default:
779 dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
780 return -EINVAL;
781 }
782 return status;
783}
Ajit Khapardedcf96f12011-02-11 13:39:30 +0000784
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530785static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000786{
787 struct be_adapter *adapter = netdev_priv(netdev);
788
Suresh Reddy76a9e082014-01-15 13:23:40 +0530789 if (adapter->wol_cap & BE_WOL_CAP) {
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000790 wol->supported |= WAKE_MAGIC;
Suresh Reddy76a9e082014-01-15 13:23:40 +0530791 if (adapter->wol_en)
Sarveshwar Bandib4243322013-04-25 00:56:56 +0000792 wol->wolopts |= WAKE_MAGIC;
Suresh Reddy76a9e082014-01-15 13:23:40 +0530793 } else {
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000794 wol->wolopts = 0;
Suresh Reddy76a9e082014-01-15 13:23:40 +0530795 }
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000796 memset(&wol->sopass, 0, sizeof(wol->sopass));
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000797}
798
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530799static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000800{
801 struct be_adapter *adapter = netdev_priv(netdev);
802
803 if (wol->wolopts & ~WAKE_MAGIC)
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000804 return -EOPNOTSUPP;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000805
Suresh Reddy76a9e082014-01-15 13:23:40 +0530806 if (!(adapter->wol_cap & BE_WOL_CAP)) {
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000807 dev_warn(&adapter->pdev->dev, "WOL not supported\n");
808 return -EOPNOTSUPP;
809 }
810
811 if (wol->wolopts & WAKE_MAGIC)
Suresh Reddy76a9e082014-01-15 13:23:40 +0530812 adapter->wol_en = true;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000813 else
Suresh Reddy76a9e082014-01-15 13:23:40 +0530814 adapter->wol_en = false;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000815
816 return 0;
817}
818
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530819static int be_test_ddr_dma(struct be_adapter *adapter)
Suresh Rff33a6e2009-12-03 16:15:52 -0800820{
821 int ret, i;
822 struct be_dma_mem ddrdma_cmd;
Joe Perches215faf92010-12-21 02:16:10 -0800823 static const u64 pattern[2] = {
824 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
825 };
Suresh Rff33a6e2009-12-03 16:15:52 -0800826
827 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000828 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
829 &ddrdma_cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +0000830 if (!ddrdma_cmd.va)
Suresh Rff33a6e2009-12-03 16:15:52 -0800831 return -ENOMEM;
Suresh Rff33a6e2009-12-03 16:15:52 -0800832
833 for (i = 0; i < 2; i++) {
834 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530835 4096, &ddrdma_cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -0800836 if (ret != 0)
837 goto err;
838 }
839
840err:
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000841 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
842 ddrdma_cmd.dma);
Kalesh AP0532d4e2014-07-17 16:20:23 +0530843 return be_cmd_status(ret);
Suresh Rff33a6e2009-12-03 16:15:52 -0800844}
845
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000846static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530847 u64 *status)
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000848{
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530849 be_cmd_set_loopback(adapter, adapter->hba_port_num, loopback_type, 1);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000850 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530851 loopback_type, 1500, 2, 0xabc);
852 be_cmd_set_loopback(adapter, adapter->hba_port_num, BE_NO_LOOPBACK, 1);
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000853 return *status;
854}
855
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530856static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
857 u64 *data)
Suresh Rff33a6e2009-12-03 16:15:52 -0800858{
859 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla323ff712012-09-28 04:39:43 +0000860 int status;
861 u8 link_status = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800862
Suresh Reddy78d0b112013-04-25 23:03:22 +0000863 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
864 dev_err(&adapter->pdev->dev, "Self test not supported\n");
865 test->flags |= ETH_TEST_FL_FAILED;
866 return;
867 }
868
Suresh Rff33a6e2009-12-03 16:15:52 -0800869 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
870
871 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530872 if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
Suresh Rff33a6e2009-12-03 16:15:52 -0800873 test->flags |= ETH_TEST_FL_FAILED;
Ivan Vecera5a8a1ab2014-03-05 11:54:05 +0100874
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530875 if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
Suresh Rff33a6e2009-12-03 16:15:52 -0800876 test->flags |= ETH_TEST_FL_FAILED;
Ivan Vecera5a8a1ab2014-03-05 11:54:05 +0100877
878 if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
879 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
880 &data[2]) != 0)
881 test->flags |= ETH_TEST_FL_FAILED;
882 test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000883 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000884 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800885
Padmanabh Ratnakara7047392012-04-25 01:46:28 +0000886 if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000887 data[3] = 1;
888 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800889 }
890
Sathya Perla323ff712012-09-28 04:39:43 +0000891 status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
892 if (status) {
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000893 test->flags |= ETH_TEST_FL_FAILED;
894 data[4] = -1;
Sathya Perla323ff712012-09-28 04:39:43 +0000895 } else if (!link_status) {
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000896 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000897 data[4] = 1;
898 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800899}
900
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530901static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
Ajit Khaparde84517482009-09-04 03:12:16 +0000902{
903 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde84517482009-09-04 03:12:16 +0000904
Ben Hutchings786f5282012-02-01 09:32:25 +0000905 return be_load_fw(adapter, efl->data);
Ajit Khaparde84517482009-09-04 03:12:16 +0000906}
907
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530908static int be_get_eeprom_len(struct net_device *netdev)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800909{
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000910 struct be_adapter *adapter = netdev_priv(netdev);
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +0000911
912 if (!check_privilege(adapter, MAX_PRIVILEGES))
913 return 0;
914
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000915 if (lancer_chip(adapter)) {
916 if (be_physfn(adapter))
917 return lancer_cmd_get_file_len(adapter,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530918 LANCER_VPD_PF_FILE);
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000919 else
920 return lancer_cmd_get_file_len(adapter,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530921 LANCER_VPD_VF_FILE);
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000922 } else {
923 return BE_READ_SEEPROM_LEN;
924 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800925}
926
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530927static int be_read_eeprom(struct net_device *netdev,
928 struct ethtool_eeprom *eeprom, uint8_t *data)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800929{
930 struct be_adapter *adapter = netdev_priv(netdev);
931 struct be_dma_mem eeprom_cmd;
932 struct be_cmd_resp_seeprom_read *resp;
933 int status;
934
935 if (!eeprom->len)
936 return -EINVAL;
937
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000938 if (lancer_chip(adapter)) {
939 if (be_physfn(adapter))
940 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530941 eeprom->len, data);
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000942 else
943 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530944 eeprom->len, data);
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000945 }
946
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800947 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
948
949 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
950 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000951 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
952 &eeprom_cmd.dma, GFP_KERNEL);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800953
Joe Perchesd0320f72013-03-14 13:07:21 +0000954 if (!eeprom_cmd.va)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800955 return -ENOMEM;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800956
957 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
958
959 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +0000960 resp = eeprom_cmd.va;
Ajit Khapardec0ad9842010-02-08 17:51:26 +0000961 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800962 }
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000963 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
964 eeprom_cmd.dma);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800965
Kalesh AP0532d4e2014-07-17 16:20:23 +0530966 return be_cmd_status(status);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800967}
968
Somnath Kotur941a77d2012-05-17 22:59:03 +0000969static u32 be_get_msg_level(struct net_device *netdev)
970{
971 struct be_adapter *adapter = netdev_priv(netdev);
972
Somnath Kotur941a77d2012-05-17 22:59:03 +0000973 return adapter->msg_enable;
974}
975
Somnath Kotur941a77d2012-05-17 22:59:03 +0000976static void be_set_msg_level(struct net_device *netdev, u32 level)
977{
978 struct be_adapter *adapter = netdev_priv(netdev);
979
Somnath Kotur941a77d2012-05-17 22:59:03 +0000980 if (adapter->msg_enable == level)
981 return;
982
983 if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
Vasundhara Volambaaa08d2014-01-15 13:23:34 +0530984 if (BEx_chip(adapter))
985 be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
986 FW_LOG_LEVEL_DEFAULT :
987 FW_LOG_LEVEL_FATAL);
Somnath Kotur941a77d2012-05-17 22:59:03 +0000988 adapter->msg_enable = level;
Somnath Kotur941a77d2012-05-17 22:59:03 +0000989}
990
Suresh Reddy594ad542013-04-25 23:03:20 +0000991static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
992{
993 u64 data = 0;
994
995 switch (flow_type) {
996 case TCP_V4_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +0530997 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +0000998 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +0530999 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +00001000 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1001 break;
1002 case UDP_V4_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +05301003 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +00001004 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +05301005 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +00001006 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1007 break;
1008 case TCP_V6_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +05301009 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +00001010 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +05301011 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +00001012 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1013 break;
1014 case UDP_V6_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +05301015 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +00001016 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +05301017 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +00001018 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1019 break;
1020 }
1021
1022 return data;
1023}
1024
1025static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
Sathya Perla05e4c6a2014-05-09 13:29:15 +05301026 u32 *rule_locs)
Suresh Reddy594ad542013-04-25 23:03:20 +00001027{
1028 struct be_adapter *adapter = netdev_priv(netdev);
1029
1030 if (!be_multi_rxq(adapter)) {
1031 dev_info(&adapter->pdev->dev,
1032 "ethtool::get_rxnfc: RX flow hashing is disabled\n");
1033 return -EINVAL;
1034 }
1035
1036 switch (cmd->cmd) {
1037 case ETHTOOL_GRXFH:
1038 cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
1039 break;
1040 case ETHTOOL_GRXRINGS:
1041 cmd->data = adapter->num_rx_qs - 1;
1042 break;
1043 default:
1044 return -EINVAL;
1045 }
1046
1047 return 0;
1048}
1049
1050static int be_set_rss_hash_opts(struct be_adapter *adapter,
1051 struct ethtool_rxnfc *cmd)
1052{
1053 struct be_rx_obj *rxo;
1054 int status = 0, i, j;
1055 u8 rsstable[128];
Venkata Duvvurue2557872014-04-21 15:38:00 +05301056 u32 rss_flags = adapter->rss_info.rss_flags;
Suresh Reddy594ad542013-04-25 23:03:20 +00001057
1058 if (cmd->data != L3_RSS_FLAGS &&
1059 cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
1060 return -EINVAL;
1061
1062 switch (cmd->flow_type) {
1063 case TCP_V4_FLOW:
1064 if (cmd->data == L3_RSS_FLAGS)
1065 rss_flags &= ~RSS_ENABLE_TCP_IPV4;
1066 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1067 rss_flags |= RSS_ENABLE_IPV4 |
1068 RSS_ENABLE_TCP_IPV4;
1069 break;
1070 case TCP_V6_FLOW:
1071 if (cmd->data == L3_RSS_FLAGS)
1072 rss_flags &= ~RSS_ENABLE_TCP_IPV6;
1073 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1074 rss_flags |= RSS_ENABLE_IPV6 |
1075 RSS_ENABLE_TCP_IPV6;
1076 break;
1077 case UDP_V4_FLOW:
1078 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1079 BEx_chip(adapter))
1080 return -EINVAL;
1081
1082 if (cmd->data == L3_RSS_FLAGS)
1083 rss_flags &= ~RSS_ENABLE_UDP_IPV4;
1084 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1085 rss_flags |= RSS_ENABLE_IPV4 |
1086 RSS_ENABLE_UDP_IPV4;
1087 break;
1088 case UDP_V6_FLOW:
1089 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1090 BEx_chip(adapter))
1091 return -EINVAL;
1092
1093 if (cmd->data == L3_RSS_FLAGS)
1094 rss_flags &= ~RSS_ENABLE_UDP_IPV6;
1095 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1096 rss_flags |= RSS_ENABLE_IPV6 |
1097 RSS_ENABLE_UDP_IPV6;
1098 break;
1099 default:
1100 return -EINVAL;
1101 }
1102
Venkata Duvvurue2557872014-04-21 15:38:00 +05301103 if (rss_flags == adapter->rss_info.rss_flags)
Suresh Reddy594ad542013-04-25 23:03:20 +00001104 return status;
1105
1106 if (be_multi_rxq(adapter)) {
Vasundhara Volam71bb8bd2015-03-04 00:44:32 -05001107 for (j = 0; j < 128; j += adapter->num_rss_qs) {
Suresh Reddy594ad542013-04-25 23:03:20 +00001108 for_all_rss_queues(adapter, rxo, i) {
1109 if ((j + i) >= 128)
1110 break;
1111 rsstable[j + i] = rxo->rss_id;
1112 }
1113 }
1114 }
Venkata Duvvurue2557872014-04-21 15:38:00 +05301115
1116 status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
1117 rss_flags, 128, adapter->rss_info.rss_hkey);
Suresh Reddy594ad542013-04-25 23:03:20 +00001118 if (!status)
Venkata Duvvurue2557872014-04-21 15:38:00 +05301119 adapter->rss_info.rss_flags = rss_flags;
Suresh Reddy594ad542013-04-25 23:03:20 +00001120
Kalesh AP0532d4e2014-07-17 16:20:23 +05301121 return be_cmd_status(status);
Suresh Reddy594ad542013-04-25 23:03:20 +00001122}
1123
1124static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1125{
1126 struct be_adapter *adapter = netdev_priv(netdev);
1127 int status = 0;
1128
1129 if (!be_multi_rxq(adapter)) {
1130 dev_err(&adapter->pdev->dev,
1131 "ethtool::set_rxnfc: RX flow hashing is disabled\n");
1132 return -EINVAL;
1133 }
1134
1135 switch (cmd->cmd) {
1136 case ETHTOOL_SRXFH:
1137 status = be_set_rss_hash_opts(adapter, cmd);
1138 break;
1139 default:
1140 return -EINVAL;
1141 }
1142
1143 return status;
1144}
1145
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301146static void be_get_channels(struct net_device *netdev,
1147 struct ethtool_channels *ch)
1148{
1149 struct be_adapter *adapter = netdev_priv(netdev);
1150
1151 ch->combined_count = adapter->num_evt_qs;
1152 ch->max_combined = be_max_qs(adapter);
1153}
1154
1155static int be_set_channels(struct net_device *netdev,
1156 struct ethtool_channels *ch)
1157{
1158 struct be_adapter *adapter = netdev_priv(netdev);
Kalesh AP0532d4e2014-07-17 16:20:23 +05301159 int status;
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301160
1161 if (ch->rx_count || ch->tx_count || ch->other_count ||
1162 !ch->combined_count || ch->combined_count > be_max_qs(adapter))
1163 return -EINVAL;
1164
1165 adapter->cfg_num_qs = ch->combined_count;
1166
Kalesh AP0532d4e2014-07-17 16:20:23 +05301167 status = be_update_queues(adapter);
1168 return be_cmd_status(status);
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301169}
1170
Venkata Duvvurue2557872014-04-21 15:38:00 +05301171static u32 be_get_rxfh_indir_size(struct net_device *netdev)
1172{
1173 return RSS_INDIR_TABLE_LEN;
1174}
1175
1176static u32 be_get_rxfh_key_size(struct net_device *netdev)
1177{
1178 return RSS_HASH_KEY_LEN;
1179}
1180
Eyal Perry892311f2014-12-02 18:12:10 +02001181static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey,
1182 u8 *hfunc)
Venkata Duvvurue2557872014-04-21 15:38:00 +05301183{
1184 struct be_adapter *adapter = netdev_priv(netdev);
1185 int i;
1186 struct rss_info *rss = &adapter->rss_info;
1187
1188 if (indir) {
1189 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
1190 indir[i] = rss->rss_queue[i];
1191 }
1192
1193 if (hkey)
1194 memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
1195
Eyal Perry892311f2014-12-02 18:12:10 +02001196 if (hfunc)
1197 *hfunc = ETH_RSS_HASH_TOP;
1198
Venkata Duvvurue2557872014-04-21 15:38:00 +05301199 return 0;
1200}
1201
Ben Hutchings33cb0fa2014-05-15 02:01:23 +01001202static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
Eyal Perry892311f2014-12-02 18:12:10 +02001203 const u8 *hkey, const u8 hfunc)
Venkata Duvvurue2557872014-04-21 15:38:00 +05301204{
1205 int rc = 0, i, j;
1206 struct be_adapter *adapter = netdev_priv(netdev);
1207 u8 rsstable[RSS_INDIR_TABLE_LEN];
1208
Eyal Perry892311f2014-12-02 18:12:10 +02001209 /* We do not allow change in unsupported parameters */
1210 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1211 return -EOPNOTSUPP;
1212
Venkata Duvvurue2557872014-04-21 15:38:00 +05301213 if (indir) {
1214 struct be_rx_obj *rxo;
Kalesh AP03d28ff2014-09-19 15:46:56 +05301215
Venkata Duvvurue2557872014-04-21 15:38:00 +05301216 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
1217 j = indir[i];
1218 rxo = &adapter->rx_obj[j];
1219 rsstable[i] = rxo->rss_id;
1220 adapter->rss_info.rss_queue[i] = j;
1221 }
1222 } else {
1223 memcpy(rsstable, adapter->rss_info.rsstable,
1224 RSS_INDIR_TABLE_LEN);
1225 }
1226
1227 if (!hkey)
1228 hkey = adapter->rss_info.rss_hkey;
1229
1230 rc = be_cmd_rss_config(adapter, rsstable,
Kalesh APcd3307aa2014-09-19 15:47:02 +05301231 adapter->rss_info.rss_flags,
1232 RSS_INDIR_TABLE_LEN, hkey);
Venkata Duvvurue2557872014-04-21 15:38:00 +05301233 if (rc) {
1234 adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
1235 return -EIO;
1236 }
1237 memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
1238 memcpy(adapter->rss_info.rsstable, rsstable,
1239 RSS_INDIR_TABLE_LEN);
1240 return 0;
1241}
1242
Mark Leonarde36edd92014-09-12 17:39:18 +05301243static int be_get_module_info(struct net_device *netdev,
1244 struct ethtool_modinfo *modinfo)
1245{
1246 struct be_adapter *adapter = netdev_priv(netdev);
1247 u8 page_data[PAGE_DATA_LEN];
1248 int status;
1249
1250 if (!check_privilege(adapter, MAX_PRIVILEGES))
1251 return -EOPNOTSUPP;
1252
1253 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1254 page_data);
1255 if (!status) {
1256 if (!page_data[SFP_PLUS_SFF_8472_COMP]) {
1257 modinfo->type = ETH_MODULE_SFF_8079;
1258 modinfo->eeprom_len = PAGE_DATA_LEN;
1259 } else {
1260 modinfo->type = ETH_MODULE_SFF_8472;
1261 modinfo->eeprom_len = 2 * PAGE_DATA_LEN;
1262 }
1263 }
1264 return be_cmd_status(status);
1265}
1266
1267static int be_get_module_eeprom(struct net_device *netdev,
1268 struct ethtool_eeprom *eeprom, u8 *data)
1269{
1270 struct be_adapter *adapter = netdev_priv(netdev);
1271 int status;
1272
1273 if (!check_privilege(adapter, MAX_PRIVILEGES))
1274 return -EOPNOTSUPP;
1275
1276 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
1277 data);
1278 if (status)
1279 goto err;
1280
1281 if (eeprom->offset + eeprom->len > PAGE_DATA_LEN) {
1282 status = be_cmd_read_port_transceiver_data(adapter,
1283 TR_PAGE_A2,
1284 data +
1285 PAGE_DATA_LEN);
1286 if (status)
1287 goto err;
1288 }
1289 if (eeprom->offset)
1290 memcpy(data, data + eeprom->offset, eeprom->len);
1291err:
1292 return be_cmd_status(status);
1293}
1294
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001295const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001296 .get_settings = be_get_settings,
1297 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001298 .get_wol = be_get_wol,
1299 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001300 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001301 .get_eeprom_len = be_get_eeprom_len,
1302 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001303 .get_coalesce = be_get_coalesce,
1304 .set_coalesce = be_set_coalesce,
1305 .get_ringparam = be_get_ringparam,
1306 .get_pauseparam = be_get_pauseparam,
1307 .set_pauseparam = be_set_pauseparam,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001308 .get_strings = be_get_stat_strings,
stephen hemminger1a642462011-04-04 11:06:40 +00001309 .set_phys_id = be_set_phys_id,
Somnath Kotur5c510812013-05-30 02:52:23 +00001310 .set_dump = be_set_dump,
Somnath Kotur941a77d2012-05-17 22:59:03 +00001311 .get_msglevel = be_get_msg_level,
1312 .set_msglevel = be_set_msg_level,
Ben Hutchings15f0a392009-10-01 11:58:24 +00001313 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001314 .get_ethtool_stats = be_get_ethtool_stats,
Somnath Kotur311fddc2011-03-16 21:22:43 +00001315 .get_regs_len = be_get_reg_len,
1316 .get_regs = be_get_regs,
Ajit Khaparde84517482009-09-04 03:12:16 +00001317 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -08001318 .self_test = be_self_test,
Suresh Reddy594ad542013-04-25 23:03:20 +00001319 .get_rxnfc = be_get_rxnfc,
1320 .set_rxnfc = be_set_rxnfc,
Venkata Duvvurue2557872014-04-21 15:38:00 +05301321 .get_rxfh_indir_size = be_get_rxfh_indir_size,
1322 .get_rxfh_key_size = be_get_rxfh_key_size,
1323 .get_rxfh = be_get_rxfh,
1324 .set_rxfh = be_set_rxfh,
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301325 .get_channels = be_get_channels,
Mark Leonarde36edd92014-09-12 17:39:18 +05301326 .set_channels = be_set_channels,
1327 .get_module_info = be_get_module_info,
1328 .get_module_eeprom = be_get_module_eeprom
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001329};