blob: ee565be91e0cebb071b95493423d30ce88ad340a [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Vasundhara Volam40263822014-02-12 16:09:07 +05302 * Copyright (C) 2005 - 2014 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(be_on_die_temperature)},
127 {DRVSTAT_INFO(rx_roce_bytes_lsd)},
128 {DRVSTAT_INFO(rx_roce_bytes_msd)},
129 {DRVSTAT_INFO(rx_roce_frames)},
130 {DRVSTAT_INFO(roce_drops_payload_len)},
131 {DRVSTAT_INFO(roce_drops_crc)}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700132};
133#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};
155#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
156
Sathya Perlaab1594e2011-07-25 19:10:15 +0000157/* Stats related to multi TX queues: get_stats routine assumes compl is the
158 * first member
159 */
Sathya Perla3c8def92011-06-12 20:01:58 +0000160static const struct be_ethtool_stat et_tx_stats[] = {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000161 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
Kalesh AP512bb8a2014-09-02 09:56:49 +0530162 /* This counter is incremented when the HW encounters an error while
163 * parsing the packet header of an outgoing TX request. This counter is
164 * applicable only for BE2, BE3 and Skyhawk based adapters.
165 */
166 {DRVSTAT_TX_INFO(tx_hdr_parse_err)},
167 /* This counter is incremented when an error occurs in the DMA
168 * operation associated with the TX request from the host to the device.
169 */
170 {DRVSTAT_TX_INFO(tx_dma_err)},
171 /* This counter is incremented when MAC or VLAN spoof checking is
172 * enabled on the interface and the TX request fails the spoof check
173 * in HW.
174 */
175 {DRVSTAT_TX_INFO(tx_spoof_check_err)},
176 /* This counter is incremented when the HW encounters an error while
177 * performing TSO offload. This counter is applicable only for Lancer
178 * adapters.
179 */
180 {DRVSTAT_TX_INFO(tx_tso_err)},
181 /* This counter is incremented when the HW detects Q-in-Q style VLAN
182 * tagging in a packet and such tagging is not expected on the outgoing
183 * interface. This counter is applicable only for Lancer adapters.
184 */
185 {DRVSTAT_TX_INFO(tx_qinq_err)},
186 /* This counter is incremented when the HW detects parity errors in the
187 * packet data. This counter is applicable only for Lancer adapters.
188 */
189 {DRVSTAT_TX_INFO(tx_internal_parity_err)},
Sathya Perlaac124ff2011-07-25 19:10:14 +0000190 {DRVSTAT_TX_INFO(tx_bytes)},
191 {DRVSTAT_TX_INFO(tx_pkts)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000192 /* Number of skbs queued for trasmission by the driver */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000193 {DRVSTAT_TX_INFO(tx_reqs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000194 /* Number of TX work request blocks DMAed to HW */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000195 {DRVSTAT_TX_INFO(tx_wrbs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000196 /* Number of times the TX queue was stopped due to lack
197 * of spaces in the TXQ.
198 */
Sathya Perlabc617522013-10-01 16:00:01 +0530199 {DRVSTAT_TX_INFO(tx_stops)},
200 /* Pkts dropped in the driver's transmit path */
201 {DRVSTAT_TX_INFO(tx_drv_drops)}
Sathya Perla3c8def92011-06-12 20:01:58 +0000202};
203#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),
277 LANCER_READ_FILE_CHUNK);
278 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 Perla6b7c5b92009-03-11 23:32:03 -0700336
Sathya Perla2632baf2013-10-01 16:00:00 +0530337 et->rx_coalesce_usecs = aic->prev_eqd;
338 et->rx_coalesce_usecs_high = aic->max_eqd;
339 et->rx_coalesce_usecs_low = aic->min_eqd;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700340
Sathya Perla2632baf2013-10-01 16:00:00 +0530341 et->tx_coalesce_usecs = aic->prev_eqd;
342 et->tx_coalesce_usecs_high = aic->max_eqd;
343 et->tx_coalesce_usecs_low = aic->min_eqd;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000344
Sathya Perla2632baf2013-10-01 16:00:00 +0530345 et->use_adaptive_rx_coalesce = aic->enable;
346 et->use_adaptive_tx_coalesce = aic->enable;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700347
348 return 0;
349}
350
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000351/* TX attributes are ignored. Only RX attributes are considered
352 * eqd cmd is issued in the worker thread.
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700353 */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000354static int be_set_coalesce(struct net_device *netdev,
355 struct ethtool_coalesce *et)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700356{
357 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla2632baf2013-10-01 16:00:00 +0530358 struct be_aic_obj *aic = &adapter->aic_obj[0];
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000359 struct be_eq_obj *eqo;
360 int i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700361
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000362 for_all_evt_queues(adapter, eqo, i) {
Sathya Perla2632baf2013-10-01 16:00:00 +0530363 aic->enable = et->use_adaptive_rx_coalesce;
364 aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
365 aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd);
366 aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd);
367 aic->et_eqd = max(aic->et_eqd, aic->min_eqd);
368 aic++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700369 }
370
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700371 return 0;
372}
373
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530374static void be_get_ethtool_stats(struct net_device *netdev,
375 struct ethtool_stats *stats, uint64_t *data)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700376{
377 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700378 struct be_rx_obj *rxo;
Sathya Perla3c8def92011-06-12 20:01:58 +0000379 struct be_tx_obj *txo;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000380 void *p;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000381 unsigned int i, j, base = 0, start;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700382
383 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
Sathya Perlaac124ff2011-07-25 19:10:14 +0000384 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000385 data[i] = *(u32 *)p;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700386 }
Sathya Perlaab1594e2011-07-25 19:10:15 +0000387 base += ETHTOOL_STATS_NUM;
Sathya Perla3abcded2010-10-03 22:12:27 -0700388
389 for_all_rx_queues(adapter, rxo, j) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000390 struct be_rx_stats *stats = rx_stats(rxo);
391
392 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700393 start = u64_stats_fetch_begin_irq(&stats->sync);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000394 data[base] = stats->rx_bytes;
395 data[base + 1] = stats->rx_pkts;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700396 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000397
398 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
399 p = (u8 *)stats + et_rx_stats[i].offset;
400 data[base + i] = *(u32 *)p;
Sathya Perla3abcded2010-10-03 22:12:27 -0700401 }
Sathya Perlaab1594e2011-07-25 19:10:15 +0000402 base += ETHTOOL_RXSTATS_NUM;
Sathya Perla3abcded2010-10-03 22:12:27 -0700403 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000404
Sathya Perla3c8def92011-06-12 20:01:58 +0000405 for_all_tx_queues(adapter, txo, j) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000406 struct be_tx_stats *stats = tx_stats(txo);
407
408 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700409 start = u64_stats_fetch_begin_irq(&stats->sync_compl);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000410 data[base] = stats->tx_compl;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700411 } while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000412
413 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700414 start = u64_stats_fetch_begin_irq(&stats->sync);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000415 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
416 p = (u8 *)stats + et_tx_stats[i].offset;
417 data[base + i] =
418 (et_tx_stats[i].size == sizeof(u64)) ?
419 *(u64 *)p : *(u32 *)p;
420 }
Eric W. Biederman57a77442014-03-13 21:26:42 -0700421 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000422 base += ETHTOOL_TXSTATS_NUM;
Sathya Perla3c8def92011-06-12 20:01:58 +0000423 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700424}
425
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530426static void be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
427 uint8_t *data)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700428{
Sathya Perla3abcded2010-10-03 22:12:27 -0700429 struct be_adapter *adapter = netdev_priv(netdev);
430 int i, j;
431
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700432 switch (stringset) {
433 case ETH_SS_STATS:
434 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
435 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
436 data += ETH_GSTRING_LEN;
437 }
Sathya Perla3abcded2010-10-03 22:12:27 -0700438 for (i = 0; i < adapter->num_rx_qs; i++) {
439 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
440 sprintf(data, "rxq%d: %s", i,
441 et_rx_stats[j].desc);
442 data += ETH_GSTRING_LEN;
443 }
444 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000445 for (i = 0; i < adapter->num_tx_qs; i++) {
446 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
447 sprintf(data, "txq%d: %s", i,
448 et_tx_stats[j].desc);
449 data += ETH_GSTRING_LEN;
450 }
451 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700452 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800453 case ETH_SS_TEST:
454 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
455 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
456 data += ETH_GSTRING_LEN;
457 }
458 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700459 }
460}
461
Ben Hutchings15f0a392009-10-01 11:58:24 +0000462static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700463{
Sathya Perla3abcded2010-10-03 22:12:27 -0700464 struct be_adapter *adapter = netdev_priv(netdev);
465
Ben Hutchings15f0a392009-10-01 11:58:24 +0000466 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800467 case ETH_SS_TEST:
468 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000469 case ETH_SS_STATS:
Sathya Perla3abcded2010-10-03 22:12:27 -0700470 return ETHTOOL_STATS_NUM +
Sathya Perla3c8def92011-06-12 20:01:58 +0000471 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
472 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000473 default:
474 return -EINVAL;
475 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700476}
477
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000478static u32 be_get_port_type(u32 phy_type, u32 dac_cable_len)
479{
480 u32 port;
481
482 switch (phy_type) {
483 case PHY_TYPE_BASET_1GB:
484 case PHY_TYPE_BASEX_1GB:
485 case PHY_TYPE_SGMII:
486 port = PORT_TP;
487 break;
488 case PHY_TYPE_SFP_PLUS_10GB:
489 port = dac_cable_len ? PORT_DA : PORT_FIBRE;
490 break;
491 case PHY_TYPE_XFP_10GB:
492 case PHY_TYPE_SFP_1GB:
493 port = PORT_FIBRE;
494 break;
495 case PHY_TYPE_BASET_10GB:
496 port = PORT_TP;
497 break;
498 default:
499 port = PORT_OTHER;
500 }
501
502 return port;
503}
504
505static u32 convert_to_et_setting(u32 if_type, u32 if_speeds)
506{
507 u32 val = 0;
508
509 switch (if_type) {
510 case PHY_TYPE_BASET_1GB:
511 case PHY_TYPE_BASEX_1GB:
512 case PHY_TYPE_SGMII:
513 val |= SUPPORTED_TP;
514 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
515 val |= SUPPORTED_1000baseT_Full;
516 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
517 val |= SUPPORTED_100baseT_Full;
518 if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
519 val |= SUPPORTED_10baseT_Full;
520 break;
521 case PHY_TYPE_KX4_10GB:
522 val |= SUPPORTED_Backplane;
523 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
524 val |= SUPPORTED_1000baseKX_Full;
525 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
526 val |= SUPPORTED_10000baseKX4_Full;
527 break;
528 case PHY_TYPE_KR_10GB:
529 val |= SUPPORTED_Backplane |
530 SUPPORTED_10000baseKR_Full;
531 break;
532 case PHY_TYPE_SFP_PLUS_10GB:
533 case PHY_TYPE_XFP_10GB:
534 case PHY_TYPE_SFP_1GB:
535 val |= SUPPORTED_FIBRE;
536 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
537 val |= SUPPORTED_10000baseT_Full;
538 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
539 val |= SUPPORTED_1000baseT_Full;
540 break;
541 case PHY_TYPE_BASET_10GB:
542 val |= SUPPORTED_TP;
543 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
544 val |= SUPPORTED_10000baseT_Full;
545 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
546 val |= SUPPORTED_1000baseT_Full;
547 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
548 val |= SUPPORTED_100baseT_Full;
549 break;
550 default:
551 val |= SUPPORTED_TP;
552 }
553
554 return val;
555}
556
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000557bool be_pause_supported(struct be_adapter *adapter)
558{
559 return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
560 adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
561 false : true;
562}
563
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700564static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
565{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700566 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000567 u8 link_status;
Sathya Perla323ff712012-09-28 04:39:43 +0000568 u16 link_speed = 0;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000569 int status;
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000570 u32 auto_speeds;
571 u32 fixed_speeds;
572 u32 dac_cable_len;
573 u16 interface_type;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700574
Sathya Perla323ff712012-09-28 04:39:43 +0000575 if (adapter->phy.link_speed < 0) {
576 status = be_cmd_link_status_query(adapter, &link_speed,
577 &link_status, 0);
578 if (!status)
579 be_link_status_update(adapter, link_status);
580 ethtool_cmd_speed_set(ecmd, link_speed);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000581
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000582 status = be_cmd_get_phy_info(adapter);
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000583 if (!status) {
584 interface_type = adapter->phy.interface_type;
585 auto_speeds = adapter->phy.auto_speeds_supported;
586 fixed_speeds = adapter->phy.fixed_speeds_supported;
587 dac_cable_len = adapter->phy.dac_cable_len;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000588
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000589 ecmd->supported =
590 convert_to_et_setting(interface_type,
591 auto_speeds |
592 fixed_speeds);
593 ecmd->advertising =
594 convert_to_et_setting(interface_type,
595 auto_speeds);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000596
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000597 ecmd->port = be_get_port_type(interface_type,
598 dac_cable_len);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000599
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000600 if (adapter->phy.auto_speeds_supported) {
601 ecmd->supported |= SUPPORTED_Autoneg;
602 ecmd->autoneg = AUTONEG_ENABLE;
603 ecmd->advertising |= ADVERTISED_Autoneg;
604 }
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000605
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000606 ecmd->supported |= SUPPORTED_Pause;
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000607 if (be_pause_supported(adapter))
608 ecmd->advertising |= ADVERTISED_Pause;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000609
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000610 switch (adapter->phy.interface_type) {
611 case PHY_TYPE_KR_10GB:
612 case PHY_TYPE_KX4_10GB:
613 ecmd->transceiver = XCVR_INTERNAL;
614 break;
615 default:
616 ecmd->transceiver = XCVR_EXTERNAL;
617 break;
618 }
619 } else {
620 ecmd->port = PORT_OTHER;
621 ecmd->autoneg = AUTONEG_DISABLE;
622 ecmd->transceiver = XCVR_DUMMY1;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700623 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000624
625 /* Save for future use */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000626 adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
627 adapter->phy.port_type = ecmd->port;
628 adapter->phy.transceiver = ecmd->transceiver;
629 adapter->phy.autoneg = ecmd->autoneg;
630 adapter->phy.advertising = ecmd->advertising;
631 adapter->phy.supported = ecmd->supported;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000632 } else {
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000633 ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
634 ecmd->port = adapter->phy.port_type;
635 ecmd->transceiver = adapter->phy.transceiver;
636 ecmd->autoneg = adapter->phy.autoneg;
637 ecmd->advertising = adapter->phy.advertising;
638 ecmd->supported = adapter->phy.supported;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700639 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000640
Somnath Kotur682256d2012-05-02 03:40:32 +0000641 ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700642 ecmd->phy_address = adapter->port_num;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000643
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700644 return 0;
645}
646
Sathya Perla110b82b2011-12-13 00:58:49 +0000647static void be_get_ringparam(struct net_device *netdev,
648 struct ethtool_ringparam *ring)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700649{
650 struct be_adapter *adapter = netdev_priv(netdev);
651
Sathya Perla110b82b2011-12-13 00:58:49 +0000652 ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len;
653 ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700654}
655
656static void
657be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
658{
659 struct be_adapter *adapter = netdev_priv(netdev);
660
Sathya Perla8788fdc2009-07-27 22:52:03 +0000661 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000662 ecmd->autoneg = adapter->phy.fc_autoneg;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700663}
664
665static int
666be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
667{
668 struct be_adapter *adapter = netdev_priv(netdev);
669 int status;
670
Padmanabh Ratnakarc871c5f2012-07-12 03:56:11 +0000671 if (ecmd->autoneg != adapter->phy.fc_autoneg)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700672 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000673 adapter->tx_fc = ecmd->tx_pause;
674 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700675
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000676 status = be_cmd_set_flow_control(adapter,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530677 adapter->tx_fc, adapter->rx_fc);
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000678 if (status)
Vasundhara Volam50762662014-09-12 17:39:14 +0530679 dev_warn(&adapter->pdev->dev, "Pause param set failed\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700680
Kalesh AP0532d4e2014-07-17 16:20:23 +0530681 return be_cmd_status(status);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700682}
683
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530684static int be_set_phys_id(struct net_device *netdev,
685 enum ethtool_phys_id_state state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700686{
687 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700688
stephen hemminger1a642462011-04-04 11:06:40 +0000689 switch (state) {
690 case ETHTOOL_ID_ACTIVE:
691 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
692 &adapter->beacon_state);
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000693 return 1; /* cycle on/off once per second */
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700694
stephen hemminger1a642462011-04-04 11:06:40 +0000695 case ETHTOOL_ID_ON:
696 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
697 BEACON_STATE_ENABLED);
698 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700699
stephen hemminger1a642462011-04-04 11:06:40 +0000700 case ETHTOOL_ID_OFF:
701 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
702 BEACON_STATE_DISABLED);
703 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700704
stephen hemminger1a642462011-04-04 11:06:40 +0000705 case ETHTOOL_ID_INACTIVE:
706 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
707 adapter->beacon_state);
708 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700709
stephen hemminger1a642462011-04-04 11:06:40 +0000710 return 0;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700711}
712
Somnath Kotur5c510812013-05-30 02:52:23 +0000713static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
714{
715 struct be_adapter *adapter = netdev_priv(netdev);
716 struct device *dev = &adapter->pdev->dev;
717 int status;
718
Kalesh APf0613382014-08-01 17:47:32 +0530719 if (!lancer_chip(adapter) ||
720 !check_privilege(adapter, MAX_PRIVILEGES))
Somnath Kotur5c510812013-05-30 02:52:23 +0000721 return -EOPNOTSUPP;
Somnath Kotur5c510812013-05-30 02:52:23 +0000722
723 switch (dump->flag) {
724 case LANCER_INITIATE_FW_DUMP:
725 status = lancer_initiate_dump(adapter);
726 if (!status)
Kalesh APf0613382014-08-01 17:47:32 +0530727 dev_info(dev, "FW dump initiated successfully\n");
Somnath Kotur5c510812013-05-30 02:52:23 +0000728 break;
Kalesh APf0613382014-08-01 17:47:32 +0530729 case LANCER_DELETE_FW_DUMP:
730 status = lancer_delete_dump(adapter);
731 if (!status)
732 dev_info(dev, "FW dump deleted successfully\n");
733 break;
Somnath Kotur5c510812013-05-30 02:52:23 +0000734 default:
735 dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
736 return -EINVAL;
737 }
738 return status;
739}
Ajit Khapardedcf96f12011-02-11 13:39:30 +0000740
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530741static void be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000742{
743 struct be_adapter *adapter = netdev_priv(netdev);
744
Suresh Reddy76a9e082014-01-15 13:23:40 +0530745 if (adapter->wol_cap & BE_WOL_CAP) {
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000746 wol->supported |= WAKE_MAGIC;
Suresh Reddy76a9e082014-01-15 13:23:40 +0530747 if (adapter->wol_en)
Sarveshwar Bandib4243322013-04-25 00:56:56 +0000748 wol->wolopts |= WAKE_MAGIC;
Suresh Reddy76a9e082014-01-15 13:23:40 +0530749 } else {
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000750 wol->wolopts = 0;
Suresh Reddy76a9e082014-01-15 13:23:40 +0530751 }
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000752 memset(&wol->sopass, 0, sizeof(wol->sopass));
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000753}
754
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530755static int be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000756{
757 struct be_adapter *adapter = netdev_priv(netdev);
758
759 if (wol->wolopts & ~WAKE_MAGIC)
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000760 return -EOPNOTSUPP;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000761
Suresh Reddy76a9e082014-01-15 13:23:40 +0530762 if (!(adapter->wol_cap & BE_WOL_CAP)) {
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000763 dev_warn(&adapter->pdev->dev, "WOL not supported\n");
764 return -EOPNOTSUPP;
765 }
766
767 if (wol->wolopts & WAKE_MAGIC)
Suresh Reddy76a9e082014-01-15 13:23:40 +0530768 adapter->wol_en = true;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000769 else
Suresh Reddy76a9e082014-01-15 13:23:40 +0530770 adapter->wol_en = false;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000771
772 return 0;
773}
774
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530775static int be_test_ddr_dma(struct be_adapter *adapter)
Suresh Rff33a6e2009-12-03 16:15:52 -0800776{
777 int ret, i;
778 struct be_dma_mem ddrdma_cmd;
Joe Perches215faf92010-12-21 02:16:10 -0800779 static const u64 pattern[2] = {
780 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
781 };
Suresh Rff33a6e2009-12-03 16:15:52 -0800782
783 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000784 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
785 &ddrdma_cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +0000786 if (!ddrdma_cmd.va)
Suresh Rff33a6e2009-12-03 16:15:52 -0800787 return -ENOMEM;
Suresh Rff33a6e2009-12-03 16:15:52 -0800788
789 for (i = 0; i < 2; i++) {
790 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530791 4096, &ddrdma_cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -0800792 if (ret != 0)
793 goto err;
794 }
795
796err:
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000797 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
798 ddrdma_cmd.dma);
Kalesh AP0532d4e2014-07-17 16:20:23 +0530799 return be_cmd_status(ret);
Suresh Rff33a6e2009-12-03 16:15:52 -0800800}
801
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000802static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530803 u64 *status)
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000804{
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530805 be_cmd_set_loopback(adapter, adapter->hba_port_num, loopback_type, 1);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000806 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530807 loopback_type, 1500, 2, 0xabc);
808 be_cmd_set_loopback(adapter, adapter->hba_port_num, BE_NO_LOOPBACK, 1);
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000809 return *status;
810}
811
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530812static void be_self_test(struct net_device *netdev, struct ethtool_test *test,
813 u64 *data)
Suresh Rff33a6e2009-12-03 16:15:52 -0800814{
815 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla323ff712012-09-28 04:39:43 +0000816 int status;
817 u8 link_status = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800818
Suresh Reddy78d0b112013-04-25 23:03:22 +0000819 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
820 dev_err(&adapter->pdev->dev, "Self test not supported\n");
821 test->flags |= ETH_TEST_FL_FAILED;
822 return;
823 }
824
Suresh Rff33a6e2009-12-03 16:15:52 -0800825 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
826
827 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530828 if (be_loopback_test(adapter, BE_MAC_LOOPBACK, &data[0]) != 0)
Suresh Rff33a6e2009-12-03 16:15:52 -0800829 test->flags |= ETH_TEST_FL_FAILED;
Ivan Vecera5a8a1ab2014-03-05 11:54:05 +0100830
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530831 if (be_loopback_test(adapter, BE_PHY_LOOPBACK, &data[1]) != 0)
Suresh Rff33a6e2009-12-03 16:15:52 -0800832 test->flags |= ETH_TEST_FL_FAILED;
Ivan Vecera5a8a1ab2014-03-05 11:54:05 +0100833
834 if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
835 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
836 &data[2]) != 0)
837 test->flags |= ETH_TEST_FL_FAILED;
838 test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000839 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000840 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800841
Padmanabh Ratnakara7047392012-04-25 01:46:28 +0000842 if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000843 data[3] = 1;
844 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800845 }
846
Sathya Perla323ff712012-09-28 04:39:43 +0000847 status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
848 if (status) {
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000849 test->flags |= ETH_TEST_FL_FAILED;
850 data[4] = -1;
Sathya Perla323ff712012-09-28 04:39:43 +0000851 } else if (!link_status) {
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000852 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000853 data[4] = 1;
854 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800855}
856
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530857static int be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
Ajit Khaparde84517482009-09-04 03:12:16 +0000858{
859 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde84517482009-09-04 03:12:16 +0000860
Ben Hutchings786f5282012-02-01 09:32:25 +0000861 return be_load_fw(adapter, efl->data);
Ajit Khaparde84517482009-09-04 03:12:16 +0000862}
863
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530864static int be_get_eeprom_len(struct net_device *netdev)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800865{
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000866 struct be_adapter *adapter = netdev_priv(netdev);
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +0000867
868 if (!check_privilege(adapter, MAX_PRIVILEGES))
869 return 0;
870
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000871 if (lancer_chip(adapter)) {
872 if (be_physfn(adapter))
873 return lancer_cmd_get_file_len(adapter,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530874 LANCER_VPD_PF_FILE);
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000875 else
876 return lancer_cmd_get_file_len(adapter,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530877 LANCER_VPD_VF_FILE);
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000878 } else {
879 return BE_READ_SEEPROM_LEN;
880 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800881}
882
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530883static int be_read_eeprom(struct net_device *netdev,
884 struct ethtool_eeprom *eeprom, uint8_t *data)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800885{
886 struct be_adapter *adapter = netdev_priv(netdev);
887 struct be_dma_mem eeprom_cmd;
888 struct be_cmd_resp_seeprom_read *resp;
889 int status;
890
891 if (!eeprom->len)
892 return -EINVAL;
893
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000894 if (lancer_chip(adapter)) {
895 if (be_physfn(adapter))
896 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530897 eeprom->len, data);
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000898 else
899 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530900 eeprom->len, data);
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000901 }
902
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800903 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
904
905 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
906 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000907 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
908 &eeprom_cmd.dma, GFP_KERNEL);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800909
Joe Perchesd0320f72013-03-14 13:07:21 +0000910 if (!eeprom_cmd.va)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800911 return -ENOMEM;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800912
913 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
914
915 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +0000916 resp = eeprom_cmd.va;
Ajit Khapardec0ad9842010-02-08 17:51:26 +0000917 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800918 }
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000919 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
920 eeprom_cmd.dma);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800921
Kalesh AP0532d4e2014-07-17 16:20:23 +0530922 return be_cmd_status(status);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800923}
924
Somnath Kotur941a77d2012-05-17 22:59:03 +0000925static u32 be_get_msg_level(struct net_device *netdev)
926{
927 struct be_adapter *adapter = netdev_priv(netdev);
928
Somnath Kotur941a77d2012-05-17 22:59:03 +0000929 return adapter->msg_enable;
930}
931
Somnath Kotur941a77d2012-05-17 22:59:03 +0000932static void be_set_msg_level(struct net_device *netdev, u32 level)
933{
934 struct be_adapter *adapter = netdev_priv(netdev);
935
Somnath Kotur941a77d2012-05-17 22:59:03 +0000936 if (adapter->msg_enable == level)
937 return;
938
939 if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
Vasundhara Volambaaa08d2014-01-15 13:23:34 +0530940 if (BEx_chip(adapter))
941 be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
942 FW_LOG_LEVEL_DEFAULT :
943 FW_LOG_LEVEL_FATAL);
Somnath Kotur941a77d2012-05-17 22:59:03 +0000944 adapter->msg_enable = level;
945
946 return;
947}
948
Suresh Reddy594ad542013-04-25 23:03:20 +0000949static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
950{
951 u64 data = 0;
952
953 switch (flow_type) {
954 case TCP_V4_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +0530955 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +0000956 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +0530957 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +0000958 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
959 break;
960 case UDP_V4_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +0530961 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +0000962 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +0530963 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +0000964 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
965 break;
966 case TCP_V6_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +0530967 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +0000968 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +0530969 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +0000970 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
971 break;
972 case UDP_V6_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +0530973 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +0000974 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +0530975 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +0000976 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
977 break;
978 }
979
980 return data;
981}
982
983static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
Sathya Perla05e4c6a2014-05-09 13:29:15 +0530984 u32 *rule_locs)
Suresh Reddy594ad542013-04-25 23:03:20 +0000985{
986 struct be_adapter *adapter = netdev_priv(netdev);
987
988 if (!be_multi_rxq(adapter)) {
989 dev_info(&adapter->pdev->dev,
990 "ethtool::get_rxnfc: RX flow hashing is disabled\n");
991 return -EINVAL;
992 }
993
994 switch (cmd->cmd) {
995 case ETHTOOL_GRXFH:
996 cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
997 break;
998 case ETHTOOL_GRXRINGS:
999 cmd->data = adapter->num_rx_qs - 1;
1000 break;
1001 default:
1002 return -EINVAL;
1003 }
1004
1005 return 0;
1006}
1007
1008static int be_set_rss_hash_opts(struct be_adapter *adapter,
1009 struct ethtool_rxnfc *cmd)
1010{
1011 struct be_rx_obj *rxo;
1012 int status = 0, i, j;
1013 u8 rsstable[128];
Venkata Duvvurue2557872014-04-21 15:38:00 +05301014 u32 rss_flags = adapter->rss_info.rss_flags;
Suresh Reddy594ad542013-04-25 23:03:20 +00001015
1016 if (cmd->data != L3_RSS_FLAGS &&
1017 cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
1018 return -EINVAL;
1019
1020 switch (cmd->flow_type) {
1021 case TCP_V4_FLOW:
1022 if (cmd->data == L3_RSS_FLAGS)
1023 rss_flags &= ~RSS_ENABLE_TCP_IPV4;
1024 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1025 rss_flags |= RSS_ENABLE_IPV4 |
1026 RSS_ENABLE_TCP_IPV4;
1027 break;
1028 case TCP_V6_FLOW:
1029 if (cmd->data == L3_RSS_FLAGS)
1030 rss_flags &= ~RSS_ENABLE_TCP_IPV6;
1031 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1032 rss_flags |= RSS_ENABLE_IPV6 |
1033 RSS_ENABLE_TCP_IPV6;
1034 break;
1035 case UDP_V4_FLOW:
1036 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1037 BEx_chip(adapter))
1038 return -EINVAL;
1039
1040 if (cmd->data == L3_RSS_FLAGS)
1041 rss_flags &= ~RSS_ENABLE_UDP_IPV4;
1042 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1043 rss_flags |= RSS_ENABLE_IPV4 |
1044 RSS_ENABLE_UDP_IPV4;
1045 break;
1046 case UDP_V6_FLOW:
1047 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1048 BEx_chip(adapter))
1049 return -EINVAL;
1050
1051 if (cmd->data == L3_RSS_FLAGS)
1052 rss_flags &= ~RSS_ENABLE_UDP_IPV6;
1053 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1054 rss_flags |= RSS_ENABLE_IPV6 |
1055 RSS_ENABLE_UDP_IPV6;
1056 break;
1057 default:
1058 return -EINVAL;
1059 }
1060
Venkata Duvvurue2557872014-04-21 15:38:00 +05301061 if (rss_flags == adapter->rss_info.rss_flags)
Suresh Reddy594ad542013-04-25 23:03:20 +00001062 return status;
1063
1064 if (be_multi_rxq(adapter)) {
1065 for (j = 0; j < 128; j += adapter->num_rx_qs - 1) {
1066 for_all_rss_queues(adapter, rxo, i) {
1067 if ((j + i) >= 128)
1068 break;
1069 rsstable[j + i] = rxo->rss_id;
1070 }
1071 }
1072 }
Venkata Duvvurue2557872014-04-21 15:38:00 +05301073
1074 status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
1075 rss_flags, 128, adapter->rss_info.rss_hkey);
Suresh Reddy594ad542013-04-25 23:03:20 +00001076 if (!status)
Venkata Duvvurue2557872014-04-21 15:38:00 +05301077 adapter->rss_info.rss_flags = rss_flags;
Suresh Reddy594ad542013-04-25 23:03:20 +00001078
Kalesh AP0532d4e2014-07-17 16:20:23 +05301079 return be_cmd_status(status);
Suresh Reddy594ad542013-04-25 23:03:20 +00001080}
1081
1082static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1083{
1084 struct be_adapter *adapter = netdev_priv(netdev);
1085 int status = 0;
1086
1087 if (!be_multi_rxq(adapter)) {
1088 dev_err(&adapter->pdev->dev,
1089 "ethtool::set_rxnfc: RX flow hashing is disabled\n");
1090 return -EINVAL;
1091 }
1092
1093 switch (cmd->cmd) {
1094 case ETHTOOL_SRXFH:
1095 status = be_set_rss_hash_opts(adapter, cmd);
1096 break;
1097 default:
1098 return -EINVAL;
1099 }
1100
1101 return status;
1102}
1103
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301104static void be_get_channels(struct net_device *netdev,
1105 struct ethtool_channels *ch)
1106{
1107 struct be_adapter *adapter = netdev_priv(netdev);
1108
1109 ch->combined_count = adapter->num_evt_qs;
1110 ch->max_combined = be_max_qs(adapter);
1111}
1112
1113static int be_set_channels(struct net_device *netdev,
1114 struct ethtool_channels *ch)
1115{
1116 struct be_adapter *adapter = netdev_priv(netdev);
Kalesh AP0532d4e2014-07-17 16:20:23 +05301117 int status;
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301118
1119 if (ch->rx_count || ch->tx_count || ch->other_count ||
1120 !ch->combined_count || ch->combined_count > be_max_qs(adapter))
1121 return -EINVAL;
1122
1123 adapter->cfg_num_qs = ch->combined_count;
1124
Kalesh AP0532d4e2014-07-17 16:20:23 +05301125 status = be_update_queues(adapter);
1126 return be_cmd_status(status);
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301127}
1128
Venkata Duvvurue2557872014-04-21 15:38:00 +05301129static u32 be_get_rxfh_indir_size(struct net_device *netdev)
1130{
1131 return RSS_INDIR_TABLE_LEN;
1132}
1133
1134static u32 be_get_rxfh_key_size(struct net_device *netdev)
1135{
1136 return RSS_HASH_KEY_LEN;
1137}
1138
1139static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey)
1140{
1141 struct be_adapter *adapter = netdev_priv(netdev);
1142 int i;
1143 struct rss_info *rss = &adapter->rss_info;
1144
1145 if (indir) {
1146 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
1147 indir[i] = rss->rss_queue[i];
1148 }
1149
1150 if (hkey)
1151 memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
1152
1153 return 0;
1154}
1155
Ben Hutchings33cb0fa2014-05-15 02:01:23 +01001156static int be_set_rxfh(struct net_device *netdev, const u32 *indir,
1157 const u8 *hkey)
Venkata Duvvurue2557872014-04-21 15:38:00 +05301158{
1159 int rc = 0, i, j;
1160 struct be_adapter *adapter = netdev_priv(netdev);
1161 u8 rsstable[RSS_INDIR_TABLE_LEN];
1162
1163 if (indir) {
1164 struct be_rx_obj *rxo;
1165 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
1166 j = indir[i];
1167 rxo = &adapter->rx_obj[j];
1168 rsstable[i] = rxo->rss_id;
1169 adapter->rss_info.rss_queue[i] = j;
1170 }
1171 } else {
1172 memcpy(rsstable, adapter->rss_info.rsstable,
1173 RSS_INDIR_TABLE_LEN);
1174 }
1175
1176 if (!hkey)
1177 hkey = adapter->rss_info.rss_hkey;
1178
1179 rc = be_cmd_rss_config(adapter, rsstable,
1180 adapter->rss_info.rss_flags,
1181 RSS_INDIR_TABLE_LEN, hkey);
1182 if (rc) {
1183 adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
1184 return -EIO;
1185 }
1186 memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
1187 memcpy(adapter->rss_info.rsstable, rsstable,
1188 RSS_INDIR_TABLE_LEN);
1189 return 0;
1190}
1191
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001192const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001193 .get_settings = be_get_settings,
1194 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001195 .get_wol = be_get_wol,
1196 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001197 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001198 .get_eeprom_len = be_get_eeprom_len,
1199 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001200 .get_coalesce = be_get_coalesce,
1201 .set_coalesce = be_set_coalesce,
1202 .get_ringparam = be_get_ringparam,
1203 .get_pauseparam = be_get_pauseparam,
1204 .set_pauseparam = be_set_pauseparam,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001205 .get_strings = be_get_stat_strings,
stephen hemminger1a642462011-04-04 11:06:40 +00001206 .set_phys_id = be_set_phys_id,
Somnath Kotur5c510812013-05-30 02:52:23 +00001207 .set_dump = be_set_dump,
Somnath Kotur941a77d2012-05-17 22:59:03 +00001208 .get_msglevel = be_get_msg_level,
1209 .set_msglevel = be_set_msg_level,
Ben Hutchings15f0a392009-10-01 11:58:24 +00001210 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001211 .get_ethtool_stats = be_get_ethtool_stats,
Somnath Kotur311fddc2011-03-16 21:22:43 +00001212 .get_regs_len = be_get_reg_len,
1213 .get_regs = be_get_regs,
Ajit Khaparde84517482009-09-04 03:12:16 +00001214 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -08001215 .self_test = be_self_test,
Suresh Reddy594ad542013-04-25 23:03:20 +00001216 .get_rxnfc = be_get_rxnfc,
1217 .set_rxnfc = be_set_rxnfc,
Venkata Duvvurue2557872014-04-21 15:38:00 +05301218 .get_rxfh_indir_size = be_get_rxfh_indir_size,
1219 .get_rxfh_key_size = be_get_rxfh_key_size,
1220 .get_rxfh = be_get_rxfh,
1221 .set_rxfh = be_set_rxfh,
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301222 .get_channels = be_get_channels,
1223 .set_channels = be_set_channels
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001224};