blob: 4dcfe9614731db70d673cc15aec6da26ff673743 [file] [log] [blame]
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001/* QLogic qede NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020032#include <linux/version.h>
33#include <linux/types.h>
34#include <linux/netdevice.h>
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040035#include <linux/etherdevice.h>
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020036#include <linux/ethtool.h>
37#include <linux/string.h>
38#include <linux/pci.h>
39#include <linux/capability.h>
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +020040#include <linux/vmalloc.h>
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020041#include "qede.h"
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +020042#include "qede_ptp.h"
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020043
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020044#define QEDE_RQSTAT_OFFSET(stat_name) \
45 (offsetof(struct qede_rx_queue, stat_name))
46#define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
47#define QEDE_RQSTAT(stat_name) \
48 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040049
50#define QEDE_SELFTEST_POLL_COUNT 100
51
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020052static const struct {
53 u64 offset;
54 char string[ETH_GSTRING_LEN];
55} qede_rqstats_arr[] = {
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040056 QEDE_RQSTAT(rcv_pkts),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020057 QEDE_RQSTAT(rx_hw_errors),
58 QEDE_RQSTAT(rx_alloc_errors),
Manish Choprac72a6122016-06-30 02:35:18 -040059 QEDE_RQSTAT(rx_ip_frags),
Mintz, Yuval496e0512016-11-29 16:47:09 +020060 QEDE_RQSTAT(xdp_no_pass),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020061};
62
63#define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040064#define QEDE_TQSTAT_OFFSET(stat_name) \
65 (offsetof(struct qede_tx_queue, stat_name))
66#define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
67#define QEDE_TQSTAT(stat_name) \
68 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
69#define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
70static const struct {
71 u64 offset;
72 char string[ETH_GSTRING_LEN];
73} qede_tqstats_arr[] = {
74 QEDE_TQSTAT(xmit_pkts),
75 QEDE_TQSTAT(stopped_cnt),
76};
77
Mintz, Yuval9c79dda2017-03-14 16:23:54 +020078#define QEDE_STAT_OFFSET(stat_name, type, base) \
79 (offsetof(type, stat_name) + (base))
80#define QEDE_STAT_STRING(stat_name) (#stat_name)
81#define _QEDE_STAT(stat_name, type, base, attr) \
82 {QEDE_STAT_OFFSET(stat_name, type, base), \
83 QEDE_STAT_STRING(stat_name), \
84 attr}
85#define QEDE_STAT(stat_name) \
86 _QEDE_STAT(stat_name, struct qede_stats_common, 0, 0x0)
87#define QEDE_PF_STAT(stat_name) \
88 _QEDE_STAT(stat_name, struct qede_stats_common, 0, \
89 BIT(QEDE_STAT_PF_ONLY))
90#define QEDE_PF_BB_STAT(stat_name) \
91 _QEDE_STAT(stat_name, struct qede_stats_bb, \
92 offsetof(struct qede_stats, bb), \
93 BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_BB_ONLY))
94#define QEDE_PF_AH_STAT(stat_name) \
95 _QEDE_STAT(stat_name, struct qede_stats_ah, \
96 offsetof(struct qede_stats, ah), \
97 BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_AH_ONLY))
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020098static const struct {
99 u64 offset;
100 char string[ETH_GSTRING_LEN];
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200101 unsigned long attr;
102#define QEDE_STAT_PF_ONLY 0
103#define QEDE_STAT_BB_ONLY 1
104#define QEDE_STAT_AH_ONLY 2
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200105} qede_stats_arr[] = {
106 QEDE_STAT(rx_ucast_bytes),
107 QEDE_STAT(rx_mcast_bytes),
108 QEDE_STAT(rx_bcast_bytes),
109 QEDE_STAT(rx_ucast_pkts),
110 QEDE_STAT(rx_mcast_pkts),
111 QEDE_STAT(rx_bcast_pkts),
112
113 QEDE_STAT(tx_ucast_bytes),
114 QEDE_STAT(tx_mcast_bytes),
115 QEDE_STAT(tx_bcast_bytes),
116 QEDE_STAT(tx_ucast_pkts),
117 QEDE_STAT(tx_mcast_pkts),
118 QEDE_STAT(tx_bcast_pkts),
119
120 QEDE_PF_STAT(rx_64_byte_packets),
Yuval Mintzd4967cf2016-04-22 08:41:01 +0300121 QEDE_PF_STAT(rx_65_to_127_byte_packets),
122 QEDE_PF_STAT(rx_128_to_255_byte_packets),
123 QEDE_PF_STAT(rx_256_to_511_byte_packets),
124 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
125 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200126 QEDE_PF_BB_STAT(rx_1519_to_1522_byte_packets),
127 QEDE_PF_BB_STAT(rx_1519_to_2047_byte_packets),
128 QEDE_PF_BB_STAT(rx_2048_to_4095_byte_packets),
129 QEDE_PF_BB_STAT(rx_4096_to_9216_byte_packets),
130 QEDE_PF_BB_STAT(rx_9217_to_16383_byte_packets),
131 QEDE_PF_AH_STAT(rx_1519_to_max_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200132 QEDE_PF_STAT(tx_64_byte_packets),
133 QEDE_PF_STAT(tx_65_to_127_byte_packets),
134 QEDE_PF_STAT(tx_128_to_255_byte_packets),
135 QEDE_PF_STAT(tx_256_to_511_byte_packets),
136 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
137 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200138 QEDE_PF_BB_STAT(tx_1519_to_2047_byte_packets),
139 QEDE_PF_BB_STAT(tx_2048_to_4095_byte_packets),
140 QEDE_PF_BB_STAT(tx_4096_to_9216_byte_packets),
141 QEDE_PF_BB_STAT(tx_9217_to_16383_byte_packets),
142 QEDE_PF_AH_STAT(tx_1519_to_max_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200143 QEDE_PF_STAT(rx_mac_crtl_frames),
144 QEDE_PF_STAT(tx_mac_ctrl_frames),
145 QEDE_PF_STAT(rx_pause_frames),
146 QEDE_PF_STAT(tx_pause_frames),
147 QEDE_PF_STAT(rx_pfc_frames),
148 QEDE_PF_STAT(tx_pfc_frames),
149
150 QEDE_PF_STAT(rx_crc_errors),
151 QEDE_PF_STAT(rx_align_errors),
152 QEDE_PF_STAT(rx_carrier_errors),
153 QEDE_PF_STAT(rx_oversize_packets),
154 QEDE_PF_STAT(rx_jabbers),
155 QEDE_PF_STAT(rx_undersize_packets),
156 QEDE_PF_STAT(rx_fragments),
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200157 QEDE_PF_BB_STAT(tx_lpi_entry_count),
158 QEDE_PF_BB_STAT(tx_total_collisions),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200159 QEDE_PF_STAT(brb_truncates),
160 QEDE_PF_STAT(brb_discards),
161 QEDE_STAT(no_buff_discards),
162 QEDE_PF_STAT(mftag_filter_discards),
163 QEDE_PF_STAT(mac_filter_discards),
164 QEDE_STAT(tx_err_drop_pkts),
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400165 QEDE_STAT(ttl0_discard),
166 QEDE_STAT(packet_too_big_discard),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200167
168 QEDE_STAT(coalesced_pkts),
169 QEDE_STAT(coalesced_events),
170 QEDE_STAT(coalesced_aborts_num),
171 QEDE_STAT(non_coalesced_pkts),
172 QEDE_STAT(coalesced_bytes),
173};
174
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200175#define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200176#define QEDE_STAT_IS_PF_ONLY(i) \
177 test_bit(QEDE_STAT_PF_ONLY, &qede_stats_arr[i].attr)
178#define QEDE_STAT_IS_BB_ONLY(i) \
179 test_bit(QEDE_STAT_BB_ONLY, &qede_stats_arr[i].attr)
180#define QEDE_STAT_IS_AH_ONLY(i) \
181 test_bit(QEDE_STAT_AH_ONLY, &qede_stats_arr[i].attr)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200182
Yuval Mintzf3e72102016-04-22 08:41:02 +0300183enum {
184 QEDE_PRI_FLAG_CMT,
185 QEDE_PRI_FLAG_LEN,
186};
187
188static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
189 "Coupled-Function",
190};
191
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400192enum qede_ethtool_tests {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400193 QEDE_ETHTOOL_INT_LOOPBACK,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400194 QEDE_ETHTOOL_INTERRUPT_TEST,
195 QEDE_ETHTOOL_MEMORY_TEST,
196 QEDE_ETHTOOL_REGISTER_TEST,
197 QEDE_ETHTOOL_CLOCK_TEST,
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200198 QEDE_ETHTOOL_NVRAM_TEST,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400199 QEDE_ETHTOOL_TEST_MAX
200};
201
202static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400203 "Internal loopback (offline)",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400204 "Interrupt (online)\t",
205 "Memory (online)\t\t",
206 "Register (online)\t",
207 "Clock (online)\t\t",
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200208 "Nvram (online)\t\t",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400209};
210
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200211static void qede_get_strings_stats_txq(struct qede_dev *edev,
212 struct qede_tx_queue *txq, u8 **buf)
213{
214 int i;
215
216 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200217 if (txq->is_xdp)
218 sprintf(*buf, "%d [XDP]: %s",
219 QEDE_TXQ_XDP_TO_IDX(edev, txq),
220 qede_tqstats_arr[i].string);
221 else
222 sprintf(*buf, "%d: %s", txq->index,
223 qede_tqstats_arr[i].string);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200224 *buf += ETH_GSTRING_LEN;
225 }
226}
227
228static void qede_get_strings_stats_rxq(struct qede_dev *edev,
229 struct qede_rx_queue *rxq, u8 **buf)
230{
231 int i;
232
233 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
234 sprintf(*buf, "%d: %s", rxq->rxq_id,
235 qede_rqstats_arr[i].string);
236 *buf += ETH_GSTRING_LEN;
237 }
238}
239
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200240static bool qede_is_irrelevant_stat(struct qede_dev *edev, int stat_index)
241{
242 return (IS_VF(edev) && QEDE_STAT_IS_PF_ONLY(stat_index)) ||
243 (QEDE_IS_BB(edev) && QEDE_STAT_IS_AH_ONLY(stat_index)) ||
244 (QEDE_IS_AH(edev) && QEDE_STAT_IS_BB_ONLY(stat_index));
245}
246
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200247static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
248{
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200249 struct qede_fastpath *fp;
250 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200251
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200252 /* Account for queue statistics */
253 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
254 fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400255
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200256 if (fp->type & QEDE_FASTPATH_RX)
257 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
Mintz, Yuvalcbbf0492016-10-30 10:25:42 +0200258
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200259 if (fp->type & QEDE_FASTPATH_XDP)
260 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
261
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200262 if (fp->type & QEDE_FASTPATH_TX)
263 qede_get_strings_stats_txq(edev, fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400264 }
265
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200266 /* Account for non-queue statistics */
267 for (i = 0; i < QEDE_NUM_STATS; i++) {
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200268 if (qede_is_irrelevant_stat(edev, i))
Yuval Mintzfefb0202016-05-11 16:36:19 +0300269 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200270 strcpy(buf, qede_stats_arr[i].string);
271 buf += ETH_GSTRING_LEN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200272 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200273}
274
275static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
276{
277 struct qede_dev *edev = netdev_priv(dev);
278
279 switch (stringset) {
280 case ETH_SS_STATS:
281 qede_get_strings_stats(edev, buf);
282 break;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300283 case ETH_SS_PRIV_FLAGS:
284 memcpy(buf, qede_private_arr,
285 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
286 break;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400287 case ETH_SS_TEST:
288 memcpy(buf, qede_tests_str_arr,
289 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
290 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200291 default:
292 DP_VERBOSE(edev, QED_MSG_DEBUG,
293 "Unsupported stringset 0x%08x\n", stringset);
294 }
295}
296
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200297static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
298{
299 int i;
300
301 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
302 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
303 (*buf)++;
304 }
305}
306
307static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
308{
309 int i;
310
311 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
312 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
313 (*buf)++;
314 }
315}
316
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200317static void qede_get_ethtool_stats(struct net_device *dev,
318 struct ethtool_stats *stats, u64 *buf)
319{
320 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200321 struct qede_fastpath *fp;
322 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200323
324 qede_fill_by_demand_stats(edev);
325
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200326 /* Need to protect the access to the fastpath array */
327 __qede_lock(edev);
328
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200329 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
330 fp = &edev->fp_array[i];
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200331
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200332 if (fp->type & QEDE_FASTPATH_RX)
333 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400334
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200335 if (fp->type & QEDE_FASTPATH_XDP)
336 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
337
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200338 if (fp->type & QEDE_FASTPATH_TX)
339 qede_get_ethtool_stats_txq(fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400340 }
341
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200342 for (i = 0; i < QEDE_NUM_STATS; i++) {
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200343 if (qede_is_irrelevant_stat(edev, i))
Yuval Mintzfefb0202016-05-11 16:36:19 +0300344 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200345 *buf = *((u64 *)(((void *)&edev->stats) +
346 qede_stats_arr[i].offset));
347
348 buf++;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300349 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200350
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200351 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200352}
353
354static int qede_get_sset_count(struct net_device *dev, int stringset)
355{
356 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200357 int num_stats = QEDE_NUM_STATS, i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200358
359 switch (stringset) {
360 case ETH_SS_STATS:
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200361 for (i = 0; i < QEDE_NUM_STATS; i++)
362 if (qede_is_irrelevant_stat(edev, i))
363 num_stats--;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200364
365 /* Account for the Regular Tx statistics */
366 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
367
368 /* Account for the Regular Rx statistics */
369 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
370
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200371 /* Account for XDP statistics [if needed] */
372 if (edev->xdp_prog)
373 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200374 return num_stats;
375
Yuval Mintzf3e72102016-04-22 08:41:02 +0300376 case ETH_SS_PRIV_FLAGS:
377 return QEDE_PRI_FLAG_LEN;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400378 case ETH_SS_TEST:
Yuval Mintz6ecb0a02016-05-26 11:01:19 +0300379 if (!IS_VF(edev))
380 return QEDE_ETHTOOL_TEST_MAX;
381 else
382 return 0;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200383 default:
384 DP_VERBOSE(edev, QED_MSG_DEBUG,
385 "Unsupported stringset 0x%08x\n", stringset);
386 return -EINVAL;
387 }
388}
389
Yuval Mintzf3e72102016-04-22 08:41:02 +0300390static u32 qede_get_priv_flags(struct net_device *dev)
391{
392 struct qede_dev *edev = netdev_priv(dev);
393
394 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
395}
396
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400397struct qede_link_mode_mapping {
398 u32 qed_link_mode;
399 u32 ethtool_link_mode;
400};
401
402static const struct qede_link_mode_mapping qed_lm_map[] = {
403 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
404 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
405 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
406 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
407 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
408 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
409 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
410 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
411 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
412 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
413 {QED_LM_100000baseKR4_Full_BIT,
414 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
415};
416
417#define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
418{ \
419 int i; \
420 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200421 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400422 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
423 __set_bit(qed_lm_map[i].ethtool_link_mode,\
424 lk_ksettings->link_modes.name); \
425 } \
426}
427
428#define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
429{ \
430 int i; \
431 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200432 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400433 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
434 lk_ksettings->link_modes.name)) \
435 caps |= qed_lm_map[i].qed_link_mode; \
436 } \
437}
438
439static int qede_get_link_ksettings(struct net_device *dev,
440 struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200441{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400442 struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200443 struct qede_dev *edev = netdev_priv(dev);
444 struct qed_link_output current_link;
445
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200446 __qede_lock(edev);
447
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200448 memset(&current_link, 0, sizeof(current_link));
449 edev->ops->common->get_link(edev->cdev, &current_link);
450
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400451 ethtool_link_ksettings_zero_link_mode(cmd, supported);
452 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
453
454 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
455 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
456
457 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
458 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
459
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200460 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400461 base->speed = current_link.speed;
462 base->duplex = current_link.duplex;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200463 } else {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400464 base->speed = SPEED_UNKNOWN;
465 base->duplex = DUPLEX_UNKNOWN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200466 }
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200467
468 __qede_unlock(edev);
469
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400470 base->port = current_link.port;
471 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
472 AUTONEG_DISABLE;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200473
474 return 0;
475}
476
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400477static int qede_set_link_ksettings(struct net_device *dev,
478 const struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200479{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400480 const struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200481 struct qede_dev *edev = netdev_priv(dev);
482 struct qed_link_output current_link;
483 struct qed_link_params params;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200484
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300485 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400486 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200487 return -EOPNOTSUPP;
488 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200489 memset(&current_link, 0, sizeof(current_link));
490 memset(&params, 0, sizeof(params));
491 edev->ops->common->get_link(edev->cdev, &current_link);
492
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200493 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
494 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400495 if (base->autoneg == AUTONEG_ENABLE) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200496 params.autoneg = true;
497 params.forced_speed = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400498 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
499 } else { /* forced speed */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200500 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
501 params.autoneg = false;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400502 params.forced_speed = base->speed;
503 switch (base->speed) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200504 case SPEED_10000:
505 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400506 QED_LM_10000baseKR_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200507 DP_INFO(edev, "10G speed not supported\n");
508 return -EINVAL;
509 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400510 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
511 break;
512 case SPEED_25000:
513 if (!(current_link.supported_caps &
514 QED_LM_25000baseKR_Full_BIT)) {
515 DP_INFO(edev, "25G speed not supported\n");
516 return -EINVAL;
517 }
518 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200519 break;
520 case SPEED_40000:
521 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400522 QED_LM_40000baseLR4_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200523 DP_INFO(edev, "40G speed not supported\n");
524 return -EINVAL;
525 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400526 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
527 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300528 case SPEED_50000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400529 if (!(current_link.supported_caps &
530 QED_LM_50000baseKR2_Full_BIT)) {
531 DP_INFO(edev, "50G speed not supported\n");
532 return -EINVAL;
533 }
534 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
535 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300536 case SPEED_100000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400537 if (!(current_link.supported_caps &
538 QED_LM_100000baseKR4_Full_BIT)) {
539 DP_INFO(edev, "100G speed not supported\n");
540 return -EINVAL;
541 }
542 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200543 break;
544 default:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400545 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200546 return -EINVAL;
547 }
548 }
549
550 params.link_up = true;
551 edev->ops->common->set_link(edev->cdev, &params);
552
553 return 0;
554}
555
556static void qede_get_drvinfo(struct net_device *ndev,
557 struct ethtool_drvinfo *info)
558{
559 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
560 struct qede_dev *edev = netdev_priv(ndev);
561
562 strlcpy(info->driver, "qede", sizeof(info->driver));
563 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
564
565 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
566 edev->dev_info.common.fw_major,
567 edev->dev_info.common.fw_minor,
568 edev->dev_info.common.fw_rev,
569 edev->dev_info.common.fw_eng);
570
571 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
572 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
573 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
574 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
575 edev->dev_info.common.mfw_rev & 0xFF);
576
577 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
578 sizeof(info->fw_version)) {
579 snprintf(info->fw_version, sizeof(info->fw_version),
580 "mfw %s storm %s", mfw, storm);
581 } else {
582 snprintf(info->fw_version, sizeof(info->fw_version),
583 "%s %s", mfw, storm);
584 }
585
586 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
587}
588
Mintz, Yuval14d39642016-10-31 07:14:23 +0200589static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
590{
591 struct qede_dev *edev = netdev_priv(ndev);
592
593 if (edev->dev_info.common.wol_support) {
594 wol->supported = WAKE_MAGIC;
595 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
596 }
597}
598
599static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
600{
601 struct qede_dev *edev = netdev_priv(ndev);
602 bool wol_requested;
603 int rc;
604
605 if (wol->wolopts & ~WAKE_MAGIC) {
606 DP_INFO(edev,
607 "Can't support WoL options other than magic-packet\n");
608 return -EINVAL;
609 }
610
611 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
612 if (wol_requested == edev->wol_enabled)
613 return 0;
614
615 /* Need to actually change configuration */
616 if (!edev->dev_info.common.wol_support) {
617 DP_INFO(edev, "Device doesn't support WoL\n");
618 return -EINVAL;
619 }
620
621 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
622 if (!rc)
623 edev->wol_enabled = wol_requested;
624
625 return rc;
626}
627
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200628static u32 qede_get_msglevel(struct net_device *ndev)
629{
630 struct qede_dev *edev = netdev_priv(ndev);
631
Yuval Mintz1a635e42016-08-15 10:42:43 +0300632 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200633}
634
635static void qede_set_msglevel(struct net_device *ndev, u32 level)
636{
637 struct qede_dev *edev = netdev_priv(ndev);
638 u32 dp_module = 0;
639 u8 dp_level = 0;
640
641 qede_config_debug(level, &dp_module, &dp_level);
642
643 edev->dp_level = dp_level;
644 edev->dp_module = dp_module;
645 edev->ops->common->update_msglvl(edev->cdev,
646 dp_module, dp_level);
647}
648
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200649static int qede_nway_reset(struct net_device *dev)
650{
651 struct qede_dev *edev = netdev_priv(dev);
652 struct qed_link_output current_link;
653 struct qed_link_params link_params;
654
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300655 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Yuval Mintz1a635e42016-08-15 10:42:43 +0300656 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300657 return -EOPNOTSUPP;
658 }
659
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200660 if (!netif_running(dev))
661 return 0;
662
663 memset(&current_link, 0, sizeof(current_link));
664 edev->ops->common->get_link(edev->cdev, &current_link);
665 if (!current_link.link_up)
666 return 0;
667
668 /* Toggle the link */
669 memset(&link_params, 0, sizeof(link_params));
670 link_params.link_up = false;
671 edev->ops->common->set_link(edev->cdev, &link_params);
672 link_params.link_up = true;
673 edev->ops->common->set_link(edev->cdev, &link_params);
674
675 return 0;
676}
677
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200678static u32 qede_get_link(struct net_device *dev)
679{
680 struct qede_dev *edev = netdev_priv(dev);
681 struct qed_link_output current_link;
682
683 memset(&current_link, 0, sizeof(current_link));
684 edev->ops->common->get_link(edev->cdev, &current_link);
685
686 return current_link.link_up;
687}
688
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400689static int qede_get_coalesce(struct net_device *dev,
690 struct ethtool_coalesce *coal)
691{
692 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400693 u16 rxc, txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400694
695 memset(coal, 0, sizeof(struct ethtool_coalesce));
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400696 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
697
698 coal->rx_coalesce_usecs = rxc;
699 coal->tx_coalesce_usecs = txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400700
701 return 0;
702}
703
704static int qede_set_coalesce(struct net_device *dev,
705 struct ethtool_coalesce *coal)
706{
707 struct qede_dev *edev = netdev_priv(dev);
708 int i, rc = 0;
709 u16 rxc, txc;
710 u8 sb_id;
711
712 if (!netif_running(dev)) {
713 DP_INFO(edev, "Interface is down\n");
714 return -EINVAL;
715 }
716
717 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
718 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
719 DP_INFO(edev,
720 "Can't support requested %s coalesce value [max supported value %d]\n",
721 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
722 : "tx",
723 QED_COALESCE_MAX);
724 return -EINVAL;
725 }
726
727 rxc = (u16)coal->rx_coalesce_usecs;
728 txc = (u16)coal->tx_coalesce_usecs;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400729 for_each_queue(i) {
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400730 sb_id = edev->fp_array[i].sb_info->igu_sb_id;
731 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
732 (u8)i, sb_id);
733 if (rc) {
734 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
735 return rc;
736 }
737 }
738
739 return rc;
740}
741
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200742static void qede_get_ringparam(struct net_device *dev,
743 struct ethtool_ringparam *ering)
744{
745 struct qede_dev *edev = netdev_priv(dev);
746
747 ering->rx_max_pending = NUM_RX_BDS_MAX;
748 ering->rx_pending = edev->q_num_rx_buffers;
749 ering->tx_max_pending = NUM_TX_BDS_MAX;
750 ering->tx_pending = edev->q_num_tx_buffers;
751}
752
753static int qede_set_ringparam(struct net_device *dev,
754 struct ethtool_ringparam *ering)
755{
756 struct qede_dev *edev = netdev_priv(dev);
757
758 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
759 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
760 ering->rx_pending, ering->tx_pending);
761
762 /* Validate legality of configuration */
763 if (ering->rx_pending > NUM_RX_BDS_MAX ||
764 ering->rx_pending < NUM_RX_BDS_MIN ||
765 ering->tx_pending > NUM_TX_BDS_MAX ||
766 ering->tx_pending < NUM_TX_BDS_MIN) {
767 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
768 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
769 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
770 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
771 return -EINVAL;
772 }
773
774 /* Change ring size and re-load */
775 edev->q_num_rx_buffers = ering->rx_pending;
776 edev->q_num_tx_buffers = ering->tx_pending;
777
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200778 qede_reload(edev, NULL, false);
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200779
780 return 0;
781}
782
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200783static void qede_get_pauseparam(struct net_device *dev,
784 struct ethtool_pauseparam *epause)
785{
786 struct qede_dev *edev = netdev_priv(dev);
787 struct qed_link_output current_link;
788
789 memset(&current_link, 0, sizeof(current_link));
790 edev->ops->common->get_link(edev->cdev, &current_link);
791
792 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
793 epause->autoneg = true;
794 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
795 epause->rx_pause = true;
796 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
797 epause->tx_pause = true;
798
799 DP_VERBOSE(edev, QED_MSG_DEBUG,
800 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
801 epause->cmd, epause->autoneg, epause->rx_pause,
802 epause->tx_pause);
803}
804
805static int qede_set_pauseparam(struct net_device *dev,
806 struct ethtool_pauseparam *epause)
807{
808 struct qede_dev *edev = netdev_priv(dev);
809 struct qed_link_params params;
810 struct qed_link_output current_link;
811
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300812 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200813 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300814 "Pause settings are not allowed to be changed\n");
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200815 return -EOPNOTSUPP;
816 }
817
818 memset(&current_link, 0, sizeof(current_link));
819 edev->ops->common->get_link(edev->cdev, &current_link);
820
821 memset(&params, 0, sizeof(params));
822 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
823 if (epause->autoneg) {
Yuval Mintzd194fd22016-08-19 08:34:57 +0300824 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200825 DP_INFO(edev, "autoneg not supported\n");
826 return -EINVAL;
827 }
828 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
829 }
830 if (epause->rx_pause)
831 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
832 if (epause->tx_pause)
833 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
834
835 params.link_up = true;
836 edev->ops->common->set_link(edev->cdev, &params);
837
838 return 0;
839}
840
Tomer Tayare0971c82016-09-07 16:36:25 +0300841static void qede_get_regs(struct net_device *ndev,
842 struct ethtool_regs *regs, void *buffer)
843{
844 struct qede_dev *edev = netdev_priv(ndev);
845
846 regs->version = 0;
847 memset(buffer, 0, regs->len);
848
849 if (edev->ops && edev->ops->common)
850 edev->ops->common->dbg_all_data(edev->cdev, buffer);
851}
852
853static int qede_get_regs_len(struct net_device *ndev)
854{
855 struct qede_dev *edev = netdev_priv(ndev);
856
857 if (edev->ops && edev->ops->common)
858 return edev->ops->common->dbg_all_data_size(edev->cdev);
859 else
860 return -EINVAL;
861}
862
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200863static void qede_update_mtu(struct qede_dev *edev,
864 struct qede_reload_args *args)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200865{
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200866 edev->ndev->mtu = args->u.mtu;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200867}
868
869/* Netdevice NDOs */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200870int qede_change_mtu(struct net_device *ndev, int new_mtu)
871{
872 struct qede_dev *edev = netdev_priv(ndev);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200873 struct qede_reload_args args;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200874
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200875 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
876 "Configuring MTU size of %d\n", new_mtu);
877
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200878 /* Set the mtu field and re-start the interface if needed */
879 args.u.mtu = new_mtu;
880 args.func = &qede_update_mtu;
881 qede_reload(edev, &args, false);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200882
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200883 edev->ops->common->update_mtu(edev->cdev, new_mtu);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200884
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200885 return 0;
886}
887
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200888static void qede_get_channels(struct net_device *dev,
889 struct ethtool_channels *channels)
890{
891 struct qede_dev *edev = netdev_priv(dev);
892
893 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kallurubdc8cbd2016-10-21 04:43:39 -0400894 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
895 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400896 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
897 edev->fp_num_rx;
898 channels->tx_count = edev->fp_num_tx;
899 channels->rx_count = edev->fp_num_rx;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200900}
901
902static int qede_set_channels(struct net_device *dev,
903 struct ethtool_channels *channels)
904{
905 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400906 u32 count;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200907
908 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
909 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
910 channels->rx_count, channels->tx_count,
911 channels->other_count, channels->combined_count);
912
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400913 count = channels->rx_count + channels->tx_count +
914 channels->combined_count;
915
916 /* We don't support `other' channels */
917 if (channels->other_count) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200918 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
919 "command parameters not supported\n");
920 return -EINVAL;
921 }
922
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400923 if (!(channels->combined_count || (channels->rx_count &&
924 channels->tx_count))) {
925 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
926 "need to request at least one transmit and one receive channel\n");
927 return -EINVAL;
928 }
929
930 if (count > QEDE_MAX_RSS_CNT(edev)) {
931 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
932 "requested channels = %d max supported channels = %d\n",
933 count, QEDE_MAX_RSS_CNT(edev));
934 return -EINVAL;
935 }
936
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200937 /* Check if there was a change in the active parameters */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400938 if ((count == QEDE_QUEUE_CNT(edev)) &&
939 (channels->tx_count == edev->fp_num_tx) &&
940 (channels->rx_count == edev->fp_num_rx)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200941 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
942 "No change in active parameters\n");
943 return 0;
944 }
945
946 /* We need the number of queues to be divisible between the hwfns */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400947 if ((count % edev->dev_info.common.num_hwfns) ||
948 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
949 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200950 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400951 "Number of channels must be divisible by %04x\n",
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200952 edev->dev_info.common.num_hwfns);
953 return -EINVAL;
954 }
955
956 /* Set number of queues and reload if necessary */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400957 edev->req_queues = count;
958 edev->req_num_tx = channels->tx_count;
959 edev->req_num_rx = channels->rx_count;
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -0400960 /* Reset the indirection table if rx queue count is updated */
961 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
962 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200963 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -0400964 }
965
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200966 qede_reload(edev, NULL, false);
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200967
968 return 0;
969}
970
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +0200971static int qede_get_ts_info(struct net_device *dev,
972 struct ethtool_ts_info *info)
973{
974 struct qede_dev *edev = netdev_priv(dev);
975
976 return qede_ptp_get_ts_info(edev, info);
977}
978
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200979static int qede_set_phys_id(struct net_device *dev,
980 enum ethtool_phys_id_state state)
981{
982 struct qede_dev *edev = netdev_priv(dev);
983 u8 led_state = 0;
984
985 switch (state) {
986 case ETHTOOL_ID_ACTIVE:
987 return 1; /* cycle on/off once per second */
988
989 case ETHTOOL_ID_ON:
990 led_state = QED_LED_MODE_ON;
991 break;
992
993 case ETHTOOL_ID_OFF:
994 led_state = QED_LED_MODE_OFF;
995 break;
996
997 case ETHTOOL_ID_INACTIVE:
998 led_state = QED_LED_MODE_RESTORE;
999 break;
1000 }
1001
1002 edev->ops->common->set_led(edev->cdev, led_state);
1003
1004 return 0;
1005}
1006
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001007static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1008{
1009 info->data = RXH_IP_SRC | RXH_IP_DST;
1010
1011 switch (info->flow_type) {
1012 case TCP_V4_FLOW:
1013 case TCP_V6_FLOW:
1014 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1015 break;
1016 case UDP_V4_FLOW:
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001017 if (edev->rss_caps & QED_RSS_IPV4_UDP)
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001018 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1019 break;
1020 case UDP_V6_FLOW:
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001021 if (edev->rss_caps & QED_RSS_IPV6_UDP)
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001022 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1023 break;
1024 case IPV4_FLOW:
1025 case IPV6_FLOW:
1026 break;
1027 default:
1028 info->data = 0;
1029 break;
1030 }
1031
1032 return 0;
1033}
1034
1035static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1036 u32 *rules __always_unused)
1037{
1038 struct qede_dev *edev = netdev_priv(dev);
1039
1040 switch (info->cmd) {
1041 case ETHTOOL_GRXRINGS:
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001042 info->data = QEDE_RSS_COUNT(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001043 return 0;
1044 case ETHTOOL_GRXFH:
1045 return qede_get_rss_flags(edev, info);
1046 default:
1047 DP_ERR(edev, "Command parameters not supported\n");
1048 return -EOPNOTSUPP;
1049 }
1050}
1051
1052static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1053{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001054 struct qed_update_vport_params *vport_update_params;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001055 u8 set_caps = 0, clr_caps = 0;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001056 int rc = 0;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001057
1058 DP_VERBOSE(edev, QED_MSG_DEBUG,
1059 "Set rss flags command parameters: flow type = %d, data = %llu\n",
1060 info->flow_type, info->data);
1061
1062 switch (info->flow_type) {
1063 case TCP_V4_FLOW:
1064 case TCP_V6_FLOW:
1065 /* For TCP only 4-tuple hash is supported */
1066 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1067 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1068 DP_INFO(edev, "Command parameters not supported\n");
1069 return -EINVAL;
1070 }
1071 return 0;
1072 case UDP_V4_FLOW:
1073 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1074 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1075 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1076 set_caps = QED_RSS_IPV4_UDP;
1077 DP_VERBOSE(edev, QED_MSG_DEBUG,
1078 "UDP 4-tuple enabled\n");
1079 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1080 clr_caps = QED_RSS_IPV4_UDP;
1081 DP_VERBOSE(edev, QED_MSG_DEBUG,
1082 "UDP 4-tuple disabled\n");
1083 } else {
1084 return -EINVAL;
1085 }
1086 break;
1087 case UDP_V6_FLOW:
1088 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1089 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1090 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1091 set_caps = QED_RSS_IPV6_UDP;
1092 DP_VERBOSE(edev, QED_MSG_DEBUG,
1093 "UDP 4-tuple enabled\n");
1094 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1095 clr_caps = QED_RSS_IPV6_UDP;
1096 DP_VERBOSE(edev, QED_MSG_DEBUG,
1097 "UDP 4-tuple disabled\n");
1098 } else {
1099 return -EINVAL;
1100 }
1101 break;
1102 case IPV4_FLOW:
1103 case IPV6_FLOW:
1104 /* For IP only 2-tuple hash is supported */
1105 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1106 DP_INFO(edev, "Command parameters not supported\n");
1107 return -EINVAL;
1108 }
1109 return 0;
1110 case SCTP_V4_FLOW:
1111 case AH_ESP_V4_FLOW:
1112 case AH_V4_FLOW:
1113 case ESP_V4_FLOW:
1114 case SCTP_V6_FLOW:
1115 case AH_ESP_V6_FLOW:
1116 case AH_V6_FLOW:
1117 case ESP_V6_FLOW:
1118 case IP_USER_FLOW:
1119 case ETHER_FLOW:
1120 /* RSS is not supported for these protocols */
1121 if (info->data) {
1122 DP_INFO(edev, "Command parameters not supported\n");
1123 return -EINVAL;
1124 }
1125 return 0;
1126 default:
1127 return -EINVAL;
1128 }
1129
1130 /* No action is needed if there is no change in the rss capability */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001131 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001132 return 0;
1133
1134 /* Update internal configuration */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001135 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001136 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1137
1138 /* Re-configure if possible */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001139 __qede_lock(edev);
1140 if (edev->state == QEDE_STATE_OPEN) {
1141 vport_update_params = vzalloc(sizeof(*vport_update_params));
1142 if (!vport_update_params) {
1143 __qede_unlock(edev);
1144 return -ENOMEM;
1145 }
1146 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1147 &vport_update_params->update_rss_flg);
1148 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1149 vfree(vport_update_params);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001150 }
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001151 __qede_unlock(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001152
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001153 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001154}
1155
1156static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1157{
1158 struct qede_dev *edev = netdev_priv(dev);
1159
1160 switch (info->cmd) {
1161 case ETHTOOL_SRXFH:
1162 return qede_set_rss_flags(edev, info);
1163 default:
1164 DP_INFO(edev, "Command parameters not supported\n");
1165 return -EOPNOTSUPP;
1166 }
1167}
1168
1169static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1170{
1171 return QED_RSS_IND_TABLE_SIZE;
1172}
1173
1174static u32 qede_get_rxfh_key_size(struct net_device *dev)
1175{
1176 struct qede_dev *edev = netdev_priv(dev);
1177
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001178 return sizeof(edev->rss_key);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001179}
1180
1181static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1182{
1183 struct qede_dev *edev = netdev_priv(dev);
1184 int i;
1185
1186 if (hfunc)
1187 *hfunc = ETH_RSS_HASH_TOP;
1188
1189 if (!indir)
1190 return 0;
1191
1192 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001193 indir[i] = edev->rss_ind_table[i];
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001194
1195 if (key)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001196 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001197
1198 return 0;
1199}
1200
1201static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1202 const u8 *key, const u8 hfunc)
1203{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001204 struct qed_update_vport_params *vport_update_params;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001205 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001206 int i, rc = 0;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001207
Sudarsana Reddy Kalluruba300ce2016-10-21 04:43:40 -04001208 if (edev->dev_info.common.num_hwfns > 1) {
1209 DP_INFO(edev,
1210 "RSS configuration is not supported for 100G devices\n");
1211 return -EOPNOTSUPP;
1212 }
1213
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001214 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1215 return -EOPNOTSUPP;
1216
1217 if (!indir && !key)
1218 return 0;
1219
1220 if (indir) {
1221 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001222 edev->rss_ind_table[i] = indir[i];
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001223 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1224 }
1225
1226 if (key) {
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001227 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001228 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1229 }
1230
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001231 __qede_lock(edev);
1232 if (edev->state == QEDE_STATE_OPEN) {
1233 vport_update_params = vzalloc(sizeof(*vport_update_params));
1234 if (!vport_update_params) {
1235 __qede_unlock(edev);
1236 return -ENOMEM;
1237 }
1238 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1239 &vport_update_params->update_rss_flg);
1240 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1241 vfree(vport_update_params);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001242 }
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001243 __qede_unlock(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001244
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001245 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001246}
1247
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001248/* This function enables the interrupt generation and the NAPI on the device */
1249static void qede_netif_start(struct qede_dev *edev)
1250{
1251 int i;
1252
1253 if (!netif_running(edev->ndev))
1254 return;
1255
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001256 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001257 /* Update and reenable interrupts */
1258 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1259 napi_enable(&edev->fp_array[i].napi);
1260 }
1261}
1262
1263/* This function disables the NAPI and the interrupt generation on the device */
1264static void qede_netif_stop(struct qede_dev *edev)
1265{
1266 int i;
1267
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001268 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001269 napi_disable(&edev->fp_array[i].napi);
1270 /* Disable interrupts */
1271 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1272 }
1273}
1274
1275static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1276 struct sk_buff *skb)
1277{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001278 struct qede_tx_queue *txq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001279 struct eth_tx_1st_bd *first_bd;
1280 dma_addr_t mapping;
1281 int i, idx, val;
1282
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001283 for_each_queue(i) {
1284 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001285 txq = edev->fp_array[i].txq;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001286 break;
1287 }
1288 }
1289
1290 if (!txq) {
1291 DP_NOTICE(edev, "Tx path is not available\n");
1292 return -1;
1293 }
1294
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001295 /* Fill the entry in the SW ring and the BDs in the FW ring */
1296 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001297 txq->sw_tx_ring.skbs[idx].skb = skb;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001298 first_bd = qed_chain_produce(&txq->tx_pbl);
1299 memset(first_bd, 0, sizeof(*first_bd));
1300 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1301 first_bd->data.bd_flags.bitfields = val;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001302 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1303 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001304
1305 /* Map skb linear data for DMA and set in the first BD */
1306 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1307 skb_headlen(skb), DMA_TO_DEVICE);
1308 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1309 DP_NOTICE(edev, "SKB mapping failed\n");
1310 return -ENOMEM;
1311 }
1312 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1313
1314 /* update the first BD with the actual num BDs */
1315 first_bd->data.nbds = 1;
1316 txq->sw_tx_prod++;
1317 /* 'next page' entries are counted in the producer value */
1318 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
1319 txq->tx_db.data.bd_prod = val;
1320
1321 /* wmb makes sure that the BDs data is updated before updating the
1322 * producer, otherwise FW may read old data from the BDs.
1323 */
1324 wmb();
1325 barrier();
1326 writel(txq->tx_db.raw, txq->doorbell_addr);
1327
1328 /* mmiowb is needed to synchronize doorbell writes from more than one
1329 * processor. It guarantees that the write arrives to the device before
1330 * the queue lock is released and another start_xmit is called (possibly
1331 * on another CPU). Without this barrier, the next doorbell can bypass
1332 * this doorbell. This is applicable to IA64/Altix systems.
1333 */
1334 mmiowb();
1335
1336 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1337 if (qede_txq_has_work(txq))
1338 break;
1339 usleep_range(100, 200);
1340 }
1341
1342 if (!qede_txq_has_work(txq)) {
1343 DP_NOTICE(edev, "Tx completion didn't happen\n");
1344 return -1;
1345 }
1346
1347 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
Manish Choprafabd5452016-10-21 04:43:45 -04001348 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1349 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001350 txq->sw_tx_cons++;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001351 txq->sw_tx_ring.skbs[idx].skb = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001352
1353 return 0;
1354}
1355
1356static int qede_selftest_receive_traffic(struct qede_dev *edev)
1357{
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001358 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1359 struct eth_fast_path_rx_reg_cqe *fp_cqe;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001360 struct qede_rx_queue *rxq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001361 struct sw_rx_data *sw_rx_data;
1362 union eth_rx_cqe *cqe;
Sudarsana Reddy Kalluruafe981d2017-02-20 22:43:37 +02001363 int i, iter, rc = 0;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001364 u8 *data_ptr;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001365
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001366 for_each_queue(i) {
1367 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1368 rxq = edev->fp_array[i].rxq;
1369 break;
1370 }
1371 }
1372
1373 if (!rxq) {
1374 DP_NOTICE(edev, "Rx path is not available\n");
1375 return -1;
1376 }
1377
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001378 /* The packet is expected to receive on rx-queue 0 even though RSS is
1379 * enabled. This is because the queue 0 is configured as the default
1380 * queue and that the loopback traffic is not IP.
1381 */
Sudarsana Reddy Kalluruafe981d2017-02-20 22:43:37 +02001382 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001383 if (!qede_has_rx_work(rxq)) {
1384 usleep_range(100, 200);
1385 continue;
1386 }
1387
1388 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1389 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1390
1391 /* Memory barrier to prevent the CPU from doing speculative
1392 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1393 * read before it is written by FW, then FW writes CQE and SB,
1394 * and then the CPU reads the hw_comp_cons, it will use an old
1395 * CQE.
1396 */
1397 rmb();
1398
1399 /* Get the CQE from the completion ring */
1400 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1401
1402 /* Get the data from the SW ring */
1403 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1404 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1405 fp_cqe = &cqe->fast_path_regular;
1406 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1407 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1408 fp_cqe->placement_offset +
1409 sw_rx_data->page_offset);
1410 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1411 ether_addr_equal(data_ptr + ETH_ALEN,
1412 edev->ndev->dev_addr)) {
1413 for (i = ETH_HLEN; i < len; i++)
1414 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1415 rc = -1;
1416 break;
1417 }
1418
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001419 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001420 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001421 break;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001422 }
1423
1424 DP_INFO(edev, "Not the transmitted packet\n");
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001425 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001426 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001427 }
1428
Sudarsana Reddy Kalluruafe981d2017-02-20 22:43:37 +02001429 if (iter == QEDE_SELFTEST_POLL_COUNT) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001430 DP_NOTICE(edev, "Failed to receive the traffic\n");
1431 return -1;
1432 }
1433
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001434 qede_update_rx_prod(edev, rxq);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001435
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001436 return rc;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001437}
1438
1439static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1440{
1441 struct qed_link_params link_params;
1442 struct sk_buff *skb = NULL;
1443 int rc = 0, i;
1444 u32 pkt_size;
1445 u8 *packet;
1446
1447 if (!netif_running(edev->ndev)) {
1448 DP_NOTICE(edev, "Interface is down\n");
1449 return -EINVAL;
1450 }
1451
1452 qede_netif_stop(edev);
1453
1454 /* Bring up the link in Loopback mode */
1455 memset(&link_params, 0, sizeof(link_params));
1456 link_params.link_up = true;
1457 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1458 link_params.loopback_mode = loopback_mode;
1459 edev->ops->common->set_link(edev->cdev, &link_params);
1460
1461 /* Wait for loopback configuration to apply */
1462 msleep_interruptible(500);
1463
1464 /* prepare the loopback packet */
1465 pkt_size = edev->ndev->mtu + ETH_HLEN;
1466
1467 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1468 if (!skb) {
1469 DP_INFO(edev, "Can't allocate skb\n");
1470 rc = -ENOMEM;
1471 goto test_loopback_exit;
1472 }
1473 packet = skb_put(skb, pkt_size);
1474 ether_addr_copy(packet, edev->ndev->dev_addr);
1475 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1476 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1477 for (i = ETH_HLEN; i < pkt_size; i++)
1478 packet[i] = (unsigned char)(i & 0xff);
1479
1480 rc = qede_selftest_transmit_traffic(edev, skb);
1481 if (rc)
1482 goto test_loopback_exit;
1483
1484 rc = qede_selftest_receive_traffic(edev);
1485 if (rc)
1486 goto test_loopback_exit;
1487
1488 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1489
1490test_loopback_exit:
1491 dev_kfree_skb(skb);
1492
1493 /* Bring up the link in Normal mode */
1494 memset(&link_params, 0, sizeof(link_params));
1495 link_params.link_up = true;
1496 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1497 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1498 edev->ops->common->set_link(edev->cdev, &link_params);
1499
1500 /* Wait for loopback configuration to apply */
1501 msleep_interruptible(500);
1502
1503 qede_netif_start(edev);
1504
1505 return rc;
1506}
1507
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001508static void qede_self_test(struct net_device *dev,
1509 struct ethtool_test *etest, u64 *buf)
1510{
1511 struct qede_dev *edev = netdev_priv(dev);
1512
1513 DP_VERBOSE(edev, QED_MSG_DEBUG,
1514 "Self-test command parameters: offline = %d, external_lb = %d\n",
1515 (etest->flags & ETH_TEST_FL_OFFLINE),
1516 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1517
1518 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1519
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001520 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1521 if (qede_selftest_run_loopback(edev,
1522 QED_LINK_LOOPBACK_INT_PHY)) {
1523 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1524 etest->flags |= ETH_TEST_FL_FAILED;
1525 }
1526 }
1527
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001528 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1529 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1530 etest->flags |= ETH_TEST_FL_FAILED;
1531 }
1532
1533 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1534 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1535 etest->flags |= ETH_TEST_FL_FAILED;
1536 }
1537
1538 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1539 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1540 etest->flags |= ETH_TEST_FL_FAILED;
1541 }
1542
1543 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1544 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1545 etest->flags |= ETH_TEST_FL_FAILED;
1546 }
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +02001547
1548 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1549 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1550 etest->flags |= ETH_TEST_FL_FAILED;
1551 }
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001552}
1553
Manish Chopra3d789992016-06-30 02:35:21 -04001554static int qede_set_tunable(struct net_device *dev,
1555 const struct ethtool_tunable *tuna,
1556 const void *data)
1557{
1558 struct qede_dev *edev = netdev_priv(dev);
1559 u32 val;
1560
1561 switch (tuna->id) {
1562 case ETHTOOL_RX_COPYBREAK:
1563 val = *(u32 *)data;
1564 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1565 DP_VERBOSE(edev, QED_MSG_DEBUG,
1566 "Invalid rx copy break value, range is [%u, %u]",
1567 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1568 return -EINVAL;
1569 }
1570
1571 edev->rx_copybreak = *(u32 *)data;
1572 break;
1573 default:
1574 return -EOPNOTSUPP;
1575 }
1576
1577 return 0;
1578}
1579
1580static int qede_get_tunable(struct net_device *dev,
1581 const struct ethtool_tunable *tuna, void *data)
1582{
1583 struct qede_dev *edev = netdev_priv(dev);
1584
1585 switch (tuna->id) {
1586 case ETHTOOL_RX_COPYBREAK:
1587 *(u32 *)data = edev->rx_copybreak;
1588 break;
1589 default:
1590 return -EOPNOTSUPP;
1591 }
1592
1593 return 0;
1594}
1595
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001596static const struct ethtool_ops qede_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001597 .get_link_ksettings = qede_get_link_ksettings,
1598 .set_link_ksettings = qede_set_link_ksettings,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001599 .get_drvinfo = qede_get_drvinfo,
Tomer Tayare0971c82016-09-07 16:36:25 +03001600 .get_regs_len = qede_get_regs_len,
1601 .get_regs = qede_get_regs,
Mintz, Yuval14d39642016-10-31 07:14:23 +02001602 .get_wol = qede_get_wol,
1603 .set_wol = qede_set_wol,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001604 .get_msglevel = qede_get_msglevel,
1605 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +02001606 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001607 .get_link = qede_get_link,
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -04001608 .get_coalesce = qede_get_coalesce,
1609 .set_coalesce = qede_set_coalesce,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +02001610 .get_ringparam = qede_get_ringparam,
1611 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +02001612 .get_pauseparam = qede_get_pauseparam,
1613 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001614 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +02001615 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001616 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +03001617 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001618 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001619 .get_rxnfc = qede_get_rxnfc,
1620 .set_rxnfc = qede_set_rxnfc,
1621 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1622 .get_rxfh_key_size = qede_get_rxfh_key_size,
1623 .get_rxfh = qede_get_rxfh,
1624 .set_rxfh = qede_set_rxfh,
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +02001625 .get_ts_info = qede_get_ts_info,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001626 .get_channels = qede_get_channels,
1627 .set_channels = qede_set_channels,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001628 .self_test = qede_self_test,
Manish Chopra3d789992016-06-30 02:35:21 -04001629 .get_tunable = qede_get_tunable,
1630 .set_tunable = qede_set_tunable,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001631};
1632
Yuval Mintzfefb0202016-05-11 16:36:19 +03001633static const struct ethtool_ops qede_vf_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001634 .get_link_ksettings = qede_get_link_ksettings,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001635 .get_drvinfo = qede_get_drvinfo,
1636 .get_msglevel = qede_get_msglevel,
1637 .set_msglevel = qede_set_msglevel,
1638 .get_link = qede_get_link,
1639 .get_ringparam = qede_get_ringparam,
1640 .set_ringparam = qede_set_ringparam,
1641 .get_strings = qede_get_strings,
1642 .get_ethtool_stats = qede_get_ethtool_stats,
1643 .get_priv_flags = qede_get_priv_flags,
1644 .get_sset_count = qede_get_sset_count,
1645 .get_rxnfc = qede_get_rxnfc,
1646 .set_rxnfc = qede_set_rxnfc,
1647 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1648 .get_rxfh_key_size = qede_get_rxfh_key_size,
1649 .get_rxfh = qede_get_rxfh,
1650 .set_rxfh = qede_set_rxfh,
1651 .get_channels = qede_get_channels,
1652 .set_channels = qede_set_channels,
Manish Chopra3d789992016-06-30 02:35:21 -04001653 .get_tunable = qede_get_tunable,
1654 .set_tunable = qede_set_tunable,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001655};
1656
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001657void qede_set_ethtool_ops(struct net_device *dev)
1658{
Yuval Mintzfefb0202016-05-11 16:36:19 +03001659 struct qede_dev *edev = netdev_priv(dev);
1660
1661 if (IS_VF(edev))
1662 dev->ethtool_ops = &qede_vf_ethtool_ops;
1663 else
1664 dev->ethtool_ops = &qede_ethtool_ops;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001665}