blob: f6b8899cda7f7162186bf99874f9e0cda9ae3046 [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
19#define QEDE_STAT_OFFSET(stat_name) (offsetof(struct qede_stats, stat_name))
20#define QEDE_STAT_STRING(stat_name) (#stat_name)
21#define _QEDE_STAT(stat_name, pf_only) \
22 {QEDE_STAT_OFFSET(stat_name), QEDE_STAT_STRING(stat_name), pf_only}
23#define QEDE_PF_STAT(stat_name) _QEDE_STAT(stat_name, true)
24#define QEDE_STAT(stat_name) _QEDE_STAT(stat_name, false)
25
26#define QEDE_RQSTAT_OFFSET(stat_name) \
27 (offsetof(struct qede_rx_queue, stat_name))
28#define QEDE_RQSTAT_STRING(stat_name) (#stat_name)
29#define QEDE_RQSTAT(stat_name) \
30 {QEDE_RQSTAT_OFFSET(stat_name), QEDE_RQSTAT_STRING(stat_name)}
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -040031
32#define QEDE_SELFTEST_POLL_COUNT 100
33
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020034static const struct {
35 u64 offset;
36 char string[ETH_GSTRING_LEN];
37} qede_rqstats_arr[] = {
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040038 QEDE_RQSTAT(rcv_pkts),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020039 QEDE_RQSTAT(rx_hw_errors),
40 QEDE_RQSTAT(rx_alloc_errors),
Manish Choprac72a6122016-06-30 02:35:18 -040041 QEDE_RQSTAT(rx_ip_frags),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020042};
43
44#define QEDE_NUM_RQSTATS ARRAY_SIZE(qede_rqstats_arr)
45#define QEDE_RQSTATS_DATA(dev, sindex, rqindex) \
46 (*((u64 *)(((char *)(dev->fp_array[(rqindex)].rxq)) +\
47 qede_rqstats_arr[(sindex)].offset)))
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -040048#define QEDE_TQSTAT_OFFSET(stat_name) \
49 (offsetof(struct qede_tx_queue, stat_name))
50#define QEDE_TQSTAT_STRING(stat_name) (#stat_name)
51#define QEDE_TQSTAT(stat_name) \
52 {QEDE_TQSTAT_OFFSET(stat_name), QEDE_TQSTAT_STRING(stat_name)}
53#define QEDE_NUM_TQSTATS ARRAY_SIZE(qede_tqstats_arr)
54static const struct {
55 u64 offset;
56 char string[ETH_GSTRING_LEN];
57} qede_tqstats_arr[] = {
58 QEDE_TQSTAT(xmit_pkts),
59 QEDE_TQSTAT(stopped_cnt),
60};
61
62#define QEDE_TQSTATS_DATA(dev, sindex, tssid, tcid) \
63 (*((u64 *)(((u64)(&dev->fp_array[tssid].txqs[tcid])) +\
64 qede_tqstats_arr[(sindex)].offset)))
65
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020066static const struct {
67 u64 offset;
68 char string[ETH_GSTRING_LEN];
69 bool pf_only;
70} qede_stats_arr[] = {
71 QEDE_STAT(rx_ucast_bytes),
72 QEDE_STAT(rx_mcast_bytes),
73 QEDE_STAT(rx_bcast_bytes),
74 QEDE_STAT(rx_ucast_pkts),
75 QEDE_STAT(rx_mcast_pkts),
76 QEDE_STAT(rx_bcast_pkts),
77
78 QEDE_STAT(tx_ucast_bytes),
79 QEDE_STAT(tx_mcast_bytes),
80 QEDE_STAT(tx_bcast_bytes),
81 QEDE_STAT(tx_ucast_pkts),
82 QEDE_STAT(tx_mcast_pkts),
83 QEDE_STAT(tx_bcast_pkts),
84
85 QEDE_PF_STAT(rx_64_byte_packets),
Yuval Mintzd4967cf2016-04-22 08:41:01 +030086 QEDE_PF_STAT(rx_65_to_127_byte_packets),
87 QEDE_PF_STAT(rx_128_to_255_byte_packets),
88 QEDE_PF_STAT(rx_256_to_511_byte_packets),
89 QEDE_PF_STAT(rx_512_to_1023_byte_packets),
90 QEDE_PF_STAT(rx_1024_to_1518_byte_packets),
91 QEDE_PF_STAT(rx_1519_to_1522_byte_packets),
92 QEDE_PF_STAT(rx_1519_to_2047_byte_packets),
93 QEDE_PF_STAT(rx_2048_to_4095_byte_packets),
94 QEDE_PF_STAT(rx_4096_to_9216_byte_packets),
95 QEDE_PF_STAT(rx_9217_to_16383_byte_packets),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +020096 QEDE_PF_STAT(tx_64_byte_packets),
97 QEDE_PF_STAT(tx_65_to_127_byte_packets),
98 QEDE_PF_STAT(tx_128_to_255_byte_packets),
99 QEDE_PF_STAT(tx_256_to_511_byte_packets),
100 QEDE_PF_STAT(tx_512_to_1023_byte_packets),
101 QEDE_PF_STAT(tx_1024_to_1518_byte_packets),
102 QEDE_PF_STAT(tx_1519_to_2047_byte_packets),
103 QEDE_PF_STAT(tx_2048_to_4095_byte_packets),
104 QEDE_PF_STAT(tx_4096_to_9216_byte_packets),
105 QEDE_PF_STAT(tx_9217_to_16383_byte_packets),
106
107 QEDE_PF_STAT(rx_mac_crtl_frames),
108 QEDE_PF_STAT(tx_mac_ctrl_frames),
109 QEDE_PF_STAT(rx_pause_frames),
110 QEDE_PF_STAT(tx_pause_frames),
111 QEDE_PF_STAT(rx_pfc_frames),
112 QEDE_PF_STAT(tx_pfc_frames),
113
114 QEDE_PF_STAT(rx_crc_errors),
115 QEDE_PF_STAT(rx_align_errors),
116 QEDE_PF_STAT(rx_carrier_errors),
117 QEDE_PF_STAT(rx_oversize_packets),
118 QEDE_PF_STAT(rx_jabbers),
119 QEDE_PF_STAT(rx_undersize_packets),
120 QEDE_PF_STAT(rx_fragments),
121 QEDE_PF_STAT(tx_lpi_entry_count),
122 QEDE_PF_STAT(tx_total_collisions),
123 QEDE_PF_STAT(brb_truncates),
124 QEDE_PF_STAT(brb_discards),
125 QEDE_STAT(no_buff_discards),
126 QEDE_PF_STAT(mftag_filter_discards),
127 QEDE_PF_STAT(mac_filter_discards),
128 QEDE_STAT(tx_err_drop_pkts),
Sudarsana Reddy Kalluru1a5a3662016-08-16 10:51:01 -0400129 QEDE_STAT(ttl0_discard),
130 QEDE_STAT(packet_too_big_discard),
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200131
132 QEDE_STAT(coalesced_pkts),
133 QEDE_STAT(coalesced_events),
134 QEDE_STAT(coalesced_aborts_num),
135 QEDE_STAT(non_coalesced_pkts),
136 QEDE_STAT(coalesced_bytes),
137};
138
139#define QEDE_STATS_DATA(dev, index) \
140 (*((u64 *)(((char *)(dev)) + offsetof(struct qede_dev, stats) \
141 + qede_stats_arr[(index)].offset)))
142
143#define QEDE_NUM_STATS ARRAY_SIZE(qede_stats_arr)
144
Yuval Mintzf3e72102016-04-22 08:41:02 +0300145enum {
146 QEDE_PRI_FLAG_CMT,
147 QEDE_PRI_FLAG_LEN,
148};
149
150static const char qede_private_arr[QEDE_PRI_FLAG_LEN][ETH_GSTRING_LEN] = {
151 "Coupled-Function",
152};
153
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400154enum qede_ethtool_tests {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400155 QEDE_ETHTOOL_INT_LOOPBACK,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400156 QEDE_ETHTOOL_INTERRUPT_TEST,
157 QEDE_ETHTOOL_MEMORY_TEST,
158 QEDE_ETHTOOL_REGISTER_TEST,
159 QEDE_ETHTOOL_CLOCK_TEST,
160 QEDE_ETHTOOL_TEST_MAX
161};
162
163static const char qede_tests_str_arr[QEDE_ETHTOOL_TEST_MAX][ETH_GSTRING_LEN] = {
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -0400164 "Internal loopback (offline)",
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400165 "Interrupt (online)\t",
166 "Memory (online)\t\t",
167 "Register (online)\t",
168 "Clock (online)\t\t",
169};
170
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200171static void qede_get_strings_stats(struct qede_dev *edev, u8 *buf)
172{
173 int i, j, k;
174
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400175 for (i = 0, k = 0; i < edev->num_rss; i++) {
176 int tc;
177
178 for (j = 0; j < QEDE_NUM_RQSTATS; j++)
179 sprintf(buf + (k + j) * ETH_GSTRING_LEN,
180 "%d: %s", i, qede_rqstats_arr[j].string);
181 k += QEDE_NUM_RQSTATS;
182 for (tc = 0; tc < edev->num_tc; tc++) {
183 for (j = 0; j < QEDE_NUM_TQSTATS; j++)
184 sprintf(buf + (k + j) * ETH_GSTRING_LEN,
185 "%d.%d: %s", i, tc,
186 qede_tqstats_arr[j].string);
187 k += QEDE_NUM_TQSTATS;
188 }
189 }
190
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200191 for (i = 0, j = 0; i < QEDE_NUM_STATS; i++) {
Yuval Mintzfefb0202016-05-11 16:36:19 +0300192 if (IS_VF(edev) && qede_stats_arr[i].pf_only)
193 continue;
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400194 strcpy(buf + (k + j) * ETH_GSTRING_LEN,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200195 qede_stats_arr[i].string);
196 j++;
197 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200198}
199
200static void qede_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
201{
202 struct qede_dev *edev = netdev_priv(dev);
203
204 switch (stringset) {
205 case ETH_SS_STATS:
206 qede_get_strings_stats(edev, buf);
207 break;
Yuval Mintzf3e72102016-04-22 08:41:02 +0300208 case ETH_SS_PRIV_FLAGS:
209 memcpy(buf, qede_private_arr,
210 ETH_GSTRING_LEN * QEDE_PRI_FLAG_LEN);
211 break;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400212 case ETH_SS_TEST:
213 memcpy(buf, qede_tests_str_arr,
214 ETH_GSTRING_LEN * QEDE_ETHTOOL_TEST_MAX);
215 break;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200216 default:
217 DP_VERBOSE(edev, QED_MSG_DEBUG,
218 "Unsupported stringset 0x%08x\n", stringset);
219 }
220}
221
222static void qede_get_ethtool_stats(struct net_device *dev,
223 struct ethtool_stats *stats, u64 *buf)
224{
225 struct qede_dev *edev = netdev_priv(dev);
226 int sidx, cnt = 0;
227 int qid;
228
229 qede_fill_by_demand_stats(edev);
230
231 mutex_lock(&edev->qede_lock);
232
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400233 for (qid = 0; qid < edev->num_rss; qid++) {
234 int tc;
235
236 for (sidx = 0; sidx < QEDE_NUM_RQSTATS; sidx++)
237 buf[cnt++] = QEDE_RQSTATS_DATA(edev, sidx, qid);
238 for (tc = 0; tc < edev->num_tc; tc++) {
239 for (sidx = 0; sidx < QEDE_NUM_TQSTATS; sidx++)
240 buf[cnt++] = QEDE_TQSTATS_DATA(edev, sidx, qid,
241 tc);
242 }
243 }
244
Yuval Mintzfefb0202016-05-11 16:36:19 +0300245 for (sidx = 0; sidx < QEDE_NUM_STATS; sidx++) {
246 if (IS_VF(edev) && qede_stats_arr[sidx].pf_only)
247 continue;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200248 buf[cnt++] = QEDE_STATS_DATA(edev, sidx);
Yuval Mintzfefb0202016-05-11 16:36:19 +0300249 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200250
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200251 mutex_unlock(&edev->qede_lock);
252}
253
254static int qede_get_sset_count(struct net_device *dev, int stringset)
255{
256 struct qede_dev *edev = netdev_priv(dev);
257 int num_stats = QEDE_NUM_STATS;
258
259 switch (stringset) {
260 case ETH_SS_STATS:
Yuval Mintzfefb0202016-05-11 16:36:19 +0300261 if (IS_VF(edev)) {
262 int i;
263
264 for (i = 0; i < QEDE_NUM_STATS; i++)
265 if (qede_stats_arr[i].pf_only)
266 num_stats--;
267 }
Sudarsana Reddy Kalluru68db9ec2016-08-16 10:51:02 -0400268 return num_stats + edev->num_rss *
269 (QEDE_NUM_RQSTATS + QEDE_NUM_TQSTATS * edev->num_tc);
Yuval Mintzf3e72102016-04-22 08:41:02 +0300270 case ETH_SS_PRIV_FLAGS:
271 return QEDE_PRI_FLAG_LEN;
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -0400272 case ETH_SS_TEST:
Yuval Mintz6ecb0a02016-05-26 11:01:19 +0300273 if (!IS_VF(edev))
274 return QEDE_ETHTOOL_TEST_MAX;
275 else
276 return 0;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200277 default:
278 DP_VERBOSE(edev, QED_MSG_DEBUG,
279 "Unsupported stringset 0x%08x\n", stringset);
280 return -EINVAL;
281 }
282}
283
Yuval Mintzf3e72102016-04-22 08:41:02 +0300284static u32 qede_get_priv_flags(struct net_device *dev)
285{
286 struct qede_dev *edev = netdev_priv(dev);
287
288 return (!!(edev->dev_info.common.num_hwfns > 1)) << QEDE_PRI_FLAG_CMT;
289}
290
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400291struct qede_link_mode_mapping {
292 u32 qed_link_mode;
293 u32 ethtool_link_mode;
294};
295
296static const struct qede_link_mode_mapping qed_lm_map[] = {
297 {QED_LM_FIBRE_BIT, ETHTOOL_LINK_MODE_FIBRE_BIT},
298 {QED_LM_Autoneg_BIT, ETHTOOL_LINK_MODE_Autoneg_BIT},
299 {QED_LM_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT},
300 {QED_LM_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT},
301 {QED_LM_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Half_BIT},
302 {QED_LM_1000baseT_Full_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT},
303 {QED_LM_10000baseKR_Full_BIT, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT},
304 {QED_LM_25000baseKR_Full_BIT, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT},
305 {QED_LM_40000baseLR4_Full_BIT, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT},
306 {QED_LM_50000baseKR2_Full_BIT, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT},
307 {QED_LM_100000baseKR4_Full_BIT,
308 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT},
309};
310
311#define QEDE_DRV_TO_ETHTOOL_CAPS(caps, lk_ksettings, name) \
312{ \
313 int i; \
314 \
315 for (i = 0; i < QED_LM_COUNT; i++) { \
316 if ((caps) & (qed_lm_map[i].qed_link_mode)) \
317 __set_bit(qed_lm_map[i].ethtool_link_mode,\
318 lk_ksettings->link_modes.name); \
319 } \
320}
321
322#define QEDE_ETHTOOL_TO_DRV_CAPS(caps, lk_ksettings, name) \
323{ \
324 int i; \
325 \
326 for (i = 0; i < QED_LM_COUNT; i++) { \
327 if (test_bit(qed_lm_map[i].ethtool_link_mode, \
328 lk_ksettings->link_modes.name)) \
329 caps |= qed_lm_map[i].qed_link_mode; \
330 } \
331}
332
333static int qede_get_link_ksettings(struct net_device *dev,
334 struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200335{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400336 struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200337 struct qede_dev *edev = netdev_priv(dev);
338 struct qed_link_output current_link;
339
340 memset(&current_link, 0, sizeof(current_link));
341 edev->ops->common->get_link(edev->cdev, &current_link);
342
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400343 ethtool_link_ksettings_zero_link_mode(cmd, supported);
344 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.supported_caps, cmd, supported)
345
346 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
347 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.advertised_caps, cmd, advertising)
348
349 ethtool_link_ksettings_zero_link_mode(cmd, lp_advertising);
350 QEDE_DRV_TO_ETHTOOL_CAPS(current_link.lp_caps, cmd, lp_advertising)
351
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200352 if ((edev->state == QEDE_STATE_OPEN) && (current_link.link_up)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400353 base->speed = current_link.speed;
354 base->duplex = current_link.duplex;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200355 } else {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400356 base->speed = SPEED_UNKNOWN;
357 base->duplex = DUPLEX_UNKNOWN;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200358 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400359 base->port = current_link.port;
360 base->autoneg = (current_link.autoneg) ? AUTONEG_ENABLE :
361 AUTONEG_DISABLE;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200362
363 return 0;
364}
365
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400366static int qede_set_link_ksettings(struct net_device *dev,
367 const struct ethtool_link_ksettings *cmd)
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200368{
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400369 const struct ethtool_link_settings *base = &cmd->base;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200370 struct qede_dev *edev = netdev_priv(dev);
371 struct qed_link_output current_link;
372 struct qed_link_params params;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200373
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300374 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400375 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200376 return -EOPNOTSUPP;
377 }
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200378 memset(&current_link, 0, sizeof(current_link));
379 memset(&params, 0, sizeof(params));
380 edev->ops->common->get_link(edev->cdev, &current_link);
381
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200382 params.override_flags |= QED_LINK_OVERRIDE_SPEED_ADV_SPEEDS;
383 params.override_flags |= QED_LINK_OVERRIDE_SPEED_AUTONEG;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400384 if (base->autoneg == AUTONEG_ENABLE) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200385 params.autoneg = true;
386 params.forced_speed = 0;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400387 QEDE_ETHTOOL_TO_DRV_CAPS(params.adv_speeds, cmd, advertising)
388 } else { /* forced speed */
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200389 params.override_flags |= QED_LINK_OVERRIDE_SPEED_FORCED_SPEED;
390 params.autoneg = false;
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400391 params.forced_speed = base->speed;
392 switch (base->speed) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200393 case SPEED_10000:
394 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400395 QED_LM_10000baseKR_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200396 DP_INFO(edev, "10G speed not supported\n");
397 return -EINVAL;
398 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400399 params.adv_speeds = QED_LM_10000baseKR_Full_BIT;
400 break;
401 case SPEED_25000:
402 if (!(current_link.supported_caps &
403 QED_LM_25000baseKR_Full_BIT)) {
404 DP_INFO(edev, "25G speed not supported\n");
405 return -EINVAL;
406 }
407 params.adv_speeds = QED_LM_25000baseKR_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200408 break;
409 case SPEED_40000:
410 if (!(current_link.supported_caps &
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400411 QED_LM_40000baseLR4_Full_BIT)) {
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200412 DP_INFO(edev, "40G speed not supported\n");
413 return -EINVAL;
414 }
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400415 params.adv_speeds = QED_LM_40000baseLR4_Full_BIT;
416 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300417 case SPEED_50000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400418 if (!(current_link.supported_caps &
419 QED_LM_50000baseKR2_Full_BIT)) {
420 DP_INFO(edev, "50G speed not supported\n");
421 return -EINVAL;
422 }
423 params.adv_speeds = QED_LM_50000baseKR2_Full_BIT;
424 break;
Yuval Mintz16d59462016-08-19 08:34:58 +0300425 case SPEED_100000:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400426 if (!(current_link.supported_caps &
427 QED_LM_100000baseKR4_Full_BIT)) {
428 DP_INFO(edev, "100G speed not supported\n");
429 return -EINVAL;
430 }
431 params.adv_speeds = QED_LM_100000baseKR4_Full_BIT;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200432 break;
433 default:
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -0400434 DP_INFO(edev, "Unsupported speed %u\n", base->speed);
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200435 return -EINVAL;
436 }
437 }
438
439 params.link_up = true;
440 edev->ops->common->set_link(edev->cdev, &params);
441
442 return 0;
443}
444
445static void qede_get_drvinfo(struct net_device *ndev,
446 struct ethtool_drvinfo *info)
447{
448 char mfw[ETHTOOL_FWVERS_LEN], storm[ETHTOOL_FWVERS_LEN];
449 struct qede_dev *edev = netdev_priv(ndev);
450
451 strlcpy(info->driver, "qede", sizeof(info->driver));
452 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
453
454 snprintf(storm, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
455 edev->dev_info.common.fw_major,
456 edev->dev_info.common.fw_minor,
457 edev->dev_info.common.fw_rev,
458 edev->dev_info.common.fw_eng);
459
460 snprintf(mfw, ETHTOOL_FWVERS_LEN, "%d.%d.%d.%d",
461 (edev->dev_info.common.mfw_rev >> 24) & 0xFF,
462 (edev->dev_info.common.mfw_rev >> 16) & 0xFF,
463 (edev->dev_info.common.mfw_rev >> 8) & 0xFF,
464 edev->dev_info.common.mfw_rev & 0xFF);
465
466 if ((strlen(storm) + strlen(mfw) + strlen("mfw storm ")) <
467 sizeof(info->fw_version)) {
468 snprintf(info->fw_version, sizeof(info->fw_version),
469 "mfw %s storm %s", mfw, storm);
470 } else {
471 snprintf(info->fw_version, sizeof(info->fw_version),
472 "%s %s", mfw, storm);
473 }
474
475 strlcpy(info->bus_info, pci_name(edev->pdev), sizeof(info->bus_info));
476}
477
478static u32 qede_get_msglevel(struct net_device *ndev)
479{
480 struct qede_dev *edev = netdev_priv(ndev);
481
Yuval Mintz1a635e42016-08-15 10:42:43 +0300482 return ((u32)edev->dp_level << QED_LOG_LEVEL_SHIFT) | edev->dp_module;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200483}
484
485static void qede_set_msglevel(struct net_device *ndev, u32 level)
486{
487 struct qede_dev *edev = netdev_priv(ndev);
488 u32 dp_module = 0;
489 u8 dp_level = 0;
490
491 qede_config_debug(level, &dp_module, &dp_level);
492
493 edev->dp_level = dp_level;
494 edev->dp_module = dp_module;
495 edev->ops->common->update_msglvl(edev->cdev,
496 dp_module, dp_level);
497}
498
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200499static int qede_nway_reset(struct net_device *dev)
500{
501 struct qede_dev *edev = netdev_priv(dev);
502 struct qed_link_output current_link;
503 struct qed_link_params link_params;
504
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300505 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Yuval Mintz1a635e42016-08-15 10:42:43 +0300506 DP_INFO(edev, "Link settings are not allowed to be changed\n");
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300507 return -EOPNOTSUPP;
508 }
509
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +0200510 if (!netif_running(dev))
511 return 0;
512
513 memset(&current_link, 0, sizeof(current_link));
514 edev->ops->common->get_link(edev->cdev, &current_link);
515 if (!current_link.link_up)
516 return 0;
517
518 /* Toggle the link */
519 memset(&link_params, 0, sizeof(link_params));
520 link_params.link_up = false;
521 edev->ops->common->set_link(edev->cdev, &link_params);
522 link_params.link_up = true;
523 edev->ops->common->set_link(edev->cdev, &link_params);
524
525 return 0;
526}
527
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200528static u32 qede_get_link(struct net_device *dev)
529{
530 struct qede_dev *edev = netdev_priv(dev);
531 struct qed_link_output current_link;
532
533 memset(&current_link, 0, sizeof(current_link));
534 edev->ops->common->get_link(edev->cdev, &current_link);
535
536 return current_link.link_up;
537}
538
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400539static int qede_get_coalesce(struct net_device *dev,
540 struct ethtool_coalesce *coal)
541{
542 struct qede_dev *edev = netdev_priv(dev);
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400543 u16 rxc, txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400544
545 memset(coal, 0, sizeof(struct ethtool_coalesce));
Sudarsana Reddy Kallurud2890de2016-06-28 02:10:59 -0400546 edev->ops->common->get_coalesce(edev->cdev, &rxc, &txc);
547
548 coal->rx_coalesce_usecs = rxc;
549 coal->tx_coalesce_usecs = txc;
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -0400550
551 return 0;
552}
553
554static int qede_set_coalesce(struct net_device *dev,
555 struct ethtool_coalesce *coal)
556{
557 struct qede_dev *edev = netdev_priv(dev);
558 int i, rc = 0;
559 u16 rxc, txc;
560 u8 sb_id;
561
562 if (!netif_running(dev)) {
563 DP_INFO(edev, "Interface is down\n");
564 return -EINVAL;
565 }
566
567 if (coal->rx_coalesce_usecs > QED_COALESCE_MAX ||
568 coal->tx_coalesce_usecs > QED_COALESCE_MAX) {
569 DP_INFO(edev,
570 "Can't support requested %s coalesce value [max supported value %d]\n",
571 coal->rx_coalesce_usecs > QED_COALESCE_MAX ? "rx"
572 : "tx",
573 QED_COALESCE_MAX);
574 return -EINVAL;
575 }
576
577 rxc = (u16)coal->rx_coalesce_usecs;
578 txc = (u16)coal->tx_coalesce_usecs;
579 for_each_rss(i) {
580 sb_id = edev->fp_array[i].sb_info->igu_sb_id;
581 rc = edev->ops->common->set_coalesce(edev->cdev, rxc, txc,
582 (u8)i, sb_id);
583 if (rc) {
584 DP_INFO(edev, "Set coalesce error, rc = %d\n", rc);
585 return rc;
586 }
587 }
588
589 return rc;
590}
591
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +0200592static void qede_get_ringparam(struct net_device *dev,
593 struct ethtool_ringparam *ering)
594{
595 struct qede_dev *edev = netdev_priv(dev);
596
597 ering->rx_max_pending = NUM_RX_BDS_MAX;
598 ering->rx_pending = edev->q_num_rx_buffers;
599 ering->tx_max_pending = NUM_TX_BDS_MAX;
600 ering->tx_pending = edev->q_num_tx_buffers;
601}
602
603static int qede_set_ringparam(struct net_device *dev,
604 struct ethtool_ringparam *ering)
605{
606 struct qede_dev *edev = netdev_priv(dev);
607
608 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
609 "Set ring params command parameters: rx_pending = %d, tx_pending = %d\n",
610 ering->rx_pending, ering->tx_pending);
611
612 /* Validate legality of configuration */
613 if (ering->rx_pending > NUM_RX_BDS_MAX ||
614 ering->rx_pending < NUM_RX_BDS_MIN ||
615 ering->tx_pending > NUM_TX_BDS_MAX ||
616 ering->tx_pending < NUM_TX_BDS_MIN) {
617 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
618 "Can only support Rx Buffer size [0%08x,...,0x%08x] and Tx Buffer size [0x%08x,...,0x%08x]\n",
619 NUM_RX_BDS_MIN, NUM_RX_BDS_MAX,
620 NUM_TX_BDS_MIN, NUM_TX_BDS_MAX);
621 return -EINVAL;
622 }
623
624 /* Change ring size and re-load */
625 edev->q_num_rx_buffers = ering->rx_pending;
626 edev->q_num_tx_buffers = ering->tx_pending;
627
628 if (netif_running(edev->ndev))
629 qede_reload(edev, NULL, NULL);
630
631 return 0;
632}
633
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200634static void qede_get_pauseparam(struct net_device *dev,
635 struct ethtool_pauseparam *epause)
636{
637 struct qede_dev *edev = netdev_priv(dev);
638 struct qed_link_output current_link;
639
640 memset(&current_link, 0, sizeof(current_link));
641 edev->ops->common->get_link(edev->cdev, &current_link);
642
643 if (current_link.pause_config & QED_LINK_PAUSE_AUTONEG_ENABLE)
644 epause->autoneg = true;
645 if (current_link.pause_config & QED_LINK_PAUSE_RX_ENABLE)
646 epause->rx_pause = true;
647 if (current_link.pause_config & QED_LINK_PAUSE_TX_ENABLE)
648 epause->tx_pause = true;
649
650 DP_VERBOSE(edev, QED_MSG_DEBUG,
651 "ethtool_pauseparam: cmd %d autoneg %d rx_pause %d tx_pause %d\n",
652 epause->cmd, epause->autoneg, epause->rx_pause,
653 epause->tx_pause);
654}
655
656static int qede_set_pauseparam(struct net_device *dev,
657 struct ethtool_pauseparam *epause)
658{
659 struct qede_dev *edev = netdev_priv(dev);
660 struct qed_link_params params;
661 struct qed_link_output current_link;
662
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300663 if (!edev->ops || !edev->ops->common->can_link_change(edev->cdev)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200664 DP_INFO(edev,
Yuval Mintzfe7cd2b2016-04-22 08:41:03 +0300665 "Pause settings are not allowed to be changed\n");
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200666 return -EOPNOTSUPP;
667 }
668
669 memset(&current_link, 0, sizeof(current_link));
670 edev->ops->common->get_link(edev->cdev, &current_link);
671
672 memset(&params, 0, sizeof(params));
673 params.override_flags |= QED_LINK_OVERRIDE_PAUSE_CONFIG;
674 if (epause->autoneg) {
Yuval Mintzd194fd22016-08-19 08:34:57 +0300675 if (!(current_link.supported_caps & QED_LM_Autoneg_BIT)) {
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +0200676 DP_INFO(edev, "autoneg not supported\n");
677 return -EINVAL;
678 }
679 params.pause_config |= QED_LINK_PAUSE_AUTONEG_ENABLE;
680 }
681 if (epause->rx_pause)
682 params.pause_config |= QED_LINK_PAUSE_RX_ENABLE;
683 if (epause->tx_pause)
684 params.pause_config |= QED_LINK_PAUSE_TX_ENABLE;
685
686 params.link_up = true;
687 edev->ops->common->set_link(edev->cdev, &params);
688
689 return 0;
690}
691
Sudarsana Kalluru133fac02015-10-26 11:02:34 +0200692static void qede_update_mtu(struct qede_dev *edev, union qede_reload_args *args)
693{
694 edev->ndev->mtu = args->mtu;
695}
696
697/* Netdevice NDOs */
698#define ETH_MAX_JUMBO_PACKET_SIZE 9600
699#define ETH_MIN_PACKET_SIZE 60
700int qede_change_mtu(struct net_device *ndev, int new_mtu)
701{
702 struct qede_dev *edev = netdev_priv(ndev);
703 union qede_reload_args args;
704
705 if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
706 ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) {
707 DP_ERR(edev, "Can't support requested MTU size\n");
708 return -EINVAL;
709 }
710
711 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
712 "Configuring MTU size of %d\n", new_mtu);
713
714 /* Set the mtu field and re-start the interface if needed*/
715 args.mtu = new_mtu;
716
717 if (netif_running(edev->ndev))
718 qede_reload(edev, &qede_update_mtu, &args);
719
720 qede_update_mtu(edev, &args);
721
722 return 0;
723}
724
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +0200725static void qede_get_channels(struct net_device *dev,
726 struct ethtool_channels *channels)
727{
728 struct qede_dev *edev = netdev_priv(dev);
729
730 channels->max_combined = QEDE_MAX_RSS_CNT(edev);
731 channels->combined_count = QEDE_RSS_CNT(edev);
732}
733
734static int qede_set_channels(struct net_device *dev,
735 struct ethtool_channels *channels)
736{
737 struct qede_dev *edev = netdev_priv(dev);
738
739 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
740 "set-channels command parameters: rx = %d, tx = %d, other = %d, combined = %d\n",
741 channels->rx_count, channels->tx_count,
742 channels->other_count, channels->combined_count);
743
744 /* We don't support separate rx / tx, nor `other' channels. */
745 if (channels->rx_count || channels->tx_count ||
746 channels->other_count || (channels->combined_count == 0) ||
747 (channels->combined_count > QEDE_MAX_RSS_CNT(edev))) {
748 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
749 "command parameters not supported\n");
750 return -EINVAL;
751 }
752
753 /* Check if there was a change in the active parameters */
754 if (channels->combined_count == QEDE_RSS_CNT(edev)) {
755 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
756 "No change in active parameters\n");
757 return 0;
758 }
759
760 /* We need the number of queues to be divisible between the hwfns */
761 if (channels->combined_count % edev->dev_info.common.num_hwfns) {
762 DP_VERBOSE(edev, (NETIF_MSG_IFUP | NETIF_MSG_IFDOWN),
763 "Number of channels must be divisable by %04x\n",
764 edev->dev_info.common.num_hwfns);
765 return -EINVAL;
766 }
767
768 /* Set number of queues and reload if necessary */
769 edev->req_rss = channels->combined_count;
770 if (netif_running(dev))
771 qede_reload(edev, NULL, NULL);
772
773 return 0;
774}
775
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +0200776static int qede_set_phys_id(struct net_device *dev,
777 enum ethtool_phys_id_state state)
778{
779 struct qede_dev *edev = netdev_priv(dev);
780 u8 led_state = 0;
781
782 switch (state) {
783 case ETHTOOL_ID_ACTIVE:
784 return 1; /* cycle on/off once per second */
785
786 case ETHTOOL_ID_ON:
787 led_state = QED_LED_MODE_ON;
788 break;
789
790 case ETHTOOL_ID_OFF:
791 led_state = QED_LED_MODE_OFF;
792 break;
793
794 case ETHTOOL_ID_INACTIVE:
795 led_state = QED_LED_MODE_RESTORE;
796 break;
797 }
798
799 edev->ops->common->set_led(edev->cdev, led_state);
800
801 return 0;
802}
803
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +0300804static int qede_get_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
805{
806 info->data = RXH_IP_SRC | RXH_IP_DST;
807
808 switch (info->flow_type) {
809 case TCP_V4_FLOW:
810 case TCP_V6_FLOW:
811 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
812 break;
813 case UDP_V4_FLOW:
814 if (edev->rss_params.rss_caps & QED_RSS_IPV4_UDP)
815 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
816 break;
817 case UDP_V6_FLOW:
818 if (edev->rss_params.rss_caps & QED_RSS_IPV6_UDP)
819 info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
820 break;
821 case IPV4_FLOW:
822 case IPV6_FLOW:
823 break;
824 default:
825 info->data = 0;
826 break;
827 }
828
829 return 0;
830}
831
832static int qede_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info,
833 u32 *rules __always_unused)
834{
835 struct qede_dev *edev = netdev_priv(dev);
836
837 switch (info->cmd) {
838 case ETHTOOL_GRXRINGS:
839 info->data = edev->num_rss;
840 return 0;
841 case ETHTOOL_GRXFH:
842 return qede_get_rss_flags(edev, info);
843 default:
844 DP_ERR(edev, "Command parameters not supported\n");
845 return -EOPNOTSUPP;
846 }
847}
848
849static int qede_set_rss_flags(struct qede_dev *edev, struct ethtool_rxnfc *info)
850{
851 struct qed_update_vport_params vport_update_params;
852 u8 set_caps = 0, clr_caps = 0;
853
854 DP_VERBOSE(edev, QED_MSG_DEBUG,
855 "Set rss flags command parameters: flow type = %d, data = %llu\n",
856 info->flow_type, info->data);
857
858 switch (info->flow_type) {
859 case TCP_V4_FLOW:
860 case TCP_V6_FLOW:
861 /* For TCP only 4-tuple hash is supported */
862 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST |
863 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
864 DP_INFO(edev, "Command parameters not supported\n");
865 return -EINVAL;
866 }
867 return 0;
868 case UDP_V4_FLOW:
869 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
870 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
871 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
872 set_caps = QED_RSS_IPV4_UDP;
873 DP_VERBOSE(edev, QED_MSG_DEBUG,
874 "UDP 4-tuple enabled\n");
875 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
876 clr_caps = QED_RSS_IPV4_UDP;
877 DP_VERBOSE(edev, QED_MSG_DEBUG,
878 "UDP 4-tuple disabled\n");
879 } else {
880 return -EINVAL;
881 }
882 break;
883 case UDP_V6_FLOW:
884 /* For UDP either 2-tuple hash or 4-tuple hash is supported */
885 if (info->data == (RXH_IP_SRC | RXH_IP_DST |
886 RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
887 set_caps = QED_RSS_IPV6_UDP;
888 DP_VERBOSE(edev, QED_MSG_DEBUG,
889 "UDP 4-tuple enabled\n");
890 } else if (info->data == (RXH_IP_SRC | RXH_IP_DST)) {
891 clr_caps = QED_RSS_IPV6_UDP;
892 DP_VERBOSE(edev, QED_MSG_DEBUG,
893 "UDP 4-tuple disabled\n");
894 } else {
895 return -EINVAL;
896 }
897 break;
898 case IPV4_FLOW:
899 case IPV6_FLOW:
900 /* For IP only 2-tuple hash is supported */
901 if (info->data ^ (RXH_IP_SRC | RXH_IP_DST)) {
902 DP_INFO(edev, "Command parameters not supported\n");
903 return -EINVAL;
904 }
905 return 0;
906 case SCTP_V4_FLOW:
907 case AH_ESP_V4_FLOW:
908 case AH_V4_FLOW:
909 case ESP_V4_FLOW:
910 case SCTP_V6_FLOW:
911 case AH_ESP_V6_FLOW:
912 case AH_V6_FLOW:
913 case ESP_V6_FLOW:
914 case IP_USER_FLOW:
915 case ETHER_FLOW:
916 /* RSS is not supported for these protocols */
917 if (info->data) {
918 DP_INFO(edev, "Command parameters not supported\n");
919 return -EINVAL;
920 }
921 return 0;
922 default:
923 return -EINVAL;
924 }
925
926 /* No action is needed if there is no change in the rss capability */
927 if (edev->rss_params.rss_caps == ((edev->rss_params.rss_caps &
928 ~clr_caps) | set_caps))
929 return 0;
930
931 /* Update internal configuration */
932 edev->rss_params.rss_caps = (edev->rss_params.rss_caps & ~clr_caps) |
933 set_caps;
934 edev->rss_params_inited |= QEDE_RSS_CAPS_INITED;
935
936 /* Re-configure if possible */
937 if (netif_running(edev->ndev)) {
938 memset(&vport_update_params, 0, sizeof(vport_update_params));
939 vport_update_params.update_rss_flg = 1;
940 vport_update_params.vport_id = 0;
941 memcpy(&vport_update_params.rss_params, &edev->rss_params,
942 sizeof(vport_update_params.rss_params));
943 return edev->ops->vport_update(edev->cdev,
944 &vport_update_params);
945 }
946
947 return 0;
948}
949
950static int qede_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *info)
951{
952 struct qede_dev *edev = netdev_priv(dev);
953
954 switch (info->cmd) {
955 case ETHTOOL_SRXFH:
956 return qede_set_rss_flags(edev, info);
957 default:
958 DP_INFO(edev, "Command parameters not supported\n");
959 return -EOPNOTSUPP;
960 }
961}
962
963static u32 qede_get_rxfh_indir_size(struct net_device *dev)
964{
965 return QED_RSS_IND_TABLE_SIZE;
966}
967
968static u32 qede_get_rxfh_key_size(struct net_device *dev)
969{
970 struct qede_dev *edev = netdev_priv(dev);
971
972 return sizeof(edev->rss_params.rss_key);
973}
974
975static int qede_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
976{
977 struct qede_dev *edev = netdev_priv(dev);
978 int i;
979
980 if (hfunc)
981 *hfunc = ETH_RSS_HASH_TOP;
982
983 if (!indir)
984 return 0;
985
986 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
987 indir[i] = edev->rss_params.rss_ind_table[i];
988
989 if (key)
990 memcpy(key, edev->rss_params.rss_key,
991 qede_get_rxfh_key_size(dev));
992
993 return 0;
994}
995
996static int qede_set_rxfh(struct net_device *dev, const u32 *indir,
997 const u8 *key, const u8 hfunc)
998{
999 struct qed_update_vport_params vport_update_params;
1000 struct qede_dev *edev = netdev_priv(dev);
1001 int i;
1002
1003 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1004 return -EOPNOTSUPP;
1005
1006 if (!indir && !key)
1007 return 0;
1008
1009 if (indir) {
1010 for (i = 0; i < QED_RSS_IND_TABLE_SIZE; i++)
1011 edev->rss_params.rss_ind_table[i] = indir[i];
1012 edev->rss_params_inited |= QEDE_RSS_INDIR_INITED;
1013 }
1014
1015 if (key) {
1016 memcpy(&edev->rss_params.rss_key, key,
1017 qede_get_rxfh_key_size(dev));
1018 edev->rss_params_inited |= QEDE_RSS_KEY_INITED;
1019 }
1020
1021 if (netif_running(edev->ndev)) {
1022 memset(&vport_update_params, 0, sizeof(vport_update_params));
1023 vport_update_params.update_rss_flg = 1;
1024 vport_update_params.vport_id = 0;
1025 memcpy(&vport_update_params.rss_params, &edev->rss_params,
1026 sizeof(vport_update_params.rss_params));
1027 return edev->ops->vport_update(edev->cdev,
1028 &vport_update_params);
1029 }
1030
1031 return 0;
1032}
1033
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001034/* This function enables the interrupt generation and the NAPI on the device */
1035static void qede_netif_start(struct qede_dev *edev)
1036{
1037 int i;
1038
1039 if (!netif_running(edev->ndev))
1040 return;
1041
1042 for_each_rss(i) {
1043 /* Update and reenable interrupts */
1044 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_ENABLE, 1);
1045 napi_enable(&edev->fp_array[i].napi);
1046 }
1047}
1048
1049/* This function disables the NAPI and the interrupt generation on the device */
1050static void qede_netif_stop(struct qede_dev *edev)
1051{
1052 int i;
1053
1054 for_each_rss(i) {
1055 napi_disable(&edev->fp_array[i].napi);
1056 /* Disable interrupts */
1057 qed_sb_ack(edev->fp_array[i].sb_info, IGU_INT_DISABLE, 0);
1058 }
1059}
1060
1061static int qede_selftest_transmit_traffic(struct qede_dev *edev,
1062 struct sk_buff *skb)
1063{
1064 struct qede_tx_queue *txq = &edev->fp_array[0].txqs[0];
1065 struct eth_tx_1st_bd *first_bd;
1066 dma_addr_t mapping;
1067 int i, idx, val;
1068
1069 /* Fill the entry in the SW ring and the BDs in the FW ring */
1070 idx = txq->sw_tx_prod & NUM_TX_BDS_MAX;
1071 txq->sw_tx_ring[idx].skb = skb;
1072 first_bd = qed_chain_produce(&txq->tx_pbl);
1073 memset(first_bd, 0, sizeof(*first_bd));
1074 val = 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1075 first_bd->data.bd_flags.bitfields = val;
Yuval Mintz351a4ded2016-06-02 10:23:29 +03001076 val = skb->len & ETH_TX_DATA_1ST_BD_PKT_LEN_MASK;
1077 first_bd->data.bitfields |= (val << ETH_TX_DATA_1ST_BD_PKT_LEN_SHIFT);
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001078
1079 /* Map skb linear data for DMA and set in the first BD */
1080 mapping = dma_map_single(&edev->pdev->dev, skb->data,
1081 skb_headlen(skb), DMA_TO_DEVICE);
1082 if (unlikely(dma_mapping_error(&edev->pdev->dev, mapping))) {
1083 DP_NOTICE(edev, "SKB mapping failed\n");
1084 return -ENOMEM;
1085 }
1086 BD_SET_UNMAP_ADDR_LEN(first_bd, mapping, skb_headlen(skb));
1087
1088 /* update the first BD with the actual num BDs */
1089 first_bd->data.nbds = 1;
1090 txq->sw_tx_prod++;
1091 /* 'next page' entries are counted in the producer value */
1092 val = cpu_to_le16(qed_chain_get_prod_idx(&txq->tx_pbl));
1093 txq->tx_db.data.bd_prod = val;
1094
1095 /* wmb makes sure that the BDs data is updated before updating the
1096 * producer, otherwise FW may read old data from the BDs.
1097 */
1098 wmb();
1099 barrier();
1100 writel(txq->tx_db.raw, txq->doorbell_addr);
1101
1102 /* mmiowb is needed to synchronize doorbell writes from more than one
1103 * processor. It guarantees that the write arrives to the device before
1104 * the queue lock is released and another start_xmit is called (possibly
1105 * on another CPU). Without this barrier, the next doorbell can bypass
1106 * this doorbell. This is applicable to IA64/Altix systems.
1107 */
1108 mmiowb();
1109
1110 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1111 if (qede_txq_has_work(txq))
1112 break;
1113 usleep_range(100, 200);
1114 }
1115
1116 if (!qede_txq_has_work(txq)) {
1117 DP_NOTICE(edev, "Tx completion didn't happen\n");
1118 return -1;
1119 }
1120
1121 first_bd = (struct eth_tx_1st_bd *)qed_chain_consume(&txq->tx_pbl);
1122 dma_unmap_page(&edev->pdev->dev, BD_UNMAP_ADDR(first_bd),
1123 BD_UNMAP_LEN(first_bd), DMA_TO_DEVICE);
1124 txq->sw_tx_cons++;
1125 txq->sw_tx_ring[idx].skb = NULL;
1126
1127 return 0;
1128}
1129
1130static int qede_selftest_receive_traffic(struct qede_dev *edev)
1131{
1132 struct qede_rx_queue *rxq = edev->fp_array[0].rxq;
1133 u16 hw_comp_cons, sw_comp_cons, sw_rx_index, len;
1134 struct eth_fast_path_rx_reg_cqe *fp_cqe;
1135 struct sw_rx_data *sw_rx_data;
1136 union eth_rx_cqe *cqe;
1137 u8 *data_ptr;
1138 int i;
1139
1140 /* The packet is expected to receive on rx-queue 0 even though RSS is
1141 * enabled. This is because the queue 0 is configured as the default
1142 * queue and that the loopback traffic is not IP.
1143 */
1144 for (i = 0; i < QEDE_SELFTEST_POLL_COUNT; i++) {
1145 if (qede_has_rx_work(rxq))
1146 break;
1147 usleep_range(100, 200);
1148 }
1149
1150 if (!qede_has_rx_work(rxq)) {
1151 DP_NOTICE(edev, "Failed to receive the traffic\n");
1152 return -1;
1153 }
1154
1155 hw_comp_cons = le16_to_cpu(*rxq->hw_cons_ptr);
1156 sw_comp_cons = qed_chain_get_cons_idx(&rxq->rx_comp_ring);
1157
1158 /* Memory barrier to prevent the CPU from doing speculative reads of CQE
1159 * / BD before reading hw_comp_cons. If the CQE is read before it is
1160 * written by FW, then FW writes CQE and SB, and then the CPU reads the
1161 * hw_comp_cons, it will use an old CQE.
1162 */
1163 rmb();
1164
1165 /* Get the CQE from the completion ring */
1166 cqe = (union eth_rx_cqe *)qed_chain_consume(&rxq->rx_comp_ring);
1167
1168 /* Get the data from the SW ring */
1169 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS_MAX;
1170 sw_rx_data = &rxq->sw_rx_ring[sw_rx_index];
1171 fp_cqe = &cqe->fast_path_regular;
1172 len = le16_to_cpu(fp_cqe->len_on_first_bd);
1173 data_ptr = (u8 *)(page_address(sw_rx_data->data) +
1174 fp_cqe->placement_offset + sw_rx_data->page_offset);
1175 for (i = ETH_HLEN; i < len; i++)
1176 if (data_ptr[i] != (unsigned char)(i & 0xff)) {
1177 DP_NOTICE(edev, "Loopback test failed\n");
1178 qede_recycle_rx_bd_ring(rxq, edev, 1);
1179 return -1;
1180 }
1181
1182 qede_recycle_rx_bd_ring(rxq, edev, 1);
1183
1184 return 0;
1185}
1186
1187static int qede_selftest_run_loopback(struct qede_dev *edev, u32 loopback_mode)
1188{
1189 struct qed_link_params link_params;
1190 struct sk_buff *skb = NULL;
1191 int rc = 0, i;
1192 u32 pkt_size;
1193 u8 *packet;
1194
1195 if (!netif_running(edev->ndev)) {
1196 DP_NOTICE(edev, "Interface is down\n");
1197 return -EINVAL;
1198 }
1199
1200 qede_netif_stop(edev);
1201
1202 /* Bring up the link in Loopback mode */
1203 memset(&link_params, 0, sizeof(link_params));
1204 link_params.link_up = true;
1205 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1206 link_params.loopback_mode = loopback_mode;
1207 edev->ops->common->set_link(edev->cdev, &link_params);
1208
1209 /* Wait for loopback configuration to apply */
1210 msleep_interruptible(500);
1211
1212 /* prepare the loopback packet */
1213 pkt_size = edev->ndev->mtu + ETH_HLEN;
1214
1215 skb = netdev_alloc_skb(edev->ndev, pkt_size);
1216 if (!skb) {
1217 DP_INFO(edev, "Can't allocate skb\n");
1218 rc = -ENOMEM;
1219 goto test_loopback_exit;
1220 }
1221 packet = skb_put(skb, pkt_size);
1222 ether_addr_copy(packet, edev->ndev->dev_addr);
1223 ether_addr_copy(packet + ETH_ALEN, edev->ndev->dev_addr);
1224 memset(packet + (2 * ETH_ALEN), 0x77, (ETH_HLEN - (2 * ETH_ALEN)));
1225 for (i = ETH_HLEN; i < pkt_size; i++)
1226 packet[i] = (unsigned char)(i & 0xff);
1227
1228 rc = qede_selftest_transmit_traffic(edev, skb);
1229 if (rc)
1230 goto test_loopback_exit;
1231
1232 rc = qede_selftest_receive_traffic(edev);
1233 if (rc)
1234 goto test_loopback_exit;
1235
1236 DP_VERBOSE(edev, NETIF_MSG_RX_STATUS, "Loopback test successful\n");
1237
1238test_loopback_exit:
1239 dev_kfree_skb(skb);
1240
1241 /* Bring up the link in Normal mode */
1242 memset(&link_params, 0, sizeof(link_params));
1243 link_params.link_up = true;
1244 link_params.override_flags = QED_LINK_OVERRIDE_LOOPBACK_MODE;
1245 link_params.loopback_mode = QED_LINK_LOOPBACK_NONE;
1246 edev->ops->common->set_link(edev->cdev, &link_params);
1247
1248 /* Wait for loopback configuration to apply */
1249 msleep_interruptible(500);
1250
1251 qede_netif_start(edev);
1252
1253 return rc;
1254}
1255
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001256static void qede_self_test(struct net_device *dev,
1257 struct ethtool_test *etest, u64 *buf)
1258{
1259 struct qede_dev *edev = netdev_priv(dev);
1260
1261 DP_VERBOSE(edev, QED_MSG_DEBUG,
1262 "Self-test command parameters: offline = %d, external_lb = %d\n",
1263 (etest->flags & ETH_TEST_FL_OFFLINE),
1264 (etest->flags & ETH_TEST_FL_EXTERNAL_LB) >> 2);
1265
1266 memset(buf, 0, sizeof(u64) * QEDE_ETHTOOL_TEST_MAX);
1267
Sudarsana Reddy Kalluru16f46bf2016-04-28 20:20:54 -04001268 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1269 if (qede_selftest_run_loopback(edev,
1270 QED_LINK_LOOPBACK_INT_PHY)) {
1271 buf[QEDE_ETHTOOL_INT_LOOPBACK] = 1;
1272 etest->flags |= ETH_TEST_FL_FAILED;
1273 }
1274 }
1275
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001276 if (edev->ops->common->selftest->selftest_interrupt(edev->cdev)) {
1277 buf[QEDE_ETHTOOL_INTERRUPT_TEST] = 1;
1278 etest->flags |= ETH_TEST_FL_FAILED;
1279 }
1280
1281 if (edev->ops->common->selftest->selftest_memory(edev->cdev)) {
1282 buf[QEDE_ETHTOOL_MEMORY_TEST] = 1;
1283 etest->flags |= ETH_TEST_FL_FAILED;
1284 }
1285
1286 if (edev->ops->common->selftest->selftest_register(edev->cdev)) {
1287 buf[QEDE_ETHTOOL_REGISTER_TEST] = 1;
1288 etest->flags |= ETH_TEST_FL_FAILED;
1289 }
1290
1291 if (edev->ops->common->selftest->selftest_clock(edev->cdev)) {
1292 buf[QEDE_ETHTOOL_CLOCK_TEST] = 1;
1293 etest->flags |= ETH_TEST_FL_FAILED;
1294 }
1295}
1296
Manish Chopra3d789992016-06-30 02:35:21 -04001297static int qede_set_tunable(struct net_device *dev,
1298 const struct ethtool_tunable *tuna,
1299 const void *data)
1300{
1301 struct qede_dev *edev = netdev_priv(dev);
1302 u32 val;
1303
1304 switch (tuna->id) {
1305 case ETHTOOL_RX_COPYBREAK:
1306 val = *(u32 *)data;
1307 if (val < QEDE_MIN_PKT_LEN || val > QEDE_RX_HDR_SIZE) {
1308 DP_VERBOSE(edev, QED_MSG_DEBUG,
1309 "Invalid rx copy break value, range is [%u, %u]",
1310 QEDE_MIN_PKT_LEN, QEDE_RX_HDR_SIZE);
1311 return -EINVAL;
1312 }
1313
1314 edev->rx_copybreak = *(u32 *)data;
1315 break;
1316 default:
1317 return -EOPNOTSUPP;
1318 }
1319
1320 return 0;
1321}
1322
1323static int qede_get_tunable(struct net_device *dev,
1324 const struct ethtool_tunable *tuna, void *data)
1325{
1326 struct qede_dev *edev = netdev_priv(dev);
1327
1328 switch (tuna->id) {
1329 case ETHTOOL_RX_COPYBREAK:
1330 *(u32 *)data = edev->rx_copybreak;
1331 break;
1332 default:
1333 return -EOPNOTSUPP;
1334 }
1335
1336 return 0;
1337}
1338
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001339static const struct ethtool_ops qede_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001340 .get_link_ksettings = qede_get_link_ksettings,
1341 .set_link_ksettings = qede_set_link_ksettings,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001342 .get_drvinfo = qede_get_drvinfo,
1343 .get_msglevel = qede_get_msglevel,
1344 .set_msglevel = qede_set_msglevel,
Sudarsana Kalluru32a7a572015-11-30 12:25:05 +02001345 .nway_reset = qede_nway_reset,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001346 .get_link = qede_get_link,
Sudarsana Reddy Kallurud552fa82016-06-21 09:36:22 -04001347 .get_coalesce = qede_get_coalesce,
1348 .set_coalesce = qede_set_coalesce,
Sudarsana Kalluru01ef7e02015-11-30 12:25:02 +02001349 .get_ringparam = qede_get_ringparam,
1350 .set_ringparam = qede_set_ringparam,
Sudarsana Kalluru0f7db142015-11-30 12:25:06 +02001351 .get_pauseparam = qede_get_pauseparam,
1352 .set_pauseparam = qede_set_pauseparam,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001353 .get_strings = qede_get_strings,
Sudarsana Kalluru3d971cb2015-11-30 12:25:04 +02001354 .set_phys_id = qede_set_phys_id,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001355 .get_ethtool_stats = qede_get_ethtool_stats,
Yuval Mintzf3e72102016-04-22 08:41:02 +03001356 .get_priv_flags = qede_get_priv_flags,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001357 .get_sset_count = qede_get_sset_count,
Sudarsana Reddy Kalluru961acde2016-04-10 12:43:01 +03001358 .get_rxnfc = qede_get_rxnfc,
1359 .set_rxnfc = qede_set_rxnfc,
1360 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1361 .get_rxfh_key_size = qede_get_rxfh_key_size,
1362 .get_rxfh = qede_get_rxfh,
1363 .set_rxfh = qede_set_rxfh,
Sudarsana Kalluru8edf0492015-11-30 12:25:01 +02001364 .get_channels = qede_get_channels,
1365 .set_channels = qede_set_channels,
Sudarsana Reddy Kalluru3044a022016-04-28 20:20:53 -04001366 .self_test = qede_self_test,
Manish Chopra3d789992016-06-30 02:35:21 -04001367 .get_tunable = qede_get_tunable,
1368 .set_tunable = qede_set_tunable,
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001369};
1370
Yuval Mintzfefb0202016-05-11 16:36:19 +03001371static const struct ethtool_ops qede_vf_ethtool_ops = {
Sudarsana Reddy Kalluru054c67d2016-08-09 03:51:23 -04001372 .get_link_ksettings = qede_get_link_ksettings,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001373 .get_drvinfo = qede_get_drvinfo,
1374 .get_msglevel = qede_get_msglevel,
1375 .set_msglevel = qede_set_msglevel,
1376 .get_link = qede_get_link,
1377 .get_ringparam = qede_get_ringparam,
1378 .set_ringparam = qede_set_ringparam,
1379 .get_strings = qede_get_strings,
1380 .get_ethtool_stats = qede_get_ethtool_stats,
1381 .get_priv_flags = qede_get_priv_flags,
1382 .get_sset_count = qede_get_sset_count,
1383 .get_rxnfc = qede_get_rxnfc,
1384 .set_rxnfc = qede_set_rxnfc,
1385 .get_rxfh_indir_size = qede_get_rxfh_indir_size,
1386 .get_rxfh_key_size = qede_get_rxfh_key_size,
1387 .get_rxfh = qede_get_rxfh,
1388 .set_rxfh = qede_set_rxfh,
1389 .get_channels = qede_get_channels,
1390 .set_channels = qede_set_channels,
Manish Chopra3d789992016-06-30 02:35:21 -04001391 .get_tunable = qede_get_tunable,
1392 .set_tunable = qede_set_tunable,
Yuval Mintzfefb0202016-05-11 16:36:19 +03001393};
1394
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001395void qede_set_ethtool_ops(struct net_device *dev)
1396{
Yuval Mintzfefb0202016-05-11 16:36:19 +03001397 struct qede_dev *edev = netdev_priv(dev);
1398
1399 if (IS_VF(edev))
1400 dev->ethtool_ops = &qede_vf_ethtool_ops;
1401 else
1402 dev->ethtool_ops = &qede_ethtool_ops;
Sudarsana Kalluru133fac02015-10-26 11:02:34 +02001403}