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