blob: baf264225c122fecc339672ad314b7ac4a6e9fea [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"
42
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020043#define QEDE_RQSTAT_OFFSET(stat_name) \
44 (offsetof(struct qede_rx_queue, stat_name))
45#define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
46#define QEDE_RQSTAT(stat_name) \
47 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040048
49#define QEDE_SELFTEST_POLL_COUNT 100
50
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020051static const struct {
52 u64 offset;
53 char string[ETH_GSTRING_LEN];
54} qede_rqstats_arr[] = {
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040055 QEDE_RQSTAT(rcv_pkts),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020056 QEDE_RQSTAT(rx_hw_errors),
57 QEDE_RQSTAT(rx_alloc_errors),
Manish Choprac72a6122016-06-30 02:35:18 -040058 QEDE_RQSTAT(rx_ip_frags),
Mintz, Yuval496e0512016-11-29 16:47:09 +020059 QEDE_RQSTAT(xdp_no_pass),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020060};
61
62#define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040063#define QEDE_TQSTAT_OFFSET(stat_name) \
64 (offsetof(struct qede_tx_queue, stat_name))
65#define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
66#define QEDE_TQSTAT(stat_name) \
67 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
68#define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
69static const struct {
70 u64 offset;
71 char string[ETH_GSTRING_LEN];
72} qede_tqstats_arr[] = {
73 QEDE_TQSTAT(xmit_pkts),
74 QEDE_TQSTAT(stopped_cnt),
75};
76
Mintz, Yuval4dbcd642016-11-29 16:47:03 +020077#define QEDE_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
78#define QEDE_STAT_STRING(stat_name) (#stat_name)
79#define _QEDE_STAT(stat_name, pf_only) \
80 {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
81#define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
82#define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020083static const struct {
84 u64 offset;
85 char string[ETH_GSTRING_LEN];
86 bool pf_only;
87} qede_stats_arr[] = {
88 QEDE_STAT(rx_ucast_bytes),
89 QEDE_STAT(rx_mcast_bytes),
90 QEDE_STAT(rx_bcast_bytes),
91 QEDE_STAT(rx_ucast_pkts),
92 QEDE_STAT(rx_mcast_pkts),
93 QEDE_STAT(rx_bcast_pkts),
94
95 QEDE_STAT(tx_ucast_bytes),
96 QEDE_STAT(tx_mcast_bytes),
97 QEDE_STAT(tx_bcast_bytes),
98 QEDE_STAT(tx_ucast_pkts),
99 QEDE_STAT(tx_mcast_pkts),
100 QEDE_STAT(tx_bcast_pkts),
101
102 QEDE_PF_STAT(rx_64_byte_packets),
Yuval Mintzd4967cf2016-04-22 08:41:01 +0300103 QEDE_PF_STAT(rx_65_to_127_byte_packets),
104 QEDE_PF_STAT(rx_128_to_255_byte_packets),
105 QEDE_PF_STAT(rx_256_to_511_byte_packets),
106 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
107 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
108 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
109 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
110 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
111 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
112 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200113 QEDE_PF_STAT(tx_64_byte_packets),
114 QEDE_PF_STAT(tx_65_to_127_byte_packets),
115 QEDE_PF_STAT(tx_128_to_255_byte_packets),
116 QEDE_PF_STAT(tx_256_to_511_byte_packets),
117 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
118 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
119 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
120 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
121 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
122 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
123
124 QEDE_PF_STAT(rx_mac_crtl_frames),
125 QEDE_PF_STAT(tx_mac_ctrl_frames),
126 QEDE_PF_STAT(rx_pause_frames),
127 QEDE_PF_STAT(tx_pause_frames),
128 QEDE_PF_STAT(rx_pfc_frames),
129 QEDE_PF_STAT(tx_pfc_frames),
130
131 QEDE_PF_STAT(rx_crc_errors),
132 QEDE_PF_STAT(rx_align_errors),
133 QEDE_PF_STAT(rx_carrier_errors),
134 QEDE_PF_STAT(rx_oversize_packets),
135 QEDE_PF_STAT(rx_jabbers),
136 QEDE_PF_STAT(rx_undersize_packets),
137 QEDE_PF_STAT(rx_fragments),
138 QEDE_PF_STAT(tx_lpi_entry_count),
139 QEDE_PF_STAT(tx_total_collisions),
140 QEDE_PF_STAT(brb_truncates),
141 QEDE_PF_STAT(brb_discards),
142 QEDE_STAT(no_buff_discards),
143 QEDE_PF_STAT(mftag_filter_discards),
144 QEDE_PF_STAT(mac_filter_discards),
145 QEDE_STAT(tx_err_drop_pkts),
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400146 QEDE_STAT(ttl0_discard),
147 QEDE_STAT(packet_too_big_discard),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200148
149 QEDE_STAT(coalesced_pkts),
150 QEDE_STAT(coalesced_events),
151 QEDE_STAT(coalesced_aborts_num),
152 QEDE_STAT(non_coalesced_pkts),
153 QEDE_STAT(coalesced_bytes),
154};
155
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200156#define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
157
Yuval Mintzf3e72102016-04-22 08:41:02 +0300158enum {
159 QEDE_PRI_FLAG_CMT,
160 QEDE_PRI_FLAG_LEN,
161};
162
163static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
164 "Coupled-Function",
165};
166
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400167enum qede_ethtool_tests {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400168 QEDE_ETHTOOL_INT_LOOPBACK,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400169 QEDE_ETHTOOL_INTERRUPT_TEST,
170 QEDE_ETHTOOL_MEMORY_TEST,
171 QEDE_ETHTOOL_REGISTER_TEST,
172 QEDE_ETHTOOL_CLOCK_TEST,
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200173 QEDE_ETHTOOL_NVRAM_TEST,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400174 QEDE_ETHTOOL_TEST_MAX
175};
176
177static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400178 "Internal loopback (offline)",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400179 "Interrupt (online)\t",
180 "Memory (online)\t\t",
181 "Register (online)\t",
182 "Clock (online)\t\t",
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200183 "Nvram (online)\t\t",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400184};
185
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200186static void qede_get_strings_stats_txq(struct qede_dev *edev,
187 struct qede_tx_queue *txq, u8 **buf)
188{
189 int i;
190
191 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200192 if (txq->is_xdp)
193 sprintf(*buf, "%d [XDP]: %s",
194 QEDE_TXQ_XDP_TO_IDX(edev, txq),
195 qede_tqstats_arr[i].string);
196 else
197 sprintf(*buf, "%d: %s", txq->index,
198 qede_tqstats_arr[i].string);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200199 *buf += ETH_GSTRING_LEN;
200 }
201}
202
203static void qede_get_strings_stats_rxq(struct qede_dev *edev,
204 struct qede_rx_queue *rxq, u8 **buf)
205{
206 int i;
207
208 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
209 sprintf(*buf, "%d: %s", rxq->rxq_id,
210 qede_rqstats_arr[i].string);
211 *buf += ETH_GSTRING_LEN;
212 }
213}
214
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200215static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
216{
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200217 struct qede_fastpath *fp;
218 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200219
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200220 /* Account for queue statistics */
221 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
222 fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400223
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200224 if (fp->type & QEDE_FASTPATH_RX)
225 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
Mintz, Yuvalcbbf0492016-10-30 10:25:42 +0200226
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200227 if (fp->type & QEDE_FASTPATH_XDP)
228 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
229
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200230 if (fp->type & QEDE_FASTPATH_TX)
231 qede_get_strings_stats_txq(edev, fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400232 }
233
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200234 /* Account for non-queue statistics */
235 for (i = 0; i < QEDE_NUM_STATS; i++) {
Yuval Mintzfefb0202016-05-11 16:36:19 +0300236 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
237 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200238 strcpy(buf, qede_stats_arr[i].string);
239 buf += ETH_GSTRING_LEN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200240 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200241}
242
243static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
244{
245 struct qede_dev *edev = netdev_priv(dev);
246
247 switch (stringset) {
248 case ETH_SS_STATS:
249 qede_get_strings_stats(edev, buf);
250 break;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300251 case ETH_SS_PRIV_FLAGS:
252 memcpy(buf, qede_private_arr,
253 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
254 break;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400255 case ETH_SS_TEST:
256 memcpy(buf, qede_tests_str_arr,
257 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
258 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200259 default:
260 DP_VERBOSE(edev, QED_MSG_DEBUG,
261 "Unsupported stringset 0x%08x\n", stringset);
262 }
263}
264
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200265static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
266{
267 int i;
268
269 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
270 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
271 (*buf)++;
272 }
273}
274
275static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
276{
277 int i;
278
279 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
280 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
281 (*buf)++;
282 }
283}
284
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200285static void qede_get_ethtool_stats(struct net_device *dev,
286 struct ethtool_stats *stats, u64 *buf)
287{
288 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200289 struct qede_fastpath *fp;
290 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200291
292 qede_fill_by_demand_stats(edev);
293
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200294 /* Need to protect the access to the fastpath array */
295 __qede_lock(edev);
296
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200297 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
298 fp = &edev->fp_array[i];
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200299
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200300 if (fp->type & QEDE_FASTPATH_RX)
301 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400302
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200303 if (fp->type & QEDE_FASTPATH_XDP)
304 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
305
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200306 if (fp->type & QEDE_FASTPATH_TX)
307 qede_get_ethtool_stats_txq(fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400308 }
309
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200310 for (i = 0; i < QEDE_NUM_STATS; i++) {
311 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
Yuval Mintzfefb0202016-05-11 16:36:19 +0300312 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200313 *buf = *((u64 *)(((void *)&edev->stats) +
314 qede_stats_arr[i].offset));
315
316 buf++;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300317 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200318
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200319 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200320}
321
322static int qede_get_sset_count(struct net_device *dev, int stringset)
323{
324 struct qede_dev *edev = netdev_priv(dev);
325 int num_stats = QEDE_NUM_STATS;
326
327 switch (stringset) {
328 case ETH_SS_STATS:
Yuval Mintzfefb0202016-05-11 16:36:19 +0300329 if (IS_VF(edev)) {
330 int i;
331
332 for (i = 0; i < QEDE_NUM_STATS; i++)
333 if (qede_stats_arr[i].pf_only)
334 num_stats--;
335 }
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200336
337 /* Account for the Regular Tx statistics */
338 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
339
340 /* Account for the Regular Rx statistics */
341 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
342
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200343 /* Account for XDP statistics [if needed] */
344 if (edev->xdp_prog)
345 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200346 return num_stats;
347
Yuval Mintzf3e72102016-04-22 08:41:02 +0300348 case ETH_SS_PRIV_FLAGS:
349 return QEDE_PRI_FLAG_LEN;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400350 case ETH_SS_TEST:
Yuval Mintz6ecb0a02016-05-26 11:01:19 +0300351 if (!IS_VF(edev))
352 return QEDE_ETHTOOL_TEST_MAX;
353 else
354 return 0;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200355 default:
356 DP_VERBOSE(edev, QED_MSG_DEBUG,
357 "Unsupported stringset 0x%08x\n", stringset);
358 return -EINVAL;
359 }
360}
361
Yuval Mintzf3e72102016-04-22 08:41:02 +0300362static u32 qede_get_priv_flags(struct net_device *dev)
363{
364 struct qede_dev *edev = netdev_priv(dev);
365
366 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
367}
368
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400369struct qede_link_mode_mapping {
370 u32 qed_link_mode;
371 u32 ethtool_link_mode;
372};
373
374static const struct qede_link_mode_mapping qed_lm_map[] = {
375 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
376 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
377 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
378 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
379 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
380 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
381 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
382 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
383 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
384 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
385 {QED_LM_100000baseKR4_Full_BIT,
386 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
387};
388
389#define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
390{ \
391 int i; \
392 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200393 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400394 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
395 __set_bit(qed_lm_map[i].ethtool_link_mode,\
396 lk_ksettings->link_modes.name); \
397 } \
398}
399
400#define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
401{ \
402 int i; \
403 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200404 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400405 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
406 lk_ksettings->link_modes.name)) \
407 caps |= qed_lm_map[i].qed_link_mode; \
408 } \
409}
410
411static int qede_get_link_ksettings(struct net_device *dev,
412 struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200413{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400414 struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200415 struct qede_dev *edev = netdev_priv(dev);
416 struct qed_link_output current_link;
417
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200418 __qede_lock(edev);
419
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200420 memset(&current_link, 0, sizeof(current_link));
421 edev->ops->common->get_link(edev->cdev, &current_link);
422
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400423 ethtool_link_ksettings_zero_link_mode(cmd, supported);
424 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
425
426 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
427 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
428
429 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
430 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
431
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200432 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400433 base->speed = current_link.speed;
434 base->duplex = current_link.duplex;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200435 } else {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400436 base->speed = SPEED_UNKNOWN;
437 base->duplex = DUPLEX_UNKNOWN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200438 }
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200439
440 __qede_unlock(edev);
441
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400442 base->port = current_link.port;
443 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
444 AUTONEG_DISABLE;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200445
446 return 0;
447}
448
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400449static int qede_set_link_ksettings(struct net_device *dev,
450 const struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200451{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400452 const struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200453 struct qede_dev *edev = netdev_priv(dev);
454 struct qed_link_output current_link;
455 struct qed_link_params params;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200456
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300457 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400458 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200459 return -EOPNOTSUPP;
460 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200461 memset(&current_link, 0, sizeof(current_link));
462 memset(&params, 0, sizeof(params));
463 edev->ops->common->get_link(edev->cdev, &current_link);
464
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200465 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
466 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400467 if (base->autoneg == AUTONEG_ENABLE) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200468 params.autoneg = true;
469 params.forced_speed = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400470 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
471 } else { /* forced speed */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200472 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
473 params.autoneg = false;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400474 params.forced_speed = base->speed;
475 switch (base->speed) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200476 case SPEED_10000:
477 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400478 QED_LM_10000baseKR_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200479 DP_INFO(edev, "10G speed not supported\n");
480 return -EINVAL;
481 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400482 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
483 break;
484 case SPEED_25000:
485 if (!(current_link.supported_caps &
486 QED_LM_25000baseKR_Full_BIT)) {
487 DP_INFO(edev, "25G speed not supported\n");
488 return -EINVAL;
489 }
490 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200491 break;
492 case SPEED_40000:
493 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400494 QED_LM_40000baseLR4_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200495 DP_INFO(edev, "40G speed not supported\n");
496 return -EINVAL;
497 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400498 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
499 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300500 case SPEED_50000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400501 if (!(current_link.supported_caps &
502 QED_LM_50000baseKR2_Full_BIT)) {
503 DP_INFO(edev, "50G speed not supported\n");
504 return -EINVAL;
505 }
506 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
507 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300508 case SPEED_100000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400509 if (!(current_link.supported_caps &
510 QED_LM_100000baseKR4_Full_BIT)) {
511 DP_INFO(edev, "100G speed not supported\n");
512 return -EINVAL;
513 }
514 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200515 break;
516 default:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400517 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200518 return -EINVAL;
519 }
520 }
521
522 params.link_up = true;
523 edev->ops->common->set_link(edev->cdev, &params);
524
525 return 0;
526}
527
528static void qede_get_drvinfo(struct net_device *ndev,
529 struct ethtool_drvinfo *info)
530{
531 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
532 struct qede_dev *edev = netdev_priv(ndev);
533
534 strlcpy(info->driver, "qede", sizeof(info->driver));
535 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
536
537 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
538 edev->dev_info.common.fw_major,
539 edev->dev_info.common.fw_minor,
540 edev->dev_info.common.fw_rev,
541 edev->dev_info.common.fw_eng);
542
543 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
544 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
545 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
546 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
547 edev->dev_info.common.mfw_rev & 0xFF);
548
549 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
550 sizeof(info->fw_version)) {
551 snprintf(info->fw_version, sizeof(info->fw_version),
552 "mfw %s storm %s", mfw, storm);
553 } else {
554 snprintf(info->fw_version, sizeof(info->fw_version),
555 "%s %s", mfw, storm);
556 }
557
558 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
559}
560
Mintz, Yuval14d39642016-10-31 07:14:23 +0200561static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
562{
563 struct qede_dev *edev = netdev_priv(ndev);
564
565 if (edev->dev_info.common.wol_support) {
566 wol->supported = WAKE_MAGIC;
567 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
568 }
569}
570
571static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
572{
573 struct qede_dev *edev = netdev_priv(ndev);
574 bool wol_requested;
575 int rc;
576
577 if (wol->wolopts & ~WAKE_MAGIC) {
578 DP_INFO(edev,
579 "Can't support WoL options other than magic-packet\n");
580 return -EINVAL;
581 }
582
583 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
584 if (wol_requested == edev->wol_enabled)
585 return 0;
586
587 /* Need to actually change configuration */
588 if (!edev->dev_info.common.wol_support) {
589 DP_INFO(edev, "Device doesn't support WoL\n");
590 return -EINVAL;
591 }
592
593 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
594 if (!rc)
595 edev->wol_enabled = wol_requested;
596
597 return rc;
598}
599
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200600static u32 qede_get_msglevel(struct net_device *ndev)
601{
602 struct qede_dev *edev = netdev_priv(ndev);
603
Yuval Mintz1a635e42016-08-15 10:42:43 +0300604 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200605}
606
607static void qede_set_msglevel(struct net_device *ndev, u32 level)
608{
609 struct qede_dev *edev = netdev_priv(ndev);
610 u32 dp_module = 0;
611 u8 dp_level = 0;
612
613 qede_config_debug(level, &dp_module, &dp_level);
614
615 edev->dp_level = dp_level;
616 edev->dp_module = dp_module;
617 edev->ops->common->update_msglvl(edev->cdev,
618 dp_module, dp_level);
619}
620
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200621static int qede_nway_reset(struct net_device *dev)
622{
623 struct qede_dev *edev = netdev_priv(dev);
624 struct qed_link_output current_link;
625 struct qed_link_params link_params;
626
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300627 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Yuval Mintz1a635e42016-08-15 10:42:43 +0300628 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300629 return -EOPNOTSUPP;
630 }
631
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200632 if (!netif_running(dev))
633 return 0;
634
635 memset(&current_link, 0, sizeof(current_link));
636 edev->ops->common->get_link(edev->cdev, &current_link);
637 if (!current_link.link_up)
638 return 0;
639
640 /* Toggle the link */
641 memset(&link_params, 0, sizeof(link_params));
642 link_params.link_up = false;
643 edev->ops->common->set_link(edev->cdev, &link_params);
644 link_params.link_up = true;
645 edev->ops->common->set_link(edev->cdev, &link_params);
646
647 return 0;
648}
649
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200650static u32 qede_get_link(struct net_device *dev)
651{
652 struct qede_dev *edev = netdev_priv(dev);
653 struct qed_link_output current_link;
654
655 memset(&current_link, 0, sizeof(current_link));
656 edev->ops->common->get_link(edev->cdev, &current_link);
657
658 return current_link.link_up;
659}
660
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400661static int qede_get_coalesce(struct net_device *dev,
662 struct ethtool_coalesce *coal)
663{
664 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400665 u16 rxc, txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400666
667 memset(coal, 0, sizeof(struct ethtool_coalesce));
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400668 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
669
670 coal->rx_coalesce_usecs = rxc;
671 coal->tx_coalesce_usecs = txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400672
673 return 0;
674}
675
676static int qede_set_coalesce(struct net_device *dev,
677 struct ethtool_coalesce *coal)
678{
679 struct qede_dev *edev = netdev_priv(dev);
680 int i, rc = 0;
681 u16 rxc, txc;
682 u8 sb_id;
683
684 if (!netif_running(dev)) {
685 DP_INFO(edev, "Interface is down\n");
686 return -EINVAL;
687 }
688
689 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
690 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
691 DP_INFO(edev,
692 "Can't support requested %s coalesce value [max supported value %d]\n",
693 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
694 : "tx",
695 QED_COALESCE_MAX);
696 return -EINVAL;
697 }
698
699 rxc = (u16)coal->rx_coalesce_usecs;
700 txc = (u16)coal->tx_coalesce_usecs;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400701 for_each_queue(i) {
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400702 sb_id = edev->fp_array[i].sb_info->igu_sb_id;
703 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
704 (u8)i, sb_id);
705 if (rc) {
706 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
707 return rc;
708 }
709 }
710
711 return rc;
712}
713
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200714static void qede_get_ringparam(struct net_device *dev,
715 struct ethtool_ringparam *ering)
716{
717 struct qede_dev *edev = netdev_priv(dev);
718
719 ering->rx_max_pending = NUM_RX_BDS_MAX;
720 ering->rx_pending = edev->q_num_rx_buffers;
721 ering->tx_max_pending = NUM_TX_BDS_MAX;
722 ering->tx_pending = edev->q_num_tx_buffers;
723}
724
725static int qede_set_ringparam(struct net_device *dev,
726 struct ethtool_ringparam *ering)
727{
728 struct qede_dev *edev = netdev_priv(dev);
729
730 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
731 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
732 ering->rx_pending, ering->tx_pending);
733
734 /* Validate legality of configuration */
735 if (ering->rx_pending > NUM_RX_BDS_MAX ||
736 ering->rx_pending < NUM_RX_BDS_MIN ||
737 ering->tx_pending > NUM_TX_BDS_MAX ||
738 ering->tx_pending < NUM_TX_BDS_MIN) {
739 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
740 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
741 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
742 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
743 return -EINVAL;
744 }
745
746 /* Change ring size and re-load */
747 edev->q_num_rx_buffers = ering->rx_pending;
748 edev->q_num_tx_buffers = ering->tx_pending;
749
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200750 qede_reload(edev, NULL, false);
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200751
752 return 0;
753}
754
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200755static void qede_get_pauseparam(struct net_device *dev,
756 struct ethtool_pauseparam *epause)
757{
758 struct qede_dev *edev = netdev_priv(dev);
759 struct qed_link_output current_link;
760
761 memset(&current_link, 0, sizeof(current_link));
762 edev->ops->common->get_link(edev->cdev, &current_link);
763
764 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
765 epause->autoneg = true;
766 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
767 epause->rx_pause = true;
768 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
769 epause->tx_pause = true;
770
771 DP_VERBOSE(edev, QED_MSG_DEBUG,
772 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
773 epause->cmd, epause->autoneg, epause->rx_pause,
774 epause->tx_pause);
775}
776
777static int qede_set_pauseparam(struct net_device *dev,
778 struct ethtool_pauseparam *epause)
779{
780 struct qede_dev *edev = netdev_priv(dev);
781 struct qed_link_params params;
782 struct qed_link_output current_link;
783
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300784 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200785 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300786 "Pause settings are not allowed to be changed\n");
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200787 return -EOPNOTSUPP;
788 }
789
790 memset(&current_link, 0, sizeof(current_link));
791 edev->ops->common->get_link(edev->cdev, &current_link);
792
793 memset(&params, 0, sizeof(params));
794 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
795 if (epause->autoneg) {
Yuval Mintzd194fd22016-08-19 08:34:57 +0300796 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200797 DP_INFO(edev, "autoneg not supported\n");
798 return -EINVAL;
799 }
800 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
801 }
802 if (epause->rx_pause)
803 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
804 if (epause->tx_pause)
805 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
806
807 params.link_up = true;
808 edev->ops->common->set_link(edev->cdev, &params);
809
810 return 0;
811}
812
Tomer Tayare0971c82016-09-07 16:36:25 +0300813static void qede_get_regs(struct net_device *ndev,
814 struct ethtool_regs *regs, void *buffer)
815{
816 struct qede_dev *edev = netdev_priv(ndev);
817
818 regs->version = 0;
819 memset(buffer, 0, regs->len);
820
821 if (edev->ops && edev->ops->common)
822 edev->ops->common->dbg_all_data(edev->cdev, buffer);
823}
824
825static int qede_get_regs_len(struct net_device *ndev)
826{
827 struct qede_dev *edev = netdev_priv(ndev);
828
829 if (edev->ops && edev->ops->common)
830 return edev->ops->common->dbg_all_data_size(edev->cdev);
831 else
832 return -EINVAL;
833}
834
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200835static void qede_update_mtu(struct qede_dev *edev,
836 struct qede_reload_args *args)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200837{
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200838 edev->ndev->mtu = args->u.mtu;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200839}
840
841/* Netdevice NDOs */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200842int qede_change_mtu(struct net_device *ndev, int new_mtu)
843{
844 struct qede_dev *edev = netdev_priv(ndev);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200845 struct qede_reload_args args;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200846
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200847 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
848 "Configuring MTU size of %d\n", new_mtu);
849
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200850 /* Set the mtu field and re-start the interface if needed */
851 args.u.mtu = new_mtu;
852 args.func = &qede_update_mtu;
853 qede_reload(edev, &args, false);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200854
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200855 edev->ops->common->update_mtu(edev->cdev, new_mtu);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200856
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200857 return 0;
858}
859
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200860static void qede_get_channels(struct net_device *dev,
861 struct ethtool_channels *channels)
862{
863 struct qede_dev *edev = netdev_priv(dev);
864
865 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kallurubdc8cbd2016-10-21 04:43:39 -0400866 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
867 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400868 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
869 edev->fp_num_rx;
870 channels->tx_count = edev->fp_num_tx;
871 channels->rx_count = edev->fp_num_rx;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200872}
873
874static int qede_set_channels(struct net_device *dev,
875 struct ethtool_channels *channels)
876{
877 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400878 u32 count;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200879
880 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
881 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
882 channels->rx_count, channels->tx_count,
883 channels->other_count, channels->combined_count);
884
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400885 count = channels->rx_count + channels->tx_count +
886 channels->combined_count;
887
888 /* We don't support `other' channels */
889 if (channels->other_count) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200890 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
891 "command parameters not supported\n");
892 return -EINVAL;
893 }
894
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400895 if (!(channels->combined_count || (channels->rx_count &&
896 channels->tx_count))) {
897 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
898 "need to request at least one transmit and one receive channel\n");
899 return -EINVAL;
900 }
901
902 if (count > QEDE_MAX_RSS_CNT(edev)) {
903 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
904 "requested channels = %d max supported channels = %d\n",
905 count, QEDE_MAX_RSS_CNT(edev));
906 return -EINVAL;
907 }
908
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200909 /* Check if there was a change in the active parameters */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400910 if ((count == QEDE_QUEUE_CNT(edev)) &&
911 (channels->tx_count == edev->fp_num_tx) &&
912 (channels->rx_count == edev->fp_num_rx)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200913 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
914 "No change in active parameters\n");
915 return 0;
916 }
917
918 /* We need the number of queues to be divisible between the hwfns */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400919 if ((count % edev->dev_info.common.num_hwfns) ||
920 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
921 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200922 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400923 "Number of channels must be divisible by %04x\n",
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200924 edev->dev_info.common.num_hwfns);
925 return -EINVAL;
926 }
927
928 /* Set number of queues and reload if necessary */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400929 edev->req_queues = count;
930 edev->req_num_tx = channels->tx_count;
931 edev->req_num_rx = channels->rx_count;
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -0400932 /* Reset the indirection table if rx queue count is updated */
933 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
934 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200935 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -0400936 }
937
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200938 qede_reload(edev, NULL, false);
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200939
940 return 0;
941}
942
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200943static int qede_set_phys_id(struct net_device *dev,
944 enum ethtool_phys_id_state state)
945{
946 struct qede_dev *edev = netdev_priv(dev);
947 u8 led_state = 0;
948
949 switch (state) {
950 case ETHTOOL_ID_ACTIVE:
951 return 1; /* cycle on/off once per second */
952
953 case ETHTOOL_ID_ON:
954 led_state = QED_LED_MODE_ON;
955 break;
956
957 case ETHTOOL_ID_OFF:
958 led_state = QED_LED_MODE_OFF;
959 break;
960
961 case ETHTOOL_ID_INACTIVE:
962 led_state = QED_LED_MODE_RESTORE;
963 break;
964 }
965
966 edev->ops->common->set_led(edev->cdev, led_state);
967
968 return 0;
969}
970
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300971static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
972{
973 info->data = RXH_IP_SRC | RXH_IP_DST;
974
975 switch (info->flow_type) {
976 case TCP_V4_FLOW:
977 case TCP_V6_FLOW:
978 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
979 break;
980 case UDP_V4_FLOW:
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200981 if (edev->rss_caps & QED_RSS_IPV4_UDP)
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300982 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
983 break;
984 case UDP_V6_FLOW:
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200985 if (edev->rss_caps & QED_RSS_IPV6_UDP)
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300986 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
987 break;
988 case IPV4_FLOW:
989 case IPV6_FLOW:
990 break;
991 default:
992 info->data = 0;
993 break;
994 }
995
996 return 0;
997}
998
999static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1000 u32 *rules __always_unused)
1001{
1002 struct qede_dev *edev = netdev_priv(dev);
1003
1004 switch (info->cmd) {
1005 case ETHTOOL_GRXRINGS:
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001006 info->data = QEDE_RSS_COUNT(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001007 return 0;
1008 case ETHTOOL_GRXFH:
1009 return qede_get_rss_flags(edev, info);
1010 default:
1011 DP_ERR(edev, "Command parameters not supported\n");
1012 return -EOPNOTSUPP;
1013 }
1014}
1015
1016static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1017{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001018 struct qed_update_vport_params *vport_update_params;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001019 u8 set_caps = 0, clr_caps = 0;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001020 int rc = 0;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001021
1022 DP_VERBOSE(edev, QED_MSG_DEBUG,
1023 "Set rss flags command parameters: flow type = %d, data = %llu\n",
1024 info->flow_type, info->data);
1025
1026 switch (info->flow_type) {
1027 case TCP_V4_FLOW:
1028 case TCP_V6_FLOW:
1029 /* For TCP only 4-tuple hash is supported */
1030 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1031 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1032 DP_INFO(edev, "Command parameters not supported\n");
1033 return -EINVAL;
1034 }
1035 return 0;
1036 case UDP_V4_FLOW:
1037 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1038 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1039 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1040 set_caps = QED_RSS_IPV4_UDP;
1041 DP_VERBOSE(edev, QED_MSG_DEBUG,
1042 "UDP 4-tuple enabled\n");
1043 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1044 clr_caps = QED_RSS_IPV4_UDP;
1045 DP_VERBOSE(edev, QED_MSG_DEBUG,
1046 "UDP 4-tuple disabled\n");
1047 } else {
1048 return -EINVAL;
1049 }
1050 break;
1051 case UDP_V6_FLOW:
1052 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1053 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1054 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1055 set_caps = QED_RSS_IPV6_UDP;
1056 DP_VERBOSE(edev, QED_MSG_DEBUG,
1057 "UDP 4-tuple enabled\n");
1058 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1059 clr_caps = QED_RSS_IPV6_UDP;
1060 DP_VERBOSE(edev, QED_MSG_DEBUG,
1061 "UDP 4-tuple disabled\n");
1062 } else {
1063 return -EINVAL;
1064 }
1065 break;
1066 case IPV4_FLOW:
1067 case IPV6_FLOW:
1068 /* For IP only 2-tuple hash is supported */
1069 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1070 DP_INFO(edev, "Command parameters not supported\n");
1071 return -EINVAL;
1072 }
1073 return 0;
1074 case SCTP_V4_FLOW:
1075 case AH_ESP_V4_FLOW:
1076 case AH_V4_FLOW:
1077 case ESP_V4_FLOW:
1078 case SCTP_V6_FLOW:
1079 case AH_ESP_V6_FLOW:
1080 case AH_V6_FLOW:
1081 case ESP_V6_FLOW:
1082 case IP_USER_FLOW:
1083 case ETHER_FLOW:
1084 /* RSS is not supported for these protocols */
1085 if (info->data) {
1086 DP_INFO(edev, "Command parameters not supported\n");
1087 return -EINVAL;
1088 }
1089 return 0;
1090 default:
1091 return -EINVAL;
1092 }
1093
1094 /* No action is needed if there is no change in the rss capability */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001095 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001096 return 0;
1097
1098 /* Update internal configuration */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001099 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001100 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1101
1102 /* Re-configure if possible */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001103 __qede_lock(edev);
1104 if (edev->state == QEDE_STATE_OPEN) {
1105 vport_update_params = vzalloc(sizeof(*vport_update_params));
1106 if (!vport_update_params) {
1107 __qede_unlock(edev);
1108 return -ENOMEM;
1109 }
1110 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1111 &vport_update_params->update_rss_flg);
1112 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1113 vfree(vport_update_params);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001114 }
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001115 __qede_unlock(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001116
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001117 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001118}
1119
1120static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1121{
1122 struct qede_dev *edev = netdev_priv(dev);
1123
1124 switch (info->cmd) {
1125 case ETHTOOL_SRXFH:
1126 return qede_set_rss_flags(edev, info);
1127 default:
1128 DP_INFO(edev, "Command parameters not supported\n");
1129 return -EOPNOTSUPP;
1130 }
1131}
1132
1133static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1134{
1135 return QED_RSS_IND_TABLE_SIZE;
1136}
1137
1138static u32 qede_get_rxfh_key_size(struct net_device *dev)
1139{
1140 struct qede_dev *edev = netdev_priv(dev);
1141
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001142 return sizeof(edev->rss_key);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001143}
1144
1145static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1146{
1147 struct qede_dev *edev = netdev_priv(dev);
1148 int i;
1149
1150 if (hfunc)
1151 *hfunc = ETH_RSS_HASH_TOP;
1152
1153 if (!indir)
1154 return 0;
1155
1156 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001157 indir[i] = edev->rss_ind_table[i];
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001158
1159 if (key)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001160 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001161
1162 return 0;
1163}
1164
1165static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1166 const u8 *key, const u8 hfunc)
1167{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001168 struct qed_update_vport_params *vport_update_params;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001169 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001170 int i, rc = 0;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001171
Sudarsana Reddy Kalluruba300ce2016-10-21 04:43:40 -04001172 if (edev->dev_info.common.num_hwfns > 1) {
1173 DP_INFO(edev,
1174 "RSS configuration is not supported for 100G devices\n");
1175 return -EOPNOTSUPP;
1176 }
1177
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001178 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1179 return -EOPNOTSUPP;
1180
1181 if (!indir && !key)
1182 return 0;
1183
1184 if (indir) {
1185 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001186 edev->rss_ind_table[i] = indir[i];
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001187 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1188 }
1189
1190 if (key) {
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001191 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001192 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1193 }
1194
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001195 __qede_lock(edev);
1196 if (edev->state == QEDE_STATE_OPEN) {
1197 vport_update_params = vzalloc(sizeof(*vport_update_params));
1198 if (!vport_update_params) {
1199 __qede_unlock(edev);
1200 return -ENOMEM;
1201 }
1202 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1203 &vport_update_params->update_rss_flg);
1204 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1205 vfree(vport_update_params);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001206 }
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001207 __qede_unlock(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001208
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001209 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001210}
1211
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001212/* This function enables the interrupt generation and the NAPI on the device */
1213static void qede_netif_start(struct qede_dev *edev)
1214{
1215 int i;
1216
1217 if (!netif_running(edev->ndev))
1218 return;
1219
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001220 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001221 /* Update and reenable interrupts */
1222 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1223 napi_enable(&edev->fp_array[i].napi);
1224 }
1225}
1226
1227/* This function disables the NAPI and the interrupt generation on the device */
1228static void qede_netif_stop(struct qede_dev *edev)
1229{
1230 int i;
1231
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001232 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001233 napi_disable(&edev->fp_array[i].napi);
1234 /* Disable interrupts */
1235 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1236 }
1237}
1238
1239static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1240 struct sk_buff *skb)
1241{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001242 struct qede_tx_queue *txq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001243 struct eth_tx_1st_bd *first_bd;
1244 dma_addr_t mapping;
1245 int i, idx, val;
1246
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001247 for_each_queue(i) {
1248 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001249 txq = edev->fp_array[i].txq;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001250 break;
1251 }
1252 }
1253
1254 if (!txq) {
1255 DP_NOTICE(edev, "Tx path is not available\n");
1256 return -1;
1257 }
1258
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001259 /* Fill the entry in the SW ring and the BDs in the FW ring */
1260 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001261 txq->sw_tx_ring.skbs[idx].skb = skb;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001262 first_bd = qed_chain_produce(&txq->tx_pbl);
1263 memset(first_bd, 0, sizeof(*first_bd));
1264 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1265 first_bd->data.bd_flags.bitfields = val;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001266 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1267 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001268
1269 /* Map skb linear data for DMA and set in the first BD */
1270 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1271 skb_headlen(skb), DMA_TO_DEVICE);
1272 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1273 DP_NOTICE(edev, "SKB mapping failed\n");
1274 return -ENOMEM;
1275 }
1276 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1277
1278 /* update the first BD with the actual num BDs */
1279 first_bd->data.nbds = 1;
1280 txq->sw_tx_prod++;
1281 /* 'next page' entries are counted in the producer value */
1282 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
1283 txq->tx_db.data.bd_prod = val;
1284
1285 /* wmb makes sure that the BDs data is updated before updating the
1286 * producer, otherwise FW may read old data from the BDs.
1287 */
1288 wmb();
1289 barrier();
1290 writel(txq->tx_db.raw, txq->doorbell_addr);
1291
1292 /* mmiowb is needed to synchronize doorbell writes from more than one
1293 * processor. It guarantees that the write arrives to the device before
1294 * the queue lock is released and another start_xmit is called (possibly
1295 * on another CPU). Without this barrier, the next doorbell can bypass
1296 * this doorbell. This is applicable to IA64/Altix systems.
1297 */
1298 mmiowb();
1299
1300 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1301 if (qede_txq_has_work(txq))
1302 break;
1303 usleep_range(100, 200);
1304 }
1305
1306 if (!qede_txq_has_work(txq)) {
1307 DP_NOTICE(edev, "Tx completion didn't happen\n");
1308 return -1;
1309 }
1310
1311 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
Manish Choprafabd5452016-10-21 04:43:45 -04001312 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1313 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001314 txq->sw_tx_cons++;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001315 txq->sw_tx_ring.skbs[idx].skb = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001316
1317 return 0;
1318}
1319
1320static int qede_selftest_receive_traffic(struct qede_dev *edev)
1321{
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001322 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1323 struct eth_fast_path_rx_reg_cqe *fp_cqe;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001324 struct qede_rx_queue *rxq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001325 struct sw_rx_data *sw_rx_data;
1326 union eth_rx_cqe *cqe;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001327 int i, rc = 0;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001328 u8 *data_ptr;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001329
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001330 for_each_queue(i) {
1331 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1332 rxq = edev->fp_array[i].rxq;
1333 break;
1334 }
1335 }
1336
1337 if (!rxq) {
1338 DP_NOTICE(edev, "Rx path is not available\n");
1339 return -1;
1340 }
1341
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001342 /* The packet is expected to receive on rx-queue 0 even though RSS is
1343 * enabled. This is because the queue 0 is configured as the default
1344 * queue and that the loopback traffic is not IP.
1345 */
1346 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001347 if (!qede_has_rx_work(rxq)) {
1348 usleep_range(100, 200);
1349 continue;
1350 }
1351
1352 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1353 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1354
1355 /* Memory barrier to prevent the CPU from doing speculative
1356 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1357 * read before it is written by FW, then FW writes CQE and SB,
1358 * and then the CPU reads the hw_comp_cons, it will use an old
1359 * CQE.
1360 */
1361 rmb();
1362
1363 /* Get the CQE from the completion ring */
1364 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1365
1366 /* Get the data from the SW ring */
1367 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1368 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1369 fp_cqe = &cqe->fast_path_regular;
1370 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1371 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1372 fp_cqe->placement_offset +
1373 sw_rx_data->page_offset);
1374 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1375 ether_addr_equal(data_ptr + ETH_ALEN,
1376 edev->ndev->dev_addr)) {
1377 for (i = ETH_HLEN; i < len; i++)
1378 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1379 rc = -1;
1380 break;
1381 }
1382
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001383 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001384 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001385 break;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001386 }
1387
1388 DP_INFO(edev, "Not the transmitted packet\n");
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001389 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001390 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001391 }
1392
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001393 if (i == QEDE_SELFTEST_POLL_COUNT) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001394 DP_NOTICE(edev, "Failed to receive the traffic\n");
1395 return -1;
1396 }
1397
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001398 qede_update_rx_prod(edev, rxq);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001399
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001400 return rc;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001401}
1402
1403static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1404{
1405 struct qed_link_params link_params;
1406 struct sk_buff *skb = NULL;
1407 int rc = 0, i;
1408 u32 pkt_size;
1409 u8 *packet;
1410
1411 if (!netif_running(edev->ndev)) {
1412 DP_NOTICE(edev, "Interface is down\n");
1413 return -EINVAL;
1414 }
1415
1416 qede_netif_stop(edev);
1417
1418 /* Bring up the link in Loopback mode */
1419 memset(&link_params, 0, sizeof(link_params));
1420 link_params.link_up = true;
1421 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1422 link_params.loopback_mode = loopback_mode;
1423 edev->ops->common->set_link(edev->cdev, &link_params);
1424
1425 /* Wait for loopback configuration to apply */
1426 msleep_interruptible(500);
1427
1428 /* prepare the loopback packet */
1429 pkt_size = edev->ndev->mtu + ETH_HLEN;
1430
1431 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1432 if (!skb) {
1433 DP_INFO(edev, "Can't allocate skb\n");
1434 rc = -ENOMEM;
1435 goto test_loopback_exit;
1436 }
1437 packet = skb_put(skb, pkt_size);
1438 ether_addr_copy(packet, edev->ndev->dev_addr);
1439 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1440 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1441 for (i = ETH_HLEN; i < pkt_size; i++)
1442 packet[i] = (unsigned char)(i & 0xff);
1443
1444 rc = qede_selftest_transmit_traffic(edev, skb);
1445 if (rc)
1446 goto test_loopback_exit;
1447
1448 rc = qede_selftest_receive_traffic(edev);
1449 if (rc)
1450 goto test_loopback_exit;
1451
1452 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1453
1454test_loopback_exit:
1455 dev_kfree_skb(skb);
1456
1457 /* Bring up the link in Normal mode */
1458 memset(&link_params, 0, sizeof(link_params));
1459 link_params.link_up = true;
1460 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1461 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1462 edev->ops->common->set_link(edev->cdev, &link_params);
1463
1464 /* Wait for loopback configuration to apply */
1465 msleep_interruptible(500);
1466
1467 qede_netif_start(edev);
1468
1469 return rc;
1470}
1471
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001472static void qede_self_test(struct net_device *dev,
1473 struct ethtool_test *etest, u64 *buf)
1474{
1475 struct qede_dev *edev = netdev_priv(dev);
1476
1477 DP_VERBOSE(edev, QED_MSG_DEBUG,
1478 "Self-test command parameters: offline = %d, external_lb = %d\n",
1479 (etest->flags & ETH_TEST_FL_OFFLINE),
1480 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1481
1482 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1483
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001484 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1485 if (qede_selftest_run_loopback(edev,
1486 QED_LINK_LOOPBACK_INT_PHY)) {
1487 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1488 etest->flags |= ETH_TEST_FL_FAILED;
1489 }
1490 }
1491
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001492 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1493 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1494 etest->flags |= ETH_TEST_FL_FAILED;
1495 }
1496
1497 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1498 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1499 etest->flags |= ETH_TEST_FL_FAILED;
1500 }
1501
1502 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1503 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1504 etest->flags |= ETH_TEST_FL_FAILED;
1505 }
1506
1507 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1508 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1509 etest->flags |= ETH_TEST_FL_FAILED;
1510 }
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +02001511
1512 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1513 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1514 etest->flags |= ETH_TEST_FL_FAILED;
1515 }
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001516}
1517
Manish Chopra3d789992016-06-30 02:35:21 -04001518static int qede_set_tunable(struct net_device *dev,
1519 const struct ethtool_tunable *tuna,
1520 const void *data)
1521{
1522 struct qede_dev *edev = netdev_priv(dev);
1523 u32 val;
1524
1525 switch (tuna->id) {
1526 case ETHTOOL_RX_COPYBREAK:
1527 val = *(u32 *)data;
1528 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1529 DP_VERBOSE(edev, QED_MSG_DEBUG,
1530 "Invalid rx copy break value, range is [%u, %u]",
1531 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1532 return -EINVAL;
1533 }
1534
1535 edev->rx_copybreak = *(u32 *)data;
1536 break;
1537 default:
1538 return -EOPNOTSUPP;
1539 }
1540
1541 return 0;
1542}
1543
1544static int qede_get_tunable(struct net_device *dev,
1545 const struct ethtool_tunable *tuna, void *data)
1546{
1547 struct qede_dev *edev = netdev_priv(dev);
1548
1549 switch (tuna->id) {
1550 case ETHTOOL_RX_COPYBREAK:
1551 *(u32 *)data = edev->rx_copybreak;
1552 break;
1553 default:
1554 return -EOPNOTSUPP;
1555 }
1556
1557 return 0;
1558}
1559
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001560static const struct ethtool_ops qede_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001561 .get_link_ksettings = qede_get_link_ksettings,
1562 .set_link_ksettings = qede_set_link_ksettings,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001563 .get_drvinfo = qede_get_drvinfo,
Tomer Tayare0971c82016-09-07 16:36:25 +03001564 .get_regs_len = qede_get_regs_len,
1565 .get_regs = qede_get_regs,
Mintz, Yuval14d39642016-10-31 07:14:23 +02001566 .get_wol = qede_get_wol,
1567 .set_wol = qede_set_wol,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001568 .get_msglevel = qede_get_msglevel,
1569 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +02001570 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001571 .get_link = qede_get_link,
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -04001572 .get_coalesce = qede_get_coalesce,
1573 .set_coalesce = qede_set_coalesce,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +02001574 .get_ringparam = qede_get_ringparam,
1575 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +02001576 .get_pauseparam = qede_get_pauseparam,
1577 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001578 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +02001579 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001580 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +03001581 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001582 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001583 .get_rxnfc = qede_get_rxnfc,
1584 .set_rxnfc = qede_set_rxnfc,
1585 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1586 .get_rxfh_key_size = qede_get_rxfh_key_size,
1587 .get_rxfh = qede_get_rxfh,
1588 .set_rxfh = qede_set_rxfh,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001589 .get_channels = qede_get_channels,
1590 .set_channels = qede_set_channels,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001591 .self_test = qede_self_test,
Manish Chopra3d789992016-06-30 02:35:21 -04001592 .get_tunable = qede_get_tunable,
1593 .set_tunable = qede_set_tunable,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001594};
1595
Yuval Mintzfefb0202016-05-11 16:36:19 +03001596static const struct ethtool_ops qede_vf_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001597 .get_link_ksettings = qede_get_link_ksettings,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001598 .get_drvinfo = qede_get_drvinfo,
1599 .get_msglevel = qede_get_msglevel,
1600 .set_msglevel = qede_set_msglevel,
1601 .get_link = qede_get_link,
1602 .get_ringparam = qede_get_ringparam,
1603 .set_ringparam = qede_set_ringparam,
1604 .get_strings = qede_get_strings,
1605 .get_ethtool_stats = qede_get_ethtool_stats,
1606 .get_priv_flags = qede_get_priv_flags,
1607 .get_sset_count = qede_get_sset_count,
1608 .get_rxnfc = qede_get_rxnfc,
1609 .set_rxnfc = qede_set_rxnfc,
1610 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1611 .get_rxfh_key_size = qede_get_rxfh_key_size,
1612 .get_rxfh = qede_get_rxfh,
1613 .set_rxfh = qede_set_rxfh,
1614 .get_channels = qede_get_channels,
1615 .set_channels = qede_set_channels,
Manish Chopra3d789992016-06-30 02:35:21 -04001616 .get_tunable = qede_get_tunable,
1617 .set_tunable = qede_set_tunable,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001618};
1619
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001620void qede_set_ethtool_ops(struct net_device *dev)
1621{
Yuval Mintzfefb0202016-05-11 16:36:19 +03001622 struct qede_dev *edev = netdev_priv(dev);
1623
1624 if (IS_VF(edev))
1625 dev->ethtool_ops = &qede_vf_ethtool_ops;
1626 else
1627 dev->ethtool_ops = &qede_ethtool_ops;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001628}