blob: 6f3494e41511f67918c68e550a70d355ad99bc2f [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)},
81 {DRVSTAT_INFO(rx_input_fifo_overflow_drop)},
82 {DRVSTAT_INFO(rx_ip_checksum_errs)},
83 {DRVSTAT_INFO(rx_tcp_checksum_errs)},
84 {DRVSTAT_INFO(rx_udp_checksum_errs)},
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000085 {DRVSTAT_INFO(tx_pauseframes)},
86 {DRVSTAT_INFO(tx_controlframes)},
87 {DRVSTAT_INFO(rx_priority_pause_frames)},
Ajit Khapardeb5adffc42013-05-01 09:38:00 +000088 {DRVSTAT_INFO(tx_priority_pauseframes)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000089 /* Received packets dropped when an internal fifo going into
90 * main packet buffer tank (PMEM) overflows.
91 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000092 {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
93 {DRVSTAT_INFO(jabber_events)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000094 /* Received packets dropped due to lack of available HW packet buffers
95 * used to temporarily hold the received packets.
96 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000097 {DRVSTAT_INFO(rx_drops_no_pbuf)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000098 /* Received packets dropped due to input receive buffer
99 * descriptor fifo overflowing.
100 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000101 {DRVSTAT_INFO(rx_drops_no_erx_descr)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000102 /* Packets dropped because the internal FIFO to the offloaded TCP
103 * receive processing block is full. This could happen only for
104 * offloaded iSCSI or FCoE trarffic.
105 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000106 {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000107 /* Received packets dropped when they need more than 8
108 * receive buffers. This cannot happen as the driver configures
109 * 2048 byte receive buffers.
110 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000111 {DRVSTAT_INFO(rx_drops_too_many_frags)},
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000112 {DRVSTAT_INFO(forwarded_packets)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000113 /* Received packets dropped when the frame length
114 * is more than 9018 bytes
115 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000116 {DRVSTAT_INFO(rx_drops_mtu)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000117 /* Number of packets dropped due to random early drop function */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000118 {DRVSTAT_INFO(eth_red_drops)},
Ajit Khaparde461ae372013-10-03 16:16:50 -0500119 {DRVSTAT_INFO(be_on_die_temperature)},
120 {DRVSTAT_INFO(rx_roce_bytes_lsd)},
121 {DRVSTAT_INFO(rx_roce_bytes_msd)},
122 {DRVSTAT_INFO(rx_roce_frames)},
123 {DRVSTAT_INFO(roce_drops_payload_len)},
124 {DRVSTAT_INFO(roce_drops_crc)}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700125};
126#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
127
Sathya Perlaab1594e2011-07-25 19:10:15 +0000128/* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
129 * are first and second members respectively.
130 */
Sathya Perla3abcded2010-10-03 22:12:27 -0700131static const struct be_ethtool_stat et_rx_stats[] = {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000132 {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
133 {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
Sathya Perla3abcded2010-10-03 22:12:27 -0700134 {DRVSTAT_RX_INFO(rx_compl)},
135 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000136 /* Number of page allocation failures while posting receive buffers
137 * to HW.
138 */
Sathya Perla3abcded2010-10-03 22:12:27 -0700139 {DRVSTAT_RX_INFO(rx_post_fail)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000140 /* Recevied packets dropped due to skb allocation failure */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000141 {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000142 /* Received packets dropped due to lack of available fetched buffers
143 * posted by the driver.
144 */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000145 {DRVSTAT_RX_INFO(rx_drops_no_frags)}
Sathya Perla3abcded2010-10-03 22:12:27 -0700146};
147#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
148
Sathya Perlaab1594e2011-07-25 19:10:15 +0000149/* Stats related to multi TX queues: get_stats routine assumes compl is the
150 * first member
151 */
Sathya Perla3c8def92011-06-12 20:01:58 +0000152static const struct be_ethtool_stat et_tx_stats[] = {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000153 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000154 {DRVSTAT_TX_INFO(tx_bytes)},
155 {DRVSTAT_TX_INFO(tx_pkts)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000156 /* Number of skbs queued for trasmission by the driver */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000157 {DRVSTAT_TX_INFO(tx_reqs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000158 /* Number of TX work request blocks DMAed to HW */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000159 {DRVSTAT_TX_INFO(tx_wrbs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000160 /* Number of times the TX queue was stopped due to lack
161 * of spaces in the TXQ.
162 */
Sathya Perlabc617522013-10-01 16:00:01 +0530163 {DRVSTAT_TX_INFO(tx_stops)},
164 /* Pkts dropped in the driver's transmit path */
165 {DRVSTAT_TX_INFO(tx_drv_drops)}
Sathya Perla3c8def92011-06-12 20:01:58 +0000166};
167#define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
168
Suresh Rff33a6e2009-12-03 16:15:52 -0800169static const char et_self_tests[][ETH_GSTRING_LEN] = {
170 "MAC Loopback test",
171 "PHY Loopback test",
172 "External Loopback test",
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000173 "DDR DMA test",
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000174 "Link test"
Suresh Rff33a6e2009-12-03 16:15:52 -0800175};
176
177#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
178#define BE_MAC_LOOPBACK 0x0
179#define BE_PHY_LOOPBACK 0x1
180#define BE_ONE_PORT_EXT_LOOPBACK 0x2
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000181#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800182
Sathya Perla04b71172011-09-27 13:30:27 -0400183static void be_get_drvinfo(struct net_device *netdev,
184 struct ethtool_drvinfo *drvinfo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700185{
186 struct be_adapter *adapter = netdev_priv(netdev);
187
Rick Jones68aad782011-11-07 13:29:27 +0000188 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
189 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
Somnath Kotureeb65ce2013-05-26 21:08:36 +0000190 if (!memcmp(adapter->fw_ver, adapter->fw_on_flash, FW_VER_LEN))
Jiri Pirko7826d432013-01-06 00:44:26 +0000191 strlcpy(drvinfo->fw_version, adapter->fw_ver,
192 sizeof(drvinfo->fw_version));
193 else
194 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
Somnath Kotureeb65ce2013-05-26 21:08:36 +0000195 "%s [%s]", adapter->fw_ver, adapter->fw_on_flash);
Sathya Perla04b71172011-09-27 13:30:27 -0400196
Rick Jones68aad782011-11-07 13:29:27 +0000197 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
198 sizeof(drvinfo->bus_info));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700199 drvinfo->testinfo_len = 0;
200 drvinfo->regdump_len = 0;
201 drvinfo->eedump_len = 0;
202}
203
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000204static u32
205lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
206{
207 u32 data_read = 0, eof;
208 u8 addn_status;
209 struct be_dma_mem data_len_cmd;
210 int status;
211
212 memset(&data_len_cmd, 0, sizeof(data_len_cmd));
213 /* data_offset and data_size should be 0 to get reg len */
214 status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
215 file_name, &data_read, &eof, &addn_status);
216
217 return data_read;
218}
219
220static int
221lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
222 u32 buf_len, void *buf)
223{
224 struct be_dma_mem read_cmd;
225 u32 read_len = 0, total_read_len = 0, chunk_size;
226 u32 eof = 0;
227 u8 addn_status;
228 int status = 0;
229
230 read_cmd.size = LANCER_READ_FILE_CHUNK;
231 read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
232 &read_cmd.dma);
233
234 if (!read_cmd.va) {
235 dev_err(&adapter->pdev->dev,
236 "Memory allocation failure while reading dump\n");
237 return -ENOMEM;
238 }
239
240 while ((total_read_len < buf_len) && !eof) {
241 chunk_size = min_t(u32, (buf_len - total_read_len),
242 LANCER_READ_FILE_CHUNK);
243 chunk_size = ALIGN(chunk_size, 4);
244 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
245 total_read_len, file_name, &read_len,
246 &eof, &addn_status);
247 if (!status) {
248 memcpy(buf + total_read_len, read_cmd.va, read_len);
249 total_read_len += read_len;
250 eof &= LANCER_READ_FILE_EOF_MASK;
251 } else {
252 status = -EIO;
253 break;
254 }
255 }
256 pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
257 read_cmd.dma);
258
259 return status;
260}
261
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700262static int
Somnath Kotur311fddc2011-03-16 21:22:43 +0000263be_get_reg_len(struct net_device *netdev)
264{
265 struct be_adapter *adapter = netdev_priv(netdev);
266 u32 log_size = 0;
267
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +0000268 if (!check_privilege(adapter, MAX_PRIVILEGES))
269 return 0;
270
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000271 if (be_physfn(adapter)) {
272 if (lancer_chip(adapter))
273 log_size = lancer_cmd_get_file_len(adapter,
274 LANCER_FW_DUMP_FILE);
275 else
276 be_cmd_get_reg_len(adapter, &log_size);
277 }
Somnath Kotur311fddc2011-03-16 21:22:43 +0000278 return log_size;
279}
280
281static void
282be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
283{
284 struct be_adapter *adapter = netdev_priv(netdev);
285
Ajit Khaparde16a871e2011-04-19 12:10:43 +0000286 if (be_physfn(adapter)) {
287 memset(buf, 0, regs->len);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000288 if (lancer_chip(adapter))
289 lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
290 regs->len, buf);
291 else
292 be_cmd_get_regs(adapter, regs->len, buf);
Ajit Khaparde16a871e2011-04-19 12:10:43 +0000293 }
Somnath Kotur311fddc2011-03-16 21:22:43 +0000294}
295
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000296static int be_get_coalesce(struct net_device *netdev,
297 struct ethtool_coalesce *et)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700298{
299 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla2632baf2013-10-01 16:00:00 +0530300 struct be_aic_obj *aic = &adapter->aic_obj[0];
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700301
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700302
Sathya Perla2632baf2013-10-01 16:00:00 +0530303 et->rx_coalesce_usecs = aic->prev_eqd;
304 et->rx_coalesce_usecs_high = aic->max_eqd;
305 et->rx_coalesce_usecs_low = aic->min_eqd;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700306
Sathya Perla2632baf2013-10-01 16:00:00 +0530307 et->tx_coalesce_usecs = aic->prev_eqd;
308 et->tx_coalesce_usecs_high = aic->max_eqd;
309 et->tx_coalesce_usecs_low = aic->min_eqd;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000310
Sathya Perla2632baf2013-10-01 16:00:00 +0530311 et->use_adaptive_rx_coalesce = aic->enable;
312 et->use_adaptive_tx_coalesce = aic->enable;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700313
314 return 0;
315}
316
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000317/* TX attributes are ignored. Only RX attributes are considered
318 * eqd cmd is issued in the worker thread.
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700319 */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000320static int be_set_coalesce(struct net_device *netdev,
321 struct ethtool_coalesce *et)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700322{
323 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla2632baf2013-10-01 16:00:00 +0530324 struct be_aic_obj *aic = &adapter->aic_obj[0];
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000325 struct be_eq_obj *eqo;
326 int i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700327
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000328 for_all_evt_queues(adapter, eqo, i) {
Sathya Perla2632baf2013-10-01 16:00:00 +0530329 aic->enable = et->use_adaptive_rx_coalesce;
330 aic->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
331 aic->min_eqd = min(et->rx_coalesce_usecs_low, aic->max_eqd);
332 aic->et_eqd = min(et->rx_coalesce_usecs, aic->max_eqd);
333 aic->et_eqd = max(aic->et_eqd, aic->min_eqd);
334 aic++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700335 }
336
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700337 return 0;
338}
339
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700340static void
341be_get_ethtool_stats(struct net_device *netdev,
342 struct ethtool_stats *stats, uint64_t *data)
343{
344 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700345 struct be_rx_obj *rxo;
Sathya Perla3c8def92011-06-12 20:01:58 +0000346 struct be_tx_obj *txo;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000347 void *p;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000348 unsigned int i, j, base = 0, start;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700349
350 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
Sathya Perlaac124ff2011-07-25 19:10:14 +0000351 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000352 data[i] = *(u32 *)p;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700353 }
Sathya Perlaab1594e2011-07-25 19:10:15 +0000354 base += ETHTOOL_STATS_NUM;
Sathya Perla3abcded2010-10-03 22:12:27 -0700355
356 for_all_rx_queues(adapter, rxo, j) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000357 struct be_rx_stats *stats = rx_stats(rxo);
358
359 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700360 start = u64_stats_fetch_begin_irq(&stats->sync);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000361 data[base] = stats->rx_bytes;
362 data[base + 1] = stats->rx_pkts;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700363 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000364
365 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
366 p = (u8 *)stats + et_rx_stats[i].offset;
367 data[base + i] = *(u32 *)p;
Sathya Perla3abcded2010-10-03 22:12:27 -0700368 }
Sathya Perlaab1594e2011-07-25 19:10:15 +0000369 base += ETHTOOL_RXSTATS_NUM;
Sathya Perla3abcded2010-10-03 22:12:27 -0700370 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000371
Sathya Perla3c8def92011-06-12 20:01:58 +0000372 for_all_tx_queues(adapter, txo, j) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000373 struct be_tx_stats *stats = tx_stats(txo);
374
375 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700376 start = u64_stats_fetch_begin_irq(&stats->sync_compl);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000377 data[base] = stats->tx_compl;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700378 } while (u64_stats_fetch_retry_irq(&stats->sync_compl, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000379
380 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700381 start = u64_stats_fetch_begin_irq(&stats->sync);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000382 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
383 p = (u8 *)stats + et_tx_stats[i].offset;
384 data[base + i] =
385 (et_tx_stats[i].size == sizeof(u64)) ?
386 *(u64 *)p : *(u32 *)p;
387 }
Eric W. Biederman57a77442014-03-13 21:26:42 -0700388 } while (u64_stats_fetch_retry_irq(&stats->sync, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000389 base += ETHTOOL_TXSTATS_NUM;
Sathya Perla3c8def92011-06-12 20:01:58 +0000390 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700391}
392
393static void
394be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
395 uint8_t *data)
396{
Sathya Perla3abcded2010-10-03 22:12:27 -0700397 struct be_adapter *adapter = netdev_priv(netdev);
398 int i, j;
399
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700400 switch (stringset) {
401 case ETH_SS_STATS:
402 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
403 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
404 data += ETH_GSTRING_LEN;
405 }
Sathya Perla3abcded2010-10-03 22:12:27 -0700406 for (i = 0; i < adapter->num_rx_qs; i++) {
407 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
408 sprintf(data, "rxq%d: %s", i,
409 et_rx_stats[j].desc);
410 data += ETH_GSTRING_LEN;
411 }
412 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000413 for (i = 0; i < adapter->num_tx_qs; i++) {
414 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
415 sprintf(data, "txq%d: %s", i,
416 et_tx_stats[j].desc);
417 data += ETH_GSTRING_LEN;
418 }
419 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700420 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800421 case ETH_SS_TEST:
422 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
423 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
424 data += ETH_GSTRING_LEN;
425 }
426 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700427 }
428}
429
Ben Hutchings15f0a392009-10-01 11:58:24 +0000430static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700431{
Sathya Perla3abcded2010-10-03 22:12:27 -0700432 struct be_adapter *adapter = netdev_priv(netdev);
433
Ben Hutchings15f0a392009-10-01 11:58:24 +0000434 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800435 case ETH_SS_TEST:
436 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000437 case ETH_SS_STATS:
Sathya Perla3abcded2010-10-03 22:12:27 -0700438 return ETHTOOL_STATS_NUM +
Sathya Perla3c8def92011-06-12 20:01:58 +0000439 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
440 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000441 default:
442 return -EINVAL;
443 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700444}
445
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000446static u32 be_get_port_type(u32 phy_type, u32 dac_cable_len)
447{
448 u32 port;
449
450 switch (phy_type) {
451 case PHY_TYPE_BASET_1GB:
452 case PHY_TYPE_BASEX_1GB:
453 case PHY_TYPE_SGMII:
454 port = PORT_TP;
455 break;
456 case PHY_TYPE_SFP_PLUS_10GB:
457 port = dac_cable_len ? PORT_DA : PORT_FIBRE;
458 break;
459 case PHY_TYPE_XFP_10GB:
460 case PHY_TYPE_SFP_1GB:
461 port = PORT_FIBRE;
462 break;
463 case PHY_TYPE_BASET_10GB:
464 port = PORT_TP;
465 break;
466 default:
467 port = PORT_OTHER;
468 }
469
470 return port;
471}
472
473static u32 convert_to_et_setting(u32 if_type, u32 if_speeds)
474{
475 u32 val = 0;
476
477 switch (if_type) {
478 case PHY_TYPE_BASET_1GB:
479 case PHY_TYPE_BASEX_1GB:
480 case PHY_TYPE_SGMII:
481 val |= SUPPORTED_TP;
482 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
483 val |= SUPPORTED_1000baseT_Full;
484 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
485 val |= SUPPORTED_100baseT_Full;
486 if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
487 val |= SUPPORTED_10baseT_Full;
488 break;
489 case PHY_TYPE_KX4_10GB:
490 val |= SUPPORTED_Backplane;
491 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
492 val |= SUPPORTED_1000baseKX_Full;
493 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
494 val |= SUPPORTED_10000baseKX4_Full;
495 break;
496 case PHY_TYPE_KR_10GB:
497 val |= SUPPORTED_Backplane |
498 SUPPORTED_10000baseKR_Full;
499 break;
500 case PHY_TYPE_SFP_PLUS_10GB:
501 case PHY_TYPE_XFP_10GB:
502 case PHY_TYPE_SFP_1GB:
503 val |= SUPPORTED_FIBRE;
504 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
505 val |= SUPPORTED_10000baseT_Full;
506 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
507 val |= SUPPORTED_1000baseT_Full;
508 break;
509 case PHY_TYPE_BASET_10GB:
510 val |= SUPPORTED_TP;
511 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
512 val |= SUPPORTED_10000baseT_Full;
513 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
514 val |= SUPPORTED_1000baseT_Full;
515 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
516 val |= SUPPORTED_100baseT_Full;
517 break;
518 default:
519 val |= SUPPORTED_TP;
520 }
521
522 return val;
523}
524
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000525bool be_pause_supported(struct be_adapter *adapter)
526{
527 return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
528 adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
529 false : true;
530}
531
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700532static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
533{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700534 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000535 u8 link_status;
Sathya Perla323ff712012-09-28 04:39:43 +0000536 u16 link_speed = 0;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000537 int status;
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000538 u32 auto_speeds;
539 u32 fixed_speeds;
540 u32 dac_cable_len;
541 u16 interface_type;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700542
Sathya Perla323ff712012-09-28 04:39:43 +0000543 if (adapter->phy.link_speed < 0) {
544 status = be_cmd_link_status_query(adapter, &link_speed,
545 &link_status, 0);
546 if (!status)
547 be_link_status_update(adapter, link_status);
548 ethtool_cmd_speed_set(ecmd, link_speed);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000549
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000550 status = be_cmd_get_phy_info(adapter);
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000551 if (!status) {
552 interface_type = adapter->phy.interface_type;
553 auto_speeds = adapter->phy.auto_speeds_supported;
554 fixed_speeds = adapter->phy.fixed_speeds_supported;
555 dac_cable_len = adapter->phy.dac_cable_len;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000556
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000557 ecmd->supported =
558 convert_to_et_setting(interface_type,
559 auto_speeds |
560 fixed_speeds);
561 ecmd->advertising =
562 convert_to_et_setting(interface_type,
563 auto_speeds);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000564
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000565 ecmd->port = be_get_port_type(interface_type,
566 dac_cable_len);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000567
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000568 if (adapter->phy.auto_speeds_supported) {
569 ecmd->supported |= SUPPORTED_Autoneg;
570 ecmd->autoneg = AUTONEG_ENABLE;
571 ecmd->advertising |= ADVERTISED_Autoneg;
572 }
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000573
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000574 ecmd->supported |= SUPPORTED_Pause;
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000575 if (be_pause_supported(adapter))
576 ecmd->advertising |= ADVERTISED_Pause;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000577
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000578 switch (adapter->phy.interface_type) {
579 case PHY_TYPE_KR_10GB:
580 case PHY_TYPE_KX4_10GB:
581 ecmd->transceiver = XCVR_INTERNAL;
582 break;
583 default:
584 ecmd->transceiver = XCVR_EXTERNAL;
585 break;
586 }
587 } else {
588 ecmd->port = PORT_OTHER;
589 ecmd->autoneg = AUTONEG_DISABLE;
590 ecmd->transceiver = XCVR_DUMMY1;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700591 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000592
593 /* Save for future use */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000594 adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
595 adapter->phy.port_type = ecmd->port;
596 adapter->phy.transceiver = ecmd->transceiver;
597 adapter->phy.autoneg = ecmd->autoneg;
598 adapter->phy.advertising = ecmd->advertising;
599 adapter->phy.supported = ecmd->supported;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000600 } else {
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000601 ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
602 ecmd->port = adapter->phy.port_type;
603 ecmd->transceiver = adapter->phy.transceiver;
604 ecmd->autoneg = adapter->phy.autoneg;
605 ecmd->advertising = adapter->phy.advertising;
606 ecmd->supported = adapter->phy.supported;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700607 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000608
Somnath Kotur682256d2012-05-02 03:40:32 +0000609 ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700610 ecmd->phy_address = adapter->port_num;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000611
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700612 return 0;
613}
614
Sathya Perla110b82b2011-12-13 00:58:49 +0000615static void be_get_ringparam(struct net_device *netdev,
616 struct ethtool_ringparam *ring)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700617{
618 struct be_adapter *adapter = netdev_priv(netdev);
619
Sathya Perla110b82b2011-12-13 00:58:49 +0000620 ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len;
621 ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700622}
623
624static void
625be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
626{
627 struct be_adapter *adapter = netdev_priv(netdev);
628
Sathya Perla8788fdc2009-07-27 22:52:03 +0000629 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000630 ecmd->autoneg = adapter->phy.fc_autoneg;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700631}
632
633static int
634be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
635{
636 struct be_adapter *adapter = netdev_priv(netdev);
637 int status;
638
Padmanabh Ratnakarc871c5f2012-07-12 03:56:11 +0000639 if (ecmd->autoneg != adapter->phy.fc_autoneg)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700640 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000641 adapter->tx_fc = ecmd->tx_pause;
642 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700643
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000644 status = be_cmd_set_flow_control(adapter,
645 adapter->tx_fc, adapter->rx_fc);
646 if (status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700647 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
648
649 return status;
650}
651
Ajit Khaparde84517482009-09-04 03:12:16 +0000652static int
stephen hemminger1a642462011-04-04 11:06:40 +0000653be_set_phys_id(struct net_device *netdev,
654 enum ethtool_phys_id_state state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700655{
656 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700657
stephen hemminger1a642462011-04-04 11:06:40 +0000658 switch (state) {
659 case ETHTOOL_ID_ACTIVE:
660 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
661 &adapter->beacon_state);
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000662 return 1; /* cycle on/off once per second */
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700663
stephen hemminger1a642462011-04-04 11:06:40 +0000664 case ETHTOOL_ID_ON:
665 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
666 BEACON_STATE_ENABLED);
667 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700668
stephen hemminger1a642462011-04-04 11:06:40 +0000669 case ETHTOOL_ID_OFF:
670 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
671 BEACON_STATE_DISABLED);
672 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700673
stephen hemminger1a642462011-04-04 11:06:40 +0000674 case ETHTOOL_ID_INACTIVE:
675 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
676 adapter->beacon_state);
677 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700678
stephen hemminger1a642462011-04-04 11:06:40 +0000679 return 0;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700680}
681
Somnath Kotur5c510812013-05-30 02:52:23 +0000682static int be_set_dump(struct net_device *netdev, struct ethtool_dump *dump)
683{
684 struct be_adapter *adapter = netdev_priv(netdev);
685 struct device *dev = &adapter->pdev->dev;
686 int status;
687
688 if (!lancer_chip(adapter)) {
689 dev_err(dev, "FW dump not supported\n");
690 return -EOPNOTSUPP;
691 }
692
693 if (dump_present(adapter)) {
694 dev_err(dev, "Previous dump not cleared, not forcing dump\n");
695 return 0;
696 }
697
698 switch (dump->flag) {
699 case LANCER_INITIATE_FW_DUMP:
700 status = lancer_initiate_dump(adapter);
701 if (!status)
702 dev_info(dev, "F/w dump initiated successfully\n");
703 break;
704 default:
705 dev_err(dev, "Invalid dump level: 0x%x\n", dump->flag);
706 return -EINVAL;
707 }
708 return status;
709}
Ajit Khapardedcf96f12011-02-11 13:39:30 +0000710
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000711static void
712be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
713{
714 struct be_adapter *adapter = netdev_priv(netdev);
715
Suresh Reddy76a9e082014-01-15 13:23:40 +0530716 if (adapter->wol_cap & BE_WOL_CAP) {
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000717 wol->supported |= WAKE_MAGIC;
Suresh Reddy76a9e082014-01-15 13:23:40 +0530718 if (adapter->wol_en)
Sarveshwar Bandib4243322013-04-25 00:56:56 +0000719 wol->wolopts |= WAKE_MAGIC;
Suresh Reddy76a9e082014-01-15 13:23:40 +0530720 } else {
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000721 wol->wolopts = 0;
Suresh Reddy76a9e082014-01-15 13:23:40 +0530722 }
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000723 memset(&wol->sopass, 0, sizeof(wol->sopass));
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000724}
725
726static int
727be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
728{
729 struct be_adapter *adapter = netdev_priv(netdev);
730
731 if (wol->wolopts & ~WAKE_MAGIC)
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000732 return -EOPNOTSUPP;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000733
Suresh Reddy76a9e082014-01-15 13:23:40 +0530734 if (!(adapter->wol_cap & BE_WOL_CAP)) {
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000735 dev_warn(&adapter->pdev->dev, "WOL not supported\n");
736 return -EOPNOTSUPP;
737 }
738
739 if (wol->wolopts & WAKE_MAGIC)
Suresh Reddy76a9e082014-01-15 13:23:40 +0530740 adapter->wol_en = true;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000741 else
Suresh Reddy76a9e082014-01-15 13:23:40 +0530742 adapter->wol_en = false;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000743
744 return 0;
745}
746
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700747static int
Suresh Rff33a6e2009-12-03 16:15:52 -0800748be_test_ddr_dma(struct be_adapter *adapter)
749{
750 int ret, i;
751 struct be_dma_mem ddrdma_cmd;
Joe Perches215faf92010-12-21 02:16:10 -0800752 static const u64 pattern[2] = {
753 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
754 };
Suresh Rff33a6e2009-12-03 16:15:52 -0800755
756 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000757 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
758 &ddrdma_cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +0000759 if (!ddrdma_cmd.va)
Suresh Rff33a6e2009-12-03 16:15:52 -0800760 return -ENOMEM;
Suresh Rff33a6e2009-12-03 16:15:52 -0800761
762 for (i = 0; i < 2; i++) {
763 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
764 4096, &ddrdma_cmd);
765 if (ret != 0)
766 goto err;
767 }
768
769err:
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000770 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
771 ddrdma_cmd.dma);
Suresh Rff33a6e2009-12-03 16:15:52 -0800772 return ret;
773}
774
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000775static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
776 u64 *status)
777{
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000778 be_cmd_set_loopback(adapter, adapter->hba_port_num,
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000779 loopback_type, 1);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000780 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000781 loopback_type, 1500,
782 2, 0xabc);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000783 be_cmd_set_loopback(adapter, adapter->hba_port_num,
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000784 BE_NO_LOOPBACK, 1);
785 return *status;
786}
787
Suresh Rff33a6e2009-12-03 16:15:52 -0800788static void
789be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
790{
791 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla323ff712012-09-28 04:39:43 +0000792 int status;
793 u8 link_status = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800794
Suresh Reddy78d0b112013-04-25 23:03:22 +0000795 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
796 dev_err(&adapter->pdev->dev, "Self test not supported\n");
797 test->flags |= ETH_TEST_FL_FAILED;
798 return;
799 }
800
Suresh Rff33a6e2009-12-03 16:15:52 -0800801 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
802
803 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000804 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
Ivan Vecera5a8a1ab2014-03-05 11:54:05 +0100805 &data[0]) != 0)
Suresh Rff33a6e2009-12-03 16:15:52 -0800806 test->flags |= ETH_TEST_FL_FAILED;
Ivan Vecera5a8a1ab2014-03-05 11:54:05 +0100807
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000808 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
Ivan Vecera5a8a1ab2014-03-05 11:54:05 +0100809 &data[1]) != 0)
Suresh Rff33a6e2009-12-03 16:15:52 -0800810 test->flags |= ETH_TEST_FL_FAILED;
Ivan Vecera5a8a1ab2014-03-05 11:54:05 +0100811
812 if (test->flags & ETH_TEST_FL_EXTERNAL_LB) {
813 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
814 &data[2]) != 0)
815 test->flags |= ETH_TEST_FL_FAILED;
816 test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000817 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000818 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800819
Padmanabh Ratnakara7047392012-04-25 01:46:28 +0000820 if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000821 data[3] = 1;
822 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800823 }
824
Sathya Perla323ff712012-09-28 04:39:43 +0000825 status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
826 if (status) {
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000827 test->flags |= ETH_TEST_FL_FAILED;
828 data[4] = -1;
Sathya Perla323ff712012-09-28 04:39:43 +0000829 } else if (!link_status) {
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000830 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000831 data[4] = 1;
832 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800833}
834
835static int
Ajit Khaparde84517482009-09-04 03:12:16 +0000836be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
837{
838 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde84517482009-09-04 03:12:16 +0000839
Ben Hutchings786f5282012-02-01 09:32:25 +0000840 return be_load_fw(adapter, efl->data);
Ajit Khaparde84517482009-09-04 03:12:16 +0000841}
842
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800843static int
844be_get_eeprom_len(struct net_device *netdev)
845{
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000846 struct be_adapter *adapter = netdev_priv(netdev);
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +0000847
848 if (!check_privilege(adapter, MAX_PRIVILEGES))
849 return 0;
850
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000851 if (lancer_chip(adapter)) {
852 if (be_physfn(adapter))
853 return lancer_cmd_get_file_len(adapter,
854 LANCER_VPD_PF_FILE);
855 else
856 return lancer_cmd_get_file_len(adapter,
857 LANCER_VPD_VF_FILE);
858 } else {
859 return BE_READ_SEEPROM_LEN;
860 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800861}
862
863static int
864be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
865 uint8_t *data)
866{
867 struct be_adapter *adapter = netdev_priv(netdev);
868 struct be_dma_mem eeprom_cmd;
869 struct be_cmd_resp_seeprom_read *resp;
870 int status;
871
872 if (!eeprom->len)
873 return -EINVAL;
874
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000875 if (lancer_chip(adapter)) {
876 if (be_physfn(adapter))
877 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
878 eeprom->len, data);
879 else
880 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
881 eeprom->len, data);
882 }
883
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800884 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
885
886 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
887 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000888 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
889 &eeprom_cmd.dma, GFP_KERNEL);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800890
Joe Perchesd0320f72013-03-14 13:07:21 +0000891 if (!eeprom_cmd.va)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800892 return -ENOMEM;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800893
894 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
895
896 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +0000897 resp = eeprom_cmd.va;
Ajit Khapardec0ad9842010-02-08 17:51:26 +0000898 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800899 }
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000900 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
901 eeprom_cmd.dma);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800902
903 return status;
904}
905
Somnath Kotur941a77d2012-05-17 22:59:03 +0000906static u32 be_get_msg_level(struct net_device *netdev)
907{
908 struct be_adapter *adapter = netdev_priv(netdev);
909
Somnath Kotur941a77d2012-05-17 22:59:03 +0000910 return adapter->msg_enable;
911}
912
Somnath Kotur941a77d2012-05-17 22:59:03 +0000913static void be_set_msg_level(struct net_device *netdev, u32 level)
914{
915 struct be_adapter *adapter = netdev_priv(netdev);
916
Somnath Kotur941a77d2012-05-17 22:59:03 +0000917 if (adapter->msg_enable == level)
918 return;
919
920 if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
Vasundhara Volambaaa08d2014-01-15 13:23:34 +0530921 if (BEx_chip(adapter))
922 be_cmd_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
923 FW_LOG_LEVEL_DEFAULT :
924 FW_LOG_LEVEL_FATAL);
Somnath Kotur941a77d2012-05-17 22:59:03 +0000925 adapter->msg_enable = level;
926
927 return;
928}
929
Suresh Reddy594ad542013-04-25 23:03:20 +0000930static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
931{
932 u64 data = 0;
933
934 switch (flow_type) {
935 case TCP_V4_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +0530936 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +0000937 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +0530938 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +0000939 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
940 break;
941 case UDP_V4_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +0530942 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +0000943 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +0530944 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV4)
Suresh Reddy594ad542013-04-25 23:03:20 +0000945 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
946 break;
947 case TCP_V6_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +0530948 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +0000949 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +0530950 if (adapter->rss_info.rss_flags & RSS_ENABLE_TCP_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +0000951 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
952 break;
953 case UDP_V6_FLOW:
Venkata Duvvurue2557872014-04-21 15:38:00 +0530954 if (adapter->rss_info.rss_flags & RSS_ENABLE_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +0000955 data |= RXH_IP_DST | RXH_IP_SRC;
Venkata Duvvurue2557872014-04-21 15:38:00 +0530956 if (adapter->rss_info.rss_flags & RSS_ENABLE_UDP_IPV6)
Suresh Reddy594ad542013-04-25 23:03:20 +0000957 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
958 break;
959 }
960
961 return data;
962}
963
964static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
965 u32 *rule_locs)
966{
967 struct be_adapter *adapter = netdev_priv(netdev);
968
969 if (!be_multi_rxq(adapter)) {
970 dev_info(&adapter->pdev->dev,
971 "ethtool::get_rxnfc: RX flow hashing is disabled\n");
972 return -EINVAL;
973 }
974
975 switch (cmd->cmd) {
976 case ETHTOOL_GRXFH:
977 cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
978 break;
979 case ETHTOOL_GRXRINGS:
980 cmd->data = adapter->num_rx_qs - 1;
981 break;
982 default:
983 return -EINVAL;
984 }
985
986 return 0;
987}
988
989static int be_set_rss_hash_opts(struct be_adapter *adapter,
990 struct ethtool_rxnfc *cmd)
991{
992 struct be_rx_obj *rxo;
993 int status = 0, i, j;
994 u8 rsstable[128];
Venkata Duvvurue2557872014-04-21 15:38:00 +0530995 u32 rss_flags = adapter->rss_info.rss_flags;
Suresh Reddy594ad542013-04-25 23:03:20 +0000996
997 if (cmd->data != L3_RSS_FLAGS &&
998 cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
999 return -EINVAL;
1000
1001 switch (cmd->flow_type) {
1002 case TCP_V4_FLOW:
1003 if (cmd->data == L3_RSS_FLAGS)
1004 rss_flags &= ~RSS_ENABLE_TCP_IPV4;
1005 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1006 rss_flags |= RSS_ENABLE_IPV4 |
1007 RSS_ENABLE_TCP_IPV4;
1008 break;
1009 case TCP_V6_FLOW:
1010 if (cmd->data == L3_RSS_FLAGS)
1011 rss_flags &= ~RSS_ENABLE_TCP_IPV6;
1012 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1013 rss_flags |= RSS_ENABLE_IPV6 |
1014 RSS_ENABLE_TCP_IPV6;
1015 break;
1016 case UDP_V4_FLOW:
1017 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1018 BEx_chip(adapter))
1019 return -EINVAL;
1020
1021 if (cmd->data == L3_RSS_FLAGS)
1022 rss_flags &= ~RSS_ENABLE_UDP_IPV4;
1023 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1024 rss_flags |= RSS_ENABLE_IPV4 |
1025 RSS_ENABLE_UDP_IPV4;
1026 break;
1027 case UDP_V6_FLOW:
1028 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1029 BEx_chip(adapter))
1030 return -EINVAL;
1031
1032 if (cmd->data == L3_RSS_FLAGS)
1033 rss_flags &= ~RSS_ENABLE_UDP_IPV6;
1034 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1035 rss_flags |= RSS_ENABLE_IPV6 |
1036 RSS_ENABLE_UDP_IPV6;
1037 break;
1038 default:
1039 return -EINVAL;
1040 }
1041
Venkata Duvvurue2557872014-04-21 15:38:00 +05301042 if (rss_flags == adapter->rss_info.rss_flags)
Suresh Reddy594ad542013-04-25 23:03:20 +00001043 return status;
1044
1045 if (be_multi_rxq(adapter)) {
1046 for (j = 0; j < 128; j += adapter->num_rx_qs - 1) {
1047 for_all_rss_queues(adapter, rxo, i) {
1048 if ((j + i) >= 128)
1049 break;
1050 rsstable[j + i] = rxo->rss_id;
1051 }
1052 }
1053 }
Venkata Duvvurue2557872014-04-21 15:38:00 +05301054
1055 status = be_cmd_rss_config(adapter, adapter->rss_info.rsstable,
1056 rss_flags, 128, adapter->rss_info.rss_hkey);
Suresh Reddy594ad542013-04-25 23:03:20 +00001057 if (!status)
Venkata Duvvurue2557872014-04-21 15:38:00 +05301058 adapter->rss_info.rss_flags = rss_flags;
Suresh Reddy594ad542013-04-25 23:03:20 +00001059
1060 return status;
1061}
1062
1063static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1064{
1065 struct be_adapter *adapter = netdev_priv(netdev);
1066 int status = 0;
1067
1068 if (!be_multi_rxq(adapter)) {
1069 dev_err(&adapter->pdev->dev,
1070 "ethtool::set_rxnfc: RX flow hashing is disabled\n");
1071 return -EINVAL;
1072 }
1073
1074 switch (cmd->cmd) {
1075 case ETHTOOL_SRXFH:
1076 status = be_set_rss_hash_opts(adapter, cmd);
1077 break;
1078 default:
1079 return -EINVAL;
1080 }
1081
1082 return status;
1083}
1084
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301085static void be_get_channels(struct net_device *netdev,
1086 struct ethtool_channels *ch)
1087{
1088 struct be_adapter *adapter = netdev_priv(netdev);
1089
1090 ch->combined_count = adapter->num_evt_qs;
1091 ch->max_combined = be_max_qs(adapter);
1092}
1093
1094static int be_set_channels(struct net_device *netdev,
1095 struct ethtool_channels *ch)
1096{
1097 struct be_adapter *adapter = netdev_priv(netdev);
1098
1099 if (ch->rx_count || ch->tx_count || ch->other_count ||
1100 !ch->combined_count || ch->combined_count > be_max_qs(adapter))
1101 return -EINVAL;
1102
1103 adapter->cfg_num_qs = ch->combined_count;
1104
1105 return be_update_queues(adapter);
1106}
1107
Venkata Duvvurue2557872014-04-21 15:38:00 +05301108static u32 be_get_rxfh_indir_size(struct net_device *netdev)
1109{
1110 return RSS_INDIR_TABLE_LEN;
1111}
1112
1113static u32 be_get_rxfh_key_size(struct net_device *netdev)
1114{
1115 return RSS_HASH_KEY_LEN;
1116}
1117
1118static int be_get_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey)
1119{
1120 struct be_adapter *adapter = netdev_priv(netdev);
1121 int i;
1122 struct rss_info *rss = &adapter->rss_info;
1123
1124 if (indir) {
1125 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++)
1126 indir[i] = rss->rss_queue[i];
1127 }
1128
1129 if (hkey)
1130 memcpy(hkey, rss->rss_hkey, RSS_HASH_KEY_LEN);
1131
1132 return 0;
1133}
1134
1135static int be_set_rxfh(struct net_device *netdev, u32 *indir, u8 *hkey)
1136{
1137 int rc = 0, i, j;
1138 struct be_adapter *adapter = netdev_priv(netdev);
1139 u8 rsstable[RSS_INDIR_TABLE_LEN];
1140
1141 if (indir) {
1142 struct be_rx_obj *rxo;
1143 for (i = 0; i < RSS_INDIR_TABLE_LEN; i++) {
1144 j = indir[i];
1145 rxo = &adapter->rx_obj[j];
1146 rsstable[i] = rxo->rss_id;
1147 adapter->rss_info.rss_queue[i] = j;
1148 }
1149 } else {
1150 memcpy(rsstable, adapter->rss_info.rsstable,
1151 RSS_INDIR_TABLE_LEN);
1152 }
1153
1154 if (!hkey)
1155 hkey = adapter->rss_info.rss_hkey;
1156
1157 rc = be_cmd_rss_config(adapter, rsstable,
1158 adapter->rss_info.rss_flags,
1159 RSS_INDIR_TABLE_LEN, hkey);
1160 if (rc) {
1161 adapter->rss_info.rss_flags = RSS_ENABLE_NONE;
1162 return -EIO;
1163 }
1164 memcpy(adapter->rss_info.rss_hkey, hkey, RSS_HASH_KEY_LEN);
1165 memcpy(adapter->rss_info.rsstable, rsstable,
1166 RSS_INDIR_TABLE_LEN);
1167 return 0;
1168}
1169
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001170const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001171 .get_settings = be_get_settings,
1172 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001173 .get_wol = be_get_wol,
1174 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001175 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001176 .get_eeprom_len = be_get_eeprom_len,
1177 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001178 .get_coalesce = be_get_coalesce,
1179 .set_coalesce = be_set_coalesce,
1180 .get_ringparam = be_get_ringparam,
1181 .get_pauseparam = be_get_pauseparam,
1182 .set_pauseparam = be_set_pauseparam,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001183 .get_strings = be_get_stat_strings,
stephen hemminger1a642462011-04-04 11:06:40 +00001184 .set_phys_id = be_set_phys_id,
Somnath Kotur5c510812013-05-30 02:52:23 +00001185 .set_dump = be_set_dump,
Somnath Kotur941a77d2012-05-17 22:59:03 +00001186 .get_msglevel = be_get_msg_level,
1187 .set_msglevel = be_set_msg_level,
Ben Hutchings15f0a392009-10-01 11:58:24 +00001188 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001189 .get_ethtool_stats = be_get_ethtool_stats,
Somnath Kotur311fddc2011-03-16 21:22:43 +00001190 .get_regs_len = be_get_reg_len,
1191 .get_regs = be_get_regs,
Ajit Khaparde84517482009-09-04 03:12:16 +00001192 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -08001193 .self_test = be_self_test,
Suresh Reddy594ad542013-04-25 23:03:20 +00001194 .get_rxnfc = be_get_rxnfc,
1195 .set_rxnfc = be_set_rxnfc,
Venkata Duvvurue2557872014-04-21 15:38:00 +05301196 .get_rxfh_indir_size = be_get_rxfh_indir_size,
1197 .get_rxfh_key_size = be_get_rxfh_key_size,
1198 .get_rxfh = be_get_rxfh,
1199 .set_rxfh = be_set_rxfh,
Sathya Perla68d7bdc2013-08-27 16:57:35 +05301200 .get_channels = be_get_channels,
1201 .set_channels = be_set_channels
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001202};