blob: 6c70e298ba77f26cb01389668bac9d64cfd4e70b [file] [log] [blame]
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001/* QLogic qede NIC Driver
2* Copyright (c) 2015 QLogic Corporation
3*
4* This software is available under the terms of the GNU General Public License
5* (GPL) Version 2, available from the file COPYING in the main directory of
6* this source tree.
7*/
8
9#include <linux/version.h>
10#include <linux/types.h>
11#include <linux/netdevice.h>
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040012#include <linux/etherdevice.h>
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020013#include <linux/ethtool.h>
14#include <linux/string.h>
15#include <linux/pci.h>
16#include <linux/capability.h>
17#include "qede.h"
18
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020019#define QEDE_RQSTAT_OFFSET(stat_name) \
20 (offsetof(struct qede_rx_queue, stat_name))
21#define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
22#define QEDE_RQSTAT(stat_name) \
23 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040024
25#define QEDE_SELFTEST_POLL_COUNT 100
26
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020027static const struct {
28 u64 offset;
29 char string[ETH_GSTRING_LEN];
30} qede_rqstats_arr[] = {
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040031 QEDE_RQSTAT(rcv_pkts),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020032 QEDE_RQSTAT(rx_hw_errors),
33 QEDE_RQSTAT(rx_alloc_errors),
Manish Choprac72a6122016-06-30 02:35:18 -040034 QEDE_RQSTAT(rx_ip_frags),
Mintz, Yuval496e0512016-11-29 16:47:09 +020035 QEDE_RQSTAT(xdp_no_pass),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020036};
37
38#define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040039#define QEDE_TQSTAT_OFFSET(stat_name) \
40 (offsetof(struct qede_tx_queue, stat_name))
41#define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
42#define QEDE_TQSTAT(stat_name) \
43 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
44#define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
45static const struct {
46 u64 offset;
47 char string[ETH_GSTRING_LEN];
48} qede_tqstats_arr[] = {
49 QEDE_TQSTAT(xmit_pkts),
50 QEDE_TQSTAT(stopped_cnt),
51};
52
Mintz, Yuval4dbcd642016-11-29 16:47:03 +020053#define QEDE_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
54#define QEDE_STAT_STRING(stat_name) (#stat_name)
55#define _QEDE_STAT(stat_name, pf_only) \
56 {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
57#define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
58#define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020059static const struct {
60 u64 offset;
61 char string[ETH_GSTRING_LEN];
62 bool pf_only;
63} qede_stats_arr[] = {
64 QEDE_STAT(rx_ucast_bytes),
65 QEDE_STAT(rx_mcast_bytes),
66 QEDE_STAT(rx_bcast_bytes),
67 QEDE_STAT(rx_ucast_pkts),
68 QEDE_STAT(rx_mcast_pkts),
69 QEDE_STAT(rx_bcast_pkts),
70
71 QEDE_STAT(tx_ucast_bytes),
72 QEDE_STAT(tx_mcast_bytes),
73 QEDE_STAT(tx_bcast_bytes),
74 QEDE_STAT(tx_ucast_pkts),
75 QEDE_STAT(tx_mcast_pkts),
76 QEDE_STAT(tx_bcast_pkts),
77
78 QEDE_PF_STAT(rx_64_byte_packets),
Yuval Mintzd4967cf2016-04-22 08:41:01 +030079 QEDE_PF_STAT(rx_65_to_127_byte_packets),
80 QEDE_PF_STAT(rx_128_to_255_byte_packets),
81 QEDE_PF_STAT(rx_256_to_511_byte_packets),
82 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
83 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
84 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
85 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
86 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
87 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
88 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020089 QEDE_PF_STAT(tx_64_byte_packets),
90 QEDE_PF_STAT(tx_65_to_127_byte_packets),
91 QEDE_PF_STAT(tx_128_to_255_byte_packets),
92 QEDE_PF_STAT(tx_256_to_511_byte_packets),
93 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
94 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
95 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
96 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
97 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
98 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
99
100 QEDE_PF_STAT(rx_mac_crtl_frames),
101 QEDE_PF_STAT(tx_mac_ctrl_frames),
102 QEDE_PF_STAT(rx_pause_frames),
103 QEDE_PF_STAT(tx_pause_frames),
104 QEDE_PF_STAT(rx_pfc_frames),
105 QEDE_PF_STAT(tx_pfc_frames),
106
107 QEDE_PF_STAT(rx_crc_errors),
108 QEDE_PF_STAT(rx_align_errors),
109 QEDE_PF_STAT(rx_carrier_errors),
110 QEDE_PF_STAT(rx_oversize_packets),
111 QEDE_PF_STAT(rx_jabbers),
112 QEDE_PF_STAT(rx_undersize_packets),
113 QEDE_PF_STAT(rx_fragments),
114 QEDE_PF_STAT(tx_lpi_entry_count),
115 QEDE_PF_STAT(tx_total_collisions),
116 QEDE_PF_STAT(brb_truncates),
117 QEDE_PF_STAT(brb_discards),
118 QEDE_STAT(no_buff_discards),
119 QEDE_PF_STAT(mftag_filter_discards),
120 QEDE_PF_STAT(mac_filter_discards),
121 QEDE_STAT(tx_err_drop_pkts),
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400122 QEDE_STAT(ttl0_discard),
123 QEDE_STAT(packet_too_big_discard),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200124
125 QEDE_STAT(coalesced_pkts),
126 QEDE_STAT(coalesced_events),
127 QEDE_STAT(coalesced_aborts_num),
128 QEDE_STAT(non_coalesced_pkts),
129 QEDE_STAT(coalesced_bytes),
130};
131
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200132#define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
133
Yuval Mintzf3e72102016-04-22 08:41:02 +0300134enum {
135 QEDE_PRI_FLAG_CMT,
136 QEDE_PRI_FLAG_LEN,
137};
138
139static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
140 "Coupled-Function",
141};
142
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400143enum qede_ethtool_tests {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400144 QEDE_ETHTOOL_INT_LOOPBACK,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400145 QEDE_ETHTOOL_INTERRUPT_TEST,
146 QEDE_ETHTOOL_MEMORY_TEST,
147 QEDE_ETHTOOL_REGISTER_TEST,
148 QEDE_ETHTOOL_CLOCK_TEST,
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200149 QEDE_ETHTOOL_NVRAM_TEST,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400150 QEDE_ETHTOOL_TEST_MAX
151};
152
153static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400154 "Internal loopback (offline)",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400155 "Interrupt (online)\t",
156 "Memory (online)\t\t",
157 "Register (online)\t",
158 "Clock (online)\t\t",
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +0200159 "Nvram (online)\t\t",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400160};
161
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200162static void qede_get_strings_stats_txq(struct qede_dev *edev,
163 struct qede_tx_queue *txq, u8 **buf)
164{
165 int i;
166
167 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
168 sprintf(*buf, "%d: %s", txq->index,
169 qede_tqstats_arr[i].string);
170 *buf += ETH_GSTRING_LEN;
171 }
172}
173
174static void qede_get_strings_stats_rxq(struct qede_dev *edev,
175 struct qede_rx_queue *rxq, u8 **buf)
176{
177 int i;
178
179 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
180 sprintf(*buf, "%d: %s", rxq->rxq_id,
181 qede_rqstats_arr[i].string);
182 *buf += ETH_GSTRING_LEN;
183 }
184}
185
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200186static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
187{
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200188 struct qede_fastpath *fp;
189 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200190
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200191 /* Account for queue statistics */
192 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
193 fp = &edev->fp_array[i];
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400194
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200195 if (fp->type & QEDE_FASTPATH_RX)
196 qede_get_strings_stats_rxq(edev, fp->rxq, &buf);
Mintz, Yuvalcbbf0492016-10-30 10:25:42 +0200197
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200198 if (fp->type & QEDE_FASTPATH_TX)
199 qede_get_strings_stats_txq(edev, fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400200 }
201
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200202 /* Account for non-queue statistics */
203 for (i = 0; i < QEDE_NUM_STATS; i++) {
Yuval Mintzfefb0202016-05-11 16:36:19 +0300204 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
205 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200206 strcpy(buf, qede_stats_arr[i].string);
207 buf += ETH_GSTRING_LEN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200208 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200209}
210
211static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
212{
213 struct qede_dev *edev = netdev_priv(dev);
214
215 switch (stringset) {
216 case ETH_SS_STATS:
217 qede_get_strings_stats(edev, buf);
218 break;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300219 case ETH_SS_PRIV_FLAGS:
220 memcpy(buf, qede_private_arr,
221 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
222 break;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400223 case ETH_SS_TEST:
224 memcpy(buf, qede_tests_str_arr,
225 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
226 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200227 default:
228 DP_VERBOSE(edev, QED_MSG_DEBUG,
229 "Unsupported stringset 0x%08x\n", stringset);
230 }
231}
232
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200233static void qede_get_ethtool_stats_txq(struct qede_tx_queue *txq, u64 **buf)
234{
235 int i;
236
237 for (i = 0; i < QEDE_NUM_TQSTATS; i++) {
238 **buf = *((u64 *)(((void *)txq) + qede_tqstats_arr[i].offset));
239 (*buf)++;
240 }
241}
242
243static void qede_get_ethtool_stats_rxq(struct qede_rx_queue *rxq, u64 **buf)
244{
245 int i;
246
247 for (i = 0; i < QEDE_NUM_RQSTATS; i++) {
248 **buf = *((u64 *)(((void *)rxq) + qede_rqstats_arr[i].offset));
249 (*buf)++;
250 }
251}
252
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200253static void qede_get_ethtool_stats(struct net_device *dev,
254 struct ethtool_stats *stats, u64 *buf)
255{
256 struct qede_dev *edev = netdev_priv(dev);
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200257 struct qede_fastpath *fp;
258 int i;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200259
260 qede_fill_by_demand_stats(edev);
261
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200262 /* Need to protect the access to the fastpath array */
263 __qede_lock(edev);
264
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200265 for (i = 0; i < QEDE_QUEUE_CNT(edev); i++) {
266 fp = &edev->fp_array[i];
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200267
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200268 if (fp->type & QEDE_FASTPATH_RX)
269 qede_get_ethtool_stats_rxq(fp->rxq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400270
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200271 if (fp->type & QEDE_FASTPATH_TX)
272 qede_get_ethtool_stats_txq(fp->txq, &buf);
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400273 }
274
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200275 for (i = 0; i < QEDE_NUM_STATS; i++) {
276 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
Yuval Mintzfefb0202016-05-11 16:36:19 +0300277 continue;
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200278 *buf = *((u64 *)(((void *)&edev->stats) +
279 qede_stats_arr[i].offset));
280
281 buf++;
Yuval Mintzfefb0202016-05-11 16:36:19 +0300282 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200283
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200284 __qede_unlock(edev);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200285}
286
287static int qede_get_sset_count(struct net_device *dev, int stringset)
288{
289 struct qede_dev *edev = netdev_priv(dev);
290 int num_stats = QEDE_NUM_STATS;
291
292 switch (stringset) {
293 case ETH_SS_STATS:
Yuval Mintzfefb0202016-05-11 16:36:19 +0300294 if (IS_VF(edev)) {
295 int i;
296
297 for (i = 0; i < QEDE_NUM_STATS; i++)
298 if (qede_stats_arr[i].pf_only)
299 num_stats--;
300 }
Mintz, Yuval4dbcd642016-11-29 16:47:03 +0200301
302 /* Account for the Regular Tx statistics */
303 num_stats += QEDE_TSS_COUNT(edev) * QEDE_NUM_TQSTATS;
304
305 /* Account for the Regular Rx statistics */
306 num_stats += QEDE_RSS_COUNT(edev) * QEDE_NUM_RQSTATS;
307
308 return num_stats;
309
Yuval Mintzf3e72102016-04-22 08:41:02 +0300310 case ETH_SS_PRIV_FLAGS:
311 return QEDE_PRI_FLAG_LEN;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400312 case ETH_SS_TEST:
Yuval Mintz6ecb0a02016-05-26 11:01:19 +0300313 if (!IS_VF(edev))
314 return QEDE_ETHTOOL_TEST_MAX;
315 else
316 return 0;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200317 default:
318 DP_VERBOSE(edev, QED_MSG_DEBUG,
319 "Unsupported stringset 0x%08x\n", stringset);
320 return -EINVAL;
321 }
322}
323
Yuval Mintzf3e72102016-04-22 08:41:02 +0300324static u32 qede_get_priv_flags(struct net_device *dev)
325{
326 struct qede_dev *edev = netdev_priv(dev);
327
328 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
329}
330
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400331struct qede_link_mode_mapping {
332 u32 qed_link_mode;
333 u32 ethtool_link_mode;
334};
335
336static const struct qede_link_mode_mapping qed_lm_map[] = {
337 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
338 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
339 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
340 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
341 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
342 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
343 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
344 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
345 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
346 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
347 {QED_LM_100000baseKR4_Full_BIT,
348 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
349};
350
351#define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
352{ \
353 int i; \
354 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200355 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400356 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
357 __set_bit(qed_lm_map[i].ethtool_link_mode,\
358 lk_ksettings->link_modes.name); \
359 } \
360}
361
362#define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
363{ \
364 int i; \
365 \
Mintz, Yuvald7455f62016-10-31 07:14:24 +0200366 for (i = 0; i < ARRAY_SIZE(qed_lm_map); i++) { \
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400367 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
368 lk_ksettings->link_modes.name)) \
369 caps |= qed_lm_map[i].qed_link_mode; \
370 } \
371}
372
373static int qede_get_link_ksettings(struct net_device *dev,
374 struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200375{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400376 struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200377 struct qede_dev *edev = netdev_priv(dev);
378 struct qed_link_output current_link;
379
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200380 __qede_lock(edev);
381
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200382 memset(&current_link, 0, sizeof(current_link));
383 edev->ops->common->get_link(edev->cdev, &current_link);
384
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400385 ethtool_link_ksettings_zero_link_mode(cmd, supported);
386 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
387
388 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
389 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
390
391 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
392 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
393
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200394 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400395 base->speed = current_link.speed;
396 base->duplex = current_link.duplex;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200397 } else {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400398 base->speed = SPEED_UNKNOWN;
399 base->duplex = DUPLEX_UNKNOWN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200400 }
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200401
402 __qede_unlock(edev);
403
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400404 base->port = current_link.port;
405 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
406 AUTONEG_DISABLE;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200407
408 return 0;
409}
410
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400411static int qede_set_link_ksettings(struct net_device *dev,
412 const struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200413{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400414 const struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200415 struct qede_dev *edev = netdev_priv(dev);
416 struct qed_link_output current_link;
417 struct qed_link_params params;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200418
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300419 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400420 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200421 return -EOPNOTSUPP;
422 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200423 memset(&current_link, 0, sizeof(current_link));
424 memset(&params, 0, sizeof(params));
425 edev->ops->common->get_link(edev->cdev, &current_link);
426
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200427 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
428 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400429 if (base->autoneg == AUTONEG_ENABLE) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200430 params.autoneg = true;
431 params.forced_speed = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400432 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
433 } else { /* forced speed */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200434 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
435 params.autoneg = false;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400436 params.forced_speed = base->speed;
437 switch (base->speed) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200438 case SPEED_10000:
439 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400440 QED_LM_10000baseKR_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200441 DP_INFO(edev, "10G speed not supported\n");
442 return -EINVAL;
443 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400444 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
445 break;
446 case SPEED_25000:
447 if (!(current_link.supported_caps &
448 QED_LM_25000baseKR_Full_BIT)) {
449 DP_INFO(edev, "25G speed not supported\n");
450 return -EINVAL;
451 }
452 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200453 break;
454 case SPEED_40000:
455 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400456 QED_LM_40000baseLR4_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200457 DP_INFO(edev, "40G speed not supported\n");
458 return -EINVAL;
459 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400460 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
461 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300462 case SPEED_50000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400463 if (!(current_link.supported_caps &
464 QED_LM_50000baseKR2_Full_BIT)) {
465 DP_INFO(edev, "50G speed not supported\n");
466 return -EINVAL;
467 }
468 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
469 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300470 case SPEED_100000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400471 if (!(current_link.supported_caps &
472 QED_LM_100000baseKR4_Full_BIT)) {
473 DP_INFO(edev, "100G speed not supported\n");
474 return -EINVAL;
475 }
476 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200477 break;
478 default:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400479 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200480 return -EINVAL;
481 }
482 }
483
484 params.link_up = true;
485 edev->ops->common->set_link(edev->cdev, &params);
486
487 return 0;
488}
489
490static void qede_get_drvinfo(struct net_device *ndev,
491 struct ethtool_drvinfo *info)
492{
493 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
494 struct qede_dev *edev = netdev_priv(ndev);
495
496 strlcpy(info->driver, "qede", sizeof(info->driver));
497 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
498
499 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
500 edev->dev_info.common.fw_major,
501 edev->dev_info.common.fw_minor,
502 edev->dev_info.common.fw_rev,
503 edev->dev_info.common.fw_eng);
504
505 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
506 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
507 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
508 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
509 edev->dev_info.common.mfw_rev & 0xFF);
510
511 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
512 sizeof(info->fw_version)) {
513 snprintf(info->fw_version, sizeof(info->fw_version),
514 "mfw %s storm %s", mfw, storm);
515 } else {
516 snprintf(info->fw_version, sizeof(info->fw_version),
517 "%s %s", mfw, storm);
518 }
519
520 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
521}
522
Mintz, Yuval14d39642016-10-31 07:14:23 +0200523static void qede_get_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
524{
525 struct qede_dev *edev = netdev_priv(ndev);
526
527 if (edev->dev_info.common.wol_support) {
528 wol->supported = WAKE_MAGIC;
529 wol->wolopts = edev->wol_enabled ? WAKE_MAGIC : 0;
530 }
531}
532
533static int qede_set_wol(struct net_device *ndev, struct ethtool_wolinfo *wol)
534{
535 struct qede_dev *edev = netdev_priv(ndev);
536 bool wol_requested;
537 int rc;
538
539 if (wol->wolopts & ~WAKE_MAGIC) {
540 DP_INFO(edev,
541 "Can't support WoL options other than magic-packet\n");
542 return -EINVAL;
543 }
544
545 wol_requested = !!(wol->wolopts & WAKE_MAGIC);
546 if (wol_requested == edev->wol_enabled)
547 return 0;
548
549 /* Need to actually change configuration */
550 if (!edev->dev_info.common.wol_support) {
551 DP_INFO(edev, "Device doesn't support WoL\n");
552 return -EINVAL;
553 }
554
555 rc = edev->ops->common->update_wol(edev->cdev, wol_requested);
556 if (!rc)
557 edev->wol_enabled = wol_requested;
558
559 return rc;
560}
561
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200562static u32 qede_get_msglevel(struct net_device *ndev)
563{
564 struct qede_dev *edev = netdev_priv(ndev);
565
Yuval Mintz1a635e42016-08-15 10:42:43 +0300566 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200567}
568
569static void qede_set_msglevel(struct net_device *ndev, u32 level)
570{
571 struct qede_dev *edev = netdev_priv(ndev);
572 u32 dp_module = 0;
573 u8 dp_level = 0;
574
575 qede_config_debug(level, &dp_module, &dp_level);
576
577 edev->dp_level = dp_level;
578 edev->dp_module = dp_module;
579 edev->ops->common->update_msglvl(edev->cdev,
580 dp_module, dp_level);
581}
582
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200583static int qede_nway_reset(struct net_device *dev)
584{
585 struct qede_dev *edev = netdev_priv(dev);
586 struct qed_link_output current_link;
587 struct qed_link_params link_params;
588
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300589 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Yuval Mintz1a635e42016-08-15 10:42:43 +0300590 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300591 return -EOPNOTSUPP;
592 }
593
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200594 if (!netif_running(dev))
595 return 0;
596
597 memset(&current_link, 0, sizeof(current_link));
598 edev->ops->common->get_link(edev->cdev, &current_link);
599 if (!current_link.link_up)
600 return 0;
601
602 /* Toggle the link */
603 memset(&link_params, 0, sizeof(link_params));
604 link_params.link_up = false;
605 edev->ops->common->set_link(edev->cdev, &link_params);
606 link_params.link_up = true;
607 edev->ops->common->set_link(edev->cdev, &link_params);
608
609 return 0;
610}
611
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200612static u32 qede_get_link(struct net_device *dev)
613{
614 struct qede_dev *edev = netdev_priv(dev);
615 struct qed_link_output current_link;
616
617 memset(&current_link, 0, sizeof(current_link));
618 edev->ops->common->get_link(edev->cdev, &current_link);
619
620 return current_link.link_up;
621}
622
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400623static int qede_get_coalesce(struct net_device *dev,
624 struct ethtool_coalesce *coal)
625{
626 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400627 u16 rxc, txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400628
629 memset(coal, 0, sizeof(struct ethtool_coalesce));
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400630 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
631
632 coal->rx_coalesce_usecs = rxc;
633 coal->tx_coalesce_usecs = txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400634
635 return 0;
636}
637
638static int qede_set_coalesce(struct net_device *dev,
639 struct ethtool_coalesce *coal)
640{
641 struct qede_dev *edev = netdev_priv(dev);
642 int i, rc = 0;
643 u16 rxc, txc;
644 u8 sb_id;
645
646 if (!netif_running(dev)) {
647 DP_INFO(edev, "Interface is down\n");
648 return -EINVAL;
649 }
650
651 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
652 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
653 DP_INFO(edev,
654 "Can't support requested %s coalesce value [max supported value %d]\n",
655 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
656 : "tx",
657 QED_COALESCE_MAX);
658 return -EINVAL;
659 }
660
661 rxc = (u16)coal->rx_coalesce_usecs;
662 txc = (u16)coal->tx_coalesce_usecs;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400663 for_each_queue(i) {
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400664 sb_id = edev->fp_array[i].sb_info->igu_sb_id;
665 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
666 (u8)i, sb_id);
667 if (rc) {
668 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
669 return rc;
670 }
671 }
672
673 return rc;
674}
675
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200676static void qede_get_ringparam(struct net_device *dev,
677 struct ethtool_ringparam *ering)
678{
679 struct qede_dev *edev = netdev_priv(dev);
680
681 ering->rx_max_pending = NUM_RX_BDS_MAX;
682 ering->rx_pending = edev->q_num_rx_buffers;
683 ering->tx_max_pending = NUM_TX_BDS_MAX;
684 ering->tx_pending = edev->q_num_tx_buffers;
685}
686
687static int qede_set_ringparam(struct net_device *dev,
688 struct ethtool_ringparam *ering)
689{
690 struct qede_dev *edev = netdev_priv(dev);
691
692 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
693 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
694 ering->rx_pending, ering->tx_pending);
695
696 /* Validate legality of configuration */
697 if (ering->rx_pending > NUM_RX_BDS_MAX ||
698 ering->rx_pending < NUM_RX_BDS_MIN ||
699 ering->tx_pending > NUM_TX_BDS_MAX ||
700 ering->tx_pending < NUM_TX_BDS_MIN) {
701 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
702 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
703 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
704 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
705 return -EINVAL;
706 }
707
708 /* Change ring size and re-load */
709 edev->q_num_rx_buffers = ering->rx_pending;
710 edev->q_num_tx_buffers = ering->tx_pending;
711
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200712 qede_reload(edev, NULL, false);
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200713
714 return 0;
715}
716
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200717static void qede_get_pauseparam(struct net_device *dev,
718 struct ethtool_pauseparam *epause)
719{
720 struct qede_dev *edev = netdev_priv(dev);
721 struct qed_link_output current_link;
722
723 memset(&current_link, 0, sizeof(current_link));
724 edev->ops->common->get_link(edev->cdev, &current_link);
725
726 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
727 epause->autoneg = true;
728 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
729 epause->rx_pause = true;
730 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
731 epause->tx_pause = true;
732
733 DP_VERBOSE(edev, QED_MSG_DEBUG,
734 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
735 epause->cmd, epause->autoneg, epause->rx_pause,
736 epause->tx_pause);
737}
738
739static int qede_set_pauseparam(struct net_device *dev,
740 struct ethtool_pauseparam *epause)
741{
742 struct qede_dev *edev = netdev_priv(dev);
743 struct qed_link_params params;
744 struct qed_link_output current_link;
745
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300746 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200747 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300748 "Pause settings are not allowed to be changed\n");
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200749 return -EOPNOTSUPP;
750 }
751
752 memset(&current_link, 0, sizeof(current_link));
753 edev->ops->common->get_link(edev->cdev, &current_link);
754
755 memset(&params, 0, sizeof(params));
756 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
757 if (epause->autoneg) {
Yuval Mintzd194fd22016-08-19 08:34:57 +0300758 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200759 DP_INFO(edev, "autoneg not supported\n");
760 return -EINVAL;
761 }
762 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
763 }
764 if (epause->rx_pause)
765 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
766 if (epause->tx_pause)
767 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
768
769 params.link_up = true;
770 edev->ops->common->set_link(edev->cdev, &params);
771
772 return 0;
773}
774
Tomer Tayare0971c82016-09-07 16:36:25 +0300775static void qede_get_regs(struct net_device *ndev,
776 struct ethtool_regs *regs, void *buffer)
777{
778 struct qede_dev *edev = netdev_priv(ndev);
779
780 regs->version = 0;
781 memset(buffer, 0, regs->len);
782
783 if (edev->ops && edev->ops->common)
784 edev->ops->common->dbg_all_data(edev->cdev, buffer);
785}
786
787static int qede_get_regs_len(struct net_device *ndev)
788{
789 struct qede_dev *edev = netdev_priv(ndev);
790
791 if (edev->ops && edev->ops->common)
792 return edev->ops->common->dbg_all_data_size(edev->cdev);
793 else
794 return -EINVAL;
795}
796
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200797static void qede_update_mtu(struct qede_dev *edev,
798 struct qede_reload_args *args)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200799{
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200800 edev->ndev->mtu = args->u.mtu;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200801}
802
803/* Netdevice NDOs */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200804int qede_change_mtu(struct net_device *ndev, int new_mtu)
805{
806 struct qede_dev *edev = netdev_priv(ndev);
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200807 struct qede_reload_args args;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200808
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200809 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
810 "Configuring MTU size of %d\n", new_mtu);
811
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200812 /* Set the mtu field and re-start the interface if needed */
813 args.u.mtu = new_mtu;
814 args.func = &qede_update_mtu;
815 qede_reload(edev, &args, false);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200816
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200817 edev->ops->common->update_mtu(edev->cdev, new_mtu);
Sudarsana Kalluru0fefbfb2016-10-31 07:14:21 +0200818
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200819 return 0;
820}
821
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200822static void qede_get_channels(struct net_device *dev,
823 struct ethtool_channels *channels)
824{
825 struct qede_dev *edev = netdev_priv(dev);
826
827 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kallurubdc8cbd2016-10-21 04:43:39 -0400828 channels->max_rx = QEDE_MAX_RSS_CNT(edev);
829 channels->max_tx = QEDE_MAX_RSS_CNT(edev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400830 channels->combined_count = QEDE_QUEUE_CNT(edev) - edev->fp_num_tx -
831 edev->fp_num_rx;
832 channels->tx_count = edev->fp_num_tx;
833 channels->rx_count = edev->fp_num_rx;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200834}
835
836static int qede_set_channels(struct net_device *dev,
837 struct ethtool_channels *channels)
838{
839 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400840 u32 count;
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200841
842 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
843 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
844 channels->rx_count, channels->tx_count,
845 channels->other_count, channels->combined_count);
846
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400847 count = channels->rx_count + channels->tx_count +
848 channels->combined_count;
849
850 /* We don't support `other' channels */
851 if (channels->other_count) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200852 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
853 "command parameters not supported\n");
854 return -EINVAL;
855 }
856
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400857 if (!(channels->combined_count || (channels->rx_count &&
858 channels->tx_count))) {
859 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
860 "need to request at least one transmit and one receive channel\n");
861 return -EINVAL;
862 }
863
864 if (count > QEDE_MAX_RSS_CNT(edev)) {
865 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
866 "requested channels = %d max supported channels = %d\n",
867 count, QEDE_MAX_RSS_CNT(edev));
868 return -EINVAL;
869 }
870
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200871 /* Check if there was a change in the active parameters */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400872 if ((count == QEDE_QUEUE_CNT(edev)) &&
873 (channels->tx_count == edev->fp_num_tx) &&
874 (channels->rx_count == edev->fp_num_rx)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200875 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
876 "No change in active parameters\n");
877 return 0;
878 }
879
880 /* We need the number of queues to be divisible between the hwfns */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400881 if ((count % edev->dev_info.common.num_hwfns) ||
882 (channels->tx_count % edev->dev_info.common.num_hwfns) ||
883 (channels->rx_count % edev->dev_info.common.num_hwfns)) {
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200884 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400885 "Number of channels must be divisible by %04x\n",
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200886 edev->dev_info.common.num_hwfns);
887 return -EINVAL;
888 }
889
890 /* Set number of queues and reload if necessary */
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400891 edev->req_queues = count;
892 edev->req_num_tx = channels->tx_count;
893 edev->req_num_rx = channels->rx_count;
Sudarsana Reddy Kallurued0dd912016-10-21 04:43:43 -0400894 /* Reset the indirection table if rx queue count is updated */
895 if ((edev->req_queues - edev->req_num_tx) != QEDE_RSS_COUNT(edev)) {
896 edev->rss_params_inited &= ~QEDE_RSS_INDIR_INITED;
897 memset(&edev->rss_params.rss_ind_table, 0,
898 sizeof(edev->rss_params.rss_ind_table));
899 }
900
Mintz, Yuval567b3c12016-11-29 16:47:05 +0200901 qede_reload(edev, NULL, false);
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200902
903 return 0;
904}
905
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200906static int qede_set_phys_id(struct net_device *dev,
907 enum ethtool_phys_id_state state)
908{
909 struct qede_dev *edev = netdev_priv(dev);
910 u8 led_state = 0;
911
912 switch (state) {
913 case ETHTOOL_ID_ACTIVE:
914 return 1; /* cycle on/off once per second */
915
916 case ETHTOOL_ID_ON:
917 led_state = QED_LED_MODE_ON;
918 break;
919
920 case ETHTOOL_ID_OFF:
921 led_state = QED_LED_MODE_OFF;
922 break;
923
924 case ETHTOOL_ID_INACTIVE:
925 led_state = QED_LED_MODE_RESTORE;
926 break;
927 }
928
929 edev->ops->common->set_led(edev->cdev, led_state);
930
931 return 0;
932}
933
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300934static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
935{
936 info->data = RXH_IP_SRC | RXH_IP_DST;
937
938 switch (info->flow_type) {
939 case TCP_V4_FLOW:
940 case TCP_V6_FLOW:
941 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
942 break;
943 case UDP_V4_FLOW:
944 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
945 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
946 break;
947 case UDP_V6_FLOW:
948 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
949 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
950 break;
951 case IPV4_FLOW:
952 case IPV6_FLOW:
953 break;
954 default:
955 info->data = 0;
956 break;
957 }
958
959 return 0;
960}
961
962static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
963 u32 *rules __always_unused)
964{
965 struct qede_dev *edev = netdev_priv(dev);
966
967 switch (info->cmd) {
968 case ETHTOOL_GRXRINGS:
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -0400969 info->data = QEDE_RSS_COUNT(edev);
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300970 return 0;
971 case ETHTOOL_GRXFH:
972 return qede_get_rss_flags(edev, info);
973 default:
974 DP_ERR(edev, "Command parameters not supported\n");
975 return -EOPNOTSUPP;
976 }
977}
978
979static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
980{
981 struct qed_update_vport_params vport_update_params;
982 u8 set_caps = 0, clr_caps = 0;
983
984 DP_VERBOSE(edev, QED_MSG_DEBUG,
985 "Set rss flags command parameters: flow type = %d, data = %llu\n",
986 info->flow_type, info->data);
987
988 switch (info->flow_type) {
989 case TCP_V4_FLOW:
990 case TCP_V6_FLOW:
991 /* For TCP only 4-tuple hash is supported */
992 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
993 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
994 DP_INFO(edev, "Command parameters not supported\n");
995 return -EINVAL;
996 }
997 return 0;
998 case UDP_V4_FLOW:
999 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1000 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1001 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1002 set_caps = QED_RSS_IPV4_UDP;
1003 DP_VERBOSE(edev, QED_MSG_DEBUG,
1004 "UDP 4-tuple enabled\n");
1005 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1006 clr_caps = QED_RSS_IPV4_UDP;
1007 DP_VERBOSE(edev, QED_MSG_DEBUG,
1008 "UDP 4-tuple disabled\n");
1009 } else {
1010 return -EINVAL;
1011 }
1012 break;
1013 case UDP_V6_FLOW:
1014 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
1015 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
1016 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1017 set_caps = QED_RSS_IPV6_UDP;
1018 DP_VERBOSE(edev, QED_MSG_DEBUG,
1019 "UDP 4-tuple enabled\n");
1020 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
1021 clr_caps = QED_RSS_IPV6_UDP;
1022 DP_VERBOSE(edev, QED_MSG_DEBUG,
1023 "UDP 4-tuple disabled\n");
1024 } else {
1025 return -EINVAL;
1026 }
1027 break;
1028 case IPV4_FLOW:
1029 case IPV6_FLOW:
1030 /* For IP only 2-tuple hash is supported */
1031 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
1032 DP_INFO(edev, "Command parameters not supported\n");
1033 return -EINVAL;
1034 }
1035 return 0;
1036 case SCTP_V4_FLOW:
1037 case AH_ESP_V4_FLOW:
1038 case AH_V4_FLOW:
1039 case ESP_V4_FLOW:
1040 case SCTP_V6_FLOW:
1041 case AH_ESP_V6_FLOW:
1042 case AH_V6_FLOW:
1043 case ESP_V6_FLOW:
1044 case IP_USER_FLOW:
1045 case ETHER_FLOW:
1046 /* RSS is not supported for these protocols */
1047 if (info->data) {
1048 DP_INFO(edev, "Command parameters not supported\n");
1049 return -EINVAL;
1050 }
1051 return 0;
1052 default:
1053 return -EINVAL;
1054 }
1055
1056 /* No action is needed if there is no change in the rss capability */
1057 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
1058 ~clr_caps) | set_caps))
1059 return 0;
1060
1061 /* Update internal configuration */
1062 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
1063 set_caps;
1064 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
1065
1066 /* Re-configure if possible */
1067 if (netif_running(edev->ndev)) {
1068 memset(&vport_update_params, 0, sizeof(vport_update_params));
1069 vport_update_params.update_rss_flg = 1;
1070 vport_update_params.vport_id = 0;
1071 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1072 sizeof(vport_update_params.rss_params));
1073 return edev->ops->vport_update(edev->cdev,
1074 &vport_update_params);
1075 }
1076
1077 return 0;
1078}
1079
1080static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
1081{
1082 struct qede_dev *edev = netdev_priv(dev);
1083
1084 switch (info->cmd) {
1085 case ETHTOOL_SRXFH:
1086 return qede_set_rss_flags(edev, info);
1087 default:
1088 DP_INFO(edev, "Command parameters not supported\n");
1089 return -EOPNOTSUPP;
1090 }
1091}
1092
1093static u32 qede_get_rxfh_indir_size(struct net_device *dev)
1094{
1095 return QED_RSS_IND_TABLE_SIZE;
1096}
1097
1098static u32 qede_get_rxfh_key_size(struct net_device *dev)
1099{
1100 struct qede_dev *edev = netdev_priv(dev);
1101
1102 return sizeof(edev->rss_params.rss_key);
1103}
1104
1105static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
1106{
1107 struct qede_dev *edev = netdev_priv(dev);
1108 int i;
1109
1110 if (hfunc)
1111 *hfunc = ETH_RSS_HASH_TOP;
1112
1113 if (!indir)
1114 return 0;
1115
1116 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1117 indir[i] = edev->rss_params.rss_ind_table[i];
1118
1119 if (key)
1120 memcpy(key, edev->rss_params.rss_key,
1121 qede_get_rxfh_key_size(dev));
1122
1123 return 0;
1124}
1125
1126static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
1127 const u8 *key, const u8 hfunc)
1128{
1129 struct qed_update_vport_params vport_update_params;
1130 struct qede_dev *edev = netdev_priv(dev);
1131 int i;
1132
Sudarsana Reddy Kalluruba300ce2016-10-21 04:43:40 -04001133 if (edev->dev_info.common.num_hwfns > 1) {
1134 DP_INFO(edev,
1135 "RSS configuration is not supported for 100G devices\n");
1136 return -EOPNOTSUPP;
1137 }
1138
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001139 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1140 return -EOPNOTSUPP;
1141
1142 if (!indir && !key)
1143 return 0;
1144
1145 if (indir) {
1146 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1147 edev->rss_params.rss_ind_table[i] = indir[i];
1148 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1149 }
1150
1151 if (key) {
1152 memcpy(&edev->rss_params.rss_key, key,
1153 qede_get_rxfh_key_size(dev));
1154 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1155 }
1156
1157 if (netif_running(edev->ndev)) {
1158 memset(&vport_update_params, 0, sizeof(vport_update_params));
1159 vport_update_params.update_rss_flg = 1;
1160 vport_update_params.vport_id = 0;
1161 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1162 sizeof(vport_update_params.rss_params));
1163 return edev->ops->vport_update(edev->cdev,
1164 &vport_update_params);
1165 }
1166
1167 return 0;
1168}
1169
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001170/* This function enables the interrupt generation and the NAPI on the device */
1171static void qede_netif_start(struct qede_dev *edev)
1172{
1173 int i;
1174
1175 if (!netif_running(edev->ndev))
1176 return;
1177
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001178 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001179 /* Update and reenable interrupts */
1180 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1181 napi_enable(&edev->fp_array[i].napi);
1182 }
1183}
1184
1185/* This function disables the NAPI and the interrupt generation on the device */
1186static void qede_netif_stop(struct qede_dev *edev)
1187{
1188 int i;
1189
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001190 for_each_queue(i) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001191 napi_disable(&edev->fp_array[i].napi);
1192 /* Disable interrupts */
1193 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1194 }
1195}
1196
1197static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1198 struct sk_buff *skb)
1199{
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001200 struct qede_tx_queue *txq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001201 struct eth_tx_1st_bd *first_bd;
1202 dma_addr_t mapping;
1203 int i, idx, val;
1204
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001205 for_each_queue(i) {
1206 if (edev->fp_array[i].type & QEDE_FASTPATH_TX) {
Mintz, Yuval80439a12016-11-29 16:47:02 +02001207 txq = edev->fp_array[i].txq;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001208 break;
1209 }
1210 }
1211
1212 if (!txq) {
1213 DP_NOTICE(edev, "Tx path is not available\n");
1214 return -1;
1215 }
1216
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001217 /* Fill the entry in the SW ring and the BDs in the FW ring */
1218 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
1219 txq->sw_tx_ring[idx].skb = skb;
1220 first_bd = qed_chain_produce(&txq->tx_pbl);
1221 memset(first_bd, 0, sizeof(*first_bd));
1222 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1223 first_bd->data.bd_flags.bitfields = val;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001224 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1225 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001226
1227 /* Map skb linear data for DMA and set in the first BD */
1228 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1229 skb_headlen(skb), DMA_TO_DEVICE);
1230 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1231 DP_NOTICE(edev, "SKB mapping failed\n");
1232 return -ENOMEM;
1233 }
1234 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1235
1236 /* update the first BD with the actual num BDs */
1237 first_bd->data.nbds = 1;
1238 txq->sw_tx_prod++;
1239 /* 'next page' entries are counted in the producer value */
1240 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
1241 txq->tx_db.data.bd_prod = val;
1242
1243 /* wmb makes sure that the BDs data is updated before updating the
1244 * producer, otherwise FW may read old data from the BDs.
1245 */
1246 wmb();
1247 barrier();
1248 writel(txq->tx_db.raw, txq->doorbell_addr);
1249
1250 /* mmiowb is needed to synchronize doorbell writes from more than one
1251 * processor. It guarantees that the write arrives to the device before
1252 * the queue lock is released and another start_xmit is called (possibly
1253 * on another CPU). Without this barrier, the next doorbell can bypass
1254 * this doorbell. This is applicable to IA64/Altix systems.
1255 */
1256 mmiowb();
1257
1258 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1259 if (qede_txq_has_work(txq))
1260 break;
1261 usleep_range(100, 200);
1262 }
1263
1264 if (!qede_txq_has_work(txq)) {
1265 DP_NOTICE(edev, "Tx completion didn't happen\n");
1266 return -1;
1267 }
1268
1269 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
Manish Choprafabd5452016-10-21 04:43:45 -04001270 dma_unmap_single(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1271 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001272 txq->sw_tx_cons++;
1273 txq->sw_tx_ring[idx].skb = NULL;
1274
1275 return 0;
1276}
1277
1278static int qede_selftest_receive_traffic(struct qede_dev *edev)
1279{
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001280 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1281 struct eth_fast_path_rx_reg_cqe *fp_cqe;
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001282 struct qede_rx_queue *rxq = NULL;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001283 struct sw_rx_data *sw_rx_data;
1284 union eth_rx_cqe *cqe;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001285 int i, rc = 0;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001286 u8 *data_ptr;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001287
Sudarsana Reddy Kalluru9a4d7e82016-08-23 10:56:55 -04001288 for_each_queue(i) {
1289 if (edev->fp_array[i].type & QEDE_FASTPATH_RX) {
1290 rxq = edev->fp_array[i].rxq;
1291 break;
1292 }
1293 }
1294
1295 if (!rxq) {
1296 DP_NOTICE(edev, "Rx path is not available\n");
1297 return -1;
1298 }
1299
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001300 /* The packet is expected to receive on rx-queue 0 even though RSS is
1301 * enabled. This is because the queue 0 is configured as the default
1302 * queue and that the loopback traffic is not IP.
1303 */
1304 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001305 if (!qede_has_rx_work(rxq)) {
1306 usleep_range(100, 200);
1307 continue;
1308 }
1309
1310 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1311 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1312
1313 /* Memory barrier to prevent the CPU from doing speculative
1314 * reads of CQE/BD before reading hw_comp_cons. If the CQE is
1315 * read before it is written by FW, then FW writes CQE and SB,
1316 * and then the CPU reads the hw_comp_cons, it will use an old
1317 * CQE.
1318 */
1319 rmb();
1320
1321 /* Get the CQE from the completion ring */
1322 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1323
1324 /* Get the data from the SW ring */
1325 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1326 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1327 fp_cqe = &cqe->fast_path_regular;
1328 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1329 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1330 fp_cqe->placement_offset +
1331 sw_rx_data->page_offset);
1332 if (ether_addr_equal(data_ptr, edev->ndev->dev_addr) &&
1333 ether_addr_equal(data_ptr + ETH_ALEN,
1334 edev->ndev->dev_addr)) {
1335 for (i = ETH_HLEN; i < len; i++)
1336 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1337 rc = -1;
1338 break;
1339 }
1340
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001341 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001342 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001343 break;
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001344 }
1345
1346 DP_INFO(edev, "Not the transmitted packet\n");
Mintz, Yuval9eb22352016-11-29 16:47:08 +02001347 qede_recycle_rx_bd_ring(rxq, 1);
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001348 qed_chain_recycle_consumed(&rxq->rx_comp_ring);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001349 }
1350
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001351 if (i == QEDE_SELFTEST_POLL_COUNT) {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001352 DP_NOTICE(edev, "Failed to receive the traffic\n");
1353 return -1;
1354 }
1355
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001356 qede_update_rx_prod(edev, rxq);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001357
Sudarsana Reddy Kalluru837d4eb2016-10-21 04:43:41 -04001358 return rc;
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001359}
1360
1361static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1362{
1363 struct qed_link_params link_params;
1364 struct sk_buff *skb = NULL;
1365 int rc = 0, i;
1366 u32 pkt_size;
1367 u8 *packet;
1368
1369 if (!netif_running(edev->ndev)) {
1370 DP_NOTICE(edev, "Interface is down\n");
1371 return -EINVAL;
1372 }
1373
1374 qede_netif_stop(edev);
1375
1376 /* Bring up the link in Loopback mode */
1377 memset(&link_params, 0, sizeof(link_params));
1378 link_params.link_up = true;
1379 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1380 link_params.loopback_mode = loopback_mode;
1381 edev->ops->common->set_link(edev->cdev, &link_params);
1382
1383 /* Wait for loopback configuration to apply */
1384 msleep_interruptible(500);
1385
1386 /* prepare the loopback packet */
1387 pkt_size = edev->ndev->mtu + ETH_HLEN;
1388
1389 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1390 if (!skb) {
1391 DP_INFO(edev, "Can't allocate skb\n");
1392 rc = -ENOMEM;
1393 goto test_loopback_exit;
1394 }
1395 packet = skb_put(skb, pkt_size);
1396 ether_addr_copy(packet, edev->ndev->dev_addr);
1397 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1398 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1399 for (i = ETH_HLEN; i < pkt_size; i++)
1400 packet[i] = (unsigned char)(i & 0xff);
1401
1402 rc = qede_selftest_transmit_traffic(edev, skb);
1403 if (rc)
1404 goto test_loopback_exit;
1405
1406 rc = qede_selftest_receive_traffic(edev);
1407 if (rc)
1408 goto test_loopback_exit;
1409
1410 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1411
1412test_loopback_exit:
1413 dev_kfree_skb(skb);
1414
1415 /* Bring up the link in Normal mode */
1416 memset(&link_params, 0, sizeof(link_params));
1417 link_params.link_up = true;
1418 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1419 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1420 edev->ops->common->set_link(edev->cdev, &link_params);
1421
1422 /* Wait for loopback configuration to apply */
1423 msleep_interruptible(500);
1424
1425 qede_netif_start(edev);
1426
1427 return rc;
1428}
1429
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001430static void qede_self_test(struct net_device *dev,
1431 struct ethtool_test *etest, u64 *buf)
1432{
1433 struct qede_dev *edev = netdev_priv(dev);
1434
1435 DP_VERBOSE(edev, QED_MSG_DEBUG,
1436 "Self-test command parameters: offline = %d, external_lb = %d\n",
1437 (etest->flags & ETH_TEST_FL_OFFLINE),
1438 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1439
1440 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1441
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001442 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1443 if (qede_selftest_run_loopback(edev,
1444 QED_LINK_LOOPBACK_INT_PHY)) {
1445 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1446 etest->flags |= ETH_TEST_FL_FAILED;
1447 }
1448 }
1449
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001450 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1451 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1452 etest->flags |= ETH_TEST_FL_FAILED;
1453 }
1454
1455 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1456 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1457 etest->flags |= ETH_TEST_FL_FAILED;
1458 }
1459
1460 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1461 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1462 etest->flags |= ETH_TEST_FL_FAILED;
1463 }
1464
1465 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1466 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1467 etest->flags |= ETH_TEST_FL_FAILED;
1468 }
Mintz, Yuval7a4b21b2016-10-31 07:14:22 +02001469
1470 if (edev->ops->common->selftest->selftest_nvram(edev->cdev)) {
1471 buf[QEDE_ETHTOOL_NVRAM_TEST] = 1;
1472 etest->flags |= ETH_TEST_FL_FAILED;
1473 }
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001474}
1475
Manish Chopra3d789992016-06-30 02:35:21 -04001476static int qede_set_tunable(struct net_device *dev,
1477 const struct ethtool_tunable *tuna,
1478 const void *data)
1479{
1480 struct qede_dev *edev = netdev_priv(dev);
1481 u32 val;
1482
1483 switch (tuna->id) {
1484 case ETHTOOL_RX_COPYBREAK:
1485 val = *(u32 *)data;
1486 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1487 DP_VERBOSE(edev, QED_MSG_DEBUG,
1488 "Invalid rx copy break value, range is [%u, %u]",
1489 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1490 return -EINVAL;
1491 }
1492
1493 edev->rx_copybreak = *(u32 *)data;
1494 break;
1495 default:
1496 return -EOPNOTSUPP;
1497 }
1498
1499 return 0;
1500}
1501
1502static int qede_get_tunable(struct net_device *dev,
1503 const struct ethtool_tunable *tuna, void *data)
1504{
1505 struct qede_dev *edev = netdev_priv(dev);
1506
1507 switch (tuna->id) {
1508 case ETHTOOL_RX_COPYBREAK:
1509 *(u32 *)data = edev->rx_copybreak;
1510 break;
1511 default:
1512 return -EOPNOTSUPP;
1513 }
1514
1515 return 0;
1516}
1517
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001518static const struct ethtool_ops qede_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001519 .get_link_ksettings = qede_get_link_ksettings,
1520 .set_link_ksettings = qede_set_link_ksettings,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001521 .get_drvinfo = qede_get_drvinfo,
Tomer Tayare0971c82016-09-07 16:36:25 +03001522 .get_regs_len = qede_get_regs_len,
1523 .get_regs = qede_get_regs,
Mintz, Yuval14d39642016-10-31 07:14:23 +02001524 .get_wol = qede_get_wol,
1525 .set_wol = qede_set_wol,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001526 .get_msglevel = qede_get_msglevel,
1527 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +02001528 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001529 .get_link = qede_get_link,
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -04001530 .get_coalesce = qede_get_coalesce,
1531 .set_coalesce = qede_set_coalesce,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +02001532 .get_ringparam = qede_get_ringparam,
1533 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +02001534 .get_pauseparam = qede_get_pauseparam,
1535 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001536 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +02001537 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001538 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +03001539 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001540 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001541 .get_rxnfc = qede_get_rxnfc,
1542 .set_rxnfc = qede_set_rxnfc,
1543 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1544 .get_rxfh_key_size = qede_get_rxfh_key_size,
1545 .get_rxfh = qede_get_rxfh,
1546 .set_rxfh = qede_set_rxfh,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001547 .get_channels = qede_get_channels,
1548 .set_channels = qede_set_channels,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001549 .self_test = qede_self_test,
Manish Chopra3d789992016-06-30 02:35:21 -04001550 .get_tunable = qede_get_tunable,
1551 .set_tunable = qede_set_tunable,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001552};
1553
Yuval Mintzfefb0202016-05-11 16:36:19 +03001554static const struct ethtool_ops qede_vf_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001555 .get_link_ksettings = qede_get_link_ksettings,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001556 .get_drvinfo = qede_get_drvinfo,
1557 .get_msglevel = qede_get_msglevel,
1558 .set_msglevel = qede_set_msglevel,
1559 .get_link = qede_get_link,
1560 .get_ringparam = qede_get_ringparam,
1561 .set_ringparam = qede_set_ringparam,
1562 .get_strings = qede_get_strings,
1563 .get_ethtool_stats = qede_get_ethtool_stats,
1564 .get_priv_flags = qede_get_priv_flags,
1565 .get_sset_count = qede_get_sset_count,
1566 .get_rxnfc = qede_get_rxnfc,
1567 .set_rxnfc = qede_set_rxnfc,
1568 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1569 .get_rxfh_key_size = qede_get_rxfh_key_size,
1570 .get_rxfh = qede_get_rxfh,
1571 .set_rxfh = qede_set_rxfh,
1572 .get_channels = qede_get_channels,
1573 .set_channels = qede_set_channels,
Manish Chopra3d789992016-06-30 02:35:21 -04001574 .get_tunable = qede_get_tunable,
1575 .set_tunable = qede_set_tunable,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001576};
1577
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001578void qede_set_ethtool_ops(struct net_device *dev)
1579{
Yuval Mintzfefb0202016-05-11 16:36:19 +03001580 struct qede_dev *edev = netdev_priv(dev);
1581
1582 if (IS_VF(edev))
1583 dev->ethtool_ops = &qede_vf_ethtool_ops;
1584 else
1585 dev->ethtool_ops = &qede_ethtool_ops;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001586}