blob: 4ef2fbd229119578ca8681294556c5d906335814 [file] [log] [blame]
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001/* Intel Ethernet Switch Host Interface Driver
Jeff Kirsher97c71e32015-04-03 13:26:52 -07002 * Copyright(c) 2013 - 2015 Intel Corporation.
Alexander Duyck82dd0f72014-09-20 19:50:15 -04003 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
19 */
20
Stephen Rothwelleb51bba2014-10-01 17:00:49 +100021#include <linux/vmalloc.h>
22
Alexander Duyck82dd0f72014-09-20 19:50:15 -040023#include "fm10k.h"
24
25struct fm10k_stats {
26 char stat_string[ETH_GSTRING_LEN];
27 int sizeof_stat;
28 int stat_offset;
29};
30
31#define FM10K_NETDEV_STAT(_net_stat) { \
32 .stat_string = #_net_stat, \
33 .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
34 .stat_offset = offsetof(struct net_device_stats, _net_stat) \
35}
36
37static const struct fm10k_stats fm10k_gstrings_net_stats[] = {
38 FM10K_NETDEV_STAT(tx_packets),
39 FM10K_NETDEV_STAT(tx_bytes),
40 FM10K_NETDEV_STAT(tx_errors),
41 FM10K_NETDEV_STAT(rx_packets),
42 FM10K_NETDEV_STAT(rx_bytes),
43 FM10K_NETDEV_STAT(rx_errors),
44 FM10K_NETDEV_STAT(rx_dropped),
45
46 /* detailed Rx errors */
47 FM10K_NETDEV_STAT(rx_length_errors),
48 FM10K_NETDEV_STAT(rx_crc_errors),
49 FM10K_NETDEV_STAT(rx_fifo_errors),
50};
51
52#define FM10K_NETDEV_STATS_LEN ARRAY_SIZE(fm10k_gstrings_net_stats)
53
54#define FM10K_STAT(_name, _stat) { \
55 .stat_string = _name, \
56 .sizeof_stat = FIELD_SIZEOF(struct fm10k_intfc, _stat), \
57 .stat_offset = offsetof(struct fm10k_intfc, _stat) \
58}
59
Jeff Kirsherfbdb1592015-04-03 13:27:00 -070060static const struct fm10k_stats fm10k_gstrings_global_stats[] = {
Alexander Duyck82dd0f72014-09-20 19:50:15 -040061 FM10K_STAT("tx_restart_queue", restart_queue),
62 FM10K_STAT("tx_busy", tx_busy),
63 FM10K_STAT("tx_csum_errors", tx_csum_errors),
64 FM10K_STAT("rx_alloc_failed", alloc_failed),
65 FM10K_STAT("rx_csum_errors", rx_csum_errors),
Alexander Duyck82dd0f72014-09-20 19:50:15 -040066
67 FM10K_STAT("tx_packets_nic", tx_packets_nic),
68 FM10K_STAT("tx_bytes_nic", tx_bytes_nic),
69 FM10K_STAT("rx_packets_nic", rx_packets_nic),
70 FM10K_STAT("rx_bytes_nic", rx_bytes_nic),
71 FM10K_STAT("rx_drops_nic", rx_drops_nic),
72 FM10K_STAT("rx_overrun_pf", rx_overrun_pf),
73 FM10K_STAT("rx_overrun_vf", rx_overrun_vf),
74
Alexander Duyck82dd0f72014-09-20 19:50:15 -040075 FM10K_STAT("swapi_status", hw.swapi.status),
76 FM10K_STAT("mac_rules_used", hw.swapi.mac.used),
77 FM10K_STAT("mac_rules_avail", hw.swapi.mac.avail),
78
Jeff Kirshere05546e2015-04-03 13:27:03 -070079 FM10K_STAT("tx_hang_count", tx_timeout_count),
80
Alexander Duycka211e012014-09-20 19:54:07 -040081 FM10K_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
Alexander Duyck82dd0f72014-09-20 19:50:15 -040082};
83
Jacob Keller80043f32015-07-01 17:38:36 -070084static const struct fm10k_stats fm10k_gstrings_debug_stats[] = {
85 FM10K_STAT("hw_sm_mbx_full", hw_sm_mbx_full),
86 FM10K_STAT("hw_csum_tx_good", hw_csum_tx_good),
87 FM10K_STAT("hw_csum_rx_good", hw_csum_rx_good),
88 FM10K_STAT("rx_switch_errors", rx_switch_errors),
89 FM10K_STAT("rx_drops", rx_drops),
90 FM10K_STAT("rx_pp_errors", rx_pp_errors),
91 FM10K_STAT("rx_link_errors", rx_link_errors),
92 FM10K_STAT("rx_length_errors", rx_length_errors),
93};
94
Jeff Kirsherfbdb1592015-04-03 13:27:00 -070095static const struct fm10k_stats fm10k_gstrings_pf_stats[] = {
96 FM10K_STAT("timeout", stats.timeout.count),
97 FM10K_STAT("ur", stats.ur.count),
98 FM10K_STAT("ca", stats.ca.count),
99 FM10K_STAT("um", stats.um.count),
100 FM10K_STAT("xec", stats.xec.count),
101 FM10K_STAT("vlan_drop", stats.vlan_drop.count),
102 FM10K_STAT("loopback_drop", stats.loopback_drop.count),
103 FM10K_STAT("nodesc_drop", stats.nodesc_drop.count),
104};
105
Jacob Keller80043f32015-07-01 17:38:36 -0700106#define FM10K_MBX_STAT(_name, _stat) { \
107 .stat_string = _name, \
108 .sizeof_stat = FIELD_SIZEOF(struct fm10k_mbx_info, _stat), \
109 .stat_offset = offsetof(struct fm10k_mbx_info, _stat) \
110}
111
112static const struct fm10k_stats fm10k_gstrings_mbx_stats[] = {
113 FM10K_MBX_STAT("mbx_tx_busy", tx_busy),
114 FM10K_MBX_STAT("mbx_tx_oversized", tx_dropped),
115 FM10K_MBX_STAT("mbx_tx_messages", tx_messages),
116 FM10K_MBX_STAT("mbx_tx_dwords", tx_dwords),
117 FM10K_MBX_STAT("mbx_rx_messages", rx_messages),
118 FM10K_MBX_STAT("mbx_rx_dwords", rx_dwords),
119 FM10K_MBX_STAT("mbx_rx_parse_err", rx_parse_err),
120};
121
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700122#define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats)
Jacob Keller80043f32015-07-01 17:38:36 -0700123#define FM10K_DEBUG_STATS_LEN ARRAY_SIZE(fm10k_gstrings_debug_stats)
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700124#define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats)
Jacob Keller80043f32015-07-01 17:38:36 -0700125#define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400126
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700127#define FM10K_QUEUE_STATS_LEN(_n) \
128 ( (_n) * 2 * (sizeof(struct fm10k_queue_stats) / sizeof(u64)))
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400129
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700130#define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
Jacob Keller80043f32015-07-01 17:38:36 -0700131 FM10K_NETDEV_STATS_LEN + \
132 FM10K_MBX_STATS_LEN)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400133
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400134static const char fm10k_gstrings_test[][ETH_GSTRING_LEN] = {
135 "Mailbox test (on/offline)"
136};
137
138#define FM10K_TEST_LEN (sizeof(fm10k_gstrings_test) / ETH_GSTRING_LEN)
139
140enum fm10k_self_test_types {
141 FM10K_TEST_MBX,
142 FM10K_TEST_MAX = FM10K_TEST_LEN
143};
144
Jacob Keller80043f32015-07-01 17:38:36 -0700145enum {
146 FM10K_PRV_FLAG_DEBUG_STATS,
147 FM10K_PRV_FLAG_LEN,
148};
149
150static const char fm10k_prv_flags[FM10K_PRV_FLAG_LEN][ETH_GSTRING_LEN] = {
151 "debug-statistics",
152};
153
154static void fm10k_get_stat_strings(struct net_device *dev, u8 *data)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400155{
Jeff Kirsher29a928e2015-04-03 13:26:58 -0700156 struct fm10k_intfc *interface = netdev_priv(dev);
Jacob Keller80043f32015-07-01 17:38:36 -0700157 struct fm10k_iov_data *iov_data = interface->iov_data;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400158 char *p = (char *)data;
Jacob Kellerc0e58e92015-06-16 13:39:11 -0700159 unsigned int i;
Jacob Keller80043f32015-07-01 17:38:36 -0700160 unsigned int j;
161
162 for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) {
163 memcpy(p, fm10k_gstrings_net_stats[i].stat_string,
164 ETH_GSTRING_LEN);
165 p += ETH_GSTRING_LEN;
166 }
167
168 for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) {
169 memcpy(p, fm10k_gstrings_global_stats[i].stat_string,
170 ETH_GSTRING_LEN);
171 p += ETH_GSTRING_LEN;
172 }
173
174 if (interface->flags & FM10K_FLAG_DEBUG_STATS) {
175 for (i = 0; i < FM10K_DEBUG_STATS_LEN; i++) {
176 memcpy(p, fm10k_gstrings_debug_stats[i].stat_string,
177 ETH_GSTRING_LEN);
178 p += ETH_GSTRING_LEN;
179 }
180 }
181
182 for (i = 0; i < FM10K_MBX_STATS_LEN; i++) {
183 memcpy(p, fm10k_gstrings_mbx_stats[i].stat_string,
184 ETH_GSTRING_LEN);
185 p += ETH_GSTRING_LEN;
186 }
187
188 if (interface->hw.mac.type != fm10k_mac_vf) {
189 for (i = 0; i < FM10K_PF_STATS_LEN; i++) {
190 memcpy(p, fm10k_gstrings_pf_stats[i].stat_string,
191 ETH_GSTRING_LEN);
192 p += ETH_GSTRING_LEN;
193 }
194 }
195
196 if ((interface->flags & FM10K_FLAG_DEBUG_STATS) && iov_data) {
197 for (i = 0; i < iov_data->num_vfs; i++) {
198 for (j = 0; j < FM10K_MBX_STATS_LEN; j++) {
199 snprintf(p,
200 ETH_GSTRING_LEN,
201 "vf_%u_%s", i,
202 fm10k_gstrings_mbx_stats[j].stat_string);
203 p += ETH_GSTRING_LEN;
204 }
205 }
206 }
207
208 for (i = 0; i < interface->hw.mac.max_queues; i++) {
209 sprintf(p, "tx_queue_%u_packets", i);
210 p += ETH_GSTRING_LEN;
211 sprintf(p, "tx_queue_%u_bytes", i);
212 p += ETH_GSTRING_LEN;
213 sprintf(p, "rx_queue_%u_packets", i);
214 p += ETH_GSTRING_LEN;
215 sprintf(p, "rx_queue_%u_bytes", i);
216 p += ETH_GSTRING_LEN;
217 }
218}
219
220static void fm10k_get_strings(struct net_device *dev,
221 u32 stringset, u8 *data)
222{
223 char *p = (char *)data;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400224
225 switch (stringset) {
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400226 case ETH_SS_TEST:
227 memcpy(data, *fm10k_gstrings_test,
228 FM10K_TEST_LEN * ETH_GSTRING_LEN);
229 break;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400230 case ETH_SS_STATS:
Jacob Keller80043f32015-07-01 17:38:36 -0700231 fm10k_get_stat_strings(dev, data);
232 break;
233 case ETH_SS_PRIV_FLAGS:
234 memcpy(p, fm10k_prv_flags,
235 FM10K_PRV_FLAG_LEN * ETH_GSTRING_LEN);
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400236 break;
237 }
238}
239
240static int fm10k_get_sset_count(struct net_device *dev, int sset)
241{
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700242 struct fm10k_intfc *interface = netdev_priv(dev);
Jacob Keller80043f32015-07-01 17:38:36 -0700243 struct fm10k_iov_data *iov_data = interface->iov_data;
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700244 struct fm10k_hw *hw = &interface->hw;
245 int stats_len = FM10K_STATIC_STATS_LEN;
246
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400247 switch (sset) {
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400248 case ETH_SS_TEST:
249 return FM10K_TEST_LEN;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400250 case ETH_SS_STATS:
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700251 stats_len += FM10K_QUEUE_STATS_LEN(hw->mac.max_queues);
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700252
253 if (hw->mac.type != fm10k_mac_vf)
254 stats_len += FM10K_PF_STATS_LEN;
255
Jacob Keller80043f32015-07-01 17:38:36 -0700256 if (interface->flags & FM10K_FLAG_DEBUG_STATS) {
257 stats_len += FM10K_DEBUG_STATS_LEN;
258
259 if (iov_data)
260 stats_len += FM10K_MBX_STATS_LEN * iov_data->num_vfs;
261 }
262
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700263 return stats_len;
Jacob Keller80043f32015-07-01 17:38:36 -0700264 case ETH_SS_PRIV_FLAGS:
265 return FM10K_PRV_FLAG_LEN;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400266 default:
267 return -EOPNOTSUPP;
268 }
269}
270
271static void fm10k_get_ethtool_stats(struct net_device *netdev,
Jeff Kirsherde445192015-04-03 13:26:56 -0700272 struct ethtool_stats __always_unused *stats,
273 u64 *data)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400274{
275 const int stat_count = sizeof(struct fm10k_queue_stats) / sizeof(u64);
276 struct fm10k_intfc *interface = netdev_priv(netdev);
Jacob Keller80043f32015-07-01 17:38:36 -0700277 struct fm10k_iov_data *iov_data = interface->iov_data;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400278 struct net_device_stats *net_stats = &netdev->stats;
279 char *p;
280 int i, j;
281
282 fm10k_update_stats(interface);
283
284 for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) {
285 p = (char *)net_stats + fm10k_gstrings_net_stats[i].stat_offset;
286 *(data++) = (fm10k_gstrings_net_stats[i].sizeof_stat ==
287 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
288 }
289
290 for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) {
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700291 p = (char *)interface +
292 fm10k_gstrings_global_stats[i].stat_offset;
293 *(data++) = (fm10k_gstrings_global_stats[i].sizeof_stat ==
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400294 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
295 }
296
Jacob Keller80043f32015-07-01 17:38:36 -0700297 if (interface->flags & FM10K_FLAG_DEBUG_STATS) {
298 for (i = 0; i < FM10K_DEBUG_STATS_LEN; i++) {
299 p = (char *)interface + fm10k_gstrings_debug_stats[i].stat_offset;
300 *(data++) = (fm10k_gstrings_debug_stats[i].sizeof_stat ==
301 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
302 }
303 }
304
305 for (i = 0; i < FM10K_MBX_STATS_LEN; i++) {
306 p = (char *)&interface->hw.mbx + fm10k_gstrings_mbx_stats[i].stat_offset;
307 *(data++) = (fm10k_gstrings_mbx_stats[i].sizeof_stat ==
308 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
309 }
310
311 if (interface->hw.mac.type != fm10k_mac_vf) {
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700312 for (i = 0; i < FM10K_PF_STATS_LEN; i++) {
313 p = (char *)interface +
314 fm10k_gstrings_pf_stats[i].stat_offset;
315 *(data++) = (fm10k_gstrings_pf_stats[i].sizeof_stat ==
316 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
317 }
Jacob Keller80043f32015-07-01 17:38:36 -0700318 }
319
320 if ((interface->flags & FM10K_FLAG_DEBUG_STATS) && iov_data) {
321 for (i = 0; i < iov_data->num_vfs; i++) {
322 struct fm10k_vf_info *vf_info;
323 vf_info = &iov_data->vf_info[i];
324
325 /* skip stats if we don't have a vf info */
326 if (!vf_info) {
327 data += FM10K_MBX_STATS_LEN;
328 continue;
329 }
330
331 for (j = 0; j < FM10K_MBX_STATS_LEN; j++) {
332 p = (char *)&vf_info->mbx + fm10k_gstrings_mbx_stats[j].stat_offset;
333 *(data++) = (fm10k_gstrings_mbx_stats[j].sizeof_stat ==
334 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
335 }
336 }
337 }
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700338
Jeff Kirsher29a928e2015-04-03 13:26:58 -0700339 for (i = 0; i < interface->hw.mac.max_queues; i++) {
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400340 struct fm10k_ring *ring;
341 u64 *queue_stat;
342
343 ring = interface->tx_ring[i];
344 if (ring)
345 queue_stat = (u64 *)&ring->stats;
346 for (j = 0; j < stat_count; j++)
347 *(data++) = ring ? queue_stat[j] : 0;
348
349 ring = interface->rx_ring[i];
350 if (ring)
351 queue_stat = (u64 *)&ring->stats;
352 for (j = 0; j < stat_count; j++)
353 *(data++) = ring ? queue_stat[j] : 0;
354 }
355}
356
357/* If function below adds more registers this define needs to be updated */
358#define FM10K_REGS_LEN_Q 29
359
360static void fm10k_get_reg_q(struct fm10k_hw *hw, u32 *buff, int i)
361{
362 int idx = 0;
363
364 buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAL(i));
365 buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAH(i));
366 buff[idx++] = fm10k_read_reg(hw, FM10K_RDLEN(i));
367 buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_RXCTRL(i));
368 buff[idx++] = fm10k_read_reg(hw, FM10K_RDH(i));
369 buff[idx++] = fm10k_read_reg(hw, FM10K_RDT(i));
370 buff[idx++] = fm10k_read_reg(hw, FM10K_RXQCTL(i));
371 buff[idx++] = fm10k_read_reg(hw, FM10K_RXDCTL(i));
372 buff[idx++] = fm10k_read_reg(hw, FM10K_RXINT(i));
373 buff[idx++] = fm10k_read_reg(hw, FM10K_SRRCTL(i));
374 buff[idx++] = fm10k_read_reg(hw, FM10K_QPRC(i));
375 buff[idx++] = fm10k_read_reg(hw, FM10K_QPRDC(i));
376 buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_L(i));
377 buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_H(i));
378 buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAL(i));
379 buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAH(i));
380 buff[idx++] = fm10k_read_reg(hw, FM10K_TDLEN(i));
381 buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_TXCTRL(i));
382 buff[idx++] = fm10k_read_reg(hw, FM10K_TDH(i));
383 buff[idx++] = fm10k_read_reg(hw, FM10K_TDT(i));
384 buff[idx++] = fm10k_read_reg(hw, FM10K_TXDCTL(i));
385 buff[idx++] = fm10k_read_reg(hw, FM10K_TXQCTL(i));
386 buff[idx++] = fm10k_read_reg(hw, FM10K_TXINT(i));
387 buff[idx++] = fm10k_read_reg(hw, FM10K_QPTC(i));
388 buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_L(i));
389 buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_H(i));
390 buff[idx++] = fm10k_read_reg(hw, FM10K_TQDLOC(i));
391 buff[idx++] = fm10k_read_reg(hw, FM10K_TX_SGLORT(i));
392 buff[idx++] = fm10k_read_reg(hw, FM10K_PFVTCTL(i));
393
394 BUG_ON(idx != FM10K_REGS_LEN_Q);
395}
396
397/* If function above adds more registers this define needs to be updated */
398#define FM10K_REGS_LEN_VSI 43
399
400static void fm10k_get_reg_vsi(struct fm10k_hw *hw, u32 *buff, int i)
401{
402 int idx = 0, j;
403
404 buff[idx++] = fm10k_read_reg(hw, FM10K_MRQC(i));
405 for (j = 0; j < 10; j++)
406 buff[idx++] = fm10k_read_reg(hw, FM10K_RSSRK(i, j));
407 for (j = 0; j < 32; j++)
408 buff[idx++] = fm10k_read_reg(hw, FM10K_RETA(i, j));
409
410 BUG_ON(idx != FM10K_REGS_LEN_VSI);
411}
412
413static void fm10k_get_regs(struct net_device *netdev,
414 struct ethtool_regs *regs, void *p)
415{
416 struct fm10k_intfc *interface = netdev_priv(netdev);
417 struct fm10k_hw *hw = &interface->hw;
418 u32 *buff = p;
419 u16 i;
420
421 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
422
423 switch (hw->mac.type) {
424 case fm10k_mac_pf:
425 /* General PF Registers */
426 *(buff++) = fm10k_read_reg(hw, FM10K_CTRL);
427 *(buff++) = fm10k_read_reg(hw, FM10K_CTRL_EXT);
428 *(buff++) = fm10k_read_reg(hw, FM10K_GCR);
429 *(buff++) = fm10k_read_reg(hw, FM10K_GCR_EXT);
430
431 for (i = 0; i < 8; i++) {
432 *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTMAP(i));
433 *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTDEC(i));
434 }
435
436 for (i = 0; i < 65; i++) {
437 fm10k_get_reg_vsi(hw, buff, i);
438 buff += FM10K_REGS_LEN_VSI;
439 }
440
441 *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL);
442 *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL2);
443
444 for (i = 0; i < FM10K_MAX_QUEUES_PF; i++) {
445 fm10k_get_reg_q(hw, buff, i);
446 buff += FM10K_REGS_LEN_Q;
447 }
448
449 *(buff++) = fm10k_read_reg(hw, FM10K_TPH_CTRL);
450
451 for (i = 0; i < 8; i++)
452 *(buff++) = fm10k_read_reg(hw, FM10K_INT_MAP(i));
453
454 /* Interrupt Throttling Registers */
455 for (i = 0; i < 130; i++)
456 *(buff++) = fm10k_read_reg(hw, FM10K_ITR(i));
457
458 break;
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400459 case fm10k_mac_vf:
460 /* General VF registers */
461 *(buff++) = fm10k_read_reg(hw, FM10K_VFCTRL);
462 *(buff++) = fm10k_read_reg(hw, FM10K_VFINT_MAP);
463 *(buff++) = fm10k_read_reg(hw, FM10K_VFSYSTIME);
464
465 /* Interrupt Throttling Registers */
466 for (i = 0; i < 8; i++)
467 *(buff++) = fm10k_read_reg(hw, FM10K_VFITR(i));
468
469 fm10k_get_reg_vsi(hw, buff, 0);
470 buff += FM10K_REGS_LEN_VSI;
471
472 for (i = 0; i < FM10K_MAX_QUEUES_POOL; i++) {
473 if (i < hw->mac.max_queues)
474 fm10k_get_reg_q(hw, buff, i);
475 else
476 memset(buff, 0, sizeof(u32) * FM10K_REGS_LEN_Q);
477 buff += FM10K_REGS_LEN_Q;
478 }
479
480 break;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400481 default:
482 return;
483 }
484}
485
486/* If function above adds more registers these define need to be updated */
487#define FM10K_REGS_LEN_PF \
488(162 + (65 * FM10K_REGS_LEN_VSI) + (FM10K_MAX_QUEUES_PF * FM10K_REGS_LEN_Q))
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400489#define FM10K_REGS_LEN_VF \
490(11 + FM10K_REGS_LEN_VSI + (FM10K_MAX_QUEUES_POOL * FM10K_REGS_LEN_Q))
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400491
492static int fm10k_get_regs_len(struct net_device *netdev)
493{
494 struct fm10k_intfc *interface = netdev_priv(netdev);
495 struct fm10k_hw *hw = &interface->hw;
496
497 switch (hw->mac.type) {
498 case fm10k_mac_pf:
499 return FM10K_REGS_LEN_PF * sizeof(u32);
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400500 case fm10k_mac_vf:
501 return FM10K_REGS_LEN_VF * sizeof(u32);
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400502 default:
503 return 0;
504 }
505}
506
507static void fm10k_get_drvinfo(struct net_device *dev,
508 struct ethtool_drvinfo *info)
509{
510 struct fm10k_intfc *interface = netdev_priv(dev);
511
512 strncpy(info->driver, fm10k_driver_name,
513 sizeof(info->driver) - 1);
514 strncpy(info->version, fm10k_driver_version,
515 sizeof(info->version) - 1);
516 strncpy(info->bus_info, pci_name(interface->pdev),
517 sizeof(info->bus_info) - 1);
518
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700519 info->n_stats = fm10k_get_sset_count(dev, ETH_SS_STATS);
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400520
521 info->regdump_len = fm10k_get_regs_len(dev);
522}
523
524static void fm10k_get_pauseparam(struct net_device *dev,
525 struct ethtool_pauseparam *pause)
526{
527 struct fm10k_intfc *interface = netdev_priv(dev);
528
529 /* record fixed values for autoneg and tx pause */
530 pause->autoneg = 0;
531 pause->tx_pause = 1;
532
533 pause->rx_pause = interface->rx_pause ? 1 : 0;
534}
535
536static int fm10k_set_pauseparam(struct net_device *dev,
537 struct ethtool_pauseparam *pause)
538{
539 struct fm10k_intfc *interface = netdev_priv(dev);
540 struct fm10k_hw *hw = &interface->hw;
541
542 if (pause->autoneg || !pause->tx_pause)
543 return -EINVAL;
544
545 /* we can only support pause on the PF to avoid head-of-line blocking */
546 if (hw->mac.type == fm10k_mac_pf)
547 interface->rx_pause = pause->rx_pause ? ~0 : 0;
548 else if (pause->rx_pause)
549 return -EINVAL;
550
551 if (netif_running(dev))
552 fm10k_update_rx_drop_en(interface);
553
554 return 0;
555}
556
557static u32 fm10k_get_msglevel(struct net_device *netdev)
558{
559 struct fm10k_intfc *interface = netdev_priv(netdev);
560
561 return interface->msg_enable;
562}
563
564static void fm10k_set_msglevel(struct net_device *netdev, u32 data)
565{
566 struct fm10k_intfc *interface = netdev_priv(netdev);
567
568 interface->msg_enable = data;
569}
570
571static void fm10k_get_ringparam(struct net_device *netdev,
572 struct ethtool_ringparam *ring)
573{
574 struct fm10k_intfc *interface = netdev_priv(netdev);
575
576 ring->rx_max_pending = FM10K_MAX_RXD;
577 ring->tx_max_pending = FM10K_MAX_TXD;
578 ring->rx_mini_max_pending = 0;
579 ring->rx_jumbo_max_pending = 0;
580 ring->rx_pending = interface->rx_ring_count;
581 ring->tx_pending = interface->tx_ring_count;
582 ring->rx_mini_pending = 0;
583 ring->rx_jumbo_pending = 0;
584}
585
586static int fm10k_set_ringparam(struct net_device *netdev,
587 struct ethtool_ringparam *ring)
588{
589 struct fm10k_intfc *interface = netdev_priv(netdev);
590 struct fm10k_ring *temp_ring;
591 int i, err = 0;
592 u32 new_rx_count, new_tx_count;
593
594 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
595 return -EINVAL;
596
597 new_tx_count = clamp_t(u32, ring->tx_pending,
598 FM10K_MIN_TXD, FM10K_MAX_TXD);
599 new_tx_count = ALIGN(new_tx_count, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE);
600
601 new_rx_count = clamp_t(u32, ring->rx_pending,
602 FM10K_MIN_RXD, FM10K_MAX_RXD);
603 new_rx_count = ALIGN(new_rx_count, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE);
604
605 if ((new_tx_count == interface->tx_ring_count) &&
606 (new_rx_count == interface->rx_ring_count)) {
607 /* nothing to do */
608 return 0;
609 }
610
611 while (test_and_set_bit(__FM10K_RESETTING, &interface->state))
612 usleep_range(1000, 2000);
613
614 if (!netif_running(interface->netdev)) {
615 for (i = 0; i < interface->num_tx_queues; i++)
616 interface->tx_ring[i]->count = new_tx_count;
617 for (i = 0; i < interface->num_rx_queues; i++)
618 interface->rx_ring[i]->count = new_rx_count;
619 interface->tx_ring_count = new_tx_count;
620 interface->rx_ring_count = new_rx_count;
621 goto clear_reset;
622 }
623
624 /* allocate temporary buffer to store rings in */
625 i = max_t(int, interface->num_tx_queues, interface->num_rx_queues);
626 temp_ring = vmalloc(i * sizeof(struct fm10k_ring));
627
628 if (!temp_ring) {
629 err = -ENOMEM;
630 goto clear_reset;
631 }
632
633 fm10k_down(interface);
634
635 /* Setup new Tx resources and free the old Tx resources in that order.
636 * We can then assign the new resources to the rings via a memcpy.
637 * The advantage to this approach is that we are guaranteed to still
638 * have resources even in the case of an allocation failure.
639 */
640 if (new_tx_count != interface->tx_ring_count) {
641 for (i = 0; i < interface->num_tx_queues; i++) {
642 memcpy(&temp_ring[i], interface->tx_ring[i],
643 sizeof(struct fm10k_ring));
644
645 temp_ring[i].count = new_tx_count;
646 err = fm10k_setup_tx_resources(&temp_ring[i]);
647 if (err) {
648 while (i) {
649 i--;
650 fm10k_free_tx_resources(&temp_ring[i]);
651 }
652 goto err_setup;
653 }
654 }
655
656 for (i = 0; i < interface->num_tx_queues; i++) {
657 fm10k_free_tx_resources(interface->tx_ring[i]);
658
659 memcpy(interface->tx_ring[i], &temp_ring[i],
660 sizeof(struct fm10k_ring));
661 }
662
663 interface->tx_ring_count = new_tx_count;
664 }
665
666 /* Repeat the process for the Rx rings if needed */
667 if (new_rx_count != interface->rx_ring_count) {
668 for (i = 0; i < interface->num_rx_queues; i++) {
669 memcpy(&temp_ring[i], interface->rx_ring[i],
670 sizeof(struct fm10k_ring));
671
672 temp_ring[i].count = new_rx_count;
673 err = fm10k_setup_rx_resources(&temp_ring[i]);
674 if (err) {
675 while (i) {
676 i--;
677 fm10k_free_rx_resources(&temp_ring[i]);
678 }
679 goto err_setup;
680 }
681 }
682
683 for (i = 0; i < interface->num_rx_queues; i++) {
684 fm10k_free_rx_resources(interface->rx_ring[i]);
685
686 memcpy(interface->rx_ring[i], &temp_ring[i],
687 sizeof(struct fm10k_ring));
688 }
689
690 interface->rx_ring_count = new_rx_count;
691 }
692
693err_setup:
694 fm10k_up(interface);
695 vfree(temp_ring);
696clear_reset:
697 clear_bit(__FM10K_RESETTING, &interface->state);
698 return err;
699}
700
701static int fm10k_get_coalesce(struct net_device *dev,
702 struct ethtool_coalesce *ec)
703{
704 struct fm10k_intfc *interface = netdev_priv(dev);
705
706 ec->use_adaptive_tx_coalesce =
707 !!(interface->tx_itr & FM10K_ITR_ADAPTIVE);
708 ec->tx_coalesce_usecs = interface->tx_itr & ~FM10K_ITR_ADAPTIVE;
709
710 ec->use_adaptive_rx_coalesce =
711 !!(interface->rx_itr & FM10K_ITR_ADAPTIVE);
712 ec->rx_coalesce_usecs = interface->rx_itr & ~FM10K_ITR_ADAPTIVE;
713
714 return 0;
715}
716
717static int fm10k_set_coalesce(struct net_device *dev,
718 struct ethtool_coalesce *ec)
719{
720 struct fm10k_intfc *interface = netdev_priv(dev);
721 struct fm10k_q_vector *qv;
722 u16 tx_itr, rx_itr;
723 int i;
724
725 /* verify limits */
726 if ((ec->rx_coalesce_usecs > FM10K_ITR_MAX) ||
727 (ec->tx_coalesce_usecs > FM10K_ITR_MAX))
728 return -EINVAL;
729
730 /* record settings */
731 tx_itr = ec->tx_coalesce_usecs;
732 rx_itr = ec->rx_coalesce_usecs;
733
734 /* set initial values for adaptive ITR */
735 if (ec->use_adaptive_tx_coalesce)
736 tx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_10K;
737
738 if (ec->use_adaptive_rx_coalesce)
739 rx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_20K;
740
741 /* update interface */
742 interface->tx_itr = tx_itr;
743 interface->rx_itr = rx_itr;
744
745 /* update q_vectors */
746 for (i = 0; i < interface->num_q_vectors; i++) {
747 qv = interface->q_vector[i];
748 qv->tx.itr = tx_itr;
749 qv->rx.itr = rx_itr;
750 }
751
752 return 0;
753}
754
755static int fm10k_get_rss_hash_opts(struct fm10k_intfc *interface,
756 struct ethtool_rxnfc *cmd)
757{
758 cmd->data = 0;
759
760 /* Report default options for RSS on fm10k */
761 switch (cmd->flow_type) {
762 case TCP_V4_FLOW:
763 case TCP_V6_FLOW:
764 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
765 /* fall through */
766 case UDP_V4_FLOW:
767 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
768 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
769 /* fall through */
770 case SCTP_V4_FLOW:
771 case SCTP_V6_FLOW:
772 case AH_ESP_V4_FLOW:
773 case AH_ESP_V6_FLOW:
774 case AH_V4_FLOW:
775 case AH_V6_FLOW:
776 case ESP_V4_FLOW:
777 case ESP_V6_FLOW:
778 case IPV4_FLOW:
779 case IPV6_FLOW:
780 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
781 break;
782 case UDP_V6_FLOW:
783 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
784 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
785 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
786 break;
787 default:
788 return -EINVAL;
789 }
790
791 return 0;
792}
793
794static int fm10k_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
Jeff Kirsherde445192015-04-03 13:26:56 -0700795 u32 __always_unused *rule_locs)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400796{
797 struct fm10k_intfc *interface = netdev_priv(dev);
798 int ret = -EOPNOTSUPP;
799
800 switch (cmd->cmd) {
801 case ETHTOOL_GRXRINGS:
802 cmd->data = interface->num_rx_queues;
803 ret = 0;
804 break;
805 case ETHTOOL_GRXFH:
806 ret = fm10k_get_rss_hash_opts(interface, cmd);
807 break;
808 default:
809 break;
810 }
811
812 return ret;
813}
814
815#define UDP_RSS_FLAGS (FM10K_FLAG_RSS_FIELD_IPV4_UDP | \
816 FM10K_FLAG_RSS_FIELD_IPV6_UDP)
817static int fm10k_set_rss_hash_opt(struct fm10k_intfc *interface,
818 struct ethtool_rxnfc *nfc)
819{
820 u32 flags = interface->flags;
821
822 /* RSS does not support anything other than hashing
823 * to queues on src and dst IPs and ports
824 */
825 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
826 RXH_L4_B_0_1 | RXH_L4_B_2_3))
827 return -EINVAL;
828
829 switch (nfc->flow_type) {
830 case TCP_V4_FLOW:
831 case TCP_V6_FLOW:
832 if (!(nfc->data & RXH_IP_SRC) ||
833 !(nfc->data & RXH_IP_DST) ||
834 !(nfc->data & RXH_L4_B_0_1) ||
835 !(nfc->data & RXH_L4_B_2_3))
836 return -EINVAL;
837 break;
838 case UDP_V4_FLOW:
839 if (!(nfc->data & RXH_IP_SRC) ||
840 !(nfc->data & RXH_IP_DST))
841 return -EINVAL;
842 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
843 case 0:
844 flags &= ~FM10K_FLAG_RSS_FIELD_IPV4_UDP;
845 break;
846 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
847 flags |= FM10K_FLAG_RSS_FIELD_IPV4_UDP;
848 break;
849 default:
850 return -EINVAL;
851 }
852 break;
853 case UDP_V6_FLOW:
854 if (!(nfc->data & RXH_IP_SRC) ||
855 !(nfc->data & RXH_IP_DST))
856 return -EINVAL;
857 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
858 case 0:
859 flags &= ~FM10K_FLAG_RSS_FIELD_IPV6_UDP;
860 break;
861 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
862 flags |= FM10K_FLAG_RSS_FIELD_IPV6_UDP;
863 break;
864 default:
865 return -EINVAL;
866 }
867 break;
868 case AH_ESP_V4_FLOW:
869 case AH_V4_FLOW:
870 case ESP_V4_FLOW:
871 case SCTP_V4_FLOW:
872 case AH_ESP_V6_FLOW:
873 case AH_V6_FLOW:
874 case ESP_V6_FLOW:
875 case SCTP_V6_FLOW:
876 if (!(nfc->data & RXH_IP_SRC) ||
877 !(nfc->data & RXH_IP_DST) ||
878 (nfc->data & RXH_L4_B_0_1) ||
879 (nfc->data & RXH_L4_B_2_3))
880 return -EINVAL;
881 break;
882 default:
883 return -EINVAL;
884 }
885
886 /* if we changed something we need to update flags */
887 if (flags != interface->flags) {
888 struct fm10k_hw *hw = &interface->hw;
889 u32 mrqc;
890
891 if ((flags & UDP_RSS_FLAGS) &&
892 !(interface->flags & UDP_RSS_FLAGS))
893 netif_warn(interface, drv, interface->netdev,
894 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
895
896 interface->flags = flags;
897
898 /* Perform hash on these packet types */
899 mrqc = FM10K_MRQC_IPV4 |
900 FM10K_MRQC_TCP_IPV4 |
901 FM10K_MRQC_IPV6 |
902 FM10K_MRQC_TCP_IPV6;
903
904 if (flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
905 mrqc |= FM10K_MRQC_UDP_IPV4;
906 if (flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
907 mrqc |= FM10K_MRQC_UDP_IPV6;
908
909 fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
910 }
911
912 return 0;
913}
914
915static int fm10k_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
916{
917 struct fm10k_intfc *interface = netdev_priv(dev);
918 int ret = -EOPNOTSUPP;
919
920 switch (cmd->cmd) {
921 case ETHTOOL_SRXFH:
922 ret = fm10k_set_rss_hash_opt(interface, cmd);
923 break;
924 default:
925 break;
926 }
927
928 return ret;
929}
930
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400931static int fm10k_mbx_test(struct fm10k_intfc *interface, u64 *data)
932{
933 struct fm10k_hw *hw = &interface->hw;
934 struct fm10k_mbx_info *mbx = &hw->mbx;
935 u32 attr_flag, test_msg[6];
936 unsigned long timeout;
937 int err;
938
939 /* For now this is a VF only feature */
940 if (hw->mac.type != fm10k_mac_vf)
941 return 0;
942
943 /* loop through both nested and unnested attribute types */
944 for (attr_flag = (1 << FM10K_TEST_MSG_UNSET);
945 attr_flag < (1 << (2 * FM10K_TEST_MSG_NESTED));
946 attr_flag += attr_flag) {
947 /* generate message to be tested */
948 fm10k_tlv_msg_test_create(test_msg, attr_flag);
949
950 fm10k_mbx_lock(interface);
951 mbx->test_result = FM10K_NOT_IMPLEMENTED;
952 err = mbx->ops.enqueue_tx(hw, mbx, test_msg);
953 fm10k_mbx_unlock(interface);
954
955 /* wait up to 1 second for response */
956 timeout = jiffies + HZ;
957 do {
958 if (err < 0)
959 goto err_out;
960
961 usleep_range(500, 1000);
962
963 fm10k_mbx_lock(interface);
964 mbx->ops.process(hw, mbx);
965 fm10k_mbx_unlock(interface);
966
967 err = mbx->test_result;
968 if (!err)
969 break;
970 } while (time_is_after_jiffies(timeout));
971
972 /* reporting errors */
973 if (err)
974 goto err_out;
975 }
976
977err_out:
978 *data = err < 0 ? (attr_flag) : (err > 0);
979 return err;
980}
981
982static void fm10k_self_test(struct net_device *dev,
983 struct ethtool_test *eth_test, u64 *data)
984{
985 struct fm10k_intfc *interface = netdev_priv(dev);
986 struct fm10k_hw *hw = &interface->hw;
987
988 memset(data, 0, sizeof(*data) * FM10K_TEST_LEN);
989
990 if (FM10K_REMOVED(hw)) {
991 netif_err(interface, drv, dev,
992 "Interface removed - test blocked\n");
993 eth_test->flags |= ETH_TEST_FL_FAILED;
994 return;
995 }
996
997 if (fm10k_mbx_test(interface, &data[FM10K_TEST_MBX]))
998 eth_test->flags |= ETH_TEST_FL_FAILED;
999}
1000
Jacob Keller80043f32015-07-01 17:38:36 -07001001static u32 fm10k_get_priv_flags(struct net_device *netdev)
1002{
1003 struct fm10k_intfc *interface = netdev_priv(netdev);
1004 u32 priv_flags = 0;
1005
1006 if (interface->flags & FM10K_FLAG_DEBUG_STATS)
1007 priv_flags |= 1 << FM10K_PRV_FLAG_DEBUG_STATS;
1008
1009 return priv_flags;
1010}
1011
1012static int fm10k_set_priv_flags(struct net_device *netdev, u32 priv_flags)
1013{
1014 struct fm10k_intfc *interface = netdev_priv(netdev);
1015
1016 if (priv_flags >= (1 << FM10K_PRV_FLAG_LEN))
1017 return -EINVAL;
1018
1019 if (priv_flags & (1 << FM10K_PRV_FLAG_DEBUG_STATS))
1020 interface->flags |= FM10K_FLAG_DEBUG_STATS;
1021 else
1022 interface->flags &= ~FM10K_FLAG_DEBUG_STATS;
1023
1024 return 0;
1025}
1026
1027
Jeff Kirsherde445192015-04-03 13:26:56 -07001028static u32 fm10k_get_reta_size(struct net_device __always_unused *netdev)
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001029{
1030 return FM10K_RETA_SIZE * FM10K_RETA_ENTRIES_PER_REG;
1031}
1032
1033static int fm10k_get_reta(struct net_device *netdev, u32 *indir)
1034{
1035 struct fm10k_intfc *interface = netdev_priv(netdev);
1036 int i;
1037
1038 if (!indir)
1039 return 0;
1040
1041 for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
1042 u32 reta = interface->reta[i];
1043
1044 indir[0] = (reta << 24) >> 24;
1045 indir[1] = (reta << 16) >> 24;
1046 indir[2] = (reta << 8) >> 24;
1047 indir[3] = (reta) >> 24;
1048 }
1049
1050 return 0;
1051}
1052
1053static int fm10k_set_reta(struct net_device *netdev, const u32 *indir)
1054{
1055 struct fm10k_intfc *interface = netdev_priv(netdev);
1056 struct fm10k_hw *hw = &interface->hw;
1057 int i;
1058 u16 rss_i;
1059
1060 if (!indir)
1061 return 0;
1062
1063 /* Verify user input. */
1064 rss_i = interface->ring_feature[RING_F_RSS].indices;
1065 for (i = fm10k_get_reta_size(netdev); i--;) {
1066 if (indir[i] < rss_i)
1067 continue;
1068 return -EINVAL;
1069 }
1070
1071 /* record entries to reta table */
1072 for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
1073 u32 reta = indir[0] |
1074 (indir[1] << 8) |
1075 (indir[2] << 16) |
1076 (indir[3] << 24);
1077
1078 if (interface->reta[i] == reta)
1079 continue;
1080
1081 interface->reta[i] = reta;
1082 fm10k_write_reg(hw, FM10K_RETA(0, i), reta);
1083 }
1084
1085 return 0;
1086}
1087
Jeff Kirsherde445192015-04-03 13:26:56 -07001088static u32 fm10k_get_rssrk_size(struct net_device __always_unused *netdev)
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001089{
1090 return FM10K_RSSRK_SIZE * FM10K_RSSRK_ENTRIES_PER_REG;
1091}
1092
Eyal Perry892311f2014-12-02 18:12:10 +02001093static int fm10k_get_rssh(struct net_device *netdev, u32 *indir, u8 *key,
1094 u8 *hfunc)
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001095{
1096 struct fm10k_intfc *interface = netdev_priv(netdev);
1097 int i, err;
1098
Eyal Perry892311f2014-12-02 18:12:10 +02001099 if (hfunc)
1100 *hfunc = ETH_RSS_HASH_TOP;
1101
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001102 err = fm10k_get_reta(netdev, indir);
1103 if (err || !key)
1104 return err;
1105
1106 for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4)
1107 *(__le32 *)key = cpu_to_le32(interface->rssrk[i]);
1108
1109 return 0;
1110}
1111
1112static int fm10k_set_rssh(struct net_device *netdev, const u32 *indir,
Eyal Perry892311f2014-12-02 18:12:10 +02001113 const u8 *key, const u8 hfunc)
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001114{
1115 struct fm10k_intfc *interface = netdev_priv(netdev);
1116 struct fm10k_hw *hw = &interface->hw;
1117 int i, err;
1118
Eyal Perry892311f2014-12-02 18:12:10 +02001119 /* We do not allow change in unsupported parameters */
1120 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1121 return -EOPNOTSUPP;
1122
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001123 err = fm10k_set_reta(netdev, indir);
1124 if (err || !key)
1125 return err;
1126
1127 for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4) {
1128 u32 rssrk = le32_to_cpu(*(__le32 *)key);
1129
1130 if (interface->rssrk[i] == rssrk)
1131 continue;
1132
1133 interface->rssrk[i] = rssrk;
1134 fm10k_write_reg(hw, FM10K_RSSRK(0, i), rssrk);
1135 }
1136
1137 return 0;
1138}
1139
Alexander Duyckaa3ac822014-09-20 19:50:42 -04001140static unsigned int fm10k_max_channels(struct net_device *dev)
1141{
1142 struct fm10k_intfc *interface = netdev_priv(dev);
1143 unsigned int max_combined = interface->hw.mac.max_queues;
1144 u8 tcs = netdev_get_num_tc(dev);
1145
1146 /* For QoS report channels per traffic class */
1147 if (tcs > 1)
1148 max_combined = 1 << (fls(max_combined / tcs) - 1);
1149
1150 return max_combined;
1151}
1152
1153static void fm10k_get_channels(struct net_device *dev,
1154 struct ethtool_channels *ch)
1155{
1156 struct fm10k_intfc *interface = netdev_priv(dev);
1157 struct fm10k_hw *hw = &interface->hw;
1158
1159 /* report maximum channels */
1160 ch->max_combined = fm10k_max_channels(dev);
1161
1162 /* report info for other vector */
1163 ch->max_other = NON_Q_VECTORS(hw);
1164 ch->other_count = ch->max_other;
1165
1166 /* record RSS queues */
1167 ch->combined_count = interface->ring_feature[RING_F_RSS].indices;
1168}
1169
1170static int fm10k_set_channels(struct net_device *dev,
1171 struct ethtool_channels *ch)
1172{
1173 struct fm10k_intfc *interface = netdev_priv(dev);
1174 unsigned int count = ch->combined_count;
1175 struct fm10k_hw *hw = &interface->hw;
1176
1177 /* verify they are not requesting separate vectors */
1178 if (!count || ch->rx_count || ch->tx_count)
1179 return -EINVAL;
1180
1181 /* verify other_count has not changed */
1182 if (ch->other_count != NON_Q_VECTORS(hw))
1183 return -EINVAL;
1184
1185 /* verify the number of channels does not exceed hardware limits */
1186 if (count > fm10k_max_channels(dev))
1187 return -EINVAL;
1188
1189 interface->ring_feature[RING_F_RSS].limit = count;
1190
1191 /* use setup TC to update any traffic class queue mapping */
1192 return fm10k_setup_tc(dev, netdev_get_num_tc(dev));
1193}
1194
Alexander Duycka211e012014-09-20 19:54:07 -04001195static int fm10k_get_ts_info(struct net_device *dev,
Matthew Vickeca32042015-01-31 02:23:05 +00001196 struct ethtool_ts_info *info)
Alexander Duycka211e012014-09-20 19:54:07 -04001197{
1198 struct fm10k_intfc *interface = netdev_priv(dev);
1199
1200 info->so_timestamping =
1201 SOF_TIMESTAMPING_TX_SOFTWARE |
1202 SOF_TIMESTAMPING_RX_SOFTWARE |
1203 SOF_TIMESTAMPING_SOFTWARE |
1204 SOF_TIMESTAMPING_TX_HARDWARE |
1205 SOF_TIMESTAMPING_RX_HARDWARE |
1206 SOF_TIMESTAMPING_RAW_HARDWARE;
1207
1208 if (interface->ptp_clock)
1209 info->phc_index = ptp_clock_index(interface->ptp_clock);
1210 else
1211 info->phc_index = -1;
1212
1213 info->tx_types = (1 << HWTSTAMP_TX_OFF) |
1214 (1 << HWTSTAMP_TX_ON);
1215
1216 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1217 (1 << HWTSTAMP_FILTER_ALL);
1218
1219 return 0;
1220}
1221
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001222static const struct ethtool_ops fm10k_ethtool_ops = {
1223 .get_strings = fm10k_get_strings,
1224 .get_sset_count = fm10k_get_sset_count,
1225 .get_ethtool_stats = fm10k_get_ethtool_stats,
1226 .get_drvinfo = fm10k_get_drvinfo,
1227 .get_link = ethtool_op_get_link,
1228 .get_pauseparam = fm10k_get_pauseparam,
1229 .set_pauseparam = fm10k_set_pauseparam,
1230 .get_msglevel = fm10k_get_msglevel,
1231 .set_msglevel = fm10k_set_msglevel,
1232 .get_ringparam = fm10k_get_ringparam,
1233 .set_ringparam = fm10k_set_ringparam,
1234 .get_coalesce = fm10k_get_coalesce,
1235 .set_coalesce = fm10k_set_coalesce,
1236 .get_rxnfc = fm10k_get_rxnfc,
1237 .set_rxnfc = fm10k_set_rxnfc,
1238 .get_regs = fm10k_get_regs,
1239 .get_regs_len = fm10k_get_regs_len,
Alexander Duyck5cb8db42014-09-20 19:51:40 -04001240 .self_test = fm10k_self_test,
Jacob Keller80043f32015-07-01 17:38:36 -07001241 .get_priv_flags = fm10k_get_priv_flags,
1242 .set_priv_flags = fm10k_set_priv_flags,
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001243 .get_rxfh_indir_size = fm10k_get_reta_size,
1244 .get_rxfh_key_size = fm10k_get_rssrk_size,
1245 .get_rxfh = fm10k_get_rssh,
1246 .set_rxfh = fm10k_set_rssh,
Alexander Duyckaa3ac822014-09-20 19:50:42 -04001247 .get_channels = fm10k_get_channels,
1248 .set_channels = fm10k_set_channels,
Alexander Duycka211e012014-09-20 19:54:07 -04001249 .get_ts_info = fm10k_get_ts_info,
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001250};
1251
1252void fm10k_set_ethtool_ops(struct net_device *dev)
1253{
1254 dev->ethtool_ops = &fm10k_ethtool_ops;
1255}