blob: 4ca3847fffd44cb9aa6500fb3b515459353ec67e [file] [log] [blame]
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001/* QLogic qede NIC Driver
Mintz, Yuvale8f1cb52017-01-01 13:57:00 +02002 * Copyright (c) 2015-2017 QLogic Corporation
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020032#include <linux/version.h>
33#include <linux/types.h>
34#include <linux/netdevice.h>
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040035#include <linux/etherdevice.h>
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020036#include <linux/ethtool.h>
37#include <linux/string.h>
38#include <linux/pci.h>
39#include <linux/capability.h>
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +020040#include <linux/vmalloc.h>
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020041#include "qede.h"
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +020042#include "qede_ptp.h"
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020043
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020044#define QEDE_RQSTAT_OFFSET(stat_name) \
45 (offsetof(struct qede_rx_queue, stat_name))
46#define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
47#define QEDE_RQSTAT(stat_name) \
48 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040049
50#define QEDE_SELFTEST_POLL_COUNT 100
51
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020052static const struct {
53 u64 offset;
54 char string[ETH_GSTRING_LEN];
55} qede_rqstats_arr[] = {
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040056 QEDE_RQSTAT(rcv_pkts),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020057 QEDE_RQSTAT(rx_hw_errors),
58 QEDE_RQSTAT(rx_alloc_errors),
Manish Choprac72a6122016-06-30 02:35:18 -040059 QEDE_RQSTAT(rx_ip_frags),
Mintz, Yuval496e0512016-11-29 16:47:09 +020060 QEDE_RQSTAT(xdp_no_pass),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020061};
62
63#define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040064#define QEDE_TQSTAT_OFFSET(stat_name) \
65 (offsetof(struct qede_tx_queue, stat_name))
66#define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
67#define QEDE_TQSTAT(stat_name) \
68 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
69#define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
70static const struct {
71 u64 offset;
72 char string[ETH_GSTRING_LEN];
73} qede_tqstats_arr[] = {
74 QEDE_TQSTAT(xmit_pkts),
75 QEDE_TQSTAT(stopped_cnt),
76};
77
Mintz, Yuval9c79dda2017-03-14 16:23:54 +020078#define QEDE_STAT_OFFSET(stat_name, type, base) \
79 (offsetof(type, stat_name) + (base))
80#define QEDE_STAT_STRING(stat_name) (#stat_name)
81#define _QEDE_STAT(stat_name, type, base, attr) \
82 {QEDE_STAT_OFFSET(stat_name, type, base), \
83 QEDE_STAT_STRING(stat_name), \
84 attr}
85#define QEDE_STAT(stat_name) \
86 _QEDE_STAT(stat_name, struct qede_stats_common, 0, 0x0)
87#define QEDE_PF_STAT(stat_name) \
88 _QEDE_STAT(stat_name, struct qede_stats_common, 0, \
89 BIT(QEDE_STAT_PF_ONLY))
90#define QEDE_PF_BB_STAT(stat_name) \
91 _QEDE_STAT(stat_name, struct qede_stats_bb, \
92 offsetof(struct qede_stats, bb), \
93 BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_BB_ONLY))
94#define QEDE_PF_AH_STAT(stat_name) \
95 _QEDE_STAT(stat_name, struct qede_stats_ah, \
96 offsetof(struct qede_stats, ah), \
97 BIT(QEDE_STAT_PF_ONLY) | BIT(QEDE_STAT_AH_ONLY))
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020098static const struct {
99 u64 offset;
100 char string[ETH_GSTRING_LEN];
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200101 unsigned long attr;
102#define QEDE_STAT_PF_ONLY 0
103#define QEDE_STAT_BB_ONLY 1
104#define QEDE_STAT_AH_ONLY 2
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200105} qede_stats_arr[] = {
106 QEDE_STAT(rx_ucast_bytes),
107 QEDE_STAT(rx_mcast_bytes),
108 QEDE_STAT(rx_bcast_bytes),
109 QEDE_STAT(rx_ucast_pkts),
110 QEDE_STAT(rx_mcast_pkts),
111 QEDE_STAT(rx_bcast_pkts),
112
113 QEDE_STAT(tx_ucast_bytes),
114 QEDE_STAT(tx_mcast_bytes),
115 QEDE_STAT(tx_bcast_bytes),
116 QEDE_STAT(tx_ucast_pkts),
117 QEDE_STAT(tx_mcast_pkts),
118 QEDE_STAT(tx_bcast_pkts),
119
120 QEDE_PF_STAT(rx_64_byte_packets),
Yuval Mintzd4967cf2016-04-22 08:41:01 +0300121 QEDE_PF_STAT(rx_65_to_127_byte_packets),
122 QEDE_PF_STAT(rx_128_to_255_byte_packets),
123 QEDE_PF_STAT(rx_256_to_511_byte_packets),
124 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
125 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200126 QEDE_PF_BB_STAT(rx_1519_to_1522_byte_packets),
127 QEDE_PF_BB_STAT(rx_1519_to_2047_byte_packets),
128 QEDE_PF_BB_STAT(rx_2048_to_4095_byte_packets),
129 QEDE_PF_BB_STAT(rx_4096_to_9216_byte_packets),
130 QEDE_PF_BB_STAT(rx_9217_to_16383_byte_packets),
131 QEDE_PF_AH_STAT(rx_1519_to_max_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200132 QEDE_PF_STAT(tx_64_byte_packets),
133 QEDE_PF_STAT(tx_65_to_127_byte_packets),
134 QEDE_PF_STAT(tx_128_to_255_byte_packets),
135 QEDE_PF_STAT(tx_256_to_511_byte_packets),
136 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
137 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200138 QEDE_PF_BB_STAT(tx_1519_to_2047_byte_packets),
139 QEDE_PF_BB_STAT(tx_2048_to_4095_byte_packets),
140 QEDE_PF_BB_STAT(tx_4096_to_9216_byte_packets),
141 QEDE_PF_BB_STAT(tx_9217_to_16383_byte_packets),
142 QEDE_PF_AH_STAT(tx_1519_to_max_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200143 QEDE_PF_STAT(rx_mac_crtl_frames),
144 QEDE_PF_STAT(tx_mac_ctrl_frames),
145 QEDE_PF_STAT(rx_pause_frames),
146 QEDE_PF_STAT(tx_pause_frames),
147 QEDE_PF_STAT(rx_pfc_frames),
148 QEDE_PF_STAT(tx_pfc_frames),
149
150 QEDE_PF_STAT(rx_crc_errors),
151 QEDE_PF_STAT(rx_align_errors),
152 QEDE_PF_STAT(rx_carrier_errors),
153 QEDE_PF_STAT(rx_oversize_packets),
154 QEDE_PF_STAT(rx_jabbers),
155 QEDE_PF_STAT(rx_undersize_packets),
156 QEDE_PF_STAT(rx_fragments),
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200157 QEDE_PF_BB_STAT(tx_lpi_entry_count),
158 QEDE_PF_BB_STAT(tx_total_collisions),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200159 QEDE_PF_STAT(brb_truncates),
160 QEDE_PF_STAT(brb_discards),
161 QEDE_STAT(no_buff_discards),
162 QEDE_PF_STAT(mftag_filter_discards),
163 QEDE_PF_STAT(mac_filter_discards),
164 QEDE_STAT(tx_err_drop_pkts),
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400165 QEDE_STAT(ttl0_discard),
166 QEDE_STAT(packet_too_big_discard),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200167
168 QEDE_STAT(coalesced_pkts),
169 QEDE_STAT(coalesced_events),
170 QEDE_STAT(coalesced_aborts_num),
171 QEDE_STAT(non_coalesced_pkts),
172 QEDE_STAT(coalesced_bytes),
173};
174
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200175#define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200176#define QEDE_STAT_IS_PF_ONLY(i) \
177 test_bit(QEDE_STAT_PF_ONLY, &qede_stats_arr[i].attr)
178#define QEDE_STAT_IS_BB_ONLY(i) \
179 test_bit(QEDE_STAT_BB_ONLY, &qede_stats_arr[i].attr)
180#define QEDE_STAT_IS_AH_ONLY(i) \
181 test_bit(QEDE_STAT_AH_ONLY, &qede_stats_arr[i].attr)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200182
Yuval Mintzf3e72102016-04-22 08:41:02 +0300183enum {
184 QEDE_PRI_FLAG_CMT,
185 QEDE_PRI_FLAG_LEN,
186};
187
188static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
189 "Coupled-Function",
190};
191
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400192enum qede_ethtool_tests {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400193 QEDE_ETHTOOL_INT_LOOPBACK,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400194 QEDE_ETHTOOL_INTERRUPT_TEST,
195 QEDE_ETHTOOL_MEMORY_TEST,
196 QEDE_ETHTOOL_REGISTER_TEST,
197 QEDE_ETHTOOL_CLOCK_TEST,
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200198 QEDE_ETHTOOL_NVRAM_TEST,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400199 QEDE_ETHTOOL_TEST_MAX
200};
201
202static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400203 "Internal loopback (offline)",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400204 "Interrupt (online)\t",
205 "Memory (online)\t\t",
206 "Register (online)\t",
207 "Clock (online)\t\t",
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200208 "Nvram (online)\t\t",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400209};
210
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200211static void qede_get_strings_stats_txq(struct qede_dev *edev,
212 struct qede_tx_queue *txq, u8 **buf)
213{
214 int i;
215
216 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200217 if (txq->is_xdp)
218 sprintf(*buf, "%d [XDP]: %s",
219 QEDE_TXQ_XDP_TO_IDX(edev, txq),
220 qede_tqstats_arr[i].string);
221 else
222 sprintf(*buf, "%d: %s", txq->index,
223 qede_tqstats_arr[i].string);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200224 *buf += ETH_GSTRING_LEN;
225 }
226}
227
228static void qede_get_strings_stats_rxq(struct qede_dev *edev,
229 struct qede_rx_queue *rxq, u8 **buf)
230{
231 int i;
232
233 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
234 sprintf(*buf, "%d: %s", rxq->rxq_id,
235 qede_rqstats_arr[i].string);
236 *buf += ETH_GSTRING_LEN;
237 }
238}
239
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200240static bool qede_is_irrelevant_stat(struct qede_dev *edev, int stat_index)
241{
242 return (IS_VF(edev) && QEDE_STAT_IS_PF_ONLY(stat_index)) ||
243 (QEDE_IS_BB(edev) && QEDE_STAT_IS_AH_ONLY(stat_index)) ||
244 (QEDE_IS_AH(edev) && QEDE_STAT_IS_BB_ONLY(stat_index));
245}
246
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200247static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
248{
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200249 struct qede_fastpath *fp;
250 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200251
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200252 /* Account for queue statistics */
253 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
254 fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400255
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200256 if (fp->type & QEDE_FASTPATH_RX)
257 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
Mintz, Yuvalcbbf0492016-10-30 10:25:42 +0200258
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200259 if (fp->type & QEDE_FASTPATH_XDP)
260 qede_get_strings_stats_txq(edev, fp->xdp_tx, &buf);
261
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200262 if (fp->type & QEDE_FASTPATH_TX)
263 qede_get_strings_stats_txq(edev, fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400264 }
265
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200266 /* Account for non-queue statistics */
267 for (i = 0; i < QEDE_NUM_STATS; i++) {
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200268 if (qede_is_irrelevant_stat(edev, i))
Yuval Mintzfefb0202016-05-11 16:36:19 +0300269 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200270 strcpy(buf, qede_stats_arr[i].string);
271 buf += ETH_GSTRING_LEN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200272 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200273}
274
275static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
276{
277 struct qede_dev *edev = netdev_priv(dev);
278
279 switch (stringset) {
280 case ETH_SS_STATS:
281 qede_get_strings_stats(edev, buf);
282 break;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300283 case ETH_SS_PRIV_FLAGS:
284 memcpy(buf, qede_private_arr,
285 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
286 break;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400287 case ETH_SS_TEST:
288 memcpy(buf, qede_tests_str_arr,
289 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
290 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200291 default:
292 DP_VERBOSE(edev, QED_MSG_DEBUG,
293 "Unsupported stringset 0x%08x\n", stringset);
294 }
295}
296
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200297static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
298{
299 int i;
300
301 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
302 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
303 (*buf)++;
304 }
305}
306
307static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
308{
309 int i;
310
311 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
312 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
313 (*buf)++;
314 }
315}
316
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200317static void qede_get_ethtool_stats(struct net_device *dev,
318 struct ethtool_stats *stats, u64 *buf)
319{
320 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200321 struct qede_fastpath *fp;
322 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200323
324 qede_fill_by_demand_stats(edev);
325
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200326 /* Need to protect the access to the fastpath array */
327 __qede_lock(edev);
328
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200329 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
330 fp = &edev->fp_array[i];
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200331
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200332 if (fp->type & QEDE_FASTPATH_RX)
333 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400334
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200335 if (fp->type & QEDE_FASTPATH_XDP)
336 qede_get_ethtool_stats_txq(fp->xdp_tx, &buf);
337
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200338 if (fp->type & QEDE_FASTPATH_TX)
339 qede_get_ethtool_stats_txq(fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400340 }
341
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200342 for (i = 0; i < QEDE_NUM_STATS; i++) {
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200343 if (qede_is_irrelevant_stat(edev, i))
Yuval Mintzfefb0202016-05-11 16:36:19 +0300344 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200345 *buf = *((u64 *)(((void *)&edev->stats) +
346 qede_stats_arr[i].offset));
347
348 buf++;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300349 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200350
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200351 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200352}
353
354static int qede_get_sset_count(struct net_device *dev, int stringset)
355{
356 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200357 int num_stats = QEDE_NUM_STATS, i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200358
359 switch (stringset) {
360 case ETH_SS_STATS:
Mintz, Yuval9c79dda2017-03-14 16:23:54 +0200361 for (i = 0; i < QEDE_NUM_STATS; i++)
362 if (qede_is_irrelevant_stat(edev, i))
363 num_stats--;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200364
365 /* Account for the Regular Tx statistics */
366 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
367
368 /* Account for the Regular Rx statistics */
369 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
370
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +0200371 /* Account for XDP statistics [if needed] */
372 if (edev->xdp_prog)
373 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_TQSTATS;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200374 return num_stats;
375
Yuval Mintzf3e72102016-04-22 08:41:02 +0300376 case ETH_SS_PRIV_FLAGS:
377 return QEDE_PRI_FLAG_LEN;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400378 case ETH_SS_TEST:
Yuval Mintz6ecb0a02016-05-26 11:01:19 +0300379 if (!IS_VF(edev))
380 return QEDE_ETHTOOL_TEST_MAX;
381 else
382 return 0;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200383 default:
384 DP_VERBOSE(edev, QED_MSG_DEBUG,
385 "Unsupported stringset 0x%08x\n", stringset);
386 return -EINVAL;
387 }
388}
389
Yuval Mintzf3e72102016-04-22 08:41:02 +0300390static u32 qede_get_priv_flags(struct net_device *dev)
391{
392 struct qede_dev *edev = netdev_priv(dev);
393
394 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
395}
396
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400397struct qede_link_mode_mapping {
398 u32 qed_link_mode;
399 u32 ethtool_link_mode;
400};
401
402static const struct qede_link_mode_mapping qed_lm_map[] = {
403 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
404 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
405 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
406 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
407 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
408 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
409 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
410 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
411 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
412 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
413 {QED_LM_100000baseKR4_Full_BIT,
414 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
415};
416
417#define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
418{ \
419 int i; \
420 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200421 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400422 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
423 __set_bit(qed_lm_map[i].ethtool_link_mode,\
424 lk_ksettings->link_modes.name); \
425 } \
426}
427
428#define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
429{ \
430 int i; \
431 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200432 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400433 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
434 lk_ksettings->link_modes.name)) \
435 caps |= qed_lm_map[i].qed_link_mode; \
436 } \
437}
438
439static int qede_get_link_ksettings(struct net_device *dev,
440 struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200441{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400442 struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200443 struct qede_dev *edev = netdev_priv(dev);
444 struct qed_link_output current_link;
445
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200446 __qede_lock(edev);
447
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200448 memset(&current_link, 0, sizeof(current_link));
449 edev->ops->common->get_link(edev->cdev, &current_link);
450
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400451 ethtool_link_ksettings_zero_link_mode(cmd, supported);
452 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
453
454 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
455 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
456
457 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
458 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
459
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200460 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400461 base->speed = current_link.speed;
462 base->duplex = current_link.duplex;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200463 } else {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400464 base->speed = SPEED_UNKNOWN;
465 base->duplex = DUPLEX_UNKNOWN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200466 }
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200467
468 __qede_unlock(edev);
469
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400470 base->port = current_link.port;
471 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
472 AUTONEG_DISABLE;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200473
474 return 0;
475}
476
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400477static int qede_set_link_ksettings(struct net_device *dev,
478 const struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200479{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400480 const struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200481 struct qede_dev *edev = netdev_priv(dev);
482 struct qed_link_output current_link;
483 struct qed_link_params params;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200484
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300485 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400486 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200487 return -EOPNOTSUPP;
488 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200489 memset(&current_link, 0, sizeof(current_link));
490 memset(&params, 0, sizeof(params));
491 edev->ops->common->get_link(edev->cdev, &current_link);
492
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200493 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
494 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400495 if (base->autoneg == AUTONEG_ENABLE) {
sudarsana.kalluru@cavium.com161adb02017-05-04 08:15:05 -0700496 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
497 DP_INFO(edev, "Auto negotiation is not supported\n");
498 return -EOPNOTSUPP;
499 }
500
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200501 params.autoneg = true;
502 params.forced_speed = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400503 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
504 } else { /* forced speed */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200505 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
506 params.autoneg = false;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400507 params.forced_speed = base->speed;
508 switch (base->speed) {
Sudarsana Reddy Kalluru9ac4c542017-05-21 12:11:00 +0300509 case SPEED_1000:
510 if (!(current_link.supported_caps &
511 QED_LM_1000baseT_Full_BIT)) {
512 DP_INFO(edev, "1G speed not supported\n");
513 return -EINVAL;
514 }
515 params.adv_speeds = QED_LM_1000baseT_Full_BIT;
516 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200517 case SPEED_10000:
518 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400519 QED_LM_10000baseKR_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200520 DP_INFO(edev, "10G speed not supported\n");
521 return -EINVAL;
522 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400523 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
524 break;
525 case SPEED_25000:
526 if (!(current_link.supported_caps &
527 QED_LM_25000baseKR_Full_BIT)) {
528 DP_INFO(edev, "25G speed not supported\n");
529 return -EINVAL;
530 }
531 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200532 break;
533 case SPEED_40000:
534 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400535 QED_LM_40000baseLR4_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200536 DP_INFO(edev, "40G speed not supported\n");
537 return -EINVAL;
538 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400539 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
540 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300541 case SPEED_50000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400542 if (!(current_link.supported_caps &
543 QED_LM_50000baseKR2_Full_BIT)) {
544 DP_INFO(edev, "50G speed not supported\n");
545 return -EINVAL;
546 }
547 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
548 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300549 case SPEED_100000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400550 if (!(current_link.supported_caps &
551 QED_LM_100000baseKR4_Full_BIT)) {
552 DP_INFO(edev, "100G speed not supported\n");
553 return -EINVAL;
554 }
555 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200556 break;
557 default:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400558 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200559 return -EINVAL;
560 }
561 }
562
563 params.link_up = true;
564 edev->ops->common->set_link(edev->cdev, &params);
565
566 return 0;
567}
568
569static void qede_get_drvinfo(struct net_device *ndev,
570 struct ethtool_drvinfo *info)
571{
572 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
573 struct qede_dev *edev = netdev_priv(ndev);
574
575 strlcpy(info->driver, "qede", sizeof(info->driver));
576 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
577
578 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
579 edev->dev_info.common.fw_major,
580 edev->dev_info.common.fw_minor,
581 edev->dev_info.common.fw_rev,
582 edev->dev_info.common.fw_eng);
583
584 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
585 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
586 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
587 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
588 edev->dev_info.common.mfw_rev & 0xFF);
589
590 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
591 sizeof(info->fw_version)) {
592 snprintf(info->fw_version, sizeof(info->fw_version),
593 "mfw %s storm %s", mfw, storm);
594 } else {
595 snprintf(info->fw_version, sizeof(info->fw_version),
596 "%s %s", mfw, storm);
597 }
598
599 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
600}
601
Mintz, Yuval14d39642016-10-31 07:14:23 +0200602static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
603{
604 struct qede_dev *edev = netdev_priv(ndev);
605
606 if (edev->dev_info.common.wol_support) {
607 wol->supported = WAKE_MAGIC;
608 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
609 }
610}
611
612static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
613{
614 struct qede_dev *edev = netdev_priv(ndev);
615 bool wol_requested;
616 int rc;
617
618 if (wol->wolopts & ~WAKE_MAGIC) {
619 DP_INFO(edev,
620 "Can't support WoL options other than magic-packet\n");
621 return -EINVAL;
622 }
623
624 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
625 if (wol_requested == edev->wol_enabled)
626 return 0;
627
628 /* Need to actually change configuration */
629 if (!edev->dev_info.common.wol_support) {
630 DP_INFO(edev, "Device doesn't support WoL\n");
631 return -EINVAL;
632 }
633
634 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
635 if (!rc)
636 edev->wol_enabled = wol_requested;
637
638 return rc;
639}
640
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200641static u32 qede_get_msglevel(struct net_device *ndev)
642{
643 struct qede_dev *edev = netdev_priv(ndev);
644
Yuval Mintz1a635e42016-08-15 10:42:43 +0300645 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200646}
647
648static void qede_set_msglevel(struct net_device *ndev, u32 level)
649{
650 struct qede_dev *edev = netdev_priv(ndev);
651 u32 dp_module = 0;
652 u8 dp_level = 0;
653
654 qede_config_debug(level, &dp_module, &dp_level);
655
656 edev->dp_level = dp_level;
657 edev->dp_module = dp_module;
658 edev->ops->common->update_msglvl(edev->cdev,
659 dp_module, dp_level);
660}
661
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200662static int qede_nway_reset(struct net_device *dev)
663{
664 struct qede_dev *edev = netdev_priv(dev);
665 struct qed_link_output current_link;
666 struct qed_link_params link_params;
667
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300668 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Yuval Mintz1a635e42016-08-15 10:42:43 +0300669 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300670 return -EOPNOTSUPP;
671 }
672
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200673 if (!netif_running(dev))
674 return 0;
675
676 memset(&current_link, 0, sizeof(current_link));
677 edev->ops->common->get_link(edev->cdev, &current_link);
678 if (!current_link.link_up)
679 return 0;
680
681 /* Toggle the link */
682 memset(&link_params, 0, sizeof(link_params));
683 link_params.link_up = false;
684 edev->ops->common->set_link(edev->cdev, &link_params);
685 link_params.link_up = true;
686 edev->ops->common->set_link(edev->cdev, &link_params);
687
688 return 0;
689}
690
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200691static u32 qede_get_link(struct net_device *dev)
692{
693 struct qede_dev *edev = netdev_priv(dev);
694 struct qed_link_output current_link;
695
696 memset(&current_link, 0, sizeof(current_link));
697 edev->ops->common->get_link(edev->cdev, &current_link);
698
699 return current_link.link_up;
700}
701
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400702static int qede_get_coalesce(struct net_device *dev,
703 struct ethtool_coalesce *coal)
704{
Rahul Vermabf5a94b2017-07-26 06:07:14 -0700705 void *rx_handle = NULL, *tx_handle = NULL;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400706 struct qede_dev *edev = netdev_priv(dev);
Rahul Vermabf5a94b2017-07-26 06:07:14 -0700707 u16 rx_coal, tx_coal, i, rc = 0;
708 struct qede_fastpath *fp;
709
710 rx_coal = QED_DEFAULT_RX_USECS;
711 tx_coal = QED_DEFAULT_TX_USECS;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400712
713 memset(coal, 0, sizeof(struct ethtool_coalesce));
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400714
Rahul Vermabf5a94b2017-07-26 06:07:14 -0700715 __qede_lock(edev);
716 if (edev->state == QEDE_STATE_OPEN) {
717 for_each_queue(i) {
718 fp = &edev->fp_array[i];
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400719
Rahul Vermabf5a94b2017-07-26 06:07:14 -0700720 if (fp->type & QEDE_FASTPATH_RX) {
721 rx_handle = fp->rxq->handle;
722 break;
723 }
724 }
725
726 rc = edev->ops->get_coalesce(edev->cdev, &rx_coal, rx_handle);
727 if (rc) {
728 DP_INFO(edev, "Read Rx coalesce error\n");
729 goto out;
730 }
731
732 for_each_queue(i) {
733 fp = &edev->fp_array[i];
734 if (fp->type & QEDE_FASTPATH_TX) {
735 tx_handle = fp->txq->handle;
736 break;
737 }
738 }
739
740 rc = edev->ops->get_coalesce(edev->cdev, &tx_coal, tx_handle);
741 if (rc)
742 DP_INFO(edev, "Read Tx coalesce error\n");
743 }
744
745out:
746 __qede_unlock(edev);
747
748 coal->rx_coalesce_usecs = rx_coal;
749 coal->tx_coalesce_usecs = tx_coal;
750
751 return rc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400752}
753
754static int qede_set_coalesce(struct net_device *dev,
755 struct ethtool_coalesce *coal)
756{
757 struct qede_dev *edev = netdev_priv(dev);
Rahul Verma477f2d12017-07-26 06:07:13 -0700758 struct qede_fastpath *fp;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400759 int i, rc = 0;
Rahul Verma477f2d12017-07-26 06:07:13 -0700760 u16 rxc, txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400761
762 if (!netif_running(dev)) {
763 DP_INFO(edev, "Interface is down\n");
764 return -EINVAL;
765 }
766
767 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
768 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
769 DP_INFO(edev,
770 "Can't support requested %s coalesce value [max supported value %d]\n",
Rahul Verma477f2d12017-07-26 06:07:13 -0700771 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx" :
772 "tx", QED_COALESCE_MAX);
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400773 return -EINVAL;
774 }
775
776 rxc = (u16)coal->rx_coalesce_usecs;
777 txc = (u16)coal->tx_coalesce_usecs;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400778 for_each_queue(i) {
Rahul Verma477f2d12017-07-26 06:07:13 -0700779 fp = &edev->fp_array[i];
780
781 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
782 rc = edev->ops->common->set_coalesce(edev->cdev,
783 rxc, 0,
784 fp->rxq->handle);
785 if (rc) {
786 DP_INFO(edev,
787 "Set RX coalesce error, rc = %d\n", rc);
788 return rc;
789 }
790 }
791
792 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
793 rc = edev->ops->common->set_coalesce(edev->cdev,
794 0, txc,
795 fp->txq->handle);
796 if (rc) {
797 DP_INFO(edev,
798 "Set TX coalesce error, rc = %d\n", rc);
799 return rc;
800 }
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400801 }
802 }
803
804 return rc;
805}
806
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200807static void qede_get_ringparam(struct net_device *dev,
808 struct ethtool_ringparam *ering)
809{
810 struct qede_dev *edev = netdev_priv(dev);
811
812 ering->rx_max_pending = NUM_RX_BDS_MAX;
813 ering->rx_pending = edev->q_num_rx_buffers;
814 ering->tx_max_pending = NUM_TX_BDS_MAX;
815 ering->tx_pending = edev->q_num_tx_buffers;
816}
817
818static int qede_set_ringparam(struct net_device *dev,
819 struct ethtool_ringparam *ering)
820{
821 struct qede_dev *edev = netdev_priv(dev);
822
823 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
824 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
825 ering->rx_pending, ering->tx_pending);
826
827 /* Validate legality of configuration */
828 if (ering->rx_pending > NUM_RX_BDS_MAX ||
829 ering->rx_pending < NUM_RX_BDS_MIN ||
830 ering->tx_pending > NUM_TX_BDS_MAX ||
831 ering->tx_pending < NUM_TX_BDS_MIN) {
832 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
833 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
834 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
835 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
836 return -EINVAL;
837 }
838
839 /* Change ring size and re-load */
840 edev->q_num_rx_buffers = ering->rx_pending;
841 edev->q_num_tx_buffers = ering->tx_pending;
842
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200843 qede_reload(edev, NULL, false);
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200844
845 return 0;
846}
847
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200848static void qede_get_pauseparam(struct net_device *dev,
849 struct ethtool_pauseparam *epause)
850{
851 struct qede_dev *edev = netdev_priv(dev);
852 struct qed_link_output current_link;
853
854 memset(&current_link, 0, sizeof(current_link));
855 edev->ops->common->get_link(edev->cdev, &current_link);
856
857 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
858 epause->autoneg = true;
859 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
860 epause->rx_pause = true;
861 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
862 epause->tx_pause = true;
863
864 DP_VERBOSE(edev, QED_MSG_DEBUG,
865 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
866 epause->cmd, epause->autoneg, epause->rx_pause,
867 epause->tx_pause);
868}
869
870static int qede_set_pauseparam(struct net_device *dev,
871 struct ethtool_pauseparam *epause)
872{
873 struct qede_dev *edev = netdev_priv(dev);
874 struct qed_link_params params;
875 struct qed_link_output current_link;
876
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300877 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200878 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300879 "Pause settings are not allowed to be changed\n");
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200880 return -EOPNOTSUPP;
881 }
882
883 memset(&current_link, 0, sizeof(current_link));
884 edev->ops->common->get_link(edev->cdev, &current_link);
885
886 memset(&params, 0, sizeof(params));
887 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
888 if (epause->autoneg) {
Yuval Mintzd194fd22016-08-19 08:34:57 +0300889 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200890 DP_INFO(edev, "autoneg not supported\n");
891 return -EINVAL;
892 }
893 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
894 }
895 if (epause->rx_pause)
896 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
897 if (epause->tx_pause)
898 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
899
900 params.link_up = true;
901 edev->ops->common->set_link(edev->cdev, &params);
902
903 return 0;
904}
905
Tomer Tayare0971c82016-09-07 16:36:25 +0300906static void qede_get_regs(struct net_device *ndev,
907 struct ethtool_regs *regs, void *buffer)
908{
909 struct qede_dev *edev = netdev_priv(ndev);
910
911 regs->version = 0;
912 memset(buffer, 0, regs->len);
913
914 if (edev->ops && edev->ops->common)
915 edev->ops->common->dbg_all_data(edev->cdev, buffer);
916}
917
918static int qede_get_regs_len(struct net_device *ndev)
919{
920 struct qede_dev *edev = netdev_priv(ndev);
921
922 if (edev->ops && edev->ops->common)
923 return edev->ops->common->dbg_all_data_size(edev->cdev);
924 else
925 return -EINVAL;
926}
927
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200928static void qede_update_mtu(struct qede_dev *edev,
929 struct qede_reload_args *args)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200930{
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200931 edev->ndev->mtu = args->u.mtu;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200932}
933
934/* Netdevice NDOs */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200935int qede_change_mtu(struct net_device *ndev, int new_mtu)
936{
937 struct qede_dev *edev = netdev_priv(ndev);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200938 struct qede_reload_args args;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200939
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200940 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
941 "Configuring MTU size of %d\n", new_mtu);
942
Michael Chan18c602d2017-12-16 03:09:44 -0500943 if (new_mtu > PAGE_SIZE)
944 ndev->features &= ~NETIF_F_GRO_HW;
945
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200946 /* Set the mtu field and re-start the interface if needed */
947 args.u.mtu = new_mtu;
948 args.func = &qede_update_mtu;
949 qede_reload(edev, &args, false);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200950
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200951 edev->ops->common->update_mtu(edev->cdev, new_mtu);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200952
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200953 return 0;
954}
955
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200956static void qede_get_channels(struct net_device *dev,
957 struct ethtool_channels *channels)
958{
959 struct qede_dev *edev = netdev_priv(dev);
960
961 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kallurubdc8cbd2016-10-21 04:43:39 -0400962 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
963 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400964 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
965 edev->fp_num_rx;
966 channels->tx_count = edev->fp_num_tx;
967 channels->rx_count = edev->fp_num_rx;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200968}
969
970static int qede_set_channels(struct net_device *dev,
971 struct ethtool_channels *channels)
972{
973 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400974 u32 count;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200975
976 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
977 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
978 channels->rx_count, channels->tx_count,
979 channels->other_count, channels->combined_count);
980
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400981 count = channels->rx_count + channels->tx_count +
982 channels->combined_count;
983
984 /* We don't support `other' channels */
985 if (channels->other_count) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200986 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
987 "command parameters not supported\n");
988 return -EINVAL;
989 }
990
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400991 if (!(channels->combined_count || (channels->rx_count &&
992 channels->tx_count))) {
993 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
994 "need to request at least one transmit and one receive channel\n");
995 return -EINVAL;
996 }
997
998 if (count > QEDE_MAX_RSS_CNT(edev)) {
999 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1000 "requested channels = %d max supported channels = %d\n",
1001 count, QEDE_MAX_RSS_CNT(edev));
1002 return -EINVAL;
1003 }
1004
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001005 /* Check if there was a change in the active parameters */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001006 if ((count == QEDE_QUEUE_CNT(edev)) &&
1007 (channels->tx_count == edev->fp_num_tx) &&
1008 (channels->rx_count == edev->fp_num_rx)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001009 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
1010 "No change in active parameters\n");
1011 return 0;
1012 }
1013
1014 /* We need the number of queues to be divisible between the hwfns */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001015 if ((count % edev->dev_info.common.num_hwfns) ||
1016 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
1017 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001018 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001019 "Number of channels must be divisible by %04x\n",
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001020 edev->dev_info.common.num_hwfns);
1021 return -EINVAL;
1022 }
1023
1024 /* Set number of queues and reload if necessary */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001025 edev->req_queues = count;
1026 edev->req_num_tx = channels->tx_count;
1027 edev->req_num_rx = channels->rx_count;
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -04001028 /* Reset the indirection table if rx queue count is updated */
1029 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
1030 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001031 memset(edev->rss_ind_table, 0, sizeof(edev->rss_ind_table));
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -04001032 }
1033
Mintz, Yuval567b3c12016-11-29 16:47:05 +02001034 qede_reload(edev, NULL, false);
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001035
1036 return 0;
1037}
1038
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +02001039static int qede_get_ts_info(struct net_device *dev,
1040 struct ethtool_ts_info *info)
1041{
1042 struct qede_dev *edev = netdev_priv(dev);
1043
1044 return qede_ptp_get_ts_info(edev, info);
1045}
1046
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +02001047static int qede_set_phys_id(struct net_device *dev,
1048 enum ethtool_phys_id_state state)
1049{
1050 struct qede_dev *edev = netdev_priv(dev);
1051 u8 led_state = 0;
1052
1053 switch (state) {
1054 case ETHTOOL_ID_ACTIVE:
1055 return 1; /* cycle on/off once per second */
1056
1057 case ETHTOOL_ID_ON:
1058 led_state = QED_LED_MODE_ON;
1059 break;
1060
1061 case ETHTOOL_ID_OFF:
1062 led_state = QED_LED_MODE_OFF;
1063 break;
1064
1065 case ETHTOOL_ID_INACTIVE:
1066 led_state = QED_LED_MODE_RESTORE;
1067 break;
1068 }
1069
1070 edev->ops->common->set_led(edev->cdev, led_state);
1071
1072 return 0;
1073}
1074
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001075static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1076{
1077 info->data = RXH_IP_SRC | RXH_IP_DST;
1078
1079 switch (info->flow_type) {
1080 case TCP_V4_FLOW:
1081 case TCP_V6_FLOW:
1082 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1083 break;
1084 case UDP_V4_FLOW:
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001085 if (edev->rss_caps & QED_RSS_IPV4_UDP)
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001086 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1087 break;
1088 case UDP_V6_FLOW:
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001089 if (edev->rss_caps & QED_RSS_IPV6_UDP)
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001090 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1091 break;
1092 case IPV4_FLOW:
1093 case IPV6_FLOW:
1094 break;
1095 default:
1096 info->data = 0;
1097 break;
1098 }
1099
1100 return 0;
1101}
1102
1103static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
Chopra, Manishec9b8db2017-07-26 06:07:09 -07001104 u32 *rule_locs)
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001105{
1106 struct qede_dev *edev = netdev_priv(dev);
Chopra, Manishec9b8db2017-07-26 06:07:09 -07001107 int rc = 0;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001108
1109 switch (info->cmd) {
1110 case ETHTOOL_GRXRINGS:
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001111 info->data = QEDE_RSS_COUNT(edev);
Chopra, Manishec9b8db2017-07-26 06:07:09 -07001112 break;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001113 case ETHTOOL_GRXFH:
Chopra, Manishec9b8db2017-07-26 06:07:09 -07001114 rc = qede_get_rss_flags(edev, info);
1115 break;
1116 case ETHTOOL_GRXCLSRLCNT:
1117 info->rule_cnt = qede_get_arfs_filter_count(edev);
1118 info->data = QEDE_RFS_MAX_FLTR;
1119 break;
1120 case ETHTOOL_GRXCLSRULE:
1121 rc = qede_get_cls_rule_entry(edev, info);
1122 break;
1123 case ETHTOOL_GRXCLSRLALL:
1124 rc = qede_get_cls_rule_all(edev, info, rule_locs);
1125 break;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001126 default:
1127 DP_ERR(edev, "Command parameters not supported\n");
Chopra, Manishec9b8db2017-07-26 06:07:09 -07001128 rc = -EOPNOTSUPP;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001129 }
Chopra, Manishec9b8db2017-07-26 06:07:09 -07001130
1131 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001132}
1133
1134static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
1135{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001136 struct qed_update_vport_params *vport_update_params;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001137 u8 set_caps = 0, clr_caps = 0;
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001138 int rc = 0;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001139
1140 DP_VERBOSE(edev, QED_MSG_DEBUG,
1141 "Set rss flags command parameters: flow type = %d, data = %llu\n",
1142 info->flow_type, info->data);
1143
1144 switch (info->flow_type) {
1145 case TCP_V4_FLOW:
1146 case TCP_V6_FLOW:
1147 /* For TCP only 4-tuple hash is supported */
1148 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
1149 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1150 DP_INFO(edev, "Command parameters not supported\n");
1151 return -EINVAL;
1152 }
1153 return 0;
1154 case UDP_V4_FLOW:
1155 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1156 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1157 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1158 set_caps = QED_RSS_IPV4_UDP;
1159 DP_VERBOSE(edev, QED_MSG_DEBUG,
1160 "UDP 4-tuple enabled\n");
1161 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1162 clr_caps = QED_RSS_IPV4_UDP;
1163 DP_VERBOSE(edev, QED_MSG_DEBUG,
1164 "UDP 4-tuple disabled\n");
1165 } else {
1166 return -EINVAL;
1167 }
1168 break;
1169 case UDP_V6_FLOW:
1170 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1171 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1172 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1173 set_caps = QED_RSS_IPV6_UDP;
1174 DP_VERBOSE(edev, QED_MSG_DEBUG,
1175 "UDP 4-tuple enabled\n");
1176 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1177 clr_caps = QED_RSS_IPV6_UDP;
1178 DP_VERBOSE(edev, QED_MSG_DEBUG,
1179 "UDP 4-tuple disabled\n");
1180 } else {
1181 return -EINVAL;
1182 }
1183 break;
1184 case IPV4_FLOW:
1185 case IPV6_FLOW:
1186 /* For IP only 2-tuple hash is supported */
1187 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1188 DP_INFO(edev, "Command parameters not supported\n");
1189 return -EINVAL;
1190 }
1191 return 0;
1192 case SCTP_V4_FLOW:
1193 case AH_ESP_V4_FLOW:
1194 case AH_V4_FLOW:
1195 case ESP_V4_FLOW:
1196 case SCTP_V6_FLOW:
1197 case AH_ESP_V6_FLOW:
1198 case AH_V6_FLOW:
1199 case ESP_V6_FLOW:
1200 case IP_USER_FLOW:
1201 case ETHER_FLOW:
1202 /* RSS is not supported for these protocols */
1203 if (info->data) {
1204 DP_INFO(edev, "Command parameters not supported\n");
1205 return -EINVAL;
1206 }
1207 return 0;
1208 default:
1209 return -EINVAL;
1210 }
1211
1212 /* No action is needed if there is no change in the rss capability */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001213 if (edev->rss_caps == ((edev->rss_caps & ~clr_caps) | set_caps))
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001214 return 0;
1215
1216 /* Update internal configuration */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001217 edev->rss_caps = ((edev->rss_caps & ~clr_caps) | set_caps);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001218 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1219
1220 /* Re-configure if possible */
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001221 __qede_lock(edev);
1222 if (edev->state == QEDE_STATE_OPEN) {
1223 vport_update_params = vzalloc(sizeof(*vport_update_params));
1224 if (!vport_update_params) {
1225 __qede_unlock(edev);
1226 return -ENOMEM;
1227 }
1228 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1229 &vport_update_params->update_rss_flg);
1230 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1231 vfree(vport_update_params);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001232 }
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001233 __qede_unlock(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001234
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001235 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001236}
1237
1238static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1239{
1240 struct qede_dev *edev = netdev_priv(dev);
Chopra, Manish3f2a2b82017-07-26 06:07:10 -07001241 int rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001242
1243 switch (info->cmd) {
1244 case ETHTOOL_SRXFH:
Chopra, Manish3f2a2b82017-07-26 06:07:10 -07001245 rc = qede_set_rss_flags(edev, info);
1246 break;
1247 case ETHTOOL_SRXCLSRLINS:
1248 rc = qede_add_cls_rule(edev, info);
1249 break;
1250 case ETHTOOL_SRXCLSRLDEL:
1251 rc = qede_del_cls_rule(edev, info);
1252 break;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001253 default:
1254 DP_INFO(edev, "Command parameters not supported\n");
Chopra, Manish3f2a2b82017-07-26 06:07:10 -07001255 rc = -EOPNOTSUPP;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001256 }
Chopra, Manish3f2a2b82017-07-26 06:07:10 -07001257
1258 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001259}
1260
1261static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1262{
1263 return QED_RSS_IND_TABLE_SIZE;
1264}
1265
1266static u32 qede_get_rxfh_key_size(struct net_device *dev)
1267{
1268 struct qede_dev *edev = netdev_priv(dev);
1269
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001270 return sizeof(edev->rss_key);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001271}
1272
1273static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1274{
1275 struct qede_dev *edev = netdev_priv(dev);
1276 int i;
1277
1278 if (hfunc)
1279 *hfunc = ETH_RSS_HASH_TOP;
1280
1281 if (!indir)
1282 return 0;
1283
1284 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001285 indir[i] = edev->rss_ind_table[i];
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001286
1287 if (key)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001288 memcpy(key, edev->rss_key, qede_get_rxfh_key_size(dev));
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001289
1290 return 0;
1291}
1292
1293static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1294 const u8 *key, const u8 hfunc)
1295{
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001296 struct qed_update_vport_params *vport_update_params;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001297 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001298 int i, rc = 0;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001299
Sudarsana Reddy Kalluruba300ce2016-10-21 04:43:40 -04001300 if (edev->dev_info.common.num_hwfns > 1) {
1301 DP_INFO(edev,
1302 "RSS configuration is not supported for 100G devices\n");
1303 return -EOPNOTSUPP;
1304 }
1305
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001306 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1307 return -EOPNOTSUPP;
1308
1309 if (!indir && !key)
1310 return 0;
1311
1312 if (indir) {
1313 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001314 edev->rss_ind_table[i] = indir[i];
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001315 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1316 }
1317
1318 if (key) {
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001319 memcpy(&edev->rss_key, key, qede_get_rxfh_key_size(dev));
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001320 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1321 }
1322
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001323 __qede_lock(edev);
1324 if (edev->state == QEDE_STATE_OPEN) {
1325 vport_update_params = vzalloc(sizeof(*vport_update_params));
1326 if (!vport_update_params) {
1327 __qede_unlock(edev);
1328 return -ENOMEM;
1329 }
1330 qede_fill_rss_params(edev, &vport_update_params->rss_params,
1331 &vport_update_params->update_rss_flg);
1332 rc = edev->ops->vport_update(edev->cdev, vport_update_params);
1333 vfree(vport_update_params);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001334 }
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001335 __qede_unlock(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001336
Mintz, Yuvalf29ffdb2017-01-01 13:57:07 +02001337 return rc;
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001338}
1339
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001340/* This function enables the interrupt generation and the NAPI on the device */
1341static void qede_netif_start(struct qede_dev *edev)
1342{
1343 int i;
1344
1345 if (!netif_running(edev->ndev))
1346 return;
1347
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001348 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001349 /* Update and reenable interrupts */
1350 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1351 napi_enable(&edev->fp_array[i].napi);
1352 }
1353}
1354
1355/* This function disables the NAPI and the interrupt generation on the device */
1356static void qede_netif_stop(struct qede_dev *edev)
1357{
1358 int i;
1359
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001360 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001361 napi_disable(&edev->fp_array[i].napi);
1362 /* Disable interrupts */
1363 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1364 }
1365}
1366
1367static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1368 struct sk_buff *skb)
1369{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001370 struct qede_tx_queue *txq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001371 struct eth_tx_1st_bd *first_bd;
1372 dma_addr_t mapping;
Manish Chopra48848a02017-05-23 09:41:18 +03001373 int i, idx;
1374 u16 val;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001375
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001376 for_each_queue(i) {
1377 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001378 txq = edev->fp_array[i].txq;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001379 break;
1380 }
1381 }
1382
1383 if (!txq) {
1384 DP_NOTICE(edev, "Tx path is not available\n");
1385 return -1;
1386 }
1387
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001388 /* Fill the entry in the SW ring and the BDs in the FW ring */
Sudarsana Reddy Kalluru5a052d62017-05-21 12:10:53 +03001389 idx = txq->sw_tx_prod;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001390 txq->sw_tx_ring.skbs[idx].skb = skb;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001391 first_bd = qed_chain_produce(&txq->tx_pbl);
1392 memset(first_bd, 0, sizeof(*first_bd));
1393 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1394 first_bd->data.bd_flags.bitfields = val;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001395 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
Manish Chopra48848a02017-05-23 09:41:18 +03001396 val = val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT;
1397 first_bd->data.bitfields |= cpu_to_le16(val);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001398
1399 /* Map skb linear data for DMA and set in the first BD */
1400 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1401 skb_headlen(skb), DMA_TO_DEVICE);
1402 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1403 DP_NOTICE(edev, "SKB mapping failed\n");
1404 return -ENOMEM;
1405 }
1406 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1407
1408 /* update the first BD with the actual num BDs */
1409 first_bd->data.nbds = 1;
Sudarsana Reddy Kalluru5a052d62017-05-21 12:10:53 +03001410 txq->sw_tx_prod = (txq->sw_tx_prod + 1) % txq->num_tx_buffers;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001411 /* 'next page' entries are counted in the producer value */
Manish Chopra48848a02017-05-23 09:41:18 +03001412 val = qed_chain_get_prod_idx(&txq->tx_pbl);
1413 txq->tx_db.data.bd_prod = cpu_to_le16(val);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001414
1415 /* wmb makes sure that the BDs data is updated before updating the
1416 * producer, otherwise FW may read old data from the BDs.
1417 */
1418 wmb();
1419 barrier();
1420 writel(txq->tx_db.raw, txq->doorbell_addr);
1421
1422 /* mmiowb is needed to synchronize doorbell writes from more than one
1423 * processor. It guarantees that the write arrives to the device before
1424 * the queue lock is released and another start_xmit is called (possibly
1425 * on another CPU). Without this barrier, the next doorbell can bypass
1426 * this doorbell. This is applicable to IA64/Altix systems.
1427 */
1428 mmiowb();
1429
1430 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1431 if (qede_txq_has_work(txq))
1432 break;
1433 usleep_range(100, 200);
1434 }
1435
1436 if (!qede_txq_has_work(txq)) {
1437 DP_NOTICE(edev, "Tx completion didn't happen\n");
1438 return -1;
1439 }
1440
1441 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
Manish Choprafabd5452016-10-21 04:43:45 -04001442 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1443 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
Sudarsana Reddy Kalluru5a052d62017-05-21 12:10:53 +03001444 txq->sw_tx_cons = (txq->sw_tx_cons + 1) % txq->num_tx_buffers;
Mintz, Yuvalcb6aeb02016-11-29 16:47:10 +02001445 txq->sw_tx_ring.skbs[idx].skb = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001446
1447 return 0;
1448}
1449
1450static int qede_selftest_receive_traffic(struct qede_dev *edev)
1451{
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001452 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1453 struct eth_fast_path_rx_reg_cqe *fp_cqe;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001454 struct qede_rx_queue *rxq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001455 struct sw_rx_data *sw_rx_data;
1456 union eth_rx_cqe *cqe;
Sudarsana Reddy Kalluruafe981d2017-02-20 22:43:37 +02001457 int i, iter, rc = 0;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001458 u8 *data_ptr;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001459
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001460 for_each_queue(i) {
1461 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1462 rxq = edev->fp_array[i].rxq;
1463 break;
1464 }
1465 }
1466
1467 if (!rxq) {
1468 DP_NOTICE(edev, "Rx path is not available\n");
1469 return -1;
1470 }
1471
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001472 /* The packet is expected to receive on rx-queue 0 even though RSS is
1473 * enabled. This is because the queue 0 is configured as the default
1474 * queue and that the loopback traffic is not IP.
1475 */
Sudarsana Reddy Kalluruafe981d2017-02-20 22:43:37 +02001476 for (iter = 0; iter < QEDE_SELFTEST_POLL_COUNT; iter++) {
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001477 if (!qede_has_rx_work(rxq)) {
1478 usleep_range(100, 200);
1479 continue;
1480 }
1481
1482 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1483 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1484
1485 /* Memory barrier to prevent the CPU from doing speculative
1486 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1487 * read before it is written by FW, then FW writes CQE and SB,
1488 * and then the CPU reads the hw_comp_cons, it will use an old
1489 * CQE.
1490 */
1491 rmb();
1492
1493 /* Get the CQE from the completion ring */
1494 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1495
1496 /* Get the data from the SW ring */
1497 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1498 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1499 fp_cqe = &cqe->fast_path_regular;
1500 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1501 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1502 fp_cqe->placement_offset +
1503 sw_rx_data->page_offset);
1504 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1505 ether_addr_equal(data_ptr + ETH_ALEN,
1506 edev->ndev->dev_addr)) {
1507 for (i = ETH_HLEN; i < len; i++)
1508 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1509 rc = -1;
1510 break;
1511 }
1512
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001513 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001514 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001515 break;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001516 }
1517
1518 DP_INFO(edev, "Not the transmitted packet\n");
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001519 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001520 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001521 }
1522
Sudarsana Reddy Kalluruafe981d2017-02-20 22:43:37 +02001523 if (iter == QEDE_SELFTEST_POLL_COUNT) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001524 DP_NOTICE(edev, "Failed to receive the traffic\n");
1525 return -1;
1526 }
1527
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001528 qede_update_rx_prod(edev, rxq);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001529
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001530 return rc;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001531}
1532
1533static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1534{
1535 struct qed_link_params link_params;
1536 struct sk_buff *skb = NULL;
1537 int rc = 0, i;
1538 u32 pkt_size;
1539 u8 *packet;
1540
1541 if (!netif_running(edev->ndev)) {
1542 DP_NOTICE(edev, "Interface is down\n");
1543 return -EINVAL;
1544 }
1545
1546 qede_netif_stop(edev);
1547
1548 /* Bring up the link in Loopback mode */
1549 memset(&link_params, 0, sizeof(link_params));
1550 link_params.link_up = true;
1551 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1552 link_params.loopback_mode = loopback_mode;
1553 edev->ops->common->set_link(edev->cdev, &link_params);
1554
1555 /* Wait for loopback configuration to apply */
1556 msleep_interruptible(500);
1557
1558 /* prepare the loopback packet */
1559 pkt_size = edev->ndev->mtu + ETH_HLEN;
1560
1561 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1562 if (!skb) {
1563 DP_INFO(edev, "Can't allocate skb\n");
1564 rc = -ENOMEM;
1565 goto test_loopback_exit;
1566 }
1567 packet = skb_put(skb, pkt_size);
1568 ether_addr_copy(packet, edev->ndev->dev_addr);
1569 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1570 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1571 for (i = ETH_HLEN; i < pkt_size; i++)
1572 packet[i] = (unsigned char)(i & 0xff);
1573
1574 rc = qede_selftest_transmit_traffic(edev, skb);
1575 if (rc)
1576 goto test_loopback_exit;
1577
1578 rc = qede_selftest_receive_traffic(edev);
1579 if (rc)
1580 goto test_loopback_exit;
1581
1582 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1583
1584test_loopback_exit:
1585 dev_kfree_skb(skb);
1586
1587 /* Bring up the link in Normal mode */
1588 memset(&link_params, 0, sizeof(link_params));
1589 link_params.link_up = true;
1590 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1591 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1592 edev->ops->common->set_link(edev->cdev, &link_params);
1593
1594 /* Wait for loopback configuration to apply */
1595 msleep_interruptible(500);
1596
1597 qede_netif_start(edev);
1598
1599 return rc;
1600}
1601
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001602static void qede_self_test(struct net_device *dev,
1603 struct ethtool_test *etest, u64 *buf)
1604{
1605 struct qede_dev *edev = netdev_priv(dev);
1606
1607 DP_VERBOSE(edev, QED_MSG_DEBUG,
1608 "Self-test command parameters: offline = %d, external_lb = %d\n",
1609 (etest->flags & ETH_TEST_FL_OFFLINE),
1610 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1611
1612 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1613
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001614 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1615 if (qede_selftest_run_loopback(edev,
1616 QED_LINK_LOOPBACK_INT_PHY)) {
1617 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1618 etest->flags |= ETH_TEST_FL_FAILED;
1619 }
1620 }
1621
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001622 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1623 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1624 etest->flags |= ETH_TEST_FL_FAILED;
1625 }
1626
1627 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1628 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1629 etest->flags |= ETH_TEST_FL_FAILED;
1630 }
1631
1632 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1633 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1634 etest->flags |= ETH_TEST_FL_FAILED;
1635 }
1636
1637 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1638 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1639 etest->flags |= ETH_TEST_FL_FAILED;
1640 }
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +02001641
1642 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1643 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1644 etest->flags |= ETH_TEST_FL_FAILED;
1645 }
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001646}
1647
Manish Chopra3d789992016-06-30 02:35:21 -04001648static int qede_set_tunable(struct net_device *dev,
1649 const struct ethtool_tunable *tuna,
1650 const void *data)
1651{
1652 struct qede_dev *edev = netdev_priv(dev);
1653 u32 val;
1654
1655 switch (tuna->id) {
1656 case ETHTOOL_RX_COPYBREAK:
1657 val = *(u32 *)data;
1658 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1659 DP_VERBOSE(edev, QED_MSG_DEBUG,
1660 "Invalid rx copy break value, range is [%u, %u]",
1661 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1662 return -EINVAL;
1663 }
1664
1665 edev->rx_copybreak = *(u32 *)data;
1666 break;
1667 default:
1668 return -EOPNOTSUPP;
1669 }
1670
1671 return 0;
1672}
1673
1674static int qede_get_tunable(struct net_device *dev,
1675 const struct ethtool_tunable *tuna, void *data)
1676{
1677 struct qede_dev *edev = netdev_priv(dev);
1678
1679 switch (tuna->id) {
1680 case ETHTOOL_RX_COPYBREAK:
1681 *(u32 *)data = edev->rx_copybreak;
1682 break;
1683 default:
1684 return -EOPNOTSUPP;
1685 }
1686
1687 return 0;
1688}
1689
Sudarsana Reddy Kalluruc3dc48f2017-07-26 06:07:12 -07001690static int qede_get_eee(struct net_device *dev, struct ethtool_eee *edata)
1691{
1692 struct qede_dev *edev = netdev_priv(dev);
1693 struct qed_link_output current_link;
1694
1695 memset(&current_link, 0, sizeof(current_link));
1696 edev->ops->common->get_link(edev->cdev, &current_link);
1697
1698 if (!current_link.eee_supported) {
1699 DP_INFO(edev, "EEE is not supported\n");
1700 return -EOPNOTSUPP;
1701 }
1702
1703 if (current_link.eee.adv_caps & QED_EEE_1G_ADV)
1704 edata->advertised = ADVERTISED_1000baseT_Full;
1705 if (current_link.eee.adv_caps & QED_EEE_10G_ADV)
1706 edata->advertised |= ADVERTISED_10000baseT_Full;
1707 if (current_link.sup_caps & QED_EEE_1G_ADV)
1708 edata->supported = ADVERTISED_1000baseT_Full;
1709 if (current_link.sup_caps & QED_EEE_10G_ADV)
1710 edata->supported |= ADVERTISED_10000baseT_Full;
1711 if (current_link.eee.lp_adv_caps & QED_EEE_1G_ADV)
1712 edata->lp_advertised = ADVERTISED_1000baseT_Full;
1713 if (current_link.eee.lp_adv_caps & QED_EEE_10G_ADV)
1714 edata->lp_advertised |= ADVERTISED_10000baseT_Full;
1715
1716 edata->tx_lpi_timer = current_link.eee.tx_lpi_timer;
1717 edata->eee_enabled = current_link.eee.enable;
1718 edata->tx_lpi_enabled = current_link.eee.tx_lpi_enable;
1719 edata->eee_active = current_link.eee_active;
1720
1721 return 0;
1722}
1723
1724static int qede_set_eee(struct net_device *dev, struct ethtool_eee *edata)
1725{
1726 struct qede_dev *edev = netdev_priv(dev);
1727 struct qed_link_output current_link;
1728 struct qed_link_params params;
1729
1730 if (!edev->ops->common->can_link_change(edev->cdev)) {
1731 DP_INFO(edev, "Link settings are not allowed to be changed\n");
1732 return -EOPNOTSUPP;
1733 }
1734
1735 memset(&current_link, 0, sizeof(current_link));
1736 edev->ops->common->get_link(edev->cdev, &current_link);
1737
1738 if (!current_link.eee_supported) {
1739 DP_INFO(edev, "EEE is not supported\n");
1740 return -EOPNOTSUPP;
1741 }
1742
1743 memset(&params, 0, sizeof(params));
1744 params.override_flags |= QED_LINK_OVERRIDE_EEE_CONFIG;
1745
1746 if (!(edata->advertised & (ADVERTISED_1000baseT_Full |
1747 ADVERTISED_10000baseT_Full)) ||
1748 ((edata->advertised & (ADVERTISED_1000baseT_Full |
1749 ADVERTISED_10000baseT_Full)) !=
1750 edata->advertised)) {
1751 DP_VERBOSE(edev, QED_MSG_DEBUG,
1752 "Invalid advertised capabilities %d\n",
1753 edata->advertised);
1754 return -EINVAL;
1755 }
1756
1757 if (edata->advertised & ADVERTISED_1000baseT_Full)
1758 params.eee.adv_caps = QED_EEE_1G_ADV;
1759 if (edata->advertised & ADVERTISED_10000baseT_Full)
1760 params.eee.adv_caps |= QED_EEE_10G_ADV;
1761 params.eee.enable = edata->eee_enabled;
1762 params.eee.tx_lpi_enable = edata->tx_lpi_enabled;
1763 params.eee.tx_lpi_timer = edata->tx_lpi_timer;
1764
1765 params.link_up = true;
1766 edev->ops->common->set_link(edev->cdev, &params);
1767
1768 return 0;
1769}
1770
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001771static const struct ethtool_ops qede_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001772 .get_link_ksettings = qede_get_link_ksettings,
1773 .set_link_ksettings = qede_set_link_ksettings,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001774 .get_drvinfo = qede_get_drvinfo,
Tomer Tayare0971c82016-09-07 16:36:25 +03001775 .get_regs_len = qede_get_regs_len,
1776 .get_regs = qede_get_regs,
Mintz, Yuval14d39642016-10-31 07:14:23 +02001777 .get_wol = qede_get_wol,
1778 .set_wol = qede_set_wol,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001779 .get_msglevel = qede_get_msglevel,
1780 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +02001781 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001782 .get_link = qede_get_link,
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -04001783 .get_coalesce = qede_get_coalesce,
1784 .set_coalesce = qede_set_coalesce,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +02001785 .get_ringparam = qede_get_ringparam,
1786 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +02001787 .get_pauseparam = qede_get_pauseparam,
1788 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001789 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +02001790 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001791 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +03001792 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001793 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001794 .get_rxnfc = qede_get_rxnfc,
1795 .set_rxnfc = qede_set_rxnfc,
1796 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1797 .get_rxfh_key_size = qede_get_rxfh_key_size,
1798 .get_rxfh = qede_get_rxfh,
1799 .set_rxfh = qede_set_rxfh,
Sudarsana Reddy Kalluru4c552152017-02-15 10:24:11 +02001800 .get_ts_info = qede_get_ts_info,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001801 .get_channels = qede_get_channels,
1802 .set_channels = qede_set_channels,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001803 .self_test = qede_self_test,
Sudarsana Reddy Kalluruc3dc48f2017-07-26 06:07:12 -07001804 .get_eee = qede_get_eee,
1805 .set_eee = qede_set_eee,
1806
Manish Chopra3d789992016-06-30 02:35:21 -04001807 .get_tunable = qede_get_tunable,
1808 .set_tunable = qede_set_tunable,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001809};
1810
Yuval Mintzfefb0202016-05-11 16:36:19 +03001811static const struct ethtool_ops qede_vf_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001812 .get_link_ksettings = qede_get_link_ksettings,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001813 .get_drvinfo = qede_get_drvinfo,
1814 .get_msglevel = qede_get_msglevel,
1815 .set_msglevel = qede_set_msglevel,
1816 .get_link = qede_get_link,
Rahul Verma477f2d12017-07-26 06:07:13 -07001817 .get_coalesce = qede_get_coalesce,
1818 .set_coalesce = qede_set_coalesce,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001819 .get_ringparam = qede_get_ringparam,
1820 .set_ringparam = qede_set_ringparam,
1821 .get_strings = qede_get_strings,
1822 .get_ethtool_stats = qede_get_ethtool_stats,
1823 .get_priv_flags = qede_get_priv_flags,
1824 .get_sset_count = qede_get_sset_count,
1825 .get_rxnfc = qede_get_rxnfc,
1826 .set_rxnfc = qede_set_rxnfc,
1827 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1828 .get_rxfh_key_size = qede_get_rxfh_key_size,
1829 .get_rxfh = qede_get_rxfh,
1830 .set_rxfh = qede_set_rxfh,
1831 .get_channels = qede_get_channels,
1832 .set_channels = qede_set_channels,
Manish Chopra3d789992016-06-30 02:35:21 -04001833 .get_tunable = qede_get_tunable,
1834 .set_tunable = qede_set_tunable,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001835};
1836
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001837void qede_set_ethtool_ops(struct net_device *dev)
1838{
Yuval Mintzfefb0202016-05-11 16:36:19 +03001839 struct qede_dev *edev = netdev_priv(dev);
1840
1841 if (IS_VF(edev))
1842 dev->ethtool_ops = &qede_vf_ethtool_ops;
1843 else
1844 dev->ethtool_ops = &qede_ethtool_ops;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001845}