blob: 8e971b289d4b458b639fc6f5514a4d1391871680 [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>
40#include "qede.h"
41
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020042#define QEDE_RQSTAT_OFFSET(stat_name) \
43 (offsetof(struct qede_rx_queue, stat_name))
44#define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
45#define QEDE_RQSTAT(stat_name) \
46 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040047
48#define QEDE_SELFTEST_POLL_COUNT 100
49
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020050static const struct {
51 u64 offset;
52 char string[ETH_GSTRING_LEN];
53} qede_rqstats_arr[] = {
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040054 QEDE_RQSTAT(rcv_pkts),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020055 QEDE_RQSTAT(rx_hw_errors),
56 QEDE_RQSTAT(rx_alloc_errors),
Manish Choprac72a6122016-06-30 02:35:18 -040057 QEDE_RQSTAT(rx_ip_frags),
Mintz, Yuval496e0512016-11-29 16:47:09 +020058 QEDE_RQSTAT(xdp_no_pass),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020059};
60
61#define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040062#define QEDE_TQSTAT_OFFSET(stat_name) \
63 (offsetof(struct qede_tx_queue, stat_name))
64#define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
65#define QEDE_TQSTAT(stat_name) \
66 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
67#define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
68static const struct {
69 u64 offset;
70 char string[ETH_GSTRING_LEN];
71} qede_tqstats_arr[] = {
72 QEDE_TQSTAT(xmit_pkts),
73 QEDE_TQSTAT(stopped_cnt),
74};
75
Mintz, Yuval4dbcd642016-11-29 16:47:03 +020076#define QEDE_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
77#define QEDE_STAT_STRING(stat_name) (#stat_name)
78#define _QEDE_STAT(stat_name, pf_only) \
79 {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
80#define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
81#define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020082static const struct {
83 u64 offset;
84 char string[ETH_GSTRING_LEN];
85 bool pf_only;
86} qede_stats_arr[] = {
87 QEDE_STAT(rx_ucast_bytes),
88 QEDE_STAT(rx_mcast_bytes),
89 QEDE_STAT(rx_bcast_bytes),
90 QEDE_STAT(rx_ucast_pkts),
91 QEDE_STAT(rx_mcast_pkts),
92 QEDE_STAT(rx_bcast_pkts),
93
94 QEDE_STAT(tx_ucast_bytes),
95 QEDE_STAT(tx_mcast_bytes),
96 QEDE_STAT(tx_bcast_bytes),
97 QEDE_STAT(tx_ucast_pkts),
98 QEDE_STAT(tx_mcast_pkts),
99 QEDE_STAT(tx_bcast_pkts),
100
101 QEDE_PF_STAT(rx_64_byte_packets),
Yuval Mintzd4967cf2016-04-22 08:41:01 +0300102 QEDE_PF_STAT(rx_65_to_127_byte_packets),
103 QEDE_PF_STAT(rx_128_to_255_byte_packets),
104 QEDE_PF_STAT(rx_256_to_511_byte_packets),
105 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
106 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
107 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
108 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
109 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
110 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
111 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200112 QEDE_PF_STAT(tx_64_byte_packets),
113 QEDE_PF_STAT(tx_65_to_127_byte_packets),
114 QEDE_PF_STAT(tx_128_to_255_byte_packets),
115 QEDE_PF_STAT(tx_256_to_511_byte_packets),
116 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
117 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
118 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
119 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
120 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
121 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
122
123 QEDE_PF_STAT(rx_mac_crtl_frames),
124 QEDE_PF_STAT(tx_mac_ctrl_frames),
125 QEDE_PF_STAT(rx_pause_frames),
126 QEDE_PF_STAT(tx_pause_frames),
127 QEDE_PF_STAT(rx_pfc_frames),
128 QEDE_PF_STAT(tx_pfc_frames),
129
130 QEDE_PF_STAT(rx_crc_errors),
131 QEDE_PF_STAT(rx_align_errors),
132 QEDE_PF_STAT(rx_carrier_errors),
133 QEDE_PF_STAT(rx_oversize_packets),
134 QEDE_PF_STAT(rx_jabbers),
135 QEDE_PF_STAT(rx_undersize_packets),
136 QEDE_PF_STAT(rx_fragments),
137 QEDE_PF_STAT(tx_lpi_entry_count),
138 QEDE_PF_STAT(tx_total_collisions),
139 QEDE_PF_STAT(brb_truncates),
140 QEDE_PF_STAT(brb_discards),
141 QEDE_STAT(no_buff_discards),
142 QEDE_PF_STAT(mftag_filter_discards),
143 QEDE_PF_STAT(mac_filter_discards),
144 QEDE_STAT(tx_err_drop_pkts),
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400145 QEDE_STAT(ttl0_discard),
146 QEDE_STAT(packet_too_big_discard),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200147
148 QEDE_STAT(coalesced_pkts),
149 QEDE_STAT(coalesced_events),
150 QEDE_STAT(coalesced_aborts_num),
151 QEDE_STAT(non_coalesced_pkts),
152 QEDE_STAT(coalesced_bytes),
153};
154
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200155#define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
156
Yuval Mintzf3e72102016-04-22 08:41:02 +0300157enum {
158 QEDE_PRI_FLAG_CMT,
159 QEDE_PRI_FLAG_LEN,
160};
161
162static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
163 "Coupled-Function",
164};
165
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400166enum qede_ethtool_tests {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400167 QEDE_ETHTOOL_INT_LOOPBACK,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400168 QEDE_ETHTOOL_INTERRUPT_TEST,
169 QEDE_ETHTOOL_MEMORY_TEST,
170 QEDE_ETHTOOL_REGISTER_TEST,
171 QEDE_ETHTOOL_CLOCK_TEST,
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200172 QEDE_ETHTOOL_NVRAM_TEST,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400173 QEDE_ETHTOOL_TEST_MAX
174};
175
176static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400177 "Internal loopback (offline)",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400178 "Interrupt (online)\t",
179 "Memory (online)\t\t",
180 "Register (online)\t",
181 "Clock (online)\t\t",
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200182 "Nvram (online)\t\t",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400183};
184
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200185static void qede_get_strings_stats_txq(struct qede_dev *edev,
186 struct qede_tx_queue *txq, u8 **buf)
187{
188 int i;
189
190 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200191 if (txq->is_xdp)
192 sprintf(*buf, "%d [XDP]: %s",
193 QEDE_TXQ_XDP_TO_IDX(edev, txq),
194 qede_tqstats_arr[i].string);
195 else
196 sprintf(*buf, "%d: %s", txq->index,
197 qede_tqstats_arr[i].string);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200198 *buf += ETH_GSTRING_LEN;
199 }
200}
201
202static void qede_get_strings_stats_rxq(struct qede_dev *edev,
203 struct qede_rx_queue *rxq, u8 **buf)
204{
205 int i;
206
207 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
208 sprintf(*buf, "%d: %s", rxq->rxq_id,
209 qede_rqstats_arr[i].string);
210 *buf += ETH_GSTRING_LEN;
211 }
212}
213
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200214static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
215{
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200216 struct qede_fastpath *fp;
217 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200218
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200219 /* Account for queue statistics */
220 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
221 fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400222
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200223 if (fp->type & QEDE_FASTPATH_RX)
224 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
Mintz, Yuvalcbbf0492016-10-30 10:25:42 +0200225
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200226 if (fp->type & QEDE_FASTPATH_XDP)
227 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
228
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200229 if (fp->type & QEDE_FASTPATH_TX)
230 qede_get_strings_stats_txq(edev, fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400231 }
232
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200233 /* Account for non-queue statistics */
234 for (i = 0; i < QEDE_NUM_STATS; i++) {
Yuval Mintzfefb0202016-05-11 16:36:19 +0300235 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
236 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200237 strcpy(buf, qede_stats_arr[i].string);
238 buf += ETH_GSTRING_LEN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200239 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200240}
241
242static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
243{
244 struct qede_dev *edev = netdev_priv(dev);
245
246 switch (stringset) {
247 case ETH_SS_STATS:
248 qede_get_strings_stats(edev, buf);
249 break;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300250 case ETH_SS_PRIV_FLAGS:
251 memcpy(buf, qede_private_arr,
252 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
253 break;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400254 case ETH_SS_TEST:
255 memcpy(buf, qede_tests_str_arr,
256 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
257 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200258 default:
259 DP_VERBOSE(edev, QED_MSG_DEBUG,
260 "Unsupported stringset 0x%08x\n", stringset);
261 }
262}
263
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200264static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
265{
266 int i;
267
268 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
269 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
270 (*buf)++;
271 }
272}
273
274static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
275{
276 int i;
277
278 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
279 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
280 (*buf)++;
281 }
282}
283
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200284static void qede_get_ethtool_stats(struct net_device *dev,
285 struct ethtool_stats *stats, u64 *buf)
286{
287 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200288 struct qede_fastpath *fp;
289 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200290
291 qede_fill_by_demand_stats(edev);
292
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200293 /* Need to protect the access to the fastpath array */
294 __qede_lock(edev);
295
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200296 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
297 fp = &edev->fp_array[i];
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200298
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200299 if (fp->type & QEDE_FASTPATH_RX)
300 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400301
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200302 if (fp->type & QEDE_FASTPATH_XDP)
303 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
304
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200305 if (fp->type & QEDE_FASTPATH_TX)
306 qede_get_ethtool_stats_txq(fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400307 }
308
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200309 for (i = 0; i < QEDE_NUM_STATS; i++) {
310 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
Yuval Mintzfefb0202016-05-11 16:36:19 +0300311 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200312 *buf = *((u64 *)(((void *)&edev->stats) +
313 qede_stats_arr[i].offset));
314
315 buf++;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300316 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200317
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200318 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200319}
320
321static int qede_get_sset_count(struct net_device *dev, int stringset)
322{
323 struct qede_dev *edev = netdev_priv(dev);
324 int num_stats = QEDE_NUM_STATS;
325
326 switch (stringset) {
327 case ETH_SS_STATS:
Yuval Mintzfefb0202016-05-11 16:36:19 +0300328 if (IS_VF(edev)) {
329 int i;
330
331 for (i = 0; i < QEDE_NUM_STATS; i++)
332 if (qede_stats_arr[i].pf_only)
333 num_stats--;
334 }
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200335
336 /* Account for the Regular Tx statistics */
337 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
338
339 /* Account for the Regular Rx statistics */
340 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
341
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200342 /* Account for XDP statistics [if needed] */
343 if (edev->xdp_prog)
344 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200345 return num_stats;
346
Yuval Mintzf3e72102016-04-22 08:41:02 +0300347 case ETH_SS_PRIV_FLAGS:
348 return QEDE_PRI_FLAG_LEN;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400349 case ETH_SS_TEST:
Yuval Mintz6ecb0a02016-05-26 11:01:19 +0300350 if (!IS_VF(edev))
351 return QEDE_ETHTOOL_TEST_MAX;
352 else
353 return 0;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200354 default:
355 DP_VERBOSE(edev, QED_MSG_DEBUG,
356 "Unsupported stringset 0x%08x\n", stringset);
357 return -EINVAL;
358 }
359}
360
Yuval Mintzf3e72102016-04-22 08:41:02 +0300361static u32 qede_get_priv_flags(struct net_device *dev)
362{
363 struct qede_dev *edev = netdev_priv(dev);
364
365 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
366}
367
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400368struct qede_link_mode_mapping {
369 u32 qed_link_mode;
370 u32 ethtool_link_mode;
371};
372
373static const struct qede_link_mode_mapping qed_lm_map[] = {
374 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
375 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
376 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
377 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
378 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
379 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
380 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
381 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
382 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
383 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
384 {QED_LM_100000baseKR4_Full_BIT,
385 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
386};
387
388#define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
389{ \
390 int i; \
391 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200392 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400393 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
394 __set_bit(qed_lm_map[i].ethtool_link_mode,\
395 lk_ksettings->link_modes.name); \
396 } \
397}
398
399#define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
400{ \
401 int i; \
402 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200403 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400404 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
405 lk_ksettings->link_modes.name)) \
406 caps |= qed_lm_map[i].qed_link_mode; \
407 } \
408}
409
410static int qede_get_link_ksettings(struct net_device *dev,
411 struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200412{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400413 struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200414 struct qede_dev *edev = netdev_priv(dev);
415 struct qed_link_output current_link;
416
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200417 __qede_lock(edev);
418
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200419 memset(&current_link, 0, sizeof(current_link));
420 edev->ops->common->get_link(edev->cdev, &current_link);
421
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400422 ethtool_link_ksettings_zero_link_mode(cmd, supported);
423 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
424
425 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
426 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
427
428 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
429 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
430
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200431 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400432 base->speed = current_link.speed;
433 base->duplex = current_link.duplex;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200434 } else {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400435 base->speed = SPEED_UNKNOWN;
436 base->duplex = DUPLEX_UNKNOWN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200437 }
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200438
439 __qede_unlock(edev);
440
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400441 base->port = current_link.port;
442 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
443 AUTONEG_DISABLE;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200444
445 return 0;
446}
447
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400448static int qede_set_link_ksettings(struct net_device *dev,
449 const struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200450{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400451 const struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200452 struct qede_dev *edev = netdev_priv(dev);
453 struct qed_link_output current_link;
454 struct qed_link_params params;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200455
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300456 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400457 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200458 return -EOPNOTSUPP;
459 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200460 memset(&current_link, 0, sizeof(current_link));
461 memset(&params, 0, sizeof(params));
462 edev->ops->common->get_link(edev->cdev, &current_link);
463
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200464 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
465 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400466 if (base->autoneg == AUTONEG_ENABLE) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200467 params.autoneg = true;
468 params.forced_speed = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400469 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
470 } else { /* forced speed */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200471 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
472 params.autoneg = false;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400473 params.forced_speed = base->speed;
474 switch (base->speed) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200475 case SPEED_10000:
476 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400477 QED_LM_10000baseKR_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200478 DP_INFO(edev, "10G speed not supported\n");
479 return -EINVAL;
480 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400481 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
482 break;
483 case SPEED_25000:
484 if (!(current_link.supported_caps &
485 QED_LM_25000baseKR_Full_BIT)) {
486 DP_INFO(edev, "25G speed not supported\n");
487 return -EINVAL;
488 }
489 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200490 break;
491 case SPEED_40000:
492 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400493 QED_LM_40000baseLR4_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200494 DP_INFO(edev, "40G speed not supported\n");
495 return -EINVAL;
496 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400497 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
498 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300499 case SPEED_50000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400500 if (!(current_link.supported_caps &
501 QED_LM_50000baseKR2_Full_BIT)) {
502 DP_INFO(edev, "50G speed not supported\n");
503 return -EINVAL;
504 }
505 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
506 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300507 case SPEED_100000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400508 if (!(current_link.supported_caps &
509 QED_LM_100000baseKR4_Full_BIT)) {
510 DP_INFO(edev, "100G speed not supported\n");
511 return -EINVAL;
512 }
513 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200514 break;
515 default:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400516 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200517 return -EINVAL;
518 }
519 }
520
521 params.link_up = true;
522 edev->ops->common->set_link(edev->cdev, &params);
523
524 return 0;
525}
526
527static void qede_get_drvinfo(struct net_device *ndev,
528 struct ethtool_drvinfo *info)
529{
530 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
531 struct qede_dev *edev = netdev_priv(ndev);
532
533 strlcpy(info->driver, "qede", sizeof(info->driver));
534 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
535
536 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
537 edev->dev_info.common.fw_major,
538 edev->dev_info.common.fw_minor,
539 edev->dev_info.common.fw_rev,
540 edev->dev_info.common.fw_eng);
541
542 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
543 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
544 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
545 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
546 edev->dev_info.common.mfw_rev & 0xFF);
547
548 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
549 sizeof(info->fw_version)) {
550 snprintf(info->fw_version, sizeof(info->fw_version),
551 "mfw %s storm %s", mfw, storm);
552 } else {
553 snprintf(info->fw_version, sizeof(info->fw_version),
554 "%s %s", mfw, storm);
555 }
556
557 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
558}
559
Mintz, Yuval14d39642016-10-31 07:14:23 +0200560static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
561{
562 struct qede_dev *edev = netdev_priv(ndev);
563
564 if (edev->dev_info.common.wol_support) {
565 wol->supported = WAKE_MAGIC;
566 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
567 }
568}
569
570static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
571{
572 struct qede_dev *edev = netdev_priv(ndev);
573 bool wol_requested;
574 int rc;
575
576 if (wol->wolopts & ~WAKE_MAGIC) {
577 DP_INFO(edev,
578 "Can't support WoL options other than magic-packet\n");
579 return -EINVAL;
580 }
581
582 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
583 if (wol_requested == edev->wol_enabled)
584 return 0;
585
586 /* Need to actually change configuration */
587 if (!edev->dev_info.common.wol_support) {
588 DP_INFO(edev, "Device doesn't support WoL\n");
589 return -EINVAL;
590 }
591
592 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
593 if (!rc)
594 edev->wol_enabled = wol_requested;
595
596 return rc;
597}
598
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200599static u32 qede_get_msglevel(struct net_device *ndev)
600{
601 struct qede_dev *edev = netdev_priv(ndev);
602
Yuval Mintz1a635e42016-08-15 10:42:43 +0300603 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200604}
605
606static void qede_set_msglevel(struct net_device *ndev, u32 level)
607{
608 struct qede_dev *edev = netdev_priv(ndev);
609 u32 dp_module = 0;
610 u8 dp_level = 0;
611
612 qede_config_debug(level, &dp_module, &dp_level);
613
614 edev->dp_level = dp_level;
615 edev->dp_module = dp_module;
616 edev->ops->common->update_msglvl(edev->cdev,
617 dp_module, dp_level);
618}
619
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200620static int qede_nway_reset(struct net_device *dev)
621{
622 struct qede_dev *edev = netdev_priv(dev);
623 struct qed_link_output current_link;
624 struct qed_link_params link_params;
625
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300626 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Yuval Mintz1a635e42016-08-15 10:42:43 +0300627 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300628 return -EOPNOTSUPP;
629 }
630
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200631 if (!netif_running(dev))
632 return 0;
633
634 memset(&current_link, 0, sizeof(current_link));
635 edev->ops->common->get_link(edev->cdev, &current_link);
636 if (!current_link.link_up)
637 return 0;
638
639 /* Toggle the link */
640 memset(&link_params, 0, sizeof(link_params));
641 link_params.link_up = false;
642 edev->ops->common->set_link(edev->cdev, &link_params);
643 link_params.link_up = true;
644 edev->ops->common->set_link(edev->cdev, &link_params);
645
646 return 0;
647}
648
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200649static u32 qede_get_link(struct net_device *dev)
650{
651 struct qede_dev *edev = netdev_priv(dev);
652 struct qed_link_output current_link;
653
654 memset(&current_link, 0, sizeof(current_link));
655 edev->ops->common->get_link(edev->cdev, &current_link);
656
657 return current_link.link_up;
658}
659
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400660static int qede_get_coalesce(struct net_device *dev,
661 struct ethtool_coalesce *coal)
662{
663 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400664 u16 rxc, txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400665
666 memset(coal, 0, sizeof(struct ethtool_coalesce));
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400667 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
668
669 coal->rx_coalesce_usecs = rxc;
670 coal->tx_coalesce_usecs = txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400671
672 return 0;
673}
674
675static int qede_set_coalesce(struct net_device *dev,
676 struct ethtool_coalesce *coal)
677{
678 struct qede_dev *edev = netdev_priv(dev);
679 int i, rc = 0;
680 u16 rxc, txc;
681 u8 sb_id;
682
683 if (!netif_running(dev)) {
684 DP_INFO(edev, "Interface is down\n");
685 return -EINVAL;
686 }
687
688 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
689 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
690 DP_INFO(edev,
691 "Can't support requested %s coalesce value [max supported value %d]\n",
692 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
693 : "tx",
694 QED_COALESCE_MAX);
695 return -EINVAL;
696 }
697
698 rxc = (u16)coal->rx_coalesce_usecs;
699 txc = (u16)coal->tx_coalesce_usecs;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400700 for_each_queue(i) {
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400701 sb_id = edev->fp_array[i].sb_info->igu_sb_id;
702 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
703 (u8)i, sb_id);
704 if (rc) {
705 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
706 return rc;
707 }
708 }
709
710 return rc;
711}
712
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200713static void qede_get_ringparam(struct net_device *dev,
714 struct ethtool_ringparam *ering)
715{
716 struct qede_dev *edev = netdev_priv(dev);
717
718 ering->rx_max_pending = NUM_RX_BDS_MAX;
719 ering->rx_pending = edev->q_num_rx_buffers;
720 ering->tx_max_pending = NUM_TX_BDS_MAX;
721 ering->tx_pending = edev->q_num_tx_buffers;
722}
723
724static int qede_set_ringparam(struct net_device *dev,
725 struct ethtool_ringparam *ering)
726{
727 struct qede_dev *edev = netdev_priv(dev);
728
729 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
730 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
731 ering->rx_pending, ering->tx_pending);
732
733 /* Validate legality of configuration */
734 if (ering->rx_pending > NUM_RX_BDS_MAX ||
735 ering->rx_pending < NUM_RX_BDS_MIN ||
736 ering->tx_pending > NUM_TX_BDS_MAX ||
737 ering->tx_pending < NUM_TX_BDS_MIN) {
738 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
739 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
740 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
741 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
742 return -EINVAL;
743 }
744
745 /* Change ring size and re-load */
746 edev->q_num_rx_buffers = ering->rx_pending;
747 edev->q_num_tx_buffers = ering->tx_pending;
748
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200749 qede_reload(edev, NULL, false);
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200750
751 return 0;
752}
753
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200754static void qede_get_pauseparam(struct net_device *dev,
755 struct ethtool_pauseparam *epause)
756{
757 struct qede_dev *edev = netdev_priv(dev);
758 struct qed_link_output current_link;
759
760 memset(&current_link, 0, sizeof(current_link));
761 edev->ops->common->get_link(edev->cdev, &current_link);
762
763 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
764 epause->autoneg = true;
765 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
766 epause->rx_pause = true;
767 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
768 epause->tx_pause = true;
769
770 DP_VERBOSE(edev, QED_MSG_DEBUG,
771 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
772 epause->cmd, epause->autoneg, epause->rx_pause,
773 epause->tx_pause);
774}
775
776static int qede_set_pauseparam(struct net_device *dev,
777 struct ethtool_pauseparam *epause)
778{
779 struct qede_dev *edev = netdev_priv(dev);
780 struct qed_link_params params;
781 struct qed_link_output current_link;
782
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300783 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200784 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300785 "Pause settings are not allowed to be changed\n");
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200786 return -EOPNOTSUPP;
787 }
788
789 memset(&current_link, 0, sizeof(current_link));
790 edev->ops->common->get_link(edev->cdev, &current_link);
791
792 memset(&params, 0, sizeof(params));
793 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
794 if (epause->autoneg) {
Yuval Mintzd194fd22016-08-19 08:34:57 +0300795 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200796 DP_INFO(edev, "autoneg not supported\n");
797 return -EINVAL;
798 }
799 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
800 }
801 if (epause->rx_pause)
802 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
803 if (epause->tx_pause)
804 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
805
806 params.link_up = true;
807 edev->ops->common->set_link(edev->cdev, &params);
808
809 return 0;
810}
811
Tomer Tayare0971c82016-09-07 16:36:25 +0300812static void qede_get_regs(struct net_device *ndev,
813 struct ethtool_regs *regs, void *buffer)
814{
815 struct qede_dev *edev = netdev_priv(ndev);
816
817 regs->version = 0;
818 memset(buffer, 0, regs->len);
819
820 if (edev->ops && edev->ops->common)
821 edev->ops->common->dbg_all_data(edev->cdev, buffer);
822}
823
824static int qede_get_regs_len(struct net_device *ndev)
825{
826 struct qede_dev *edev = netdev_priv(ndev);
827
828 if (edev->ops && edev->ops->common)
829 return edev->ops->common->dbg_all_data_size(edev->cdev);
830 else
831 return -EINVAL;
832}
833
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200834static void qede_update_mtu(struct qede_dev *edev,
835 struct qede_reload_args *args)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200836{
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200837 edev->ndev->mtu = args->u.mtu;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200838}
839
840/* Netdevice NDOs */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200841int qede_change_mtu(struct net_device *ndev, int new_mtu)
842{
843 struct qede_dev *edev = netdev_priv(ndev);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200844 struct qede_reload_args args;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200845
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200846 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
847 "Configuring MTU size of %d\n", new_mtu);
848
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200849 /* Set the mtu field and re-start the interface if needed */
850 args.u.mtu = new_mtu;
851 args.func = &qede_update_mtu;
852 qede_reload(edev, &args, false);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200853
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200854 edev->ops->common->update_mtu(edev->cdev, new_mtu);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200855
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200856 return 0;
857}
858
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200859static void qede_get_channels(struct net_device *dev,
860 struct ethtool_channels *channels)
861{
862 struct qede_dev *edev = netdev_priv(dev);
863
864 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kallurubdc8cbd2016-10-21 04:43:39 -0400865 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
866 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400867 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
868 edev->fp_num_rx;
869 channels->tx_count = edev->fp_num_tx;
870 channels->rx_count = edev->fp_num_rx;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200871}
872
873static int qede_set_channels(struct net_device *dev,
874 struct ethtool_channels *channels)
875{
876 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400877 u32 count;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200878
879 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
880 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
881 channels->rx_count, channels->tx_count,
882 channels->other_count, channels->combined_count);
883
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400884 count = channels->rx_count + channels->tx_count +
885 channels->combined_count;
886
887 /* We don't support `other' channels */
888 if (channels->other_count) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200889 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
890 "command parameters not supported\n");
891 return -EINVAL;
892 }
893
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400894 if (!(channels->combined_count || (channels->rx_count &&
895 channels->tx_count))) {
896 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
897 "need to request at least one transmit and one receive channel\n");
898 return -EINVAL;
899 }
900
901 if (count > QEDE_MAX_RSS_CNT(edev)) {
902 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
903 "requested channels = %d max supported channels = %d\n",
904 count, QEDE_MAX_RSS_CNT(edev));
905 return -EINVAL;
906 }
907
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200908 /* Check if there was a change in the active parameters */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400909 if ((count == QEDE_QUEUE_CNT(edev)) &&
910 (channels->tx_count == edev->fp_num_tx) &&
911 (channels->rx_count == edev->fp_num_rx)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200912 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
913 "No change in active parameters\n");
914 return 0;
915 }
916
917 /* We need the number of queues to be divisible between the hwfns */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400918 if ((count % edev->dev_info.common.num_hwfns) ||
919 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
920 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200921 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400922 "Number of channels must be divisible by %04x\n",
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200923 edev->dev_info.common.num_hwfns);
924 return -EINVAL;
925 }
926
927 /* Set number of queues and reload if necessary */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400928 edev->req_queues = count;
929 edev->req_num_tx = channels->tx_count;
930 edev->req_num_rx = channels->rx_count;
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -0400931 /* Reset the indirection table if rx queue count is updated */
932 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
933 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
934 memset(&edev->rss_params.rss_ind_table, 0,
935 sizeof(edev->rss_params.rss_ind_table));
936 }
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:
981 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
982 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
983 break;
984 case UDP_V6_FLOW:
985 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
986 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{
1018 struct qed_update_vport_params vport_update_params;
1019 u8 set_caps = 0, clr_caps = 0;
1020
1021 DP_VERBOSE(edev, QED_MSG_DEBUG,
1022 "Set rss flags command parameters: flow type = %d, data = %llu\n",
1023 info->flow_type, info->data);
1024
1025 switch (info->flow_type) {
1026 case TCP_V4_FLOW:
1027 case TCP_V6_FLOW:
1028 /* For TCP only 4-tuple hash is supported */
1029 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1030 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1031 DP_INFO(edev, "Command parameters not supported\n");
1032 return -EINVAL;
1033 }
1034 return 0;
1035 case UDP_V4_FLOW:
1036 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1037 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1038 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1039 set_caps = QED_RSS_IPV4_UDP;
1040 DP_VERBOSE(edev, QED_MSG_DEBUG,
1041 "UDP 4-tuple enabled\n");
1042 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1043 clr_caps = QED_RSS_IPV4_UDP;
1044 DP_VERBOSE(edev, QED_MSG_DEBUG,
1045 "UDP 4-tuple disabled\n");
1046 } else {
1047 return -EINVAL;
1048 }
1049 break;
1050 case UDP_V6_FLOW:
1051 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1052 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1053 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1054 set_caps = QED_RSS_IPV6_UDP;
1055 DP_VERBOSE(edev, QED_MSG_DEBUG,
1056 "UDP 4-tuple enabled\n");
1057 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1058 clr_caps = QED_RSS_IPV6_UDP;
1059 DP_VERBOSE(edev, QED_MSG_DEBUG,
1060 "UDP 4-tuple disabled\n");
1061 } else {
1062 return -EINVAL;
1063 }
1064 break;
1065 case IPV4_FLOW:
1066 case IPV6_FLOW:
1067 /* For IP only 2-tuple hash is supported */
1068 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1069 DP_INFO(edev, "Command parameters not supported\n");
1070 return -EINVAL;
1071 }
1072 return 0;
1073 case SCTP_V4_FLOW:
1074 case AH_ESP_V4_FLOW:
1075 case AH_V4_FLOW:
1076 case ESP_V4_FLOW:
1077 case SCTP_V6_FLOW:
1078 case AH_ESP_V6_FLOW:
1079 case AH_V6_FLOW:
1080 case ESP_V6_FLOW:
1081 case IP_USER_FLOW:
1082 case ETHER_FLOW:
1083 /* RSS is not supported for these protocols */
1084 if (info->data) {
1085 DP_INFO(edev, "Command parameters not supported\n");
1086 return -EINVAL;
1087 }
1088 return 0;
1089 default:
1090 return -EINVAL;
1091 }
1092
1093 /* No action is needed if there is no change in the rss capability */
1094 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
1095 ~clr_caps) | set_caps))
1096 return 0;
1097
1098 /* Update internal configuration */
1099 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
1100 set_caps;
1101 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1102
1103 /* Re-configure if possible */
1104 if (netif_running(edev->ndev)) {
1105 memset(&vport_update_params, 0, sizeof(vport_update_params));
1106 vport_update_params.update_rss_flg = 1;
1107 vport_update_params.vport_id = 0;
1108 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1109 sizeof(vport_update_params.rss_params));
1110 return edev->ops->vport_update(edev->cdev,
1111 &vport_update_params);
1112 }
1113
1114 return 0;
1115}
1116
1117static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1118{
1119 struct qede_dev *edev = netdev_priv(dev);
1120
1121 switch (info->cmd) {
1122 case ETHTOOL_SRXFH:
1123 return qede_set_rss_flags(edev, info);
1124 default:
1125 DP_INFO(edev, "Command parameters not supported\n");
1126 return -EOPNOTSUPP;
1127 }
1128}
1129
1130static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1131{
1132 return QED_RSS_IND_TABLE_SIZE;
1133}
1134
1135static u32 qede_get_rxfh_key_size(struct net_device *dev)
1136{
1137 struct qede_dev *edev = netdev_priv(dev);
1138
1139 return sizeof(edev->rss_params.rss_key);
1140}
1141
1142static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1143{
1144 struct qede_dev *edev = netdev_priv(dev);
1145 int i;
1146
1147 if (hfunc)
1148 *hfunc = ETH_RSS_HASH_TOP;
1149
1150 if (!indir)
1151 return 0;
1152
1153 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1154 indir[i] = edev->rss_params.rss_ind_table[i];
1155
1156 if (key)
1157 memcpy(key, edev->rss_params.rss_key,
1158 qede_get_rxfh_key_size(dev));
1159
1160 return 0;
1161}
1162
1163static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1164 const u8 *key, const u8 hfunc)
1165{
1166 struct qed_update_vport_params vport_update_params;
1167 struct qede_dev *edev = netdev_priv(dev);
1168 int i;
1169
Sudarsana Reddy Kalluruba300ce2016-10-21 04:43:40 -04001170 if (edev->dev_info.common.num_hwfns > 1) {
1171 DP_INFO(edev,
1172 "RSS configuration is not supported for 100G devices\n");
1173 return -EOPNOTSUPP;
1174 }
1175
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001176 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1177 return -EOPNOTSUPP;
1178
1179 if (!indir && !key)
1180 return 0;
1181
1182 if (indir) {
1183 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1184 edev->rss_params.rss_ind_table[i] = indir[i];
1185 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1186 }
1187
1188 if (key) {
1189 memcpy(&edev->rss_params.rss_key, key,
1190 qede_get_rxfh_key_size(dev));
1191 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1192 }
1193
1194 if (netif_running(edev->ndev)) {
1195 memset(&vport_update_params, 0, sizeof(vport_update_params));
1196 vport_update_params.update_rss_flg = 1;
1197 vport_update_params.vport_id = 0;
1198 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1199 sizeof(vport_update_params.rss_params));
1200 return edev->ops->vport_update(edev->cdev,
1201 &vport_update_params);
1202 }
1203
1204 return 0;
1205}
1206
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001207/* This function enables the interrupt generation and the NAPI on the device */
1208static void qede_netif_start(struct qede_dev *edev)
1209{
1210 int i;
1211
1212 if (!netif_running(edev->ndev))
1213 return;
1214
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001215 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001216 /* Update and reenable interrupts */
1217 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1218 napi_enable(&edev->fp_array[i].napi);
1219 }
1220}
1221
1222/* This function disables the NAPI and the interrupt generation on the device */
1223static void qede_netif_stop(struct qede_dev *edev)
1224{
1225 int i;
1226
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001227 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001228 napi_disable(&edev->fp_array[i].napi);
1229 /* Disable interrupts */
1230 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1231 }
1232}
1233
1234static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1235 struct sk_buff *skb)
1236{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001237 struct qede_tx_queue *txq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001238 struct eth_tx_1st_bd *first_bd;
1239 dma_addr_t mapping;
1240 int i, idx, val;
1241
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001242 for_each_queue(i) {
1243 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001244 txq = edev->fp_array[i].txq;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001245 break;
1246 }
1247 }
1248
1249 if (!txq) {
1250 DP_NOTICE(edev, "Tx path is not available\n");
1251 return -1;
1252 }
1253
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001254 /* Fill the entry in the SW ring and the BDs in the FW ring */
1255 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001256 txq->sw_tx_ring.skbs[idx].skb = skb;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001257 first_bd = qed_chain_produce(&txq->tx_pbl);
1258 memset(first_bd, 0, sizeof(*first_bd));
1259 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1260 first_bd->data.bd_flags.bitfields = val;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001261 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1262 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001263
1264 /* Map skb linear data for DMA and set in the first BD */
1265 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1266 skb_headlen(skb), DMA_TO_DEVICE);
1267 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1268 DP_NOTICE(edev, "SKB mapping failed\n");
1269 return -ENOMEM;
1270 }
1271 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1272
1273 /* update the first BD with the actual num BDs */
1274 first_bd->data.nbds = 1;
1275 txq->sw_tx_prod++;
1276 /* 'next page' entries are counted in the producer value */
1277 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
1278 txq->tx_db.data.bd_prod = val;
1279
1280 /* wmb makes sure that the BDs data is updated before updating the
1281 * producer, otherwise FW may read old data from the BDs.
1282 */
1283 wmb();
1284 barrier();
1285 writel(txq->tx_db.raw, txq->doorbell_addr);
1286
1287 /* mmiowb is needed to synchronize doorbell writes from more than one
1288 * processor. It guarantees that the write arrives to the device before
1289 * the queue lock is released and another start_xmit is called (possibly
1290 * on another CPU). Without this barrier, the next doorbell can bypass
1291 * this doorbell. This is applicable to IA64/Altix systems.
1292 */
1293 mmiowb();
1294
1295 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1296 if (qede_txq_has_work(txq))
1297 break;
1298 usleep_range(100, 200);
1299 }
1300
1301 if (!qede_txq_has_work(txq)) {
1302 DP_NOTICE(edev, "Tx completion didn't happen\n");
1303 return -1;
1304 }
1305
1306 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
Manish Choprafabd5452016-10-21 04:43:45 -04001307 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1308 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001309 txq->sw_tx_cons++;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001310 txq->sw_tx_ring.skbs[idx].skb = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001311
1312 return 0;
1313}
1314
1315static int qede_selftest_receive_traffic(struct qede_dev *edev)
1316{
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001317 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1318 struct eth_fast_path_rx_reg_cqe *fp_cqe;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001319 struct qede_rx_queue *rxq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001320 struct sw_rx_data *sw_rx_data;
1321 union eth_rx_cqe *cqe;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001322 int i, rc = 0;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001323 u8 *data_ptr;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001324
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001325 for_each_queue(i) {
1326 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1327 rxq = edev->fp_array[i].rxq;
1328 break;
1329 }
1330 }
1331
1332 if (!rxq) {
1333 DP_NOTICE(edev, "Rx path is not available\n");
1334 return -1;
1335 }
1336
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001337 /* The packet is expected to receive on rx-queue 0 even though RSS is
1338 * enabled. This is because the queue 0 is configured as the default
1339 * queue and that the loopback traffic is not IP.
1340 */
1341 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001342 if (!qede_has_rx_work(rxq)) {
1343 usleep_range(100, 200);
1344 continue;
1345 }
1346
1347 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1348 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1349
1350 /* Memory barrier to prevent the CPU from doing speculative
1351 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1352 * read before it is written by FW, then FW writes CQE and SB,
1353 * and then the CPU reads the hw_comp_cons, it will use an old
1354 * CQE.
1355 */
1356 rmb();
1357
1358 /* Get the CQE from the completion ring */
1359 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1360
1361 /* Get the data from the SW ring */
1362 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1363 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1364 fp_cqe = &cqe->fast_path_regular;
1365 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1366 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1367 fp_cqe->placement_offset +
1368 sw_rx_data->page_offset);
1369 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1370 ether_addr_equal(data_ptr + ETH_ALEN,
1371 edev->ndev->dev_addr)) {
1372 for (i = ETH_HLEN; i < len; i++)
1373 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1374 rc = -1;
1375 break;
1376 }
1377
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001378 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001379 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001380 break;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001381 }
1382
1383 DP_INFO(edev, "Not the transmitted packet\n");
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001384 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001385 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001386 }
1387
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001388 if (i == QEDE_SELFTEST_POLL_COUNT) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001389 DP_NOTICE(edev, "Failed to receive the traffic\n");
1390 return -1;
1391 }
1392
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001393 qede_update_rx_prod(edev, rxq);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001394
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001395 return rc;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001396}
1397
1398static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1399{
1400 struct qed_link_params link_params;
1401 struct sk_buff *skb = NULL;
1402 int rc = 0, i;
1403 u32 pkt_size;
1404 u8 *packet;
1405
1406 if (!netif_running(edev->ndev)) {
1407 DP_NOTICE(edev, "Interface is down\n");
1408 return -EINVAL;
1409 }
1410
1411 qede_netif_stop(edev);
1412
1413 /* Bring up the link in Loopback mode */
1414 memset(&link_params, 0, sizeof(link_params));
1415 link_params.link_up = true;
1416 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1417 link_params.loopback_mode = loopback_mode;
1418 edev->ops->common->set_link(edev->cdev, &link_params);
1419
1420 /* Wait for loopback configuration to apply */
1421 msleep_interruptible(500);
1422
1423 /* prepare the loopback packet */
1424 pkt_size = edev->ndev->mtu + ETH_HLEN;
1425
1426 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1427 if (!skb) {
1428 DP_INFO(edev, "Can't allocate skb\n");
1429 rc = -ENOMEM;
1430 goto test_loopback_exit;
1431 }
1432 packet = skb_put(skb, pkt_size);
1433 ether_addr_copy(packet, edev->ndev->dev_addr);
1434 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1435 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1436 for (i = ETH_HLEN; i < pkt_size; i++)
1437 packet[i] = (unsigned char)(i & 0xff);
1438
1439 rc = qede_selftest_transmit_traffic(edev, skb);
1440 if (rc)
1441 goto test_loopback_exit;
1442
1443 rc = qede_selftest_receive_traffic(edev);
1444 if (rc)
1445 goto test_loopback_exit;
1446
1447 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1448
1449test_loopback_exit:
1450 dev_kfree_skb(skb);
1451
1452 /* Bring up the link in Normal mode */
1453 memset(&link_params, 0, sizeof(link_params));
1454 link_params.link_up = true;
1455 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1456 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1457 edev->ops->common->set_link(edev->cdev, &link_params);
1458
1459 /* Wait for loopback configuration to apply */
1460 msleep_interruptible(500);
1461
1462 qede_netif_start(edev);
1463
1464 return rc;
1465}
1466
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001467static void qede_self_test(struct net_device *dev,
1468 struct ethtool_test *etest, u64 *buf)
1469{
1470 struct qede_dev *edev = netdev_priv(dev);
1471
1472 DP_VERBOSE(edev, QED_MSG_DEBUG,
1473 "Self-test command parameters: offline = %d, external_lb = %d\n",
1474 (etest->flags & ETH_TEST_FL_OFFLINE),
1475 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1476
1477 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1478
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001479 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1480 if (qede_selftest_run_loopback(edev,
1481 QED_LINK_LOOPBACK_INT_PHY)) {
1482 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1483 etest->flags |= ETH_TEST_FL_FAILED;
1484 }
1485 }
1486
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001487 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1488 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1489 etest->flags |= ETH_TEST_FL_FAILED;
1490 }
1491
1492 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1493 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1494 etest->flags |= ETH_TEST_FL_FAILED;
1495 }
1496
1497 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1498 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1499 etest->flags |= ETH_TEST_FL_FAILED;
1500 }
1501
1502 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1503 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1504 etest->flags |= ETH_TEST_FL_FAILED;
1505 }
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +02001506
1507 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1508 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1509 etest->flags |= ETH_TEST_FL_FAILED;
1510 }
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001511}
1512
Manish Chopra3d789992016-06-30 02:35:21 -04001513static int qede_set_tunable(struct net_device *dev,
1514 const struct ethtool_tunable *tuna,
1515 const void *data)
1516{
1517 struct qede_dev *edev = netdev_priv(dev);
1518 u32 val;
1519
1520 switch (tuna->id) {
1521 case ETHTOOL_RX_COPYBREAK:
1522 val = *(u32 *)data;
1523 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1524 DP_VERBOSE(edev, QED_MSG_DEBUG,
1525 "Invalid rx copy break value, range is [%u, %u]",
1526 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1527 return -EINVAL;
1528 }
1529
1530 edev->rx_copybreak = *(u32 *)data;
1531 break;
1532 default:
1533 return -EOPNOTSUPP;
1534 }
1535
1536 return 0;
1537}
1538
1539static int qede_get_tunable(struct net_device *dev,
1540 const struct ethtool_tunable *tuna, void *data)
1541{
1542 struct qede_dev *edev = netdev_priv(dev);
1543
1544 switch (tuna->id) {
1545 case ETHTOOL_RX_COPYBREAK:
1546 *(u32 *)data = edev->rx_copybreak;
1547 break;
1548 default:
1549 return -EOPNOTSUPP;
1550 }
1551
1552 return 0;
1553}
1554
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001555static const struct ethtool_ops qede_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001556 .get_link_ksettings = qede_get_link_ksettings,
1557 .set_link_ksettings = qede_set_link_ksettings,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001558 .get_drvinfo = qede_get_drvinfo,
Tomer Tayare0971c82016-09-07 16:36:25 +03001559 .get_regs_len = qede_get_regs_len,
1560 .get_regs = qede_get_regs,
Mintz, Yuval14d39642016-10-31 07:14:23 +02001561 .get_wol = qede_get_wol,
1562 .set_wol = qede_set_wol,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001563 .get_msglevel = qede_get_msglevel,
1564 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +02001565 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001566 .get_link = qede_get_link,
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -04001567 .get_coalesce = qede_get_coalesce,
1568 .set_coalesce = qede_set_coalesce,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +02001569 .get_ringparam = qede_get_ringparam,
1570 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +02001571 .get_pauseparam = qede_get_pauseparam,
1572 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001573 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +02001574 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001575 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +03001576 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001577 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001578 .get_rxnfc = qede_get_rxnfc,
1579 .set_rxnfc = qede_set_rxnfc,
1580 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1581 .get_rxfh_key_size = qede_get_rxfh_key_size,
1582 .get_rxfh = qede_get_rxfh,
1583 .set_rxfh = qede_set_rxfh,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001584 .get_channels = qede_get_channels,
1585 .set_channels = qede_set_channels,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001586 .self_test = qede_self_test,
Manish Chopra3d789992016-06-30 02:35:21 -04001587 .get_tunable = qede_get_tunable,
1588 .set_tunable = qede_set_tunable,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001589};
1590
Yuval Mintzfefb0202016-05-11 16:36:19 +03001591static const struct ethtool_ops qede_vf_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001592 .get_link_ksettings = qede_get_link_ksettings,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001593 .get_drvinfo = qede_get_drvinfo,
1594 .get_msglevel = qede_get_msglevel,
1595 .set_msglevel = qede_set_msglevel,
1596 .get_link = qede_get_link,
1597 .get_ringparam = qede_get_ringparam,
1598 .set_ringparam = qede_set_ringparam,
1599 .get_strings = qede_get_strings,
1600 .get_ethtool_stats = qede_get_ethtool_stats,
1601 .get_priv_flags = qede_get_priv_flags,
1602 .get_sset_count = qede_get_sset_count,
1603 .get_rxnfc = qede_get_rxnfc,
1604 .set_rxnfc = qede_set_rxnfc,
1605 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1606 .get_rxfh_key_size = qede_get_rxfh_key_size,
1607 .get_rxfh = qede_get_rxfh,
1608 .set_rxfh = qede_set_rxfh,
1609 .get_channels = qede_get_channels,
1610 .set_channels = qede_set_channels,
Manish Chopra3d789992016-06-30 02:35:21 -04001611 .get_tunable = qede_get_tunable,
1612 .set_tunable = qede_set_tunable,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001613};
1614
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001615void qede_set_ethtool_ops(struct net_device *dev)
1616{
Yuval Mintzfefb0202016-05-11 16:36:19 +03001617 struct qede_dev *edev = netdev_priv(dev);
1618
1619 if (IS_VF(edev))
1620 dev->ethtool_ops = &qede_vf_ethtool_ops;
1621 else
1622 dev->ethtool_ops = &qede_ethtool_ops;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001623}