fm10k: add statistics for actual DWORD count of mbmem mailbox
[deliverable/linux.git] / drivers / net / ethernet / intel / fm10k / fm10k_ethtool.c
CommitLineData
82dd0f7e 1/* Intel Ethernet Switch Host Interface Driver
97c71e3c 2 * Copyright(c) 2013 - 2015 Intel Corporation.
82dd0f7e
AD
3 *
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
eb51bbaf
SR
21#include <linux/vmalloc.h>
22
82dd0f7e
AD
23#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
fbdb159f 60static const struct fm10k_stats fm10k_gstrings_global_stats[] = {
82dd0f7e
AD
61 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),
82dd0f7e
AD
66
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
82dd0f7e
AD
75 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
e05546ec
JK
79 FM10K_STAT("tx_hang_count", tx_timeout_count),
80
a211e013 81 FM10K_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
82dd0f7e
AD
82};
83
80043f3b
JK
84static 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
fbdb159f
JK
95static 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
80043f3b
JK
106#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),
17d39fac 117 FM10K_MBX_STAT("mbx_tx_mbmem_pulled", tx_mbmem_pulled),
80043f3b
JK
118 FM10K_MBX_STAT("mbx_rx_messages", rx_messages),
119 FM10K_MBX_STAT("mbx_rx_dwords", rx_dwords),
120 FM10K_MBX_STAT("mbx_rx_parse_err", rx_parse_err),
17d39fac 121 FM10K_MBX_STAT("mbx_rx_mbmem_pushed", rx_mbmem_pushed),
80043f3b
JK
122};
123
fbdb159f 124#define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats)
80043f3b 125#define FM10K_DEBUG_STATS_LEN ARRAY_SIZE(fm10k_gstrings_debug_stats)
fbdb159f 126#define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats)
80043f3b 127#define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats)
82dd0f7e 128
c0e61781
JK
129#define FM10K_QUEUE_STATS_LEN(_n) \
130 ( (_n) * 2 * (sizeof(struct fm10k_queue_stats) / sizeof(u64)))
82dd0f7e 131
c0e61781 132#define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
80043f3b
JK
133 FM10K_NETDEV_STATS_LEN + \
134 FM10K_MBX_STATS_LEN)
82dd0f7e 135
5cb8db4a
AD
136static const char fm10k_gstrings_test[][ETH_GSTRING_LEN] = {
137 "Mailbox test (on/offline)"
138};
139
140#define FM10K_TEST_LEN (sizeof(fm10k_gstrings_test) / ETH_GSTRING_LEN)
141
142enum fm10k_self_test_types {
143 FM10K_TEST_MBX,
144 FM10K_TEST_MAX = FM10K_TEST_LEN
145};
146
80043f3b
JK
147enum {
148 FM10K_PRV_FLAG_DEBUG_STATS,
149 FM10K_PRV_FLAG_LEN,
150};
151
152static const char fm10k_prv_flags[FM10K_PRV_FLAG_LEN][ETH_GSTRING_LEN] = {
153 "debug-statistics",
154};
155
156static void fm10k_get_stat_strings(struct net_device *dev, u8 *data)
82dd0f7e 157{
29a928ee 158 struct fm10k_intfc *interface = netdev_priv(dev);
80043f3b 159 struct fm10k_iov_data *iov_data = interface->iov_data;
82dd0f7e 160 char *p = (char *)data;
c0e58e93 161 unsigned int i;
80043f3b 162 unsigned int j;
82dd0f7e 163
80043f3b
JK
164 for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) {
165 memcpy(p, fm10k_gstrings_net_stats[i].stat_string,
166 ETH_GSTRING_LEN);
167 p += ETH_GSTRING_LEN;
168 }
169
170 for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) {
171 memcpy(p, fm10k_gstrings_global_stats[i].stat_string,
172 ETH_GSTRING_LEN);
173 p += ETH_GSTRING_LEN;
174 }
175
176 if (interface->flags & FM10K_FLAG_DEBUG_STATS) {
177 for (i = 0; i < FM10K_DEBUG_STATS_LEN; i++) {
178 memcpy(p, fm10k_gstrings_debug_stats[i].stat_string,
82dd0f7e
AD
179 ETH_GSTRING_LEN);
180 p += ETH_GSTRING_LEN;
181 }
80043f3b
JK
182 }
183
184 for (i = 0; i < FM10K_MBX_STATS_LEN; i++) {
185 memcpy(p, fm10k_gstrings_mbx_stats[i].stat_string,
186 ETH_GSTRING_LEN);
187 p += ETH_GSTRING_LEN;
188 }
189
190 if (interface->hw.mac.type != fm10k_mac_vf) {
191 for (i = 0; i < FM10K_PF_STATS_LEN; i++) {
192 memcpy(p, fm10k_gstrings_pf_stats[i].stat_string,
82dd0f7e
AD
193 ETH_GSTRING_LEN);
194 p += ETH_GSTRING_LEN;
195 }
80043f3b 196 }
82dd0f7e 197
80043f3b
JK
198 if ((interface->flags & FM10K_FLAG_DEBUG_STATS) && iov_data) {
199 for (i = 0; i < iov_data->num_vfs; i++) {
200 for (j = 0; j < FM10K_MBX_STATS_LEN; j++) {
201 snprintf(p,
202 ETH_GSTRING_LEN,
203 "vf_%u_%s", i,
204 fm10k_gstrings_mbx_stats[j].stat_string);
fbdb159f
JK
205 p += ETH_GSTRING_LEN;
206 }
986eec43 207 }
80043f3b 208 }
fbdb159f 209
80043f3b 210 for (i = 0; i < interface->hw.mac.max_queues; i++) {
f6f19f8b 211 snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_packets", i);
80043f3b 212 p += ETH_GSTRING_LEN;
f6f19f8b 213 snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
80043f3b 214 p += ETH_GSTRING_LEN;
f6f19f8b 215 snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_packets", i);
80043f3b 216 p += ETH_GSTRING_LEN;
f6f19f8b 217 snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
80043f3b
JK
218 p += ETH_GSTRING_LEN;
219 }
220}
221
222static void fm10k_get_strings(struct net_device *dev,
223 u32 stringset, u8 *data)
224{
225 char *p = (char *)data;
226
227 switch (stringset) {
228 case ETH_SS_TEST:
229 memcpy(data, *fm10k_gstrings_test,
230 FM10K_TEST_LEN * ETH_GSTRING_LEN);
231 break;
232 case ETH_SS_STATS:
233 fm10k_get_stat_strings(dev, data);
234 break;
235 case ETH_SS_PRIV_FLAGS:
236 memcpy(p, fm10k_prv_flags,
237 FM10K_PRV_FLAG_LEN * ETH_GSTRING_LEN);
82dd0f7e
AD
238 break;
239 }
240}
241
242static int fm10k_get_sset_count(struct net_device *dev, int sset)
243{
c0e61781 244 struct fm10k_intfc *interface = netdev_priv(dev);
80043f3b 245 struct fm10k_iov_data *iov_data = interface->iov_data;
c0e61781
JK
246 struct fm10k_hw *hw = &interface->hw;
247 int stats_len = FM10K_STATIC_STATS_LEN;
248
82dd0f7e 249 switch (sset) {
5cb8db4a
AD
250 case ETH_SS_TEST:
251 return FM10K_TEST_LEN;
82dd0f7e 252 case ETH_SS_STATS:
c0e61781 253 stats_len += FM10K_QUEUE_STATS_LEN(hw->mac.max_queues);
fbdb159f
JK
254
255 if (hw->mac.type != fm10k_mac_vf)
256 stats_len += FM10K_PF_STATS_LEN;
257
80043f3b
JK
258 if (interface->flags & FM10K_FLAG_DEBUG_STATS) {
259 stats_len += FM10K_DEBUG_STATS_LEN;
260
261 if (iov_data)
262 stats_len += FM10K_MBX_STATS_LEN * iov_data->num_vfs;
263 }
264
c0e61781 265 return stats_len;
80043f3b
JK
266 case ETH_SS_PRIV_FLAGS:
267 return FM10K_PRV_FLAG_LEN;
82dd0f7e
AD
268 default:
269 return -EOPNOTSUPP;
270 }
271}
272
273static void fm10k_get_ethtool_stats(struct net_device *netdev,
de445199
JK
274 struct ethtool_stats __always_unused *stats,
275 u64 *data)
82dd0f7e
AD
276{
277 const int stat_count = sizeof(struct fm10k_queue_stats) / sizeof(u64);
278 struct fm10k_intfc *interface = netdev_priv(netdev);
80043f3b 279 struct fm10k_iov_data *iov_data = interface->iov_data;
82dd0f7e
AD
280 struct net_device_stats *net_stats = &netdev->stats;
281 char *p;
282 int i, j;
283
284 fm10k_update_stats(interface);
285
286 for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) {
287 p = (char *)net_stats + fm10k_gstrings_net_stats[i].stat_offset;
288 *(data++) = (fm10k_gstrings_net_stats[i].sizeof_stat ==
289 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
290 }
291
292 for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) {
fbdb159f
JK
293 p = (char *)interface +
294 fm10k_gstrings_global_stats[i].stat_offset;
295 *(data++) = (fm10k_gstrings_global_stats[i].sizeof_stat ==
82dd0f7e
AD
296 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
297 }
298
80043f3b
JK
299 if (interface->flags & FM10K_FLAG_DEBUG_STATS) {
300 for (i = 0; i < FM10K_DEBUG_STATS_LEN; i++) {
301 p = (char *)interface + fm10k_gstrings_debug_stats[i].stat_offset;
302 *(data++) = (fm10k_gstrings_debug_stats[i].sizeof_stat ==
303 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
304 }
305 }
306
307 for (i = 0; i < FM10K_MBX_STATS_LEN; i++) {
308 p = (char *)&interface->hw.mbx + fm10k_gstrings_mbx_stats[i].stat_offset;
309 *(data++) = (fm10k_gstrings_mbx_stats[i].sizeof_stat ==
310 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
311 }
312
313 if (interface->hw.mac.type != fm10k_mac_vf) {
fbdb159f
JK
314 for (i = 0; i < FM10K_PF_STATS_LEN; i++) {
315 p = (char *)interface +
316 fm10k_gstrings_pf_stats[i].stat_offset;
317 *(data++) = (fm10k_gstrings_pf_stats[i].sizeof_stat ==
318 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
319 }
80043f3b
JK
320 }
321
322 if ((interface->flags & FM10K_FLAG_DEBUG_STATS) && iov_data) {
323 for (i = 0; i < iov_data->num_vfs; i++) {
324 struct fm10k_vf_info *vf_info;
325 vf_info = &iov_data->vf_info[i];
326
327 /* skip stats if we don't have a vf info */
328 if (!vf_info) {
329 data += FM10K_MBX_STATS_LEN;
330 continue;
331 }
332
333 for (j = 0; j < FM10K_MBX_STATS_LEN; j++) {
334 p = (char *)&vf_info->mbx + fm10k_gstrings_mbx_stats[j].stat_offset;
335 *(data++) = (fm10k_gstrings_mbx_stats[j].sizeof_stat ==
336 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
337 }
338 }
339 }
fbdb159f 340
29a928ee 341 for (i = 0; i < interface->hw.mac.max_queues; i++) {
82dd0f7e
AD
342 struct fm10k_ring *ring;
343 u64 *queue_stat;
344
345 ring = interface->tx_ring[i];
346 if (ring)
347 queue_stat = (u64 *)&ring->stats;
348 for (j = 0; j < stat_count; j++)
349 *(data++) = ring ? queue_stat[j] : 0;
350
351 ring = interface->rx_ring[i];
352 if (ring)
353 queue_stat = (u64 *)&ring->stats;
354 for (j = 0; j < stat_count; j++)
355 *(data++) = ring ? queue_stat[j] : 0;
356 }
357}
358
359/* If function below adds more registers this define needs to be updated */
360#define FM10K_REGS_LEN_Q 29
361
362static void fm10k_get_reg_q(struct fm10k_hw *hw, u32 *buff, int i)
363{
364 int idx = 0;
365
366 buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAL(i));
367 buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAH(i));
368 buff[idx++] = fm10k_read_reg(hw, FM10K_RDLEN(i));
369 buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_RXCTRL(i));
370 buff[idx++] = fm10k_read_reg(hw, FM10K_RDH(i));
371 buff[idx++] = fm10k_read_reg(hw, FM10K_RDT(i));
372 buff[idx++] = fm10k_read_reg(hw, FM10K_RXQCTL(i));
373 buff[idx++] = fm10k_read_reg(hw, FM10K_RXDCTL(i));
374 buff[idx++] = fm10k_read_reg(hw, FM10K_RXINT(i));
375 buff[idx++] = fm10k_read_reg(hw, FM10K_SRRCTL(i));
376 buff[idx++] = fm10k_read_reg(hw, FM10K_QPRC(i));
377 buff[idx++] = fm10k_read_reg(hw, FM10K_QPRDC(i));
378 buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_L(i));
379 buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_H(i));
380 buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAL(i));
381 buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAH(i));
382 buff[idx++] = fm10k_read_reg(hw, FM10K_TDLEN(i));
383 buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_TXCTRL(i));
384 buff[idx++] = fm10k_read_reg(hw, FM10K_TDH(i));
385 buff[idx++] = fm10k_read_reg(hw, FM10K_TDT(i));
386 buff[idx++] = fm10k_read_reg(hw, FM10K_TXDCTL(i));
387 buff[idx++] = fm10k_read_reg(hw, FM10K_TXQCTL(i));
388 buff[idx++] = fm10k_read_reg(hw, FM10K_TXINT(i));
389 buff[idx++] = fm10k_read_reg(hw, FM10K_QPTC(i));
390 buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_L(i));
391 buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_H(i));
392 buff[idx++] = fm10k_read_reg(hw, FM10K_TQDLOC(i));
393 buff[idx++] = fm10k_read_reg(hw, FM10K_TX_SGLORT(i));
394 buff[idx++] = fm10k_read_reg(hw, FM10K_PFVTCTL(i));
395
396 BUG_ON(idx != FM10K_REGS_LEN_Q);
397}
398
399/* If function above adds more registers this define needs to be updated */
400#define FM10K_REGS_LEN_VSI 43
401
402static void fm10k_get_reg_vsi(struct fm10k_hw *hw, u32 *buff, int i)
403{
404 int idx = 0, j;
405
406 buff[idx++] = fm10k_read_reg(hw, FM10K_MRQC(i));
407 for (j = 0; j < 10; j++)
408 buff[idx++] = fm10k_read_reg(hw, FM10K_RSSRK(i, j));
409 for (j = 0; j < 32; j++)
410 buff[idx++] = fm10k_read_reg(hw, FM10K_RETA(i, j));
411
412 BUG_ON(idx != FM10K_REGS_LEN_VSI);
413}
414
415static void fm10k_get_regs(struct net_device *netdev,
416 struct ethtool_regs *regs, void *p)
417{
418 struct fm10k_intfc *interface = netdev_priv(netdev);
419 struct fm10k_hw *hw = &interface->hw;
420 u32 *buff = p;
421 u16 i;
422
423 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
424
425 switch (hw->mac.type) {
426 case fm10k_mac_pf:
427 /* General PF Registers */
428 *(buff++) = fm10k_read_reg(hw, FM10K_CTRL);
429 *(buff++) = fm10k_read_reg(hw, FM10K_CTRL_EXT);
430 *(buff++) = fm10k_read_reg(hw, FM10K_GCR);
431 *(buff++) = fm10k_read_reg(hw, FM10K_GCR_EXT);
432
433 for (i = 0; i < 8; i++) {
434 *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTMAP(i));
435 *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTDEC(i));
436 }
437
438 for (i = 0; i < 65; i++) {
439 fm10k_get_reg_vsi(hw, buff, i);
440 buff += FM10K_REGS_LEN_VSI;
441 }
442
443 *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL);
444 *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL2);
445
446 for (i = 0; i < FM10K_MAX_QUEUES_PF; i++) {
447 fm10k_get_reg_q(hw, buff, i);
448 buff += FM10K_REGS_LEN_Q;
449 }
450
451 *(buff++) = fm10k_read_reg(hw, FM10K_TPH_CTRL);
452
453 for (i = 0; i < 8; i++)
454 *(buff++) = fm10k_read_reg(hw, FM10K_INT_MAP(i));
455
456 /* Interrupt Throttling Registers */
457 for (i = 0; i < 130; i++)
458 *(buff++) = fm10k_read_reg(hw, FM10K_ITR(i));
459
5cb8db4a
AD
460 break;
461 case fm10k_mac_vf:
462 /* General VF registers */
463 *(buff++) = fm10k_read_reg(hw, FM10K_VFCTRL);
464 *(buff++) = fm10k_read_reg(hw, FM10K_VFINT_MAP);
465 *(buff++) = fm10k_read_reg(hw, FM10K_VFSYSTIME);
466
467 /* Interrupt Throttling Registers */
468 for (i = 0; i < 8; i++)
469 *(buff++) = fm10k_read_reg(hw, FM10K_VFITR(i));
470
471 fm10k_get_reg_vsi(hw, buff, 0);
472 buff += FM10K_REGS_LEN_VSI;
473
474 for (i = 0; i < FM10K_MAX_QUEUES_POOL; i++) {
475 if (i < hw->mac.max_queues)
476 fm10k_get_reg_q(hw, buff, i);
477 else
478 memset(buff, 0, sizeof(u32) * FM10K_REGS_LEN_Q);
479 buff += FM10K_REGS_LEN_Q;
480 }
481
82dd0f7e
AD
482 break;
483 default:
484 return;
485 }
486}
487
488/* If function above adds more registers these define need to be updated */
489#define FM10K_REGS_LEN_PF \
490(162 + (65 * FM10K_REGS_LEN_VSI) + (FM10K_MAX_QUEUES_PF * FM10K_REGS_LEN_Q))
5cb8db4a
AD
491#define FM10K_REGS_LEN_VF \
492(11 + FM10K_REGS_LEN_VSI + (FM10K_MAX_QUEUES_POOL * FM10K_REGS_LEN_Q))
82dd0f7e
AD
493
494static int fm10k_get_regs_len(struct net_device *netdev)
495{
496 struct fm10k_intfc *interface = netdev_priv(netdev);
497 struct fm10k_hw *hw = &interface->hw;
498
499 switch (hw->mac.type) {
500 case fm10k_mac_pf:
501 return FM10K_REGS_LEN_PF * sizeof(u32);
5cb8db4a
AD
502 case fm10k_mac_vf:
503 return FM10K_REGS_LEN_VF * sizeof(u32);
82dd0f7e
AD
504 default:
505 return 0;
506 }
507}
508
509static void fm10k_get_drvinfo(struct net_device *dev,
510 struct ethtool_drvinfo *info)
511{
512 struct fm10k_intfc *interface = netdev_priv(dev);
513
514 strncpy(info->driver, fm10k_driver_name,
515 sizeof(info->driver) - 1);
516 strncpy(info->version, fm10k_driver_version,
517 sizeof(info->version) - 1);
518 strncpy(info->bus_info, pci_name(interface->pdev),
519 sizeof(info->bus_info) - 1);
82dd0f7e
AD
520}
521
522static void fm10k_get_pauseparam(struct net_device *dev,
523 struct ethtool_pauseparam *pause)
524{
525 struct fm10k_intfc *interface = netdev_priv(dev);
526
527 /* record fixed values for autoneg and tx pause */
528 pause->autoneg = 0;
529 pause->tx_pause = 1;
530
531 pause->rx_pause = interface->rx_pause ? 1 : 0;
532}
533
534static int fm10k_set_pauseparam(struct net_device *dev,
535 struct ethtool_pauseparam *pause)
536{
537 struct fm10k_intfc *interface = netdev_priv(dev);
538 struct fm10k_hw *hw = &interface->hw;
539
540 if (pause->autoneg || !pause->tx_pause)
541 return -EINVAL;
542
543 /* we can only support pause on the PF to avoid head-of-line blocking */
544 if (hw->mac.type == fm10k_mac_pf)
545 interface->rx_pause = pause->rx_pause ? ~0 : 0;
546 else if (pause->rx_pause)
547 return -EINVAL;
548
549 if (netif_running(dev))
550 fm10k_update_rx_drop_en(interface);
551
552 return 0;
553}
554
555static u32 fm10k_get_msglevel(struct net_device *netdev)
556{
557 struct fm10k_intfc *interface = netdev_priv(netdev);
558
559 return interface->msg_enable;
560}
561
562static void fm10k_set_msglevel(struct net_device *netdev, u32 data)
563{
564 struct fm10k_intfc *interface = netdev_priv(netdev);
565
566 interface->msg_enable = data;
567}
568
569static void fm10k_get_ringparam(struct net_device *netdev,
570 struct ethtool_ringparam *ring)
571{
572 struct fm10k_intfc *interface = netdev_priv(netdev);
573
574 ring->rx_max_pending = FM10K_MAX_RXD;
575 ring->tx_max_pending = FM10K_MAX_TXD;
576 ring->rx_mini_max_pending = 0;
577 ring->rx_jumbo_max_pending = 0;
578 ring->rx_pending = interface->rx_ring_count;
579 ring->tx_pending = interface->tx_ring_count;
580 ring->rx_mini_pending = 0;
581 ring->rx_jumbo_pending = 0;
582}
583
584static int fm10k_set_ringparam(struct net_device *netdev,
585 struct ethtool_ringparam *ring)
586{
587 struct fm10k_intfc *interface = netdev_priv(netdev);
588 struct fm10k_ring *temp_ring;
589 int i, err = 0;
590 u32 new_rx_count, new_tx_count;
591
592 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
593 return -EINVAL;
594
595 new_tx_count = clamp_t(u32, ring->tx_pending,
596 FM10K_MIN_TXD, FM10K_MAX_TXD);
597 new_tx_count = ALIGN(new_tx_count, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE);
598
599 new_rx_count = clamp_t(u32, ring->rx_pending,
600 FM10K_MIN_RXD, FM10K_MAX_RXD);
601 new_rx_count = ALIGN(new_rx_count, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE);
602
603 if ((new_tx_count == interface->tx_ring_count) &&
604 (new_rx_count == interface->rx_ring_count)) {
605 /* nothing to do */
606 return 0;
607 }
608
609 while (test_and_set_bit(__FM10K_RESETTING, &interface->state))
610 usleep_range(1000, 2000);
611
612 if (!netif_running(interface->netdev)) {
613 for (i = 0; i < interface->num_tx_queues; i++)
614 interface->tx_ring[i]->count = new_tx_count;
615 for (i = 0; i < interface->num_rx_queues; i++)
616 interface->rx_ring[i]->count = new_rx_count;
617 interface->tx_ring_count = new_tx_count;
618 interface->rx_ring_count = new_rx_count;
619 goto clear_reset;
620 }
621
622 /* allocate temporary buffer to store rings in */
623 i = max_t(int, interface->num_tx_queues, interface->num_rx_queues);
624 temp_ring = vmalloc(i * sizeof(struct fm10k_ring));
625
626 if (!temp_ring) {
627 err = -ENOMEM;
628 goto clear_reset;
629 }
630
631 fm10k_down(interface);
632
633 /* Setup new Tx resources and free the old Tx resources in that order.
634 * We can then assign the new resources to the rings via a memcpy.
635 * The advantage to this approach is that we are guaranteed to still
636 * have resources even in the case of an allocation failure.
637 */
638 if (new_tx_count != interface->tx_ring_count) {
639 for (i = 0; i < interface->num_tx_queues; i++) {
640 memcpy(&temp_ring[i], interface->tx_ring[i],
641 sizeof(struct fm10k_ring));
642
643 temp_ring[i].count = new_tx_count;
644 err = fm10k_setup_tx_resources(&temp_ring[i]);
645 if (err) {
646 while (i) {
647 i--;
648 fm10k_free_tx_resources(&temp_ring[i]);
649 }
650 goto err_setup;
651 }
652 }
653
654 for (i = 0; i < interface->num_tx_queues; i++) {
655 fm10k_free_tx_resources(interface->tx_ring[i]);
656
657 memcpy(interface->tx_ring[i], &temp_ring[i],
658 sizeof(struct fm10k_ring));
659 }
660
661 interface->tx_ring_count = new_tx_count;
662 }
663
664 /* Repeat the process for the Rx rings if needed */
665 if (new_rx_count != interface->rx_ring_count) {
666 for (i = 0; i < interface->num_rx_queues; i++) {
667 memcpy(&temp_ring[i], interface->rx_ring[i],
668 sizeof(struct fm10k_ring));
669
670 temp_ring[i].count = new_rx_count;
671 err = fm10k_setup_rx_resources(&temp_ring[i]);
672 if (err) {
673 while (i) {
674 i--;
675 fm10k_free_rx_resources(&temp_ring[i]);
676 }
677 goto err_setup;
678 }
679 }
680
681 for (i = 0; i < interface->num_rx_queues; i++) {
682 fm10k_free_rx_resources(interface->rx_ring[i]);
683
684 memcpy(interface->rx_ring[i], &temp_ring[i],
685 sizeof(struct fm10k_ring));
686 }
687
688 interface->rx_ring_count = new_rx_count;
689 }
690
691err_setup:
692 fm10k_up(interface);
693 vfree(temp_ring);
694clear_reset:
695 clear_bit(__FM10K_RESETTING, &interface->state);
696 return err;
697}
698
699static int fm10k_get_coalesce(struct net_device *dev,
700 struct ethtool_coalesce *ec)
701{
702 struct fm10k_intfc *interface = netdev_priv(dev);
703
704 ec->use_adaptive_tx_coalesce =
705 !!(interface->tx_itr & FM10K_ITR_ADAPTIVE);
706 ec->tx_coalesce_usecs = interface->tx_itr & ~FM10K_ITR_ADAPTIVE;
707
708 ec->use_adaptive_rx_coalesce =
709 !!(interface->rx_itr & FM10K_ITR_ADAPTIVE);
710 ec->rx_coalesce_usecs = interface->rx_itr & ~FM10K_ITR_ADAPTIVE;
711
712 return 0;
713}
714
715static int fm10k_set_coalesce(struct net_device *dev,
716 struct ethtool_coalesce *ec)
717{
718 struct fm10k_intfc *interface = netdev_priv(dev);
719 struct fm10k_q_vector *qv;
720 u16 tx_itr, rx_itr;
721 int i;
722
723 /* verify limits */
724 if ((ec->rx_coalesce_usecs > FM10K_ITR_MAX) ||
725 (ec->tx_coalesce_usecs > FM10K_ITR_MAX))
726 return -EINVAL;
727
728 /* record settings */
729 tx_itr = ec->tx_coalesce_usecs;
730 rx_itr = ec->rx_coalesce_usecs;
731
732 /* set initial values for adaptive ITR */
733 if (ec->use_adaptive_tx_coalesce)
734 tx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_10K;
735
736 if (ec->use_adaptive_rx_coalesce)
737 rx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_20K;
738
739 /* update interface */
740 interface->tx_itr = tx_itr;
741 interface->rx_itr = rx_itr;
742
743 /* update q_vectors */
744 for (i = 0; i < interface->num_q_vectors; i++) {
745 qv = interface->q_vector[i];
746 qv->tx.itr = tx_itr;
747 qv->rx.itr = rx_itr;
748 }
749
750 return 0;
751}
752
753static int fm10k_get_rss_hash_opts(struct fm10k_intfc *interface,
754 struct ethtool_rxnfc *cmd)
755{
756 cmd->data = 0;
757
758 /* Report default options for RSS on fm10k */
759 switch (cmd->flow_type) {
760 case TCP_V4_FLOW:
761 case TCP_V6_FLOW:
762 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
763 /* fall through */
764 case UDP_V4_FLOW:
765 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
766 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
767 /* fall through */
768 case SCTP_V4_FLOW:
769 case SCTP_V6_FLOW:
770 case AH_ESP_V4_FLOW:
771 case AH_ESP_V6_FLOW:
772 case AH_V4_FLOW:
773 case AH_V6_FLOW:
774 case ESP_V4_FLOW:
775 case ESP_V6_FLOW:
776 case IPV4_FLOW:
777 case IPV6_FLOW:
778 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
779 break;
780 case UDP_V6_FLOW:
781 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
782 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
783 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
784 break;
785 default:
786 return -EINVAL;
787 }
788
789 return 0;
790}
791
792static int fm10k_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
de445199 793 u32 __always_unused *rule_locs)
82dd0f7e
AD
794{
795 struct fm10k_intfc *interface = netdev_priv(dev);
796 int ret = -EOPNOTSUPP;
797
798 switch (cmd->cmd) {
799 case ETHTOOL_GRXRINGS:
800 cmd->data = interface->num_rx_queues;
801 ret = 0;
802 break;
803 case ETHTOOL_GRXFH:
804 ret = fm10k_get_rss_hash_opts(interface, cmd);
805 break;
806 default:
807 break;
808 }
809
810 return ret;
811}
812
813#define UDP_RSS_FLAGS (FM10K_FLAG_RSS_FIELD_IPV4_UDP | \
814 FM10K_FLAG_RSS_FIELD_IPV6_UDP)
815static int fm10k_set_rss_hash_opt(struct fm10k_intfc *interface,
816 struct ethtool_rxnfc *nfc)
817{
818 u32 flags = interface->flags;
819
820 /* RSS does not support anything other than hashing
821 * to queues on src and dst IPs and ports
822 */
823 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
824 RXH_L4_B_0_1 | RXH_L4_B_2_3))
825 return -EINVAL;
826
827 switch (nfc->flow_type) {
828 case TCP_V4_FLOW:
829 case TCP_V6_FLOW:
830 if (!(nfc->data & RXH_IP_SRC) ||
831 !(nfc->data & RXH_IP_DST) ||
832 !(nfc->data & RXH_L4_B_0_1) ||
833 !(nfc->data & RXH_L4_B_2_3))
834 return -EINVAL;
835 break;
836 case UDP_V4_FLOW:
837 if (!(nfc->data & RXH_IP_SRC) ||
838 !(nfc->data & RXH_IP_DST))
839 return -EINVAL;
840 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
841 case 0:
842 flags &= ~FM10K_FLAG_RSS_FIELD_IPV4_UDP;
843 break;
844 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
845 flags |= FM10K_FLAG_RSS_FIELD_IPV4_UDP;
846 break;
847 default:
848 return -EINVAL;
849 }
850 break;
851 case UDP_V6_FLOW:
852 if (!(nfc->data & RXH_IP_SRC) ||
853 !(nfc->data & RXH_IP_DST))
854 return -EINVAL;
855 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
856 case 0:
857 flags &= ~FM10K_FLAG_RSS_FIELD_IPV6_UDP;
858 break;
859 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
860 flags |= FM10K_FLAG_RSS_FIELD_IPV6_UDP;
861 break;
862 default:
863 return -EINVAL;
864 }
865 break;
866 case AH_ESP_V4_FLOW:
867 case AH_V4_FLOW:
868 case ESP_V4_FLOW:
869 case SCTP_V4_FLOW:
870 case AH_ESP_V6_FLOW:
871 case AH_V6_FLOW:
872 case ESP_V6_FLOW:
873 case SCTP_V6_FLOW:
874 if (!(nfc->data & RXH_IP_SRC) ||
875 !(nfc->data & RXH_IP_DST) ||
876 (nfc->data & RXH_L4_B_0_1) ||
877 (nfc->data & RXH_L4_B_2_3))
878 return -EINVAL;
879 break;
880 default:
881 return -EINVAL;
882 }
883
884 /* if we changed something we need to update flags */
885 if (flags != interface->flags) {
886 struct fm10k_hw *hw = &interface->hw;
887 u32 mrqc;
888
889 if ((flags & UDP_RSS_FLAGS) &&
890 !(interface->flags & UDP_RSS_FLAGS))
891 netif_warn(interface, drv, interface->netdev,
892 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
893
894 interface->flags = flags;
895
896 /* Perform hash on these packet types */
897 mrqc = FM10K_MRQC_IPV4 |
898 FM10K_MRQC_TCP_IPV4 |
899 FM10K_MRQC_IPV6 |
900 FM10K_MRQC_TCP_IPV6;
901
902 if (flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
903 mrqc |= FM10K_MRQC_UDP_IPV4;
904 if (flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
905 mrqc |= FM10K_MRQC_UDP_IPV6;
906
907 fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
908 }
909
910 return 0;
911}
912
913static int fm10k_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
914{
915 struct fm10k_intfc *interface = netdev_priv(dev);
916 int ret = -EOPNOTSUPP;
917
918 switch (cmd->cmd) {
919 case ETHTOOL_SRXFH:
920 ret = fm10k_set_rss_hash_opt(interface, cmd);
921 break;
922 default:
923 break;
924 }
925
926 return ret;
927}
928
5cb8db4a
AD
929static int fm10k_mbx_test(struct fm10k_intfc *interface, u64 *data)
930{
931 struct fm10k_hw *hw = &interface->hw;
932 struct fm10k_mbx_info *mbx = &hw->mbx;
933 u32 attr_flag, test_msg[6];
934 unsigned long timeout;
935 int err;
936
937 /* For now this is a VF only feature */
938 if (hw->mac.type != fm10k_mac_vf)
939 return 0;
940
941 /* loop through both nested and unnested attribute types */
942 for (attr_flag = (1 << FM10K_TEST_MSG_UNSET);
943 attr_flag < (1 << (2 * FM10K_TEST_MSG_NESTED));
944 attr_flag += attr_flag) {
945 /* generate message to be tested */
946 fm10k_tlv_msg_test_create(test_msg, attr_flag);
947
948 fm10k_mbx_lock(interface);
949 mbx->test_result = FM10K_NOT_IMPLEMENTED;
950 err = mbx->ops.enqueue_tx(hw, mbx, test_msg);
951 fm10k_mbx_unlock(interface);
952
953 /* wait up to 1 second for response */
954 timeout = jiffies + HZ;
955 do {
956 if (err < 0)
957 goto err_out;
958
959 usleep_range(500, 1000);
960
961 fm10k_mbx_lock(interface);
962 mbx->ops.process(hw, mbx);
963 fm10k_mbx_unlock(interface);
964
965 err = mbx->test_result;
966 if (!err)
967 break;
968 } while (time_is_after_jiffies(timeout));
969
970 /* reporting errors */
971 if (err)
972 goto err_out;
973 }
974
975err_out:
976 *data = err < 0 ? (attr_flag) : (err > 0);
977 return err;
978}
979
980static void fm10k_self_test(struct net_device *dev,
981 struct ethtool_test *eth_test, u64 *data)
982{
983 struct fm10k_intfc *interface = netdev_priv(dev);
984 struct fm10k_hw *hw = &interface->hw;
985
986 memset(data, 0, sizeof(*data) * FM10K_TEST_LEN);
987
988 if (FM10K_REMOVED(hw)) {
989 netif_err(interface, drv, dev,
990 "Interface removed - test blocked\n");
991 eth_test->flags |= ETH_TEST_FL_FAILED;
992 return;
993 }
994
995 if (fm10k_mbx_test(interface, &data[FM10K_TEST_MBX]))
996 eth_test->flags |= ETH_TEST_FL_FAILED;
997}
998
80043f3b
JK
999static u32 fm10k_get_priv_flags(struct net_device *netdev)
1000{
1001 struct fm10k_intfc *interface = netdev_priv(netdev);
1002 u32 priv_flags = 0;
1003
1004 if (interface->flags & FM10K_FLAG_DEBUG_STATS)
1005 priv_flags |= 1 << FM10K_PRV_FLAG_DEBUG_STATS;
1006
1007 return priv_flags;
1008}
1009
1010static int fm10k_set_priv_flags(struct net_device *netdev, u32 priv_flags)
1011{
1012 struct fm10k_intfc *interface = netdev_priv(netdev);
1013
1014 if (priv_flags >= (1 << FM10K_PRV_FLAG_LEN))
1015 return -EINVAL;
1016
1017 if (priv_flags & (1 << FM10K_PRV_FLAG_DEBUG_STATS))
1018 interface->flags |= FM10K_FLAG_DEBUG_STATS;
1019 else
1020 interface->flags &= ~FM10K_FLAG_DEBUG_STATS;
1021
1022 return 0;
1023}
1024
1025
de445199 1026static u32 fm10k_get_reta_size(struct net_device __always_unused *netdev)
82dd0f7e
AD
1027{
1028 return FM10K_RETA_SIZE * FM10K_RETA_ENTRIES_PER_REG;
1029}
1030
1031static int fm10k_get_reta(struct net_device *netdev, u32 *indir)
1032{
1033 struct fm10k_intfc *interface = netdev_priv(netdev);
1034 int i;
1035
1036 if (!indir)
1037 return 0;
1038
1039 for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
1040 u32 reta = interface->reta[i];
1041
1042 indir[0] = (reta << 24) >> 24;
1043 indir[1] = (reta << 16) >> 24;
1044 indir[2] = (reta << 8) >> 24;
1045 indir[3] = (reta) >> 24;
1046 }
1047
1048 return 0;
1049}
1050
1051static int fm10k_set_reta(struct net_device *netdev, const u32 *indir)
1052{
1053 struct fm10k_intfc *interface = netdev_priv(netdev);
1054 struct fm10k_hw *hw = &interface->hw;
1055 int i;
1056 u16 rss_i;
1057
1058 if (!indir)
1059 return 0;
1060
1061 /* Verify user input. */
1062 rss_i = interface->ring_feature[RING_F_RSS].indices;
1063 for (i = fm10k_get_reta_size(netdev); i--;) {
1064 if (indir[i] < rss_i)
1065 continue;
1066 return -EINVAL;
1067 }
1068
1069 /* record entries to reta table */
1070 for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
1071 u32 reta = indir[0] |
1072 (indir[1] << 8) |
1073 (indir[2] << 16) |
1074 (indir[3] << 24);
1075
1076 if (interface->reta[i] == reta)
1077 continue;
1078
1079 interface->reta[i] = reta;
1080 fm10k_write_reg(hw, FM10K_RETA(0, i), reta);
1081 }
1082
1083 return 0;
1084}
1085
de445199 1086static u32 fm10k_get_rssrk_size(struct net_device __always_unused *netdev)
82dd0f7e
AD
1087{
1088 return FM10K_RSSRK_SIZE * FM10K_RSSRK_ENTRIES_PER_REG;
1089}
1090
892311f6
EP
1091static int fm10k_get_rssh(struct net_device *netdev, u32 *indir, u8 *key,
1092 u8 *hfunc)
82dd0f7e
AD
1093{
1094 struct fm10k_intfc *interface = netdev_priv(netdev);
1095 int i, err;
1096
892311f6
EP
1097 if (hfunc)
1098 *hfunc = ETH_RSS_HASH_TOP;
1099
82dd0f7e
AD
1100 err = fm10k_get_reta(netdev, indir);
1101 if (err || !key)
1102 return err;
1103
1104 for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4)
1105 *(__le32 *)key = cpu_to_le32(interface->rssrk[i]);
1106
1107 return 0;
1108}
1109
1110static int fm10k_set_rssh(struct net_device *netdev, const u32 *indir,
892311f6 1111 const u8 *key, const u8 hfunc)
82dd0f7e
AD
1112{
1113 struct fm10k_intfc *interface = netdev_priv(netdev);
1114 struct fm10k_hw *hw = &interface->hw;
1115 int i, err;
1116
892311f6
EP
1117 /* We do not allow change in unsupported parameters */
1118 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1119 return -EOPNOTSUPP;
1120
82dd0f7e
AD
1121 err = fm10k_set_reta(netdev, indir);
1122 if (err || !key)
1123 return err;
1124
1125 for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4) {
1126 u32 rssrk = le32_to_cpu(*(__le32 *)key);
1127
1128 if (interface->rssrk[i] == rssrk)
1129 continue;
1130
1131 interface->rssrk[i] = rssrk;
1132 fm10k_write_reg(hw, FM10K_RSSRK(0, i), rssrk);
1133 }
1134
1135 return 0;
1136}
1137
aa3ac822
AD
1138static unsigned int fm10k_max_channels(struct net_device *dev)
1139{
1140 struct fm10k_intfc *interface = netdev_priv(dev);
1141 unsigned int max_combined = interface->hw.mac.max_queues;
1142 u8 tcs = netdev_get_num_tc(dev);
1143
1144 /* For QoS report channels per traffic class */
1145 if (tcs > 1)
1146 max_combined = 1 << (fls(max_combined / tcs) - 1);
1147
1148 return max_combined;
1149}
1150
1151static void fm10k_get_channels(struct net_device *dev,
1152 struct ethtool_channels *ch)
1153{
1154 struct fm10k_intfc *interface = netdev_priv(dev);
1155 struct fm10k_hw *hw = &interface->hw;
1156
1157 /* report maximum channels */
1158 ch->max_combined = fm10k_max_channels(dev);
1159
1160 /* report info for other vector */
1161 ch->max_other = NON_Q_VECTORS(hw);
1162 ch->other_count = ch->max_other;
1163
1164 /* record RSS queues */
1165 ch->combined_count = interface->ring_feature[RING_F_RSS].indices;
1166}
1167
1168static int fm10k_set_channels(struct net_device *dev,
1169 struct ethtool_channels *ch)
1170{
1171 struct fm10k_intfc *interface = netdev_priv(dev);
1172 unsigned int count = ch->combined_count;
1173 struct fm10k_hw *hw = &interface->hw;
1174
1175 /* verify they are not requesting separate vectors */
1176 if (!count || ch->rx_count || ch->tx_count)
1177 return -EINVAL;
1178
1179 /* verify other_count has not changed */
1180 if (ch->other_count != NON_Q_VECTORS(hw))
1181 return -EINVAL;
1182
1183 /* verify the number of channels does not exceed hardware limits */
1184 if (count > fm10k_max_channels(dev))
1185 return -EINVAL;
1186
1187 interface->ring_feature[RING_F_RSS].limit = count;
1188
1189 /* use setup TC to update any traffic class queue mapping */
1190 return fm10k_setup_tc(dev, netdev_get_num_tc(dev));
1191}
1192
a211e013 1193static int fm10k_get_ts_info(struct net_device *dev,
eca32047 1194 struct ethtool_ts_info *info)
a211e013
AD
1195{
1196 struct fm10k_intfc *interface = netdev_priv(dev);
1197
1198 info->so_timestamping =
1199 SOF_TIMESTAMPING_TX_SOFTWARE |
1200 SOF_TIMESTAMPING_RX_SOFTWARE |
1201 SOF_TIMESTAMPING_SOFTWARE |
1202 SOF_TIMESTAMPING_TX_HARDWARE |
1203 SOF_TIMESTAMPING_RX_HARDWARE |
1204 SOF_TIMESTAMPING_RAW_HARDWARE;
1205
1206 if (interface->ptp_clock)
1207 info->phc_index = ptp_clock_index(interface->ptp_clock);
1208 else
1209 info->phc_index = -1;
1210
1211 info->tx_types = (1 << HWTSTAMP_TX_OFF) |
1212 (1 << HWTSTAMP_TX_ON);
1213
1214 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1215 (1 << HWTSTAMP_FILTER_ALL);
1216
1217 return 0;
1218}
1219
82dd0f7e
AD
1220static const struct ethtool_ops fm10k_ethtool_ops = {
1221 .get_strings = fm10k_get_strings,
1222 .get_sset_count = fm10k_get_sset_count,
1223 .get_ethtool_stats = fm10k_get_ethtool_stats,
1224 .get_drvinfo = fm10k_get_drvinfo,
1225 .get_link = ethtool_op_get_link,
1226 .get_pauseparam = fm10k_get_pauseparam,
1227 .set_pauseparam = fm10k_set_pauseparam,
1228 .get_msglevel = fm10k_get_msglevel,
1229 .set_msglevel = fm10k_set_msglevel,
1230 .get_ringparam = fm10k_get_ringparam,
1231 .set_ringparam = fm10k_set_ringparam,
1232 .get_coalesce = fm10k_get_coalesce,
1233 .set_coalesce = fm10k_set_coalesce,
1234 .get_rxnfc = fm10k_get_rxnfc,
1235 .set_rxnfc = fm10k_set_rxnfc,
1236 .get_regs = fm10k_get_regs,
1237 .get_regs_len = fm10k_get_regs_len,
5cb8db4a 1238 .self_test = fm10k_self_test,
80043f3b
JK
1239 .get_priv_flags = fm10k_get_priv_flags,
1240 .set_priv_flags = fm10k_set_priv_flags,
82dd0f7e
AD
1241 .get_rxfh_indir_size = fm10k_get_reta_size,
1242 .get_rxfh_key_size = fm10k_get_rssrk_size,
1243 .get_rxfh = fm10k_get_rssh,
1244 .set_rxfh = fm10k_set_rssh,
aa3ac822
AD
1245 .get_channels = fm10k_get_channels,
1246 .set_channels = fm10k_set_channels,
a211e013 1247 .get_ts_info = fm10k_get_ts_info,
82dd0f7e
AD
1248};
1249
1250void fm10k_set_ethtool_ops(struct net_device *dev)
1251{
1252 dev->ethtool_ops = &fm10k_ethtool_ops;
1253}
This page took 0.184696 seconds and 5 git commands to generate.