blob: c02754ddc0e9183293e1a84a5b4ceaad068897f5 [file] [log] [blame]
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001/* QLogic qede NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020032#include <linux/version.h>
33#include <linux/types.h>
34#include <linux/netdevice.h>
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040035#include <linux/etherdevice.h>
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020036#include <linux/ethtool.h>
37#include <linux/string.h>
38#include <linux/pci.h>
39#include <linux/capability.h>
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +020040#include <linux/vmalloc.h>
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020041#include "qede.h"
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +020042#include "qede_ptp.h"
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020043
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020044#define QEDE_RQSTAT_OFFSET(stat_name) \
45 (offsetof(struct qede_rx_queue, stat_name))
46#define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
47#define QEDE_RQSTAT(stat_name) \
48 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040049
50#define QEDE_SELFTEST_POLL_COUNT 100
51
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020052static const struct {
53 u64 offset;
54 char string[ETH_GSTRING_LEN];
55} qede_rqstats_arr[] = {
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040056 QEDE_RQSTAT(rcv_pkts),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020057 QEDE_RQSTAT(rx_hw_errors),
58 QEDE_RQSTAT(rx_alloc_errors),
Manish Choprac72a6122016-06-30 02:35:18 -040059 QEDE_RQSTAT(rx_ip_frags),
Mintz, Yuval496e0512016-11-29 16:47:09 +020060 QEDE_RQSTAT(xdp_no_pass),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020061};
62
63#define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040064#define QEDE_TQSTAT_OFFSET(stat_name) \
65 (offsetof(struct qede_tx_queue, stat_name))
66#define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
67#define QEDE_TQSTAT(stat_name) \
68 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
69#define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
70static const struct {
71 u64 offset;
72 char string[ETH_GSTRING_LEN];
73} qede_tqstats_arr[] = {
74 QEDE_TQSTAT(xmit_pkts),
75 QEDE_TQSTAT(stopped_cnt),
76};
77
Mintz, Yuval4dbcd642016-11-29 16:47:03 +020078#define QEDE_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
79#define QEDE_STAT_STRING(stat_name) (#stat_name)
80#define _QEDE_STAT(stat_name, pf_only) \
81 {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
82#define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
83#define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020084static const struct {
85 u64 offset;
86 char string[ETH_GSTRING_LEN];
87 bool pf_only;
88} qede_stats_arr[] = {
89 QEDE_STAT(rx_ucast_bytes),
90 QEDE_STAT(rx_mcast_bytes),
91 QEDE_STAT(rx_bcast_bytes),
92 QEDE_STAT(rx_ucast_pkts),
93 QEDE_STAT(rx_mcast_pkts),
94 QEDE_STAT(rx_bcast_pkts),
95
96 QEDE_STAT(tx_ucast_bytes),
97 QEDE_STAT(tx_mcast_bytes),
98 QEDE_STAT(tx_bcast_bytes),
99 QEDE_STAT(tx_ucast_pkts),
100 QEDE_STAT(tx_mcast_pkts),
101 QEDE_STAT(tx_bcast_pkts),
102
103 QEDE_PF_STAT(rx_64_byte_packets),
Yuval Mintzd4967cf2016-04-22 08:41:01 +0300104 QEDE_PF_STAT(rx_65_to_127_byte_packets),
105 QEDE_PF_STAT(rx_128_to_255_byte_packets),
106 QEDE_PF_STAT(rx_256_to_511_byte_packets),
107 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
108 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
109 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
110 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
111 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
112 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
113 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200114 QEDE_PF_STAT(tx_64_byte_packets),
115 QEDE_PF_STAT(tx_65_to_127_byte_packets),
116 QEDE_PF_STAT(tx_128_to_255_byte_packets),
117 QEDE_PF_STAT(tx_256_to_511_byte_packets),
118 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
119 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
120 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
121 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
122 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
123 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
124
125 QEDE_PF_STAT(rx_mac_crtl_frames),
126 QEDE_PF_STAT(tx_mac_ctrl_frames),
127 QEDE_PF_STAT(rx_pause_frames),
128 QEDE_PF_STAT(tx_pause_frames),
129 QEDE_PF_STAT(rx_pfc_frames),
130 QEDE_PF_STAT(tx_pfc_frames),
131
132 QEDE_PF_STAT(rx_crc_errors),
133 QEDE_PF_STAT(rx_align_errors),
134 QEDE_PF_STAT(rx_carrier_errors),
135 QEDE_PF_STAT(rx_oversize_packets),
136 QEDE_PF_STAT(rx_jabbers),
137 QEDE_PF_STAT(rx_undersize_packets),
138 QEDE_PF_STAT(rx_fragments),
139 QEDE_PF_STAT(tx_lpi_entry_count),
140 QEDE_PF_STAT(tx_total_collisions),
141 QEDE_PF_STAT(brb_truncates),
142 QEDE_PF_STAT(brb_discards),
143 QEDE_STAT(no_buff_discards),
144 QEDE_PF_STAT(mftag_filter_discards),
145 QEDE_PF_STAT(mac_filter_discards),
146 QEDE_STAT(tx_err_drop_pkts),
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400147 QEDE_STAT(ttl0_discard),
148 QEDE_STAT(packet_too_big_discard),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200149
150 QEDE_STAT(coalesced_pkts),
151 QEDE_STAT(coalesced_events),
152 QEDE_STAT(coalesced_aborts_num),
153 QEDE_STAT(non_coalesced_pkts),
154 QEDE_STAT(coalesced_bytes),
155};
156
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200157#define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
158
Yuval Mintzf3e72102016-04-22 08:41:02 +0300159enum {
160 QEDE_PRI_FLAG_CMT,
161 QEDE_PRI_FLAG_LEN,
162};
163
164static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
165 "Coupled-Function",
166};
167
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400168enum qede_ethtool_tests {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400169 QEDE_ETHTOOL_INT_LOOPBACK,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400170 QEDE_ETHTOOL_INTERRUPT_TEST,
171 QEDE_ETHTOOL_MEMORY_TEST,
172 QEDE_ETHTOOL_REGISTER_TEST,
173 QEDE_ETHTOOL_CLOCK_TEST,
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200174 QEDE_ETHTOOL_NVRAM_TEST,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400175 QEDE_ETHTOOL_TEST_MAX
176};
177
178static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400179 "Internal loopback (offline)",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400180 "Interrupt (online)\t",
181 "Memory (online)\t\t",
182 "Register (online)\t",
183 "Clock (online)\t\t",
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200184 "Nvram (online)\t\t",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400185};
186
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200187static void qede_get_strings_stats_txq(struct qede_dev *edev,
188 struct qede_tx_queue *txq, u8 **buf)
189{
190 int i;
191
192 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200193 if (txq->is_xdp)
194 sprintf(*buf, "%d [XDP]: %s",
195 QEDE_TXQ_XDP_TO_IDX(edev, txq),
196 qede_tqstats_arr[i].string);
197 else
198 sprintf(*buf, "%d: %s", txq->index,
199 qede_tqstats_arr[i].string);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200200 *buf += ETH_GSTRING_LEN;
201 }
202}
203
204static void qede_get_strings_stats_rxq(struct qede_dev *edev,
205 struct qede_rx_queue *rxq, u8 **buf)
206{
207 int i;
208
209 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
210 sprintf(*buf, "%d: %s", rxq->rxq_id,
211 qede_rqstats_arr[i].string);
212 *buf += ETH_GSTRING_LEN;
213 }
214}
215
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200216static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
217{
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200218 struct qede_fastpath *fp;
219 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200220
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200221 /* Account for queue statistics */
222 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
223 fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400224
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200225 if (fp->type & QEDE_FASTPATH_RX)
226 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
Mintz, Yuvalcbbf0492016-10-30 10:25:42 +0200227
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200228 if (fp->type & QEDE_FASTPATH_XDP)
229 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
230
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200231 if (fp->type & QEDE_FASTPATH_TX)
232 qede_get_strings_stats_txq(edev, fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400233 }
234
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200235 /* Account for non-queue statistics */
236 for (i = 0; i < QEDE_NUM_STATS; i++) {
Yuval Mintzfefb0202016-05-11 16:36:19 +0300237 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
238 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200239 strcpy(buf, qede_stats_arr[i].string);
240 buf += ETH_GSTRING_LEN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200241 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200242}
243
244static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
245{
246 struct qede_dev *edev = netdev_priv(dev);
247
248 switch (stringset) {
249 case ETH_SS_STATS:
250 qede_get_strings_stats(edev, buf);
251 break;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300252 case ETH_SS_PRIV_FLAGS:
253 memcpy(buf, qede_private_arr,
254 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
255 break;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400256 case ETH_SS_TEST:
257 memcpy(buf, qede_tests_str_arr,
258 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
259 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200260 default:
261 DP_VERBOSE(edev, QED_MSG_DEBUG,
262 "Unsupported stringset 0x%08x\n", stringset);
263 }
264}
265
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200266static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
267{
268 int i;
269
270 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
271 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
272 (*buf)++;
273 }
274}
275
276static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
277{
278 int i;
279
280 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
281 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
282 (*buf)++;
283 }
284}
285
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200286static void qede_get_ethtool_stats(struct net_device *dev,
287 struct ethtool_stats *stats, u64 *buf)
288{
289 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200290 struct qede_fastpath *fp;
291 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200292
293 qede_fill_by_demand_stats(edev);
294
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200295 /* Need to protect the access to the fastpath array */
296 __qede_lock(edev);
297
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200298 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
299 fp = &edev->fp_array[i];
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200300
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200301 if (fp->type & QEDE_FASTPATH_RX)
302 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400303
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200304 if (fp->type & QEDE_FASTPATH_XDP)
305 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
306
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200307 if (fp->type & QEDE_FASTPATH_TX)
308 qede_get_ethtool_stats_txq(fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400309 }
310
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200311 for (i = 0; i < QEDE_NUM_STATS; i++) {
312 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
Yuval Mintzfefb0202016-05-11 16:36:19 +0300313 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200314 *buf = *((u64 *)(((void *)&edev->stats) +
315 qede_stats_arr[i].offset));
316
317 buf++;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300318 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200319
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200320 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200321}
322
323static int qede_get_sset_count(struct net_device *dev, int stringset)
324{
325 struct qede_dev *edev = netdev_priv(dev);
326 int num_stats = QEDE_NUM_STATS;
327
328 switch (stringset) {
329 case ETH_SS_STATS:
Yuval Mintzfefb0202016-05-11 16:36:19 +0300330 if (IS_VF(edev)) {
331 int i;
332
333 for (i = 0; i < QEDE_NUM_STATS; i++)
334 if (qede_stats_arr[i].pf_only)
335 num_stats--;
336 }
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200337
338 /* Account for the Regular Tx statistics */
339 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
340
341 /* Account for the Regular Rx statistics */
342 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
343
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200344 /* Account for XDP statistics [if needed] */
345 if (edev->xdp_prog)
346 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200347 return num_stats;
348
Yuval Mintzf3e72102016-04-22 08:41:02 +0300349 case ETH_SS_PRIV_FLAGS:
350 return QEDE_PRI_FLAG_LEN;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400351 case ETH_SS_TEST:
Yuval Mintz6ecb0a02016-05-26 11:01:19 +0300352 if (!IS_VF(edev))
353 return QEDE_ETHTOOL_TEST_MAX;
354 else
355 return 0;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200356 default:
357 DP_VERBOSE(edev, QED_MSG_DEBUG,
358 "Unsupported stringset 0x%08x\n", stringset);
359 return -EINVAL;
360 }
361}
362
Yuval Mintzf3e72102016-04-22 08:41:02 +0300363static u32 qede_get_priv_flags(struct net_device *dev)
364{
365 struct qede_dev *edev = netdev_priv(dev);
366
367 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
368}
369
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400370struct qede_link_mode_mapping {
371 u32 qed_link_mode;
372 u32 ethtool_link_mode;
373};
374
375static const struct qede_link_mode_mapping qed_lm_map[] = {
376 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
377 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
378 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
379 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
380 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
381 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
382 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
383 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
384 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
385 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
386 {QED_LM_100000baseKR4_Full_BIT,
387 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
388};
389
390#define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
391{ \
392 int i; \
393 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200394 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400395 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
396 __set_bit(qed_lm_map[i].ethtool_link_mode,\
397 lk_ksettings->link_modes.name); \
398 } \
399}
400
401#define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
402{ \
403 int i; \
404 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200405 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400406 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
407 lk_ksettings->link_modes.name)) \
408 caps |= qed_lm_map[i].qed_link_mode; \
409 } \
410}
411
412static int qede_get_link_ksettings(struct net_device *dev,
413 struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200414{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400415 struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200416 struct qede_dev *edev = netdev_priv(dev);
417 struct qed_link_output current_link;
418
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200419 __qede_lock(edev);
420
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200421 memset(&current_link, 0, sizeof(current_link));
422 edev->ops->common->get_link(edev->cdev, &current_link);
423
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400424 ethtool_link_ksettings_zero_link_mode(cmd, supported);
425 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
426
427 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
428 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
429
430 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
431 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
432
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200433 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400434 base->speed = current_link.speed;
435 base->duplex = current_link.duplex;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200436 } else {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400437 base->speed = SPEED_UNKNOWN;
438 base->duplex = DUPLEX_UNKNOWN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200439 }
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200440
441 __qede_unlock(edev);
442
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400443 base->port = current_link.port;
444 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
445 AUTONEG_DISABLE;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200446
447 return 0;
448}
449
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400450static int qede_set_link_ksettings(struct net_device *dev,
451 const struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200452{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400453 const struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200454 struct qede_dev *edev = netdev_priv(dev);
455 struct qed_link_output current_link;
456 struct qed_link_params params;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200457
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300458 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400459 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200460 return -EOPNOTSUPP;
461 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200462 memset(&current_link, 0, sizeof(current_link));
463 memset(&params, 0, sizeof(params));
464 edev->ops->common->get_link(edev->cdev, &current_link);
465
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200466 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
467 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400468 if (base->autoneg == AUTONEG_ENABLE) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200469 params.autoneg = true;
470 params.forced_speed = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400471 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
472 } else { /* forced speed */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200473 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
474 params.autoneg = false;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400475 params.forced_speed = base->speed;
476 switch (base->speed) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200477 case SPEED_10000:
478 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400479 QED_LM_10000baseKR_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200480 DP_INFO(edev, "10G speed not supported\n");
481 return -EINVAL;
482 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400483 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
484 break;
485 case SPEED_25000:
486 if (!(current_link.supported_caps &
487 QED_LM_25000baseKR_Full_BIT)) {
488 DP_INFO(edev, "25G speed not supported\n");
489 return -EINVAL;
490 }
491 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200492 break;
493 case SPEED_40000:
494 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400495 QED_LM_40000baseLR4_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200496 DP_INFO(edev, "40G speed not supported\n");
497 return -EINVAL;
498 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400499 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
500 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300501 case SPEED_50000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400502 if (!(current_link.supported_caps &
503 QED_LM_50000baseKR2_Full_BIT)) {
504 DP_INFO(edev, "50G speed not supported\n");
505 return -EINVAL;
506 }
507 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
508 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300509 case SPEED_100000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400510 if (!(current_link.supported_caps &
511 QED_LM_100000baseKR4_Full_BIT)) {
512 DP_INFO(edev, "100G speed not supported\n");
513 return -EINVAL;
514 }
515 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200516 break;
517 default:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400518 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200519 return -EINVAL;
520 }
521 }
522
523 params.link_up = true;
524 edev->ops->common->set_link(edev->cdev, &params);
525
526 return 0;
527}
528
529static void qede_get_drvinfo(struct net_device *ndev,
530 struct ethtool_drvinfo *info)
531{
532 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
533 struct qede_dev *edev = netdev_priv(ndev);
534
535 strlcpy(info->driver, "qede", sizeof(info->driver));
536 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
537
538 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
539 edev->dev_info.common.fw_major,
540 edev->dev_info.common.fw_minor,
541 edev->dev_info.common.fw_rev,
542 edev->dev_info.common.fw_eng);
543
544 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
545 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
546 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
547 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
548 edev->dev_info.common.mfw_rev & 0xFF);
549
550 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
551 sizeof(info->fw_version)) {
552 snprintf(info->fw_version, sizeof(info->fw_version),
553 "mfw %s storm %s", mfw, storm);
554 } else {
555 snprintf(info->fw_version, sizeof(info->fw_version),
556 "%s %s", mfw, storm);
557 }
558
559 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
560}
561
Mintz, Yuval14d39642016-10-31 07:14:23 +0200562static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
563{
564 struct qede_dev *edev = netdev_priv(ndev);
565
566 if (edev->dev_info.common.wol_support) {
567 wol->supported = WAKE_MAGIC;
568 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
569 }
570}
571
572static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
573{
574 struct qede_dev *edev = netdev_priv(ndev);
575 bool wol_requested;
576 int rc;
577
578 if (wol->wolopts & ~WAKE_MAGIC) {
579 DP_INFO(edev,
580 "Can't support WoL options other than magic-packet\n");
581 return -EINVAL;
582 }
583
584 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
585 if (wol_requested == edev->wol_enabled)
586 return 0;
587
588 /* Need to actually change configuration */
589 if (!edev->dev_info.common.wol_support) {
590 DP_INFO(edev, "Device doesn't support WoL\n");
591 return -EINVAL;
592 }
593
594 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
595 if (!rc)
596 edev->wol_enabled = wol_requested;
597
598 return rc;
599}
600
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200601static u32 qede_get_msglevel(struct net_device *ndev)
602{
603 struct qede_dev *edev = netdev_priv(ndev);
604
Yuval Mintz1a635e42016-08-15 10:42:43 +0300605 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200606}
607
608static void qede_set_msglevel(struct net_device *ndev, u32 level)
609{
610 struct qede_dev *edev = netdev_priv(ndev);
611 u32 dp_module = 0;
612 u8 dp_level = 0;
613
614 qede_config_debug(level, &dp_module, &dp_level);
615
616 edev->dp_level = dp_level;
617 edev->dp_module = dp_module;
618 edev->ops->common->update_msglvl(edev->cdev,
619 dp_module, dp_level);
620}
621
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200622static int qede_nway_reset(struct net_device *dev)
623{
624 struct qede_dev *edev = netdev_priv(dev);
625 struct qed_link_output current_link;
626 struct qed_link_params link_params;
627
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300628 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Yuval Mintz1a635e42016-08-15 10:42:43 +0300629 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300630 return -EOPNOTSUPP;
631 }
632
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200633 if (!netif_running(dev))
634 return 0;
635
636 memset(&current_link, 0, sizeof(current_link));
637 edev->ops->common->get_link(edev->cdev, &current_link);
638 if (!current_link.link_up)
639 return 0;
640
641 /* Toggle the link */
642 memset(&link_params, 0, sizeof(link_params));
643 link_params.link_up = false;
644 edev->ops->common->set_link(edev->cdev, &link_params);
645 link_params.link_up = true;
646 edev->ops->common->set_link(edev->cdev, &link_params);
647
648 return 0;
649}
650
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200651static u32 qede_get_link(struct net_device *dev)
652{
653 struct qede_dev *edev = netdev_priv(dev);
654 struct qed_link_output current_link;
655
656 memset(&current_link, 0, sizeof(current_link));
657 edev->ops->common->get_link(edev->cdev, &current_link);
658
659 return current_link.link_up;
660}
661
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400662static int qede_get_coalesce(struct net_device *dev,
663 struct ethtool_coalesce *coal)
664{
665 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400666 u16 rxc, txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400667
668 memset(coal, 0, sizeof(struct ethtool_coalesce));
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400669 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
670
671 coal->rx_coalesce_usecs = rxc;
672 coal->tx_coalesce_usecs = txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400673
674 return 0;
675}
676
677static int qede_set_coalesce(struct net_device *dev,
678 struct ethtool_coalesce *coal)
679{
680 struct qede_dev *edev = netdev_priv(dev);
681 int i, rc = 0;
682 u16 rxc, txc;
683 u8 sb_id;
684
685 if (!netif_running(dev)) {
686 DP_INFO(edev, "Interface is down\n");
687 return -EINVAL;
688 }
689
690 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
691 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
692 DP_INFO(edev,
693 "Can't support requested %s coalesce value [max supported value %d]\n",
694 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
695 : "tx",
696 QED_COALESCE_MAX);
697 return -EINVAL;
698 }
699
700 rxc = (u16)coal->rx_coalesce_usecs;
701 txc = (u16)coal->tx_coalesce_usecs;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400702 for_each_queue(i) {
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400703 sb_id = edev->fp_array[i].sb_info->igu_sb_id;
704 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
705 (u8)i, sb_id);
706 if (rc) {
707 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
708 return rc;
709 }
710 }
711
712 return rc;
713}
714
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200715static void qede_get_ringparam(struct net_device *dev,
716 struct ethtool_ringparam *ering)
717{
718 struct qede_dev *edev = netdev_priv(dev);
719
720 ering->rx_max_pending = NUM_RX_BDS_MAX;
721 ering->rx_pending = edev->q_num_rx_buffers;
722 ering->tx_max_pending = NUM_TX_BDS_MAX;
723 ering->tx_pending = edev->q_num_tx_buffers;
724}
725
726static int qede_set_ringparam(struct net_device *dev,
727 struct ethtool_ringparam *ering)
728{
729 struct qede_dev *edev = netdev_priv(dev);
730
731 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
732 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
733 ering->rx_pending, ering->tx_pending);
734
735 /* Validate legality of configuration */
736 if (ering->rx_pending > NUM_RX_BDS_MAX ||
737 ering->rx_pending < NUM_RX_BDS_MIN ||
738 ering->tx_pending > NUM_TX_BDS_MAX ||
739 ering->tx_pending < NUM_TX_BDS_MIN) {
740 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
741 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
742 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
743 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
744 return -EINVAL;
745 }
746
747 /* Change ring size and re-load */
748 edev->q_num_rx_buffers = ering->rx_pending;
749 edev->q_num_tx_buffers = ering->tx_pending;
750
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200751 qede_reload(edev, NULL, false);
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200752
753 return 0;
754}
755
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200756static void qede_get_pauseparam(struct net_device *dev,
757 struct ethtool_pauseparam *epause)
758{
759 struct qede_dev *edev = netdev_priv(dev);
760 struct qed_link_output current_link;
761
762 memset(&current_link, 0, sizeof(current_link));
763 edev->ops->common->get_link(edev->cdev, &current_link);
764
765 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
766 epause->autoneg = true;
767 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
768 epause->rx_pause = true;
769 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
770 epause->tx_pause = true;
771
772 DP_VERBOSE(edev, QED_MSG_DEBUG,
773 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
774 epause->cmd, epause->autoneg, epause->rx_pause,
775 epause->tx_pause);
776}
777
778static int qede_set_pauseparam(struct net_device *dev,
779 struct ethtool_pauseparam *epause)
780{
781 struct qede_dev *edev = netdev_priv(dev);
782 struct qed_link_params params;
783 struct qed_link_output current_link;
784
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300785 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200786 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300787 "Pause settings are not allowed to be changed\n");
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200788 return -EOPNOTSUPP;
789 }
790
791 memset(&current_link, 0, sizeof(current_link));
792 edev->ops->common->get_link(edev->cdev, &current_link);
793
794 memset(&params, 0, sizeof(params));
795 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
796 if (epause->autoneg) {
Yuval Mintzd194fd22016-08-19 08:34:57 +0300797 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200798 DP_INFO(edev, "autoneg not supported\n");
799 return -EINVAL;
800 }
801 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
802 }
803 if (epause->rx_pause)
804 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
805 if (epause->tx_pause)
806 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
807
808 params.link_up = true;
809 edev->ops->common->set_link(edev->cdev, &params);
810
811 return 0;
812}
813
Tomer Tayare0971c82016-09-07 16:36:25 +0300814static void qede_get_regs(struct net_device *ndev,
815 struct ethtool_regs *regs, void *buffer)
816{
817 struct qede_dev *edev = netdev_priv(ndev);
818
819 regs->version = 0;
820 memset(buffer, 0, regs->len);
821
822 if (edev->ops && edev->ops->common)
823 edev->ops->common->dbg_all_data(edev->cdev, buffer);
824}
825
826static int qede_get_regs_len(struct net_device *ndev)
827{
828 struct qede_dev *edev = netdev_priv(ndev);
829
830 if (edev->ops && edev->ops->common)
831 return edev->ops->common->dbg_all_data_size(edev->cdev);
832 else
833 return -EINVAL;
834}
835
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200836static void qede_update_mtu(struct qede_dev *edev,
837 struct qede_reload_args *args)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200838{
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200839 edev->ndev->mtu = args->u.mtu;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200840}
841
842/* Netdevice NDOs */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200843int qede_change_mtu(struct net_device *ndev, int new_mtu)
844{
845 struct qede_dev *edev = netdev_priv(ndev);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200846 struct qede_reload_args args;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200847
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200848 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
849 "Configuring MTU size of %d\n", new_mtu);
850
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200851 /* Set the mtu field and re-start the interface if needed */
852 args.u.mtu = new_mtu;
853 args.func = &qede_update_mtu;
854 qede_reload(edev, &args, false);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200855
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200856 edev->ops->common->update_mtu(edev->cdev, new_mtu);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200857
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200858 return 0;
859}
860
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200861static void qede_get_channels(struct net_device *dev,
862 struct ethtool_channels *channels)
863{
864 struct qede_dev *edev = netdev_priv(dev);
865
866 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kallurubdc8cbd2016-10-21 04:43:39 -0400867 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
868 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400869 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
870 edev->fp_num_rx;
871 channels->tx_count = edev->fp_num_tx;
872 channels->rx_count = edev->fp_num_rx;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200873}
874
875static int qede_set_channels(struct net_device *dev,
876 struct ethtool_channels *channels)
877{
878 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400879 u32 count;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200880
881 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
882 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
883 channels->rx_count, channels->tx_count,
884 channels->other_count, channels->combined_count);
885
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400886 count = channels->rx_count + channels->tx_count +
887 channels->combined_count;
888
889 /* We don't support `other' channels */
890 if (channels->other_count) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200891 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
892 "command parameters not supported\n");
893 return -EINVAL;
894 }
895
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400896 if (!(channels->combined_count || (channels->rx_count &&
897 channels->tx_count))) {
898 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
899 "need to request at least one transmit and one receive channel\n");
900 return -EINVAL;
901 }
902
903 if (count > QEDE_MAX_RSS_CNT(edev)) {
904 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
905 "requested channels = %d max supported channels = %d\n",
906 count, QEDE_MAX_RSS_CNT(edev));
907 return -EINVAL;
908 }
909
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200910 /* Check if there was a change in the active parameters */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400911 if ((count == QEDE_QUEUE_CNT(edev)) &&
912 (channels->tx_count == edev->fp_num_tx) &&
913 (channels->rx_count == edev->fp_num_rx)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200914 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
915 "No change in active parameters\n");
916 return 0;
917 }
918
919 /* We need the number of queues to be divisible between the hwfns */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400920 if ((count % edev->dev_info.common.num_hwfns) ||
921 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
922 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200923 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400924 "Number of channels must be divisible by %04x\n",
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200925 edev->dev_info.common.num_hwfns);
926 return -EINVAL;
927 }
928
929 /* Set number of queues and reload if necessary */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400930 edev->req_queues = count;
931 edev->req_num_tx = channels->tx_count;
932 edev->req_num_rx = channels->rx_count;
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -0400933 /* Reset the indirection table if rx queue count is updated */
934 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
935 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200936 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -0400937 }
938
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200939 qede_reload(edev, NULL, false);
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200940
941 return 0;
942}
943
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +0200944static int qede_get_ts_info(struct net_device *dev,
945 struct ethtool_ts_info *info)
946{
947 struct qede_dev *edev = netdev_priv(dev);
948
949 return qede_ptp_get_ts_info(edev, info);
950}
951
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200952static int qede_set_phys_id(struct net_device *dev,
953 enum ethtool_phys_id_state state)
954{
955 struct qede_dev *edev = netdev_priv(dev);
956 u8 led_state = 0;
957
958 switch (state) {
959 case ETHTOOL_ID_ACTIVE:
960 return 1; /* cycle on/off once per second */
961
962 case ETHTOOL_ID_ON:
963 led_state = QED_LED_MODE_ON;
964 break;
965
966 case ETHTOOL_ID_OFF:
967 led_state = QED_LED_MODE_OFF;
968 break;
969
970 case ETHTOOL_ID_INACTIVE:
971 led_state = QED_LED_MODE_RESTORE;
972 break;
973 }
974
975 edev->ops->common->set_led(edev->cdev, led_state);
976
977 return 0;
978}
979
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300980static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
981{
982 info->data = RXH_IP_SRC | RXH_IP_DST;
983
984 switch (info->flow_type) {
985 case TCP_V4_FLOW:
986 case TCP_V6_FLOW:
987 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
988 break;
989 case UDP_V4_FLOW:
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200990 if (edev->rss_caps & QED_RSS_IPV4_UDP)
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300991 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
992 break;
993 case UDP_V6_FLOW:
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +0200994 if (edev->rss_caps & QED_RSS_IPV6_UDP)
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300995 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
996 break;
997 case IPV4_FLOW:
998 case IPV6_FLOW:
999 break;
1000 default:
1001 info->data = 0;
1002 break;
1003 }
1004
1005 return 0;
1006}
1007
1008static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
1009 u32 *rules __always_unused)
1010{
1011 struct qede_dev *edev = netdev_priv(dev);
1012
1013 switch (info->cmd) {
1014 case ETHTOOL_GRXRINGS:
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001015 info->data = QEDE_RSS_COUNT(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001016 return 0;
1017 case ETHTOOL_GRXFH:
1018 return qede_get_rss_flags(edev, info);
1019 default:
1020 DP_ERR(edev, "Command parameters not supported\n");
1021 return -EOPNOTSUPP;
1022 }
1023}
1024
1025static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1026{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001027 struct qed_update_vport_params *vport_update_params;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001028 u8 set_caps = 0, clr_caps = 0;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001029 int rc = 0;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001030
1031 DP_VERBOSE(edev, QED_MSG_DEBUG,
1032 "Set rss flags command parameters: flow type = %d, data = %llu\n",
1033 info->flow_type, info->data);
1034
1035 switch (info->flow_type) {
1036 case TCP_V4_FLOW:
1037 case TCP_V6_FLOW:
1038 /* For TCP only 4-tuple hash is supported */
1039 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1040 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1041 DP_INFO(edev, "Command parameters not supported\n");
1042 return -EINVAL;
1043 }
1044 return 0;
1045 case UDP_V4_FLOW:
1046 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1047 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1048 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1049 set_caps = QED_RSS_IPV4_UDP;
1050 DP_VERBOSE(edev, QED_MSG_DEBUG,
1051 "UDP 4-tuple enabled\n");
1052 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1053 clr_caps = QED_RSS_IPV4_UDP;
1054 DP_VERBOSE(edev, QED_MSG_DEBUG,
1055 "UDP 4-tuple disabled\n");
1056 } else {
1057 return -EINVAL;
1058 }
1059 break;
1060 case UDP_V6_FLOW:
1061 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1062 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1063 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1064 set_caps = QED_RSS_IPV6_UDP;
1065 DP_VERBOSE(edev, QED_MSG_DEBUG,
1066 "UDP 4-tuple enabled\n");
1067 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1068 clr_caps = QED_RSS_IPV6_UDP;
1069 DP_VERBOSE(edev, QED_MSG_DEBUG,
1070 "UDP 4-tuple disabled\n");
1071 } else {
1072 return -EINVAL;
1073 }
1074 break;
1075 case IPV4_FLOW:
1076 case IPV6_FLOW:
1077 /* For IP only 2-tuple hash is supported */
1078 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1079 DP_INFO(edev, "Command parameters not supported\n");
1080 return -EINVAL;
1081 }
1082 return 0;
1083 case SCTP_V4_FLOW:
1084 case AH_ESP_V4_FLOW:
1085 case AH_V4_FLOW:
1086 case ESP_V4_FLOW:
1087 case SCTP_V6_FLOW:
1088 case AH_ESP_V6_FLOW:
1089 case AH_V6_FLOW:
1090 case ESP_V6_FLOW:
1091 case IP_USER_FLOW:
1092 case ETHER_FLOW:
1093 /* RSS is not supported for these protocols */
1094 if (info->data) {
1095 DP_INFO(edev, "Command parameters not supported\n");
1096 return -EINVAL;
1097 }
1098 return 0;
1099 default:
1100 return -EINVAL;
1101 }
1102
1103 /* No action is needed if there is no change in the rss capability */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001104 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001105 return 0;
1106
1107 /* Update internal configuration */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001108 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001109 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1110
1111 /* Re-configure if possible */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001112 __qede_lock(edev);
1113 if (edev->state == QEDE_STATE_OPEN) {
1114 vport_update_params = vzalloc(sizeof(*vport_update_params));
1115 if (!vport_update_params) {
1116 __qede_unlock(edev);
1117 return -ENOMEM;
1118 }
1119 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1120 &vport_update_params->update_rss_flg);
1121 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1122 vfree(vport_update_params);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001123 }
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001124 __qede_unlock(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001125
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001126 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001127}
1128
1129static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1130{
1131 struct qede_dev *edev = netdev_priv(dev);
1132
1133 switch (info->cmd) {
1134 case ETHTOOL_SRXFH:
1135 return qede_set_rss_flags(edev, info);
1136 default:
1137 DP_INFO(edev, "Command parameters not supported\n");
1138 return -EOPNOTSUPP;
1139 }
1140}
1141
1142static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1143{
1144 return QED_RSS_IND_TABLE_SIZE;
1145}
1146
1147static u32 qede_get_rxfh_key_size(struct net_device *dev)
1148{
1149 struct qede_dev *edev = netdev_priv(dev);
1150
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001151 return sizeof(edev->rss_key);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001152}
1153
1154static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1155{
1156 struct qede_dev *edev = netdev_priv(dev);
1157 int i;
1158
1159 if (hfunc)
1160 *hfunc = ETH_RSS_HASH_TOP;
1161
1162 if (!indir)
1163 return 0;
1164
1165 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001166 indir[i] = edev->rss_ind_table[i];
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001167
1168 if (key)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001169 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001170
1171 return 0;
1172}
1173
1174static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1175 const u8 *key, const u8 hfunc)
1176{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001177 struct qed_update_vport_params *vport_update_params;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001178 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001179 int i, rc = 0;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001180
Sudarsana Reddy Kalluruba300ce2016-10-21 04:43:40 -04001181 if (edev->dev_info.common.num_hwfns > 1) {
1182 DP_INFO(edev,
1183 "RSS configuration is not supported for 100G devices\n");
1184 return -EOPNOTSUPP;
1185 }
1186
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001187 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1188 return -EOPNOTSUPP;
1189
1190 if (!indir && !key)
1191 return 0;
1192
1193 if (indir) {
1194 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001195 edev->rss_ind_table[i] = indir[i];
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001196 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1197 }
1198
1199 if (key) {
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001200 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001201 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1202 }
1203
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001204 __qede_lock(edev);
1205 if (edev->state == QEDE_STATE_OPEN) {
1206 vport_update_params = vzalloc(sizeof(*vport_update_params));
1207 if (!vport_update_params) {
1208 __qede_unlock(edev);
1209 return -ENOMEM;
1210 }
1211 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1212 &vport_update_params->update_rss_flg);
1213 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1214 vfree(vport_update_params);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001215 }
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001216 __qede_unlock(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001217
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001218 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001219}
1220
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001221/* This function enables the interrupt generation and the NAPI on the device */
1222static void qede_netif_start(struct qede_dev *edev)
1223{
1224 int i;
1225
1226 if (!netif_running(edev->ndev))
1227 return;
1228
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001229 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001230 /* Update and reenable interrupts */
1231 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1232 napi_enable(&edev->fp_array[i].napi);
1233 }
1234}
1235
1236/* This function disables the NAPI and the interrupt generation on the device */
1237static void qede_netif_stop(struct qede_dev *edev)
1238{
1239 int i;
1240
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001241 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001242 napi_disable(&edev->fp_array[i].napi);
1243 /* Disable interrupts */
1244 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1245 }
1246}
1247
1248static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1249 struct sk_buff *skb)
1250{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001251 struct qede_tx_queue *txq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001252 struct eth_tx_1st_bd *first_bd;
1253 dma_addr_t mapping;
1254 int i, idx, val;
1255
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001256 for_each_queue(i) {
1257 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001258 txq = edev->fp_array[i].txq;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001259 break;
1260 }
1261 }
1262
1263 if (!txq) {
1264 DP_NOTICE(edev, "Tx path is not available\n");
1265 return -1;
1266 }
1267
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001268 /* Fill the entry in the SW ring and the BDs in the FW ring */
1269 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001270 txq->sw_tx_ring.skbs[idx].skb = skb;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001271 first_bd = qed_chain_produce(&txq->tx_pbl);
1272 memset(first_bd, 0, sizeof(*first_bd));
1273 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1274 first_bd->data.bd_flags.bitfields = val;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001275 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1276 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001277
1278 /* Map skb linear data for DMA and set in the first BD */
1279 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1280 skb_headlen(skb), DMA_TO_DEVICE);
1281 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1282 DP_NOTICE(edev, "SKB mapping failed\n");
1283 return -ENOMEM;
1284 }
1285 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1286
1287 /* update the first BD with the actual num BDs */
1288 first_bd->data.nbds = 1;
1289 txq->sw_tx_prod++;
1290 /* 'next page' entries are counted in the producer value */
1291 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
1292 txq->tx_db.data.bd_prod = val;
1293
1294 /* wmb makes sure that the BDs data is updated before updating the
1295 * producer, otherwise FW may read old data from the BDs.
1296 */
1297 wmb();
1298 barrier();
1299 writel(txq->tx_db.raw, txq->doorbell_addr);
1300
1301 /* mmiowb is needed to synchronize doorbell writes from more than one
1302 * processor. It guarantees that the write arrives to the device before
1303 * the queue lock is released and another start_xmit is called (possibly
1304 * on another CPU). Without this barrier, the next doorbell can bypass
1305 * this doorbell. This is applicable to IA64/Altix systems.
1306 */
1307 mmiowb();
1308
1309 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1310 if (qede_txq_has_work(txq))
1311 break;
1312 usleep_range(100, 200);
1313 }
1314
1315 if (!qede_txq_has_work(txq)) {
1316 DP_NOTICE(edev, "Tx completion didn't happen\n");
1317 return -1;
1318 }
1319
1320 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
Manish Choprafabd5452016-10-21 04:43:45 -04001321 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1322 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001323 txq->sw_tx_cons++;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001324 txq->sw_tx_ring.skbs[idx].skb = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001325
1326 return 0;
1327}
1328
1329static int qede_selftest_receive_traffic(struct qede_dev *edev)
1330{
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001331 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1332 struct eth_fast_path_rx_reg_cqe *fp_cqe;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001333 struct qede_rx_queue *rxq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001334 struct sw_rx_data *sw_rx_data;
1335 union eth_rx_cqe *cqe;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001336 int i, rc = 0;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001337 u8 *data_ptr;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001338
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001339 for_each_queue(i) {
1340 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1341 rxq = edev->fp_array[i].rxq;
1342 break;
1343 }
1344 }
1345
1346 if (!rxq) {
1347 DP_NOTICE(edev, "Rx path is not available\n");
1348 return -1;
1349 }
1350
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001351 /* The packet is expected to receive on rx-queue 0 even though RSS is
1352 * enabled. This is because the queue 0 is configured as the default
1353 * queue and that the loopback traffic is not IP.
1354 */
1355 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001356 if (!qede_has_rx_work(rxq)) {
1357 usleep_range(100, 200);
1358 continue;
1359 }
1360
1361 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1362 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1363
1364 /* Memory barrier to prevent the CPU from doing speculative
1365 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1366 * read before it is written by FW, then FW writes CQE and SB,
1367 * and then the CPU reads the hw_comp_cons, it will use an old
1368 * CQE.
1369 */
1370 rmb();
1371
1372 /* Get the CQE from the completion ring */
1373 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1374
1375 /* Get the data from the SW ring */
1376 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1377 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1378 fp_cqe = &cqe->fast_path_regular;
1379 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1380 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1381 fp_cqe->placement_offset +
1382 sw_rx_data->page_offset);
1383 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1384 ether_addr_equal(data_ptr + ETH_ALEN,
1385 edev->ndev->dev_addr)) {
1386 for (i = ETH_HLEN; i < len; i++)
1387 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1388 rc = -1;
1389 break;
1390 }
1391
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001392 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001393 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001394 break;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001395 }
1396
1397 DP_INFO(edev, "Not the transmitted packet\n");
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001398 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001399 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001400 }
1401
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001402 if (i == QEDE_SELFTEST_POLL_COUNT) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001403 DP_NOTICE(edev, "Failed to receive the traffic\n");
1404 return -1;
1405 }
1406
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001407 qede_update_rx_prod(edev, rxq);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001408
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001409 return rc;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001410}
1411
1412static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1413{
1414 struct qed_link_params link_params;
1415 struct sk_buff *skb = NULL;
1416 int rc = 0, i;
1417 u32 pkt_size;
1418 u8 *packet;
1419
1420 if (!netif_running(edev->ndev)) {
1421 DP_NOTICE(edev, "Interface is down\n");
1422 return -EINVAL;
1423 }
1424
1425 qede_netif_stop(edev);
1426
1427 /* Bring up the link in Loopback mode */
1428 memset(&link_params, 0, sizeof(link_params));
1429 link_params.link_up = true;
1430 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1431 link_params.loopback_mode = loopback_mode;
1432 edev->ops->common->set_link(edev->cdev, &link_params);
1433
1434 /* Wait for loopback configuration to apply */
1435 msleep_interruptible(500);
1436
1437 /* prepare the loopback packet */
1438 pkt_size = edev->ndev->mtu + ETH_HLEN;
1439
1440 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1441 if (!skb) {
1442 DP_INFO(edev, "Can't allocate skb\n");
1443 rc = -ENOMEM;
1444 goto test_loopback_exit;
1445 }
1446 packet = skb_put(skb, pkt_size);
1447 ether_addr_copy(packet, edev->ndev->dev_addr);
1448 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1449 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1450 for (i = ETH_HLEN; i < pkt_size; i++)
1451 packet[i] = (unsigned char)(i & 0xff);
1452
1453 rc = qede_selftest_transmit_traffic(edev, skb);
1454 if (rc)
1455 goto test_loopback_exit;
1456
1457 rc = qede_selftest_receive_traffic(edev);
1458 if (rc)
1459 goto test_loopback_exit;
1460
1461 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1462
1463test_loopback_exit:
1464 dev_kfree_skb(skb);
1465
1466 /* Bring up the link in Normal mode */
1467 memset(&link_params, 0, sizeof(link_params));
1468 link_params.link_up = true;
1469 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1470 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1471 edev->ops->common->set_link(edev->cdev, &link_params);
1472
1473 /* Wait for loopback configuration to apply */
1474 msleep_interruptible(500);
1475
1476 qede_netif_start(edev);
1477
1478 return rc;
1479}
1480
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001481static void qede_self_test(struct net_device *dev,
1482 struct ethtool_test *etest, u64 *buf)
1483{
1484 struct qede_dev *edev = netdev_priv(dev);
1485
1486 DP_VERBOSE(edev, QED_MSG_DEBUG,
1487 "Self-test command parameters: offline = %d, external_lb = %d\n",
1488 (etest->flags & ETH_TEST_FL_OFFLINE),
1489 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1490
1491 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1492
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001493 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1494 if (qede_selftest_run_loopback(edev,
1495 QED_LINK_LOOPBACK_INT_PHY)) {
1496 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1497 etest->flags |= ETH_TEST_FL_FAILED;
1498 }
1499 }
1500
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001501 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1502 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1503 etest->flags |= ETH_TEST_FL_FAILED;
1504 }
1505
1506 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1507 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1508 etest->flags |= ETH_TEST_FL_FAILED;
1509 }
1510
1511 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1512 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1513 etest->flags |= ETH_TEST_FL_FAILED;
1514 }
1515
1516 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1517 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1518 etest->flags |= ETH_TEST_FL_FAILED;
1519 }
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +02001520
1521 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1522 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1523 etest->flags |= ETH_TEST_FL_FAILED;
1524 }
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001525}
1526
Manish Chopra3d789992016-06-30 02:35:21 -04001527static int qede_set_tunable(struct net_device *dev,
1528 const struct ethtool_tunable *tuna,
1529 const void *data)
1530{
1531 struct qede_dev *edev = netdev_priv(dev);
1532 u32 val;
1533
1534 switch (tuna->id) {
1535 case ETHTOOL_RX_COPYBREAK:
1536 val = *(u32 *)data;
1537 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1538 DP_VERBOSE(edev, QED_MSG_DEBUG,
1539 "Invalid rx copy break value, range is [%u, %u]",
1540 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1541 return -EINVAL;
1542 }
1543
1544 edev->rx_copybreak = *(u32 *)data;
1545 break;
1546 default:
1547 return -EOPNOTSUPP;
1548 }
1549
1550 return 0;
1551}
1552
1553static int qede_get_tunable(struct net_device *dev,
1554 const struct ethtool_tunable *tuna, void *data)
1555{
1556 struct qede_dev *edev = netdev_priv(dev);
1557
1558 switch (tuna->id) {
1559 case ETHTOOL_RX_COPYBREAK:
1560 *(u32 *)data = edev->rx_copybreak;
1561 break;
1562 default:
1563 return -EOPNOTSUPP;
1564 }
1565
1566 return 0;
1567}
1568
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001569static const struct ethtool_ops qede_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001570 .get_link_ksettings = qede_get_link_ksettings,
1571 .set_link_ksettings = qede_set_link_ksettings,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001572 .get_drvinfo = qede_get_drvinfo,
Tomer Tayare0971c82016-09-07 16:36:25 +03001573 .get_regs_len = qede_get_regs_len,
1574 .get_regs = qede_get_regs,
Mintz, Yuval14d39642016-10-31 07:14:23 +02001575 .get_wol = qede_get_wol,
1576 .set_wol = qede_set_wol,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001577 .get_msglevel = qede_get_msglevel,
1578 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +02001579 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001580 .get_link = qede_get_link,
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -04001581 .get_coalesce = qede_get_coalesce,
1582 .set_coalesce = qede_set_coalesce,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +02001583 .get_ringparam = qede_get_ringparam,
1584 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +02001585 .get_pauseparam = qede_get_pauseparam,
1586 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001587 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +02001588 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001589 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +03001590 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001591 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001592 .get_rxnfc = qede_get_rxnfc,
1593 .set_rxnfc = qede_set_rxnfc,
1594 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1595 .get_rxfh_key_size = qede_get_rxfh_key_size,
1596 .get_rxfh = qede_get_rxfh,
1597 .set_rxfh = qede_set_rxfh,
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +02001598 .get_ts_info = qede_get_ts_info,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001599 .get_channels = qede_get_channels,
1600 .set_channels = qede_set_channels,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001601 .self_test = qede_self_test,
Manish Chopra3d789992016-06-30 02:35:21 -04001602 .get_tunable = qede_get_tunable,
1603 .set_tunable = qede_set_tunable,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001604};
1605
Yuval Mintzfefb0202016-05-11 16:36:19 +03001606static const struct ethtool_ops qede_vf_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001607 .get_link_ksettings = qede_get_link_ksettings,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001608 .get_drvinfo = qede_get_drvinfo,
1609 .get_msglevel = qede_get_msglevel,
1610 .set_msglevel = qede_set_msglevel,
1611 .get_link = qede_get_link,
1612 .get_ringparam = qede_get_ringparam,
1613 .set_ringparam = qede_set_ringparam,
1614 .get_strings = qede_get_strings,
1615 .get_ethtool_stats = qede_get_ethtool_stats,
1616 .get_priv_flags = qede_get_priv_flags,
1617 .get_sset_count = qede_get_sset_count,
1618 .get_rxnfc = qede_get_rxnfc,
1619 .set_rxnfc = qede_set_rxnfc,
1620 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1621 .get_rxfh_key_size = qede_get_rxfh_key_size,
1622 .get_rxfh = qede_get_rxfh,
1623 .set_rxfh = qede_set_rxfh,
1624 .get_channels = qede_get_channels,
1625 .set_channels = qede_set_channels,
Manish Chopra3d789992016-06-30 02:35:21 -04001626 .get_tunable = qede_get_tunable,
1627 .set_tunable = qede_set_tunable,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001628};
1629
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001630void qede_set_ethtool_ops(struct net_device *dev)
1631{
Yuval Mintzfefb0202016-05-11 16:36:19 +03001632 struct qede_dev *edev = netdev_priv(dev);
1633
1634 if (IS_VF(edev))
1635 dev->ethtool_ops = &qede_vf_ethtool_ops;
1636 else
1637 dev->ethtool_ops = &qede_ethtool_ops;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001638}