blob: ec3050b3133e3946ea3d9062d8fdb611a4b13e79 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Vasundhara Volamc7bb15a2013-03-06 20:05:05 +00002 * Copyright (C) 2005 - 2013 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)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000088 /* Received packets dropped when an internal fifo going into
89 * main packet buffer tank (PMEM) overflows.
90 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000091 {DRVSTAT_INFO(pmem_fifo_overflow_drop)},
92 {DRVSTAT_INFO(jabber_events)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000093 /* Received packets dropped due to lack of available HW packet buffers
94 * used to temporarily hold the received packets.
95 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000096 {DRVSTAT_INFO(rx_drops_no_pbuf)},
Sathya Perlad45b9d32012-01-29 20:17:39 +000097 /* Received packets dropped due to input receive buffer
98 * descriptor fifo overflowing.
99 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000100 {DRVSTAT_INFO(rx_drops_no_erx_descr)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000101 /* Packets dropped because the internal FIFO to the offloaded TCP
102 * receive processing block is full. This could happen only for
103 * offloaded iSCSI or FCoE trarffic.
104 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000105 {DRVSTAT_INFO(rx_drops_no_tpre_descr)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000106 /* Received packets dropped when they need more than 8
107 * receive buffers. This cannot happen as the driver configures
108 * 2048 byte receive buffers.
109 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000110 {DRVSTAT_INFO(rx_drops_too_many_frags)},
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000111 {DRVSTAT_INFO(forwarded_packets)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000112 /* Received packets dropped when the frame length
113 * is more than 9018 bytes
114 */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000115 {DRVSTAT_INFO(rx_drops_mtu)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000116 /* Number of packets dropped due to random early drop function */
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000117 {DRVSTAT_INFO(eth_red_drops)},
Ajit Khaparde609ff3b2011-02-20 11:42:07 +0000118 {DRVSTAT_INFO(be_on_die_temperature)}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700119};
120#define ETHTOOL_STATS_NUM ARRAY_SIZE(et_stats)
121
Sathya Perlaab1594e2011-07-25 19:10:15 +0000122/* Stats related to multi RX queues: get_stats routine assumes bytes, pkts
123 * are first and second members respectively.
124 */
Sathya Perla3abcded2010-10-03 22:12:27 -0700125static const struct be_ethtool_stat et_rx_stats[] = {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000126 {DRVSTAT_RX_INFO(rx_bytes)},/* If moving this member see above note */
127 {DRVSTAT_RX_INFO(rx_pkts)}, /* If moving this member see above note */
Sathya Perla3abcded2010-10-03 22:12:27 -0700128 {DRVSTAT_RX_INFO(rx_compl)},
129 {DRVSTAT_RX_INFO(rx_mcast_pkts)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000130 /* Number of page allocation failures while posting receive buffers
131 * to HW.
132 */
Sathya Perla3abcded2010-10-03 22:12:27 -0700133 {DRVSTAT_RX_INFO(rx_post_fail)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000134 /* Recevied packets dropped due to skb allocation failure */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000135 {DRVSTAT_RX_INFO(rx_drops_no_skbs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000136 /* Received packets dropped due to lack of available fetched buffers
137 * posted by the driver.
138 */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000139 {DRVSTAT_RX_INFO(rx_drops_no_frags)}
Sathya Perla3abcded2010-10-03 22:12:27 -0700140};
141#define ETHTOOL_RXSTATS_NUM (ARRAY_SIZE(et_rx_stats))
142
Sathya Perlaab1594e2011-07-25 19:10:15 +0000143/* Stats related to multi TX queues: get_stats routine assumes compl is the
144 * first member
145 */
Sathya Perla3c8def92011-06-12 20:01:58 +0000146static const struct be_ethtool_stat et_tx_stats[] = {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000147 {DRVSTAT_TX_INFO(tx_compl)}, /* If moving this member see above note */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000148 {DRVSTAT_TX_INFO(tx_bytes)},
149 {DRVSTAT_TX_INFO(tx_pkts)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000150 /* Number of skbs queued for trasmission by the driver */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000151 {DRVSTAT_TX_INFO(tx_reqs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000152 /* Number of TX work request blocks DMAed to HW */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000153 {DRVSTAT_TX_INFO(tx_wrbs)},
Sathya Perlad45b9d32012-01-29 20:17:39 +0000154 /* Number of times the TX queue was stopped due to lack
155 * of spaces in the TXQ.
156 */
Sathya Perlaac124ff2011-07-25 19:10:14 +0000157 {DRVSTAT_TX_INFO(tx_stops)}
Sathya Perla3c8def92011-06-12 20:01:58 +0000158};
159#define ETHTOOL_TXSTATS_NUM (ARRAY_SIZE(et_tx_stats))
160
Suresh Rff33a6e2009-12-03 16:15:52 -0800161static const char et_self_tests[][ETH_GSTRING_LEN] = {
162 "MAC Loopback test",
163 "PHY Loopback test",
164 "External Loopback test",
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000165 "DDR DMA test",
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000166 "Link test"
Suresh Rff33a6e2009-12-03 16:15:52 -0800167};
168
169#define ETHTOOL_TESTS_NUM ARRAY_SIZE(et_self_tests)
170#define BE_MAC_LOOPBACK 0x0
171#define BE_PHY_LOOPBACK 0x1
172#define BE_ONE_PORT_EXT_LOOPBACK 0x2
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000173#define BE_NO_LOOPBACK 0xff
Suresh Rff33a6e2009-12-03 16:15:52 -0800174
Sathya Perla04b71172011-09-27 13:30:27 -0400175static void be_get_drvinfo(struct net_device *netdev,
176 struct ethtool_drvinfo *drvinfo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700177{
178 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla04b71172011-09-27 13:30:27 -0400179 char fw_on_flash[FW_VER_LEN];
180
181 memset(fw_on_flash, 0 , sizeof(fw_on_flash));
182 be_cmd_get_fw_ver(adapter, adapter->fw_ver, fw_on_flash);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700183
Rick Jones68aad782011-11-07 13:29:27 +0000184 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
185 strlcpy(drvinfo->version, DRV_VER, sizeof(drvinfo->version));
Jiri Pirko7826d432013-01-06 00:44:26 +0000186 if (!memcmp(adapter->fw_ver, fw_on_flash, FW_VER_LEN))
187 strlcpy(drvinfo->fw_version, adapter->fw_ver,
188 sizeof(drvinfo->fw_version));
189 else
190 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
191 "%s [%s]", adapter->fw_ver, fw_on_flash);
Sathya Perla04b71172011-09-27 13:30:27 -0400192
Rick Jones68aad782011-11-07 13:29:27 +0000193 strlcpy(drvinfo->bus_info, pci_name(adapter->pdev),
194 sizeof(drvinfo->bus_info));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700195 drvinfo->testinfo_len = 0;
196 drvinfo->regdump_len = 0;
197 drvinfo->eedump_len = 0;
198}
199
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000200static u32
201lancer_cmd_get_file_len(struct be_adapter *adapter, u8 *file_name)
202{
203 u32 data_read = 0, eof;
204 u8 addn_status;
205 struct be_dma_mem data_len_cmd;
206 int status;
207
208 memset(&data_len_cmd, 0, sizeof(data_len_cmd));
209 /* data_offset and data_size should be 0 to get reg len */
210 status = lancer_cmd_read_object(adapter, &data_len_cmd, 0, 0,
211 file_name, &data_read, &eof, &addn_status);
212
213 return data_read;
214}
215
216static int
217lancer_cmd_read_file(struct be_adapter *adapter, u8 *file_name,
218 u32 buf_len, void *buf)
219{
220 struct be_dma_mem read_cmd;
221 u32 read_len = 0, total_read_len = 0, chunk_size;
222 u32 eof = 0;
223 u8 addn_status;
224 int status = 0;
225
226 read_cmd.size = LANCER_READ_FILE_CHUNK;
227 read_cmd.va = pci_alloc_consistent(adapter->pdev, read_cmd.size,
228 &read_cmd.dma);
229
230 if (!read_cmd.va) {
231 dev_err(&adapter->pdev->dev,
232 "Memory allocation failure while reading dump\n");
233 return -ENOMEM;
234 }
235
236 while ((total_read_len < buf_len) && !eof) {
237 chunk_size = min_t(u32, (buf_len - total_read_len),
238 LANCER_READ_FILE_CHUNK);
239 chunk_size = ALIGN(chunk_size, 4);
240 status = lancer_cmd_read_object(adapter, &read_cmd, chunk_size,
241 total_read_len, file_name, &read_len,
242 &eof, &addn_status);
243 if (!status) {
244 memcpy(buf + total_read_len, read_cmd.va, read_len);
245 total_read_len += read_len;
246 eof &= LANCER_READ_FILE_EOF_MASK;
247 } else {
248 status = -EIO;
249 break;
250 }
251 }
252 pci_free_consistent(adapter->pdev, read_cmd.size, read_cmd.va,
253 read_cmd.dma);
254
255 return status;
256}
257
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700258static int
Somnath Kotur311fddc2011-03-16 21:22:43 +0000259be_get_reg_len(struct net_device *netdev)
260{
261 struct be_adapter *adapter = netdev_priv(netdev);
262 u32 log_size = 0;
263
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +0000264 if (!check_privilege(adapter, MAX_PRIVILEGES))
265 return 0;
266
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000267 if (be_physfn(adapter)) {
268 if (lancer_chip(adapter))
269 log_size = lancer_cmd_get_file_len(adapter,
270 LANCER_FW_DUMP_FILE);
271 else
272 be_cmd_get_reg_len(adapter, &log_size);
273 }
Somnath Kotur311fddc2011-03-16 21:22:43 +0000274 return log_size;
275}
276
277static void
278be_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *buf)
279{
280 struct be_adapter *adapter = netdev_priv(netdev);
281
Ajit Khaparde16a871e2011-04-19 12:10:43 +0000282 if (be_physfn(adapter)) {
283 memset(buf, 0, regs->len);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +0000284 if (lancer_chip(adapter))
285 lancer_cmd_read_file(adapter, LANCER_FW_DUMP_FILE,
286 regs->len, buf);
287 else
288 be_cmd_get_regs(adapter, regs->len, buf);
Ajit Khaparde16a871e2011-04-19 12:10:43 +0000289 }
Somnath Kotur311fddc2011-03-16 21:22:43 +0000290}
291
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000292static int be_get_coalesce(struct net_device *netdev,
293 struct ethtool_coalesce *et)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700294{
295 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000296 struct be_eq_obj *eqo = &adapter->eq_obj[0];
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700297
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700298
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000299 et->rx_coalesce_usecs = eqo->cur_eqd;
300 et->rx_coalesce_usecs_high = eqo->max_eqd;
301 et->rx_coalesce_usecs_low = eqo->min_eqd;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700302
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000303 et->tx_coalesce_usecs = eqo->cur_eqd;
304 et->tx_coalesce_usecs_high = eqo->max_eqd;
305 et->tx_coalesce_usecs_low = eqo->min_eqd;
306
307 et->use_adaptive_rx_coalesce = eqo->enable_aic;
308 et->use_adaptive_tx_coalesce = eqo->enable_aic;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700309
310 return 0;
311}
312
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000313/* TX attributes are ignored. Only RX attributes are considered
314 * eqd cmd is issued in the worker thread.
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700315 */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000316static int be_set_coalesce(struct net_device *netdev,
317 struct ethtool_coalesce *et)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700318{
319 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000320 struct be_eq_obj *eqo;
321 int i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700322
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000323 for_all_evt_queues(adapter, eqo, i) {
324 eqo->enable_aic = et->use_adaptive_rx_coalesce;
325 eqo->max_eqd = min(et->rx_coalesce_usecs_high, BE_MAX_EQD);
326 eqo->min_eqd = min(et->rx_coalesce_usecs_low, eqo->max_eqd);
327 eqo->eqd = et->rx_coalesce_usecs;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700328 }
329
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700330 return 0;
331}
332
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700333static void
334be_get_ethtool_stats(struct net_device *netdev,
335 struct ethtool_stats *stats, uint64_t *data)
336{
337 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla3abcded2010-10-03 22:12:27 -0700338 struct be_rx_obj *rxo;
Sathya Perla3c8def92011-06-12 20:01:58 +0000339 struct be_tx_obj *txo;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000340 void *p;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000341 unsigned int i, j, base = 0, start;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700342
343 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
Sathya Perlaac124ff2011-07-25 19:10:14 +0000344 p = (u8 *)&adapter->drv_stats + et_stats[i].offset;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000345 data[i] = *(u32 *)p;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700346 }
Sathya Perlaab1594e2011-07-25 19:10:15 +0000347 base += ETHTOOL_STATS_NUM;
Sathya Perla3abcded2010-10-03 22:12:27 -0700348
349 for_all_rx_queues(adapter, rxo, j) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000350 struct be_rx_stats *stats = rx_stats(rxo);
351
352 do {
353 start = u64_stats_fetch_begin_bh(&stats->sync);
354 data[base] = stats->rx_bytes;
355 data[base + 1] = stats->rx_pkts;
356 } while (u64_stats_fetch_retry_bh(&stats->sync, start));
357
358 for (i = 2; i < ETHTOOL_RXSTATS_NUM; i++) {
359 p = (u8 *)stats + et_rx_stats[i].offset;
360 data[base + i] = *(u32 *)p;
Sathya Perla3abcded2010-10-03 22:12:27 -0700361 }
Sathya Perlaab1594e2011-07-25 19:10:15 +0000362 base += ETHTOOL_RXSTATS_NUM;
Sathya Perla3abcded2010-10-03 22:12:27 -0700363 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000364
Sathya Perla3c8def92011-06-12 20:01:58 +0000365 for_all_tx_queues(adapter, txo, j) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000366 struct be_tx_stats *stats = tx_stats(txo);
367
368 do {
369 start = u64_stats_fetch_begin_bh(&stats->sync_compl);
370 data[base] = stats->tx_compl;
371 } while (u64_stats_fetch_retry_bh(&stats->sync_compl, start));
372
373 do {
374 start = u64_stats_fetch_begin_bh(&stats->sync);
375 for (i = 1; i < ETHTOOL_TXSTATS_NUM; i++) {
376 p = (u8 *)stats + et_tx_stats[i].offset;
377 data[base + i] =
378 (et_tx_stats[i].size == sizeof(u64)) ?
379 *(u64 *)p : *(u32 *)p;
380 }
381 } while (u64_stats_fetch_retry_bh(&stats->sync, start));
382 base += ETHTOOL_TXSTATS_NUM;
Sathya Perla3c8def92011-06-12 20:01:58 +0000383 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700384}
385
386static void
387be_get_stat_strings(struct net_device *netdev, uint32_t stringset,
388 uint8_t *data)
389{
Sathya Perla3abcded2010-10-03 22:12:27 -0700390 struct be_adapter *adapter = netdev_priv(netdev);
391 int i, j;
392
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700393 switch (stringset) {
394 case ETH_SS_STATS:
395 for (i = 0; i < ETHTOOL_STATS_NUM; i++) {
396 memcpy(data, et_stats[i].desc, ETH_GSTRING_LEN);
397 data += ETH_GSTRING_LEN;
398 }
Sathya Perla3abcded2010-10-03 22:12:27 -0700399 for (i = 0; i < adapter->num_rx_qs; i++) {
400 for (j = 0; j < ETHTOOL_RXSTATS_NUM; j++) {
401 sprintf(data, "rxq%d: %s", i,
402 et_rx_stats[j].desc);
403 data += ETH_GSTRING_LEN;
404 }
405 }
Sathya Perla3c8def92011-06-12 20:01:58 +0000406 for (i = 0; i < adapter->num_tx_qs; i++) {
407 for (j = 0; j < ETHTOOL_TXSTATS_NUM; j++) {
408 sprintf(data, "txq%d: %s", i,
409 et_tx_stats[j].desc);
410 data += ETH_GSTRING_LEN;
411 }
412 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700413 break;
Suresh Rff33a6e2009-12-03 16:15:52 -0800414 case ETH_SS_TEST:
415 for (i = 0; i < ETHTOOL_TESTS_NUM; i++) {
416 memcpy(data, et_self_tests[i], ETH_GSTRING_LEN);
417 data += ETH_GSTRING_LEN;
418 }
419 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700420 }
421}
422
Ben Hutchings15f0a392009-10-01 11:58:24 +0000423static int be_get_sset_count(struct net_device *netdev, int stringset)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700424{
Sathya Perla3abcded2010-10-03 22:12:27 -0700425 struct be_adapter *adapter = netdev_priv(netdev);
426
Ben Hutchings15f0a392009-10-01 11:58:24 +0000427 switch (stringset) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800428 case ETH_SS_TEST:
429 return ETHTOOL_TESTS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000430 case ETH_SS_STATS:
Sathya Perla3abcded2010-10-03 22:12:27 -0700431 return ETHTOOL_STATS_NUM +
Sathya Perla3c8def92011-06-12 20:01:58 +0000432 adapter->num_rx_qs * ETHTOOL_RXSTATS_NUM +
433 adapter->num_tx_qs * ETHTOOL_TXSTATS_NUM;
Ben Hutchings15f0a392009-10-01 11:58:24 +0000434 default:
435 return -EINVAL;
436 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700437}
438
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000439static u32 be_get_port_type(u32 phy_type, u32 dac_cable_len)
440{
441 u32 port;
442
443 switch (phy_type) {
444 case PHY_TYPE_BASET_1GB:
445 case PHY_TYPE_BASEX_1GB:
446 case PHY_TYPE_SGMII:
447 port = PORT_TP;
448 break;
449 case PHY_TYPE_SFP_PLUS_10GB:
450 port = dac_cable_len ? PORT_DA : PORT_FIBRE;
451 break;
452 case PHY_TYPE_XFP_10GB:
453 case PHY_TYPE_SFP_1GB:
454 port = PORT_FIBRE;
455 break;
456 case PHY_TYPE_BASET_10GB:
457 port = PORT_TP;
458 break;
459 default:
460 port = PORT_OTHER;
461 }
462
463 return port;
464}
465
466static u32 convert_to_et_setting(u32 if_type, u32 if_speeds)
467{
468 u32 val = 0;
469
470 switch (if_type) {
471 case PHY_TYPE_BASET_1GB:
472 case PHY_TYPE_BASEX_1GB:
473 case PHY_TYPE_SGMII:
474 val |= SUPPORTED_TP;
475 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
476 val |= SUPPORTED_1000baseT_Full;
477 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
478 val |= SUPPORTED_100baseT_Full;
479 if (if_speeds & BE_SUPPORTED_SPEED_10MBPS)
480 val |= SUPPORTED_10baseT_Full;
481 break;
482 case PHY_TYPE_KX4_10GB:
483 val |= SUPPORTED_Backplane;
484 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
485 val |= SUPPORTED_1000baseKX_Full;
486 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
487 val |= SUPPORTED_10000baseKX4_Full;
488 break;
489 case PHY_TYPE_KR_10GB:
490 val |= SUPPORTED_Backplane |
491 SUPPORTED_10000baseKR_Full;
492 break;
493 case PHY_TYPE_SFP_PLUS_10GB:
494 case PHY_TYPE_XFP_10GB:
495 case PHY_TYPE_SFP_1GB:
496 val |= SUPPORTED_FIBRE;
497 if (if_speeds & BE_SUPPORTED_SPEED_10GBPS)
498 val |= SUPPORTED_10000baseT_Full;
499 if (if_speeds & BE_SUPPORTED_SPEED_1GBPS)
500 val |= SUPPORTED_1000baseT_Full;
501 break;
502 case PHY_TYPE_BASET_10GB:
503 val |= SUPPORTED_TP;
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 if (if_speeds & BE_SUPPORTED_SPEED_100MBPS)
509 val |= SUPPORTED_100baseT_Full;
510 break;
511 default:
512 val |= SUPPORTED_TP;
513 }
514
515 return val;
516}
517
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000518bool be_pause_supported(struct be_adapter *adapter)
519{
520 return (adapter->phy.interface_type == PHY_TYPE_SFP_PLUS_10GB ||
521 adapter->phy.interface_type == PHY_TYPE_XFP_10GB) ?
522 false : true;
523}
524
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700525static int be_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
526{
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700527 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000528 u8 link_status;
Sathya Perla323ff712012-09-28 04:39:43 +0000529 u16 link_speed = 0;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000530 int status;
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000531 u32 auto_speeds;
532 u32 fixed_speeds;
533 u32 dac_cable_len;
534 u16 interface_type;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700535
Sathya Perla323ff712012-09-28 04:39:43 +0000536 if (adapter->phy.link_speed < 0) {
537 status = be_cmd_link_status_query(adapter, &link_speed,
538 &link_status, 0);
539 if (!status)
540 be_link_status_update(adapter, link_status);
541 ethtool_cmd_speed_set(ecmd, link_speed);
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000542
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000543 status = be_cmd_get_phy_info(adapter);
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000544 if (!status) {
545 interface_type = adapter->phy.interface_type;
546 auto_speeds = adapter->phy.auto_speeds_supported;
547 fixed_speeds = adapter->phy.fixed_speeds_supported;
548 dac_cable_len = adapter->phy.dac_cable_len;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000549
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000550 ecmd->supported =
551 convert_to_et_setting(interface_type,
552 auto_speeds |
553 fixed_speeds);
554 ecmd->advertising =
555 convert_to_et_setting(interface_type,
556 auto_speeds);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000557
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000558 ecmd->port = be_get_port_type(interface_type,
559 dac_cable_len);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000560
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000561 if (adapter->phy.auto_speeds_supported) {
562 ecmd->supported |= SUPPORTED_Autoneg;
563 ecmd->autoneg = AUTONEG_ENABLE;
564 ecmd->advertising |= ADVERTISED_Autoneg;
565 }
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000566
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000567 ecmd->supported |= SUPPORTED_Pause;
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000568 if (be_pause_supported(adapter))
569 ecmd->advertising |= ADVERTISED_Pause;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000570
Padmanabh Ratnakardb15dfa2012-10-20 06:03:04 +0000571 switch (adapter->phy.interface_type) {
572 case PHY_TYPE_KR_10GB:
573 case PHY_TYPE_KX4_10GB:
574 ecmd->transceiver = XCVR_INTERNAL;
575 break;
576 default:
577 ecmd->transceiver = XCVR_EXTERNAL;
578 break;
579 }
580 } else {
581 ecmd->port = PORT_OTHER;
582 ecmd->autoneg = AUTONEG_DISABLE;
583 ecmd->transceiver = XCVR_DUMMY1;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700584 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000585
586 /* Save for future use */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000587 adapter->phy.link_speed = ethtool_cmd_speed(ecmd);
588 adapter->phy.port_type = ecmd->port;
589 adapter->phy.transceiver = ecmd->transceiver;
590 adapter->phy.autoneg = ecmd->autoneg;
591 adapter->phy.advertising = ecmd->advertising;
592 adapter->phy.supported = ecmd->supported;
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000593 } else {
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000594 ethtool_cmd_speed_set(ecmd, adapter->phy.link_speed);
595 ecmd->port = adapter->phy.port_type;
596 ecmd->transceiver = adapter->phy.transceiver;
597 ecmd->autoneg = adapter->phy.autoneg;
598 ecmd->advertising = adapter->phy.advertising;
599 ecmd->supported = adapter->phy.supported;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700600 }
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000601
Somnath Kotur682256d2012-05-02 03:40:32 +0000602 ecmd->duplex = netif_carrier_ok(netdev) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700603 ecmd->phy_address = adapter->port_num;
Ajit Khapardeee3cb622010-07-01 03:51:00 +0000604
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700605 return 0;
606}
607
Sathya Perla110b82b2011-12-13 00:58:49 +0000608static void be_get_ringparam(struct net_device *netdev,
609 struct ethtool_ringparam *ring)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700610{
611 struct be_adapter *adapter = netdev_priv(netdev);
612
Sathya Perla110b82b2011-12-13 00:58:49 +0000613 ring->rx_max_pending = ring->rx_pending = adapter->rx_obj[0].q.len;
614 ring->tx_max_pending = ring->tx_pending = adapter->tx_obj[0].q.len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700615}
616
617static void
618be_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
619{
620 struct be_adapter *adapter = netdev_priv(netdev);
621
Sathya Perla8788fdc2009-07-27 22:52:03 +0000622 be_cmd_get_flow_control(adapter, &ecmd->tx_pause, &ecmd->rx_pause);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000623 ecmd->autoneg = adapter->phy.fc_autoneg;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700624}
625
626static int
627be_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *ecmd)
628{
629 struct be_adapter *adapter = netdev_priv(netdev);
630 int status;
631
Padmanabh Ratnakarc871c5f2012-07-12 03:56:11 +0000632 if (ecmd->autoneg != adapter->phy.fc_autoneg)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700633 return -EINVAL;
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000634 adapter->tx_fc = ecmd->tx_pause;
635 adapter->rx_fc = ecmd->rx_pause;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700636
Ajit Khaparde9e90c962009-11-06 02:06:59 +0000637 status = be_cmd_set_flow_control(adapter,
638 adapter->tx_fc, adapter->rx_fc);
639 if (status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700640 dev_warn(&adapter->pdev->dev, "Pause param set failed.\n");
641
642 return status;
643}
644
Ajit Khaparde84517482009-09-04 03:12:16 +0000645static int
stephen hemminger1a642462011-04-04 11:06:40 +0000646be_set_phys_id(struct net_device *netdev,
647 enum ethtool_phys_id_state state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700648{
649 struct be_adapter *adapter = netdev_priv(netdev);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700650
stephen hemminger1a642462011-04-04 11:06:40 +0000651 switch (state) {
652 case ETHTOOL_ID_ACTIVE:
653 be_cmd_get_beacon_state(adapter, adapter->hba_port_num,
654 &adapter->beacon_state);
Allan, Bruce Wfce55922011-04-13 13:09:10 +0000655 return 1; /* cycle on/off once per second */
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700656
stephen hemminger1a642462011-04-04 11:06:40 +0000657 case ETHTOOL_ID_ON:
658 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
659 BEACON_STATE_ENABLED);
660 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700661
stephen hemminger1a642462011-04-04 11:06:40 +0000662 case ETHTOOL_ID_OFF:
663 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
664 BEACON_STATE_DISABLED);
665 break;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700666
stephen hemminger1a642462011-04-04 11:06:40 +0000667 case ETHTOOL_ID_INACTIVE:
668 be_cmd_set_beacon_state(adapter, adapter->hba_port_num, 0, 0,
669 adapter->beacon_state);
670 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700671
stephen hemminger1a642462011-04-04 11:06:40 +0000672 return 0;
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700673}
674
Ajit Khapardedcf96f12011-02-11 13:39:30 +0000675
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000676static void
677be_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
678{
679 struct be_adapter *adapter = netdev_priv(netdev);
680
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000681 if (be_is_wol_supported(adapter)) {
682 wol->supported |= WAKE_MAGIC;
683 wol->wolopts |= WAKE_MAGIC;
684 } else
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000685 wol->wolopts = 0;
686 memset(&wol->sopass, 0, sizeof(wol->sopass));
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000687}
688
689static int
690be_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
691{
692 struct be_adapter *adapter = netdev_priv(netdev);
693
694 if (wol->wolopts & ~WAKE_MAGIC)
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000695 return -EOPNOTSUPP;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000696
Ajit Khaparde4762f6c2012-03-18 06:23:11 +0000697 if (!be_is_wol_supported(adapter)) {
698 dev_warn(&adapter->pdev->dev, "WOL not supported\n");
699 return -EOPNOTSUPP;
700 }
701
702 if (wol->wolopts & WAKE_MAGIC)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +0000703 adapter->wol = true;
704 else
705 adapter->wol = false;
706
707 return 0;
708}
709
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -0700710static int
Suresh Rff33a6e2009-12-03 16:15:52 -0800711be_test_ddr_dma(struct be_adapter *adapter)
712{
713 int ret, i;
714 struct be_dma_mem ddrdma_cmd;
Joe Perches215faf92010-12-21 02:16:10 -0800715 static const u64 pattern[2] = {
716 0x5a5a5a5a5a5a5a5aULL, 0xa5a5a5a5a5a5a5a5ULL
717 };
Suresh Rff33a6e2009-12-03 16:15:52 -0800718
719 ddrdma_cmd.size = sizeof(struct be_cmd_req_ddrdma_test);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000720 ddrdma_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, ddrdma_cmd.size,
721 &ddrdma_cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +0000722 if (!ddrdma_cmd.va)
Suresh Rff33a6e2009-12-03 16:15:52 -0800723 return -ENOMEM;
Suresh Rff33a6e2009-12-03 16:15:52 -0800724
725 for (i = 0; i < 2; i++) {
726 ret = be_cmd_ddr_dma_test(adapter, pattern[i],
727 4096, &ddrdma_cmd);
728 if (ret != 0)
729 goto err;
730 }
731
732err:
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000733 dma_free_coherent(&adapter->pdev->dev, ddrdma_cmd.size, ddrdma_cmd.va,
734 ddrdma_cmd.dma);
Suresh Rff33a6e2009-12-03 16:15:52 -0800735 return ret;
736}
737
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000738static u64 be_loopback_test(struct be_adapter *adapter, u8 loopback_type,
739 u64 *status)
740{
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000741 be_cmd_set_loopback(adapter, adapter->hba_port_num,
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000742 loopback_type, 1);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000743 *status = be_cmd_loopback_test(adapter, adapter->hba_port_num,
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000744 loopback_type, 1500,
745 2, 0xabc);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +0000746 be_cmd_set_loopback(adapter, adapter->hba_port_num,
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000747 BE_NO_LOOPBACK, 1);
748 return *status;
749}
750
Suresh Rff33a6e2009-12-03 16:15:52 -0800751static void
752be_self_test(struct net_device *netdev, struct ethtool_test *test, u64 *data)
753{
754 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla323ff712012-09-28 04:39:43 +0000755 int status;
756 u8 link_status = 0;
Suresh Rff33a6e2009-12-03 16:15:52 -0800757
Suresh Reddy78d0b112013-04-25 23:03:22 +0000758 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) {
759 dev_err(&adapter->pdev->dev, "Self test not supported\n");
760 test->flags |= ETH_TEST_FL_FAILED;
761 return;
762 }
763
Suresh Rff33a6e2009-12-03 16:15:52 -0800764 memset(data, 0, sizeof(u64) * ETHTOOL_TESTS_NUM);
765
766 if (test->flags & ETH_TEST_FL_OFFLINE) {
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000767 if (be_loopback_test(adapter, BE_MAC_LOOPBACK,
768 &data[0]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800769 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000770 }
771 if (be_loopback_test(adapter, BE_PHY_LOOPBACK,
772 &data[1]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800773 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000774 }
775 if (be_loopback_test(adapter, BE_ONE_PORT_EXT_LOOPBACK,
776 &data[2]) != 0) {
Suresh Rff33a6e2009-12-03 16:15:52 -0800777 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandifced9992009-12-23 04:41:44 +0000778 }
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000779 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800780
Padmanabh Ratnakara7047392012-04-25 01:46:28 +0000781 if (!lancer_chip(adapter) && be_test_ddr_dma(adapter) != 0) {
Sarveshwar Bandi8f47afe2010-01-19 05:15:00 +0000782 data[3] = 1;
783 test->flags |= ETH_TEST_FL_FAILED;
Suresh Rff33a6e2009-12-03 16:15:52 -0800784 }
785
Sathya Perla323ff712012-09-28 04:39:43 +0000786 status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
787 if (status) {
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000788 test->flags |= ETH_TEST_FL_FAILED;
789 data[4] = -1;
Sathya Perla323ff712012-09-28 04:39:43 +0000790 } else if (!link_status) {
Ajit Khaparde4ee77212011-02-20 11:41:20 +0000791 test->flags |= ETH_TEST_FL_FAILED;
Sarveshwar Bandi4276e472010-01-19 05:15:36 +0000792 data[4] = 1;
793 }
Suresh Rff33a6e2009-12-03 16:15:52 -0800794}
795
796static int
Ajit Khaparde84517482009-09-04 03:12:16 +0000797be_do_flash(struct net_device *netdev, struct ethtool_flash *efl)
798{
799 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde84517482009-09-04 03:12:16 +0000800
Ben Hutchings786f5282012-02-01 09:32:25 +0000801 return be_load_fw(adapter, efl->data);
Ajit Khaparde84517482009-09-04 03:12:16 +0000802}
803
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800804static int
805be_get_eeprom_len(struct net_device *netdev)
806{
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000807 struct be_adapter *adapter = netdev_priv(netdev);
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +0000808
809 if (!check_privilege(adapter, MAX_PRIVILEGES))
810 return 0;
811
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000812 if (lancer_chip(adapter)) {
813 if (be_physfn(adapter))
814 return lancer_cmd_get_file_len(adapter,
815 LANCER_VPD_PF_FILE);
816 else
817 return lancer_cmd_get_file_len(adapter,
818 LANCER_VPD_VF_FILE);
819 } else {
820 return BE_READ_SEEPROM_LEN;
821 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800822}
823
824static int
825be_read_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
826 uint8_t *data)
827{
828 struct be_adapter *adapter = netdev_priv(netdev);
829 struct be_dma_mem eeprom_cmd;
830 struct be_cmd_resp_seeprom_read *resp;
831 int status;
832
833 if (!eeprom->len)
834 return -EINVAL;
835
Padmanabh Ratnakaraf5875b2011-11-16 02:03:07 +0000836 if (lancer_chip(adapter)) {
837 if (be_physfn(adapter))
838 return lancer_cmd_read_file(adapter, LANCER_VPD_PF_FILE,
839 eeprom->len, data);
840 else
841 return lancer_cmd_read_file(adapter, LANCER_VPD_VF_FILE,
842 eeprom->len, data);
843 }
844
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800845 eeprom->magic = BE_VENDOR_ID | (adapter->pdev->device<<16);
846
847 memset(&eeprom_cmd, 0, sizeof(struct be_dma_mem));
848 eeprom_cmd.size = sizeof(struct be_cmd_req_seeprom_read);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000849 eeprom_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, eeprom_cmd.size,
850 &eeprom_cmd.dma, GFP_KERNEL);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800851
Joe Perchesd0320f72013-03-14 13:07:21 +0000852 if (!eeprom_cmd.va)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800853 return -ENOMEM;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800854
855 status = be_cmd_get_seeprom_data(adapter, &eeprom_cmd);
856
857 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +0000858 resp = eeprom_cmd.va;
Ajit Khapardec0ad9842010-02-08 17:51:26 +0000859 memcpy(data, resp->seeprom_data + eeprom->offset, eeprom->len);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800860 }
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000861 dma_free_coherent(&adapter->pdev->dev, eeprom_cmd.size, eeprom_cmd.va,
862 eeprom_cmd.dma);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -0800863
864 return status;
865}
866
Somnath Kotur941a77d2012-05-17 22:59:03 +0000867static u32 be_get_msg_level(struct net_device *netdev)
868{
869 struct be_adapter *adapter = netdev_priv(netdev);
870
871 if (lancer_chip(adapter)) {
872 dev_err(&adapter->pdev->dev, "Operation not supported\n");
873 return -EOPNOTSUPP;
874 }
875
876 return adapter->msg_enable;
877}
878
879static void be_set_fw_log_level(struct be_adapter *adapter, u32 level)
880{
881 struct be_dma_mem extfat_cmd;
882 struct be_fat_conf_params *cfgs;
883 int status;
884 int i, j;
885
886 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
887 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
888 extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size,
889 &extfat_cmd.dma);
890 if (!extfat_cmd.va) {
891 dev_err(&adapter->pdev->dev, "%s: Memory allocation failure\n",
892 __func__);
893 goto err;
894 }
895 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
896 if (!status) {
897 cfgs = (struct be_fat_conf_params *)(extfat_cmd.va +
898 sizeof(struct be_cmd_resp_hdr));
Anton Blanchardac46a462012-07-24 15:05:25 +0000899 for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) {
900 u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes);
901 for (j = 0; j < num_modes; j++) {
Somnath Kotur941a77d2012-05-17 22:59:03 +0000902 if (cfgs->module[i].trace_lvl[j].mode ==
903 MODE_UART)
904 cfgs->module[i].trace_lvl[j].dbg_lvl =
905 cpu_to_le32(level);
906 }
907 }
908 status = be_cmd_set_ext_fat_capabilites(adapter, &extfat_cmd,
909 cfgs);
910 if (status)
911 dev_err(&adapter->pdev->dev,
912 "Message level set failed\n");
913 } else {
914 dev_err(&adapter->pdev->dev, "Message level get failed\n");
915 }
916
917 pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va,
918 extfat_cmd.dma);
919err:
920 return;
921}
922
923static void be_set_msg_level(struct net_device *netdev, u32 level)
924{
925 struct be_adapter *adapter = netdev_priv(netdev);
926
927 if (lancer_chip(adapter)) {
928 dev_err(&adapter->pdev->dev, "Operation not supported\n");
929 return;
930 }
931
932 if (adapter->msg_enable == level)
933 return;
934
935 if ((level & NETIF_MSG_HW) != (adapter->msg_enable & NETIF_MSG_HW))
936 be_set_fw_log_level(adapter, level & NETIF_MSG_HW ?
937 FW_LOG_LEVEL_DEFAULT : FW_LOG_LEVEL_FATAL);
938 adapter->msg_enable = level;
939
940 return;
941}
942
Suresh Reddy594ad542013-04-25 23:03:20 +0000943static u64 be_get_rss_hash_opts(struct be_adapter *adapter, u64 flow_type)
944{
945 u64 data = 0;
946
947 switch (flow_type) {
948 case TCP_V4_FLOW:
949 if (adapter->rss_flags & RSS_ENABLE_IPV4)
950 data |= RXH_IP_DST | RXH_IP_SRC;
951 if (adapter->rss_flags & RSS_ENABLE_TCP_IPV4)
952 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
953 break;
954 case UDP_V4_FLOW:
955 if (adapter->rss_flags & RSS_ENABLE_IPV4)
956 data |= RXH_IP_DST | RXH_IP_SRC;
957 if (adapter->rss_flags & RSS_ENABLE_UDP_IPV4)
958 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
959 break;
960 case TCP_V6_FLOW:
961 if (adapter->rss_flags & RSS_ENABLE_IPV6)
962 data |= RXH_IP_DST | RXH_IP_SRC;
963 if (adapter->rss_flags & RSS_ENABLE_TCP_IPV6)
964 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
965 break;
966 case UDP_V6_FLOW:
967 if (adapter->rss_flags & RSS_ENABLE_IPV6)
968 data |= RXH_IP_DST | RXH_IP_SRC;
969 if (adapter->rss_flags & RSS_ENABLE_UDP_IPV6)
970 data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
971 break;
972 }
973
974 return data;
975}
976
977static int be_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
978 u32 *rule_locs)
979{
980 struct be_adapter *adapter = netdev_priv(netdev);
981
982 if (!be_multi_rxq(adapter)) {
983 dev_info(&adapter->pdev->dev,
984 "ethtool::get_rxnfc: RX flow hashing is disabled\n");
985 return -EINVAL;
986 }
987
988 switch (cmd->cmd) {
989 case ETHTOOL_GRXFH:
990 cmd->data = be_get_rss_hash_opts(adapter, cmd->flow_type);
991 break;
992 case ETHTOOL_GRXRINGS:
993 cmd->data = adapter->num_rx_qs - 1;
994 break;
995 default:
996 return -EINVAL;
997 }
998
999 return 0;
1000}
1001
1002static int be_set_rss_hash_opts(struct be_adapter *adapter,
1003 struct ethtool_rxnfc *cmd)
1004{
1005 struct be_rx_obj *rxo;
1006 int status = 0, i, j;
1007 u8 rsstable[128];
1008 u32 rss_flags = adapter->rss_flags;
1009
1010 if (cmd->data != L3_RSS_FLAGS &&
1011 cmd->data != (L3_RSS_FLAGS | L4_RSS_FLAGS))
1012 return -EINVAL;
1013
1014 switch (cmd->flow_type) {
1015 case TCP_V4_FLOW:
1016 if (cmd->data == L3_RSS_FLAGS)
1017 rss_flags &= ~RSS_ENABLE_TCP_IPV4;
1018 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1019 rss_flags |= RSS_ENABLE_IPV4 |
1020 RSS_ENABLE_TCP_IPV4;
1021 break;
1022 case TCP_V6_FLOW:
1023 if (cmd->data == L3_RSS_FLAGS)
1024 rss_flags &= ~RSS_ENABLE_TCP_IPV6;
1025 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1026 rss_flags |= RSS_ENABLE_IPV6 |
1027 RSS_ENABLE_TCP_IPV6;
1028 break;
1029 case UDP_V4_FLOW:
1030 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1031 BEx_chip(adapter))
1032 return -EINVAL;
1033
1034 if (cmd->data == L3_RSS_FLAGS)
1035 rss_flags &= ~RSS_ENABLE_UDP_IPV4;
1036 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1037 rss_flags |= RSS_ENABLE_IPV4 |
1038 RSS_ENABLE_UDP_IPV4;
1039 break;
1040 case UDP_V6_FLOW:
1041 if ((cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS)) &&
1042 BEx_chip(adapter))
1043 return -EINVAL;
1044
1045 if (cmd->data == L3_RSS_FLAGS)
1046 rss_flags &= ~RSS_ENABLE_UDP_IPV6;
1047 else if (cmd->data == (L3_RSS_FLAGS | L4_RSS_FLAGS))
1048 rss_flags |= RSS_ENABLE_IPV6 |
1049 RSS_ENABLE_UDP_IPV6;
1050 break;
1051 default:
1052 return -EINVAL;
1053 }
1054
1055 if (rss_flags == adapter->rss_flags)
1056 return status;
1057
1058 if (be_multi_rxq(adapter)) {
1059 for (j = 0; j < 128; j += adapter->num_rx_qs - 1) {
1060 for_all_rss_queues(adapter, rxo, i) {
1061 if ((j + i) >= 128)
1062 break;
1063 rsstable[j + i] = rxo->rss_id;
1064 }
1065 }
1066 }
1067 status = be_cmd_rss_config(adapter, rsstable, rss_flags, 128);
1068 if (!status)
1069 adapter->rss_flags = rss_flags;
1070
1071 return status;
1072}
1073
1074static int be_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1075{
1076 struct be_adapter *adapter = netdev_priv(netdev);
1077 int status = 0;
1078
1079 if (!be_multi_rxq(adapter)) {
1080 dev_err(&adapter->pdev->dev,
1081 "ethtool::set_rxnfc: RX flow hashing is disabled\n");
1082 return -EINVAL;
1083 }
1084
1085 switch (cmd->cmd) {
1086 case ETHTOOL_SRXFH:
1087 status = be_set_rss_hash_opts(adapter, cmd);
1088 break;
1089 default:
1090 return -EINVAL;
1091 }
1092
1093 return status;
1094}
1095
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001096const struct ethtool_ops be_ethtool_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001097 .get_settings = be_get_settings,
1098 .get_drvinfo = be_get_drvinfo,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001099 .get_wol = be_get_wol,
1100 .set_wol = be_set_wol,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001101 .get_link = ethtool_op_get_link,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001102 .get_eeprom_len = be_get_eeprom_len,
1103 .get_eeprom = be_read_eeprom,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001104 .get_coalesce = be_get_coalesce,
1105 .set_coalesce = be_set_coalesce,
1106 .get_ringparam = be_get_ringparam,
1107 .get_pauseparam = be_get_pauseparam,
1108 .set_pauseparam = be_set_pauseparam,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001109 .get_strings = be_get_stat_strings,
stephen hemminger1a642462011-04-04 11:06:40 +00001110 .set_phys_id = be_set_phys_id,
Somnath Kotur941a77d2012-05-17 22:59:03 +00001111 .get_msglevel = be_get_msg_level,
1112 .set_msglevel = be_set_msg_level,
Ben Hutchings15f0a392009-10-01 11:58:24 +00001113 .get_sset_count = be_get_sset_count,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001114 .get_ethtool_stats = be_get_ethtool_stats,
Somnath Kotur311fddc2011-03-16 21:22:43 +00001115 .get_regs_len = be_get_reg_len,
1116 .get_regs = be_get_regs,
Ajit Khaparde84517482009-09-04 03:12:16 +00001117 .flash_device = be_do_flash,
Suresh Rff33a6e2009-12-03 16:15:52 -08001118 .self_test = be_self_test,
Suresh Reddy594ad542013-04-25 23:03:20 +00001119 .get_rxnfc = be_get_rxnfc,
1120 .set_rxnfc = be_set_rxnfc,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001121};