blob: 3b857f46f6122c7edeec989ee7dd2b0909b91d5b [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),
Jacob Keller5680ea62015-10-16 10:57:03 -0700114 FM10K_MBX_STAT("mbx_tx_dropped", tx_dropped),
Jacob Keller80043f32015-07-01 17:38:36 -0700115 FM10K_MBX_STAT("mbx_tx_messages", tx_messages),
116 FM10K_MBX_STAT("mbx_tx_dwords", tx_dwords),
Jacob Keller17d39fa2015-10-16 10:57:02 -0700117 FM10K_MBX_STAT("mbx_tx_mbmem_pulled", tx_mbmem_pulled),
Jacob Keller80043f32015-07-01 17:38:36 -0700118 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),
Jacob Keller17d39fa2015-10-16 10:57:02 -0700121 FM10K_MBX_STAT("mbx_rx_mbmem_pushed", rx_mbmem_pushed),
Jacob Keller80043f32015-07-01 17:38:36 -0700122};
123
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700124#define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats)
Jacob Keller80043f32015-07-01 17:38:36 -0700125#define FM10K_DEBUG_STATS_LEN ARRAY_SIZE(fm10k_gstrings_debug_stats)
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700126#define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats)
Jacob Keller80043f32015-07-01 17:38:36 -0700127#define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400128
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700129#define FM10K_QUEUE_STATS_LEN(_n) \
Bruce Allana4fcad62015-10-28 17:19:40 -0700130 ((_n) * 2 * (sizeof(struct fm10k_queue_stats) / sizeof(u64)))
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400131
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700132#define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
Jacob Keller80043f32015-07-01 17:38:36 -0700133 FM10K_NETDEV_STATS_LEN + \
134 FM10K_MBX_STATS_LEN)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400135
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400136static 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
Jacob Keller80043f32015-07-01 17:38:36 -0700147enum {
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)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400157{
Jeff Kirsher29a928e2015-04-03 13:26:58 -0700158 struct fm10k_intfc *interface = netdev_priv(dev);
Jacob Keller80043f32015-07-01 17:38:36 -0700159 struct fm10k_iov_data *iov_data = interface->iov_data;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400160 char *p = (char *)data;
Jacob Kellerc0e58e92015-06-16 13:39:11 -0700161 unsigned int i;
Jacob Keller80043f32015-07-01 17:38:36 -0700162 unsigned int j;
163
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,
179 ETH_GSTRING_LEN);
180 p += ETH_GSTRING_LEN;
181 }
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,
193 ETH_GSTRING_LEN);
194 p += ETH_GSTRING_LEN;
195 }
196 }
197
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);
205 p += ETH_GSTRING_LEN;
206 }
207 }
208 }
209
210 for (i = 0; i < interface->hw.mac.max_queues; i++) {
Jacob Kellerf6f19f82015-08-24 17:01:58 -0700211 snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_packets", i);
Jacob Keller80043f32015-07-01 17:38:36 -0700212 p += ETH_GSTRING_LEN;
Jacob Kellerf6f19f82015-08-24 17:01:58 -0700213 snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
Jacob Keller80043f32015-07-01 17:38:36 -0700214 p += ETH_GSTRING_LEN;
Jacob Kellerf6f19f82015-08-24 17:01:58 -0700215 snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_packets", i);
Jacob Keller80043f32015-07-01 17:38:36 -0700216 p += ETH_GSTRING_LEN;
Jacob Kellerf6f19f82015-08-24 17:01:58 -0700217 snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
Jacob Keller80043f32015-07-01 17:38:36 -0700218 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;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400226
227 switch (stringset) {
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400228 case ETH_SS_TEST:
229 memcpy(data, *fm10k_gstrings_test,
230 FM10K_TEST_LEN * ETH_GSTRING_LEN);
231 break;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400232 case ETH_SS_STATS:
Jacob Keller80043f32015-07-01 17:38:36 -0700233 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);
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400238 break;
239 }
240}
241
242static int fm10k_get_sset_count(struct net_device *dev, int sset)
243{
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700244 struct fm10k_intfc *interface = netdev_priv(dev);
Jacob Keller80043f32015-07-01 17:38:36 -0700245 struct fm10k_iov_data *iov_data = interface->iov_data;
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700246 struct fm10k_hw *hw = &interface->hw;
247 int stats_len = FM10K_STATIC_STATS_LEN;
248
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400249 switch (sset) {
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400250 case ETH_SS_TEST:
251 return FM10K_TEST_LEN;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400252 case ETH_SS_STATS:
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700253 stats_len += FM10K_QUEUE_STATS_LEN(hw->mac.max_queues);
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700254
255 if (hw->mac.type != fm10k_mac_vf)
256 stats_len += FM10K_PF_STATS_LEN;
257
Jacob Keller80043f32015-07-01 17:38:36 -0700258 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
Jeff Kirsherc0e61782015-04-03 13:26:59 -0700265 return stats_len;
Jacob Keller80043f32015-07-01 17:38:36 -0700266 case ETH_SS_PRIV_FLAGS:
267 return FM10K_PRV_FLAG_LEN;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400268 default:
269 return -EOPNOTSUPP;
270 }
271}
272
273static void fm10k_get_ethtool_stats(struct net_device *netdev,
Jeff Kirsherde445192015-04-03 13:26:56 -0700274 struct ethtool_stats __always_unused *stats,
275 u64 *data)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400276{
277 const int stat_count = sizeof(struct fm10k_queue_stats) / sizeof(u64);
278 struct fm10k_intfc *interface = netdev_priv(netdev);
Jacob Keller80043f32015-07-01 17:38:36 -0700279 struct fm10k_iov_data *iov_data = interface->iov_data;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400280 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++) {
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700293 p = (char *)interface +
294 fm10k_gstrings_global_stats[i].stat_offset;
295 *(data++) = (fm10k_gstrings_global_stats[i].sizeof_stat ==
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400296 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
297 }
298
Jacob Keller80043f32015-07-01 17:38:36 -0700299 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) {
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700314 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 }
Jacob Keller80043f32015-07-01 17:38:36 -0700320 }
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;
Bruce Allana4fcad62015-10-28 17:19:40 -0700325
Jacob Keller80043f32015-07-01 17:38:36 -0700326 vf_info = &iov_data->vf_info[i];
327
328 /* skip stats if we don't have a vf info */
329 if (!vf_info) {
330 data += FM10K_MBX_STATS_LEN;
331 continue;
332 }
333
334 for (j = 0; j < FM10K_MBX_STATS_LEN; j++) {
335 p = (char *)&vf_info->mbx + fm10k_gstrings_mbx_stats[j].stat_offset;
336 *(data++) = (fm10k_gstrings_mbx_stats[j].sizeof_stat ==
337 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
338 }
339 }
340 }
Jeff Kirsherfbdb1592015-04-03 13:27:00 -0700341
Jeff Kirsher29a928e2015-04-03 13:26:58 -0700342 for (i = 0; i < interface->hw.mac.max_queues; i++) {
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400343 struct fm10k_ring *ring;
344 u64 *queue_stat;
345
346 ring = interface->tx_ring[i];
347 if (ring)
348 queue_stat = (u64 *)&ring->stats;
349 for (j = 0; j < stat_count; j++)
350 *(data++) = ring ? queue_stat[j] : 0;
351
352 ring = interface->rx_ring[i];
353 if (ring)
354 queue_stat = (u64 *)&ring->stats;
355 for (j = 0; j < stat_count; j++)
356 *(data++) = ring ? queue_stat[j] : 0;
357 }
358}
359
360/* If function below adds more registers this define needs to be updated */
361#define FM10K_REGS_LEN_Q 29
362
363static void fm10k_get_reg_q(struct fm10k_hw *hw, u32 *buff, int i)
364{
365 int idx = 0;
366
367 buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAL(i));
368 buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAH(i));
369 buff[idx++] = fm10k_read_reg(hw, FM10K_RDLEN(i));
370 buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_RXCTRL(i));
371 buff[idx++] = fm10k_read_reg(hw, FM10K_RDH(i));
372 buff[idx++] = fm10k_read_reg(hw, FM10K_RDT(i));
373 buff[idx++] = fm10k_read_reg(hw, FM10K_RXQCTL(i));
374 buff[idx++] = fm10k_read_reg(hw, FM10K_RXDCTL(i));
375 buff[idx++] = fm10k_read_reg(hw, FM10K_RXINT(i));
376 buff[idx++] = fm10k_read_reg(hw, FM10K_SRRCTL(i));
377 buff[idx++] = fm10k_read_reg(hw, FM10K_QPRC(i));
378 buff[idx++] = fm10k_read_reg(hw, FM10K_QPRDC(i));
379 buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_L(i));
380 buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_H(i));
381 buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAL(i));
382 buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAH(i));
383 buff[idx++] = fm10k_read_reg(hw, FM10K_TDLEN(i));
384 buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_TXCTRL(i));
385 buff[idx++] = fm10k_read_reg(hw, FM10K_TDH(i));
386 buff[idx++] = fm10k_read_reg(hw, FM10K_TDT(i));
387 buff[idx++] = fm10k_read_reg(hw, FM10K_TXDCTL(i));
388 buff[idx++] = fm10k_read_reg(hw, FM10K_TXQCTL(i));
389 buff[idx++] = fm10k_read_reg(hw, FM10K_TXINT(i));
390 buff[idx++] = fm10k_read_reg(hw, FM10K_QPTC(i));
391 buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_L(i));
392 buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_H(i));
393 buff[idx++] = fm10k_read_reg(hw, FM10K_TQDLOC(i));
394 buff[idx++] = fm10k_read_reg(hw, FM10K_TX_SGLORT(i));
395 buff[idx++] = fm10k_read_reg(hw, FM10K_PFVTCTL(i));
396
397 BUG_ON(idx != FM10K_REGS_LEN_Q);
398}
399
400/* If function above adds more registers this define needs to be updated */
401#define FM10K_REGS_LEN_VSI 43
402
403static void fm10k_get_reg_vsi(struct fm10k_hw *hw, u32 *buff, int i)
404{
405 int idx = 0, j;
406
407 buff[idx++] = fm10k_read_reg(hw, FM10K_MRQC(i));
408 for (j = 0; j < 10; j++)
409 buff[idx++] = fm10k_read_reg(hw, FM10K_RSSRK(i, j));
410 for (j = 0; j < 32; j++)
411 buff[idx++] = fm10k_read_reg(hw, FM10K_RETA(i, j));
412
413 BUG_ON(idx != FM10K_REGS_LEN_VSI);
414}
415
416static void fm10k_get_regs(struct net_device *netdev,
417 struct ethtool_regs *regs, void *p)
418{
419 struct fm10k_intfc *interface = netdev_priv(netdev);
420 struct fm10k_hw *hw = &interface->hw;
421 u32 *buff = p;
422 u16 i;
423
424 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
425
426 switch (hw->mac.type) {
427 case fm10k_mac_pf:
428 /* General PF Registers */
429 *(buff++) = fm10k_read_reg(hw, FM10K_CTRL);
430 *(buff++) = fm10k_read_reg(hw, FM10K_CTRL_EXT);
431 *(buff++) = fm10k_read_reg(hw, FM10K_GCR);
432 *(buff++) = fm10k_read_reg(hw, FM10K_GCR_EXT);
433
434 for (i = 0; i < 8; i++) {
435 *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTMAP(i));
436 *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTDEC(i));
437 }
438
439 for (i = 0; i < 65; i++) {
440 fm10k_get_reg_vsi(hw, buff, i);
441 buff += FM10K_REGS_LEN_VSI;
442 }
443
444 *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL);
445 *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL2);
446
447 for (i = 0; i < FM10K_MAX_QUEUES_PF; i++) {
448 fm10k_get_reg_q(hw, buff, i);
449 buff += FM10K_REGS_LEN_Q;
450 }
451
452 *(buff++) = fm10k_read_reg(hw, FM10K_TPH_CTRL);
453
454 for (i = 0; i < 8; i++)
455 *(buff++) = fm10k_read_reg(hw, FM10K_INT_MAP(i));
456
457 /* Interrupt Throttling Registers */
458 for (i = 0; i < 130; i++)
459 *(buff++) = fm10k_read_reg(hw, FM10K_ITR(i));
460
461 break;
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400462 case fm10k_mac_vf:
463 /* General VF registers */
464 *(buff++) = fm10k_read_reg(hw, FM10K_VFCTRL);
465 *(buff++) = fm10k_read_reg(hw, FM10K_VFINT_MAP);
466 *(buff++) = fm10k_read_reg(hw, FM10K_VFSYSTIME);
467
468 /* Interrupt Throttling Registers */
469 for (i = 0; i < 8; i++)
470 *(buff++) = fm10k_read_reg(hw, FM10K_VFITR(i));
471
472 fm10k_get_reg_vsi(hw, buff, 0);
473 buff += FM10K_REGS_LEN_VSI;
474
475 for (i = 0; i < FM10K_MAX_QUEUES_POOL; i++) {
476 if (i < hw->mac.max_queues)
477 fm10k_get_reg_q(hw, buff, i);
478 else
479 memset(buff, 0, sizeof(u32) * FM10K_REGS_LEN_Q);
480 buff += FM10K_REGS_LEN_Q;
481 }
482
483 break;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400484 default:
485 return;
486 }
487}
488
489/* If function above adds more registers these define need to be updated */
490#define FM10K_REGS_LEN_PF \
491(162 + (65 * FM10K_REGS_LEN_VSI) + (FM10K_MAX_QUEUES_PF * FM10K_REGS_LEN_Q))
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400492#define FM10K_REGS_LEN_VF \
493(11 + FM10K_REGS_LEN_VSI + (FM10K_MAX_QUEUES_POOL * FM10K_REGS_LEN_Q))
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400494
495static int fm10k_get_regs_len(struct net_device *netdev)
496{
497 struct fm10k_intfc *interface = netdev_priv(netdev);
498 struct fm10k_hw *hw = &interface->hw;
499
500 switch (hw->mac.type) {
501 case fm10k_mac_pf:
502 return FM10K_REGS_LEN_PF * sizeof(u32);
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400503 case fm10k_mac_vf:
504 return FM10K_REGS_LEN_VF * sizeof(u32);
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400505 default:
506 return 0;
507 }
508}
509
510static void fm10k_get_drvinfo(struct net_device *dev,
511 struct ethtool_drvinfo *info)
512{
513 struct fm10k_intfc *interface = netdev_priv(dev);
514
515 strncpy(info->driver, fm10k_driver_name,
516 sizeof(info->driver) - 1);
517 strncpy(info->version, fm10k_driver_version,
518 sizeof(info->version) - 1);
519 strncpy(info->bus_info, pci_name(interface->pdev),
520 sizeof(info->bus_info) - 1);
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400521}
522
523static void fm10k_get_pauseparam(struct net_device *dev,
524 struct ethtool_pauseparam *pause)
525{
526 struct fm10k_intfc *interface = netdev_priv(dev);
527
528 /* record fixed values for autoneg and tx pause */
529 pause->autoneg = 0;
530 pause->tx_pause = 1;
531
532 pause->rx_pause = interface->rx_pause ? 1 : 0;
533}
534
535static int fm10k_set_pauseparam(struct net_device *dev,
536 struct ethtool_pauseparam *pause)
537{
538 struct fm10k_intfc *interface = netdev_priv(dev);
539 struct fm10k_hw *hw = &interface->hw;
540
541 if (pause->autoneg || !pause->tx_pause)
542 return -EINVAL;
543
544 /* we can only support pause on the PF to avoid head-of-line blocking */
545 if (hw->mac.type == fm10k_mac_pf)
546 interface->rx_pause = pause->rx_pause ? ~0 : 0;
547 else if (pause->rx_pause)
548 return -EINVAL;
549
550 if (netif_running(dev))
551 fm10k_update_rx_drop_en(interface);
552
553 return 0;
554}
555
556static u32 fm10k_get_msglevel(struct net_device *netdev)
557{
558 struct fm10k_intfc *interface = netdev_priv(netdev);
559
560 return interface->msg_enable;
561}
562
563static void fm10k_set_msglevel(struct net_device *netdev, u32 data)
564{
565 struct fm10k_intfc *interface = netdev_priv(netdev);
566
567 interface->msg_enable = data;
568}
569
570static void fm10k_get_ringparam(struct net_device *netdev,
571 struct ethtool_ringparam *ring)
572{
573 struct fm10k_intfc *interface = netdev_priv(netdev);
574
575 ring->rx_max_pending = FM10K_MAX_RXD;
576 ring->tx_max_pending = FM10K_MAX_TXD;
577 ring->rx_mini_max_pending = 0;
578 ring->rx_jumbo_max_pending = 0;
579 ring->rx_pending = interface->rx_ring_count;
580 ring->tx_pending = interface->tx_ring_count;
581 ring->rx_mini_pending = 0;
582 ring->rx_jumbo_pending = 0;
583}
584
585static int fm10k_set_ringparam(struct net_device *netdev,
586 struct ethtool_ringparam *ring)
587{
588 struct fm10k_intfc *interface = netdev_priv(netdev);
589 struct fm10k_ring *temp_ring;
590 int i, err = 0;
591 u32 new_rx_count, new_tx_count;
592
593 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
594 return -EINVAL;
595
596 new_tx_count = clamp_t(u32, ring->tx_pending,
597 FM10K_MIN_TXD, FM10K_MAX_TXD);
598 new_tx_count = ALIGN(new_tx_count, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE);
599
600 new_rx_count = clamp_t(u32, ring->rx_pending,
601 FM10K_MIN_RXD, FM10K_MAX_RXD);
602 new_rx_count = ALIGN(new_rx_count, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE);
603
604 if ((new_tx_count == interface->tx_ring_count) &&
605 (new_rx_count == interface->rx_ring_count)) {
606 /* nothing to do */
607 return 0;
608 }
609
610 while (test_and_set_bit(__FM10K_RESETTING, &interface->state))
611 usleep_range(1000, 2000);
612
613 if (!netif_running(interface->netdev)) {
614 for (i = 0; i < interface->num_tx_queues; i++)
615 interface->tx_ring[i]->count = new_tx_count;
616 for (i = 0; i < interface->num_rx_queues; i++)
617 interface->rx_ring[i]->count = new_rx_count;
618 interface->tx_ring_count = new_tx_count;
619 interface->rx_ring_count = new_rx_count;
620 goto clear_reset;
621 }
622
623 /* allocate temporary buffer to store rings in */
624 i = max_t(int, interface->num_tx_queues, interface->num_rx_queues);
625 temp_ring = vmalloc(i * sizeof(struct fm10k_ring));
626
627 if (!temp_ring) {
628 err = -ENOMEM;
629 goto clear_reset;
630 }
631
632 fm10k_down(interface);
633
634 /* Setup new Tx resources and free the old Tx resources in that order.
635 * We can then assign the new resources to the rings via a memcpy.
636 * The advantage to this approach is that we are guaranteed to still
637 * have resources even in the case of an allocation failure.
638 */
639 if (new_tx_count != interface->tx_ring_count) {
640 for (i = 0; i < interface->num_tx_queues; i++) {
641 memcpy(&temp_ring[i], interface->tx_ring[i],
642 sizeof(struct fm10k_ring));
643
644 temp_ring[i].count = new_tx_count;
645 err = fm10k_setup_tx_resources(&temp_ring[i]);
646 if (err) {
647 while (i) {
648 i--;
649 fm10k_free_tx_resources(&temp_ring[i]);
650 }
651 goto err_setup;
652 }
653 }
654
655 for (i = 0; i < interface->num_tx_queues; i++) {
656 fm10k_free_tx_resources(interface->tx_ring[i]);
657
658 memcpy(interface->tx_ring[i], &temp_ring[i],
659 sizeof(struct fm10k_ring));
660 }
661
662 interface->tx_ring_count = new_tx_count;
663 }
664
665 /* Repeat the process for the Rx rings if needed */
666 if (new_rx_count != interface->rx_ring_count) {
667 for (i = 0; i < interface->num_rx_queues; i++) {
668 memcpy(&temp_ring[i], interface->rx_ring[i],
669 sizeof(struct fm10k_ring));
670
671 temp_ring[i].count = new_rx_count;
672 err = fm10k_setup_rx_resources(&temp_ring[i]);
673 if (err) {
674 while (i) {
675 i--;
676 fm10k_free_rx_resources(&temp_ring[i]);
677 }
678 goto err_setup;
679 }
680 }
681
682 for (i = 0; i < interface->num_rx_queues; i++) {
683 fm10k_free_rx_resources(interface->rx_ring[i]);
684
685 memcpy(interface->rx_ring[i], &temp_ring[i],
686 sizeof(struct fm10k_ring));
687 }
688
689 interface->rx_ring_count = new_rx_count;
690 }
691
692err_setup:
693 fm10k_up(interface);
694 vfree(temp_ring);
695clear_reset:
696 clear_bit(__FM10K_RESETTING, &interface->state);
697 return err;
698}
699
700static int fm10k_get_coalesce(struct net_device *dev,
701 struct ethtool_coalesce *ec)
702{
703 struct fm10k_intfc *interface = netdev_priv(dev);
704
Jacob Keller584373f2015-10-16 10:57:06 -0700705 ec->use_adaptive_tx_coalesce = ITR_IS_ADAPTIVE(interface->tx_itr);
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400706 ec->tx_coalesce_usecs = interface->tx_itr & ~FM10K_ITR_ADAPTIVE;
707
Jacob Keller584373f2015-10-16 10:57:06 -0700708 ec->use_adaptive_rx_coalesce = ITR_IS_ADAPTIVE(interface->rx_itr);
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400709 ec->rx_coalesce_usecs = interface->rx_itr & ~FM10K_ITR_ADAPTIVE;
710
711 return 0;
712}
713
714static int fm10k_set_coalesce(struct net_device *dev,
715 struct ethtool_coalesce *ec)
716{
717 struct fm10k_intfc *interface = netdev_priv(dev);
718 struct fm10k_q_vector *qv;
719 u16 tx_itr, rx_itr;
720 int i;
721
722 /* verify limits */
723 if ((ec->rx_coalesce_usecs > FM10K_ITR_MAX) ||
724 (ec->tx_coalesce_usecs > FM10K_ITR_MAX))
725 return -EINVAL;
726
727 /* record settings */
728 tx_itr = ec->tx_coalesce_usecs;
729 rx_itr = ec->rx_coalesce_usecs;
730
731 /* set initial values for adaptive ITR */
732 if (ec->use_adaptive_tx_coalesce)
Jacob Keller436ea952015-10-16 10:57:08 -0700733 tx_itr = FM10K_ITR_ADAPTIVE | FM10K_TX_ITR_DEFAULT;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400734
735 if (ec->use_adaptive_rx_coalesce)
Jacob Keller436ea952015-10-16 10:57:08 -0700736 rx_itr = FM10K_ITR_ADAPTIVE | FM10K_RX_ITR_DEFAULT;
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400737
738 /* update interface */
739 interface->tx_itr = tx_itr;
740 interface->rx_itr = rx_itr;
741
742 /* update q_vectors */
743 for (i = 0; i < interface->num_q_vectors; i++) {
744 qv = interface->q_vector[i];
745 qv->tx.itr = tx_itr;
746 qv->rx.itr = rx_itr;
747 }
748
749 return 0;
750}
751
752static int fm10k_get_rss_hash_opts(struct fm10k_intfc *interface,
753 struct ethtool_rxnfc *cmd)
754{
755 cmd->data = 0;
756
757 /* Report default options for RSS on fm10k */
758 switch (cmd->flow_type) {
759 case TCP_V4_FLOW:
760 case TCP_V6_FLOW:
761 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
762 /* fall through */
763 case UDP_V4_FLOW:
764 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
765 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
766 /* fall through */
767 case SCTP_V4_FLOW:
768 case SCTP_V6_FLOW:
769 case AH_ESP_V4_FLOW:
770 case AH_ESP_V6_FLOW:
771 case AH_V4_FLOW:
772 case AH_V6_FLOW:
773 case ESP_V4_FLOW:
774 case ESP_V6_FLOW:
775 case IPV4_FLOW:
776 case IPV6_FLOW:
777 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
778 break;
779 case UDP_V6_FLOW:
780 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
781 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
782 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
783 break;
784 default:
785 return -EINVAL;
786 }
787
788 return 0;
789}
790
791static int fm10k_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
Jeff Kirsherde445192015-04-03 13:26:56 -0700792 u32 __always_unused *rule_locs)
Alexander Duyck82dd0f72014-09-20 19:50:15 -0400793{
794 struct fm10k_intfc *interface = netdev_priv(dev);
795 int ret = -EOPNOTSUPP;
796
797 switch (cmd->cmd) {
798 case ETHTOOL_GRXRINGS:
799 cmd->data = interface->num_rx_queues;
800 ret = 0;
801 break;
802 case ETHTOOL_GRXFH:
803 ret = fm10k_get_rss_hash_opts(interface, cmd);
804 break;
805 default:
806 break;
807 }
808
809 return ret;
810}
811
812#define UDP_RSS_FLAGS (FM10K_FLAG_RSS_FIELD_IPV4_UDP | \
813 FM10K_FLAG_RSS_FIELD_IPV6_UDP)
814static int fm10k_set_rss_hash_opt(struct fm10k_intfc *interface,
815 struct ethtool_rxnfc *nfc)
816{
817 u32 flags = interface->flags;
818
819 /* RSS does not support anything other than hashing
820 * to queues on src and dst IPs and ports
821 */
822 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
823 RXH_L4_B_0_1 | RXH_L4_B_2_3))
824 return -EINVAL;
825
826 switch (nfc->flow_type) {
827 case TCP_V4_FLOW:
828 case TCP_V6_FLOW:
829 if (!(nfc->data & RXH_IP_SRC) ||
830 !(nfc->data & RXH_IP_DST) ||
831 !(nfc->data & RXH_L4_B_0_1) ||
832 !(nfc->data & RXH_L4_B_2_3))
833 return -EINVAL;
834 break;
835 case UDP_V4_FLOW:
836 if (!(nfc->data & RXH_IP_SRC) ||
837 !(nfc->data & RXH_IP_DST))
838 return -EINVAL;
839 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
840 case 0:
841 flags &= ~FM10K_FLAG_RSS_FIELD_IPV4_UDP;
842 break;
843 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
844 flags |= FM10K_FLAG_RSS_FIELD_IPV4_UDP;
845 break;
846 default:
847 return -EINVAL;
848 }
849 break;
850 case UDP_V6_FLOW:
851 if (!(nfc->data & RXH_IP_SRC) ||
852 !(nfc->data & RXH_IP_DST))
853 return -EINVAL;
854 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
855 case 0:
856 flags &= ~FM10K_FLAG_RSS_FIELD_IPV6_UDP;
857 break;
858 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
859 flags |= FM10K_FLAG_RSS_FIELD_IPV6_UDP;
860 break;
861 default:
862 return -EINVAL;
863 }
864 break;
865 case AH_ESP_V4_FLOW:
866 case AH_V4_FLOW:
867 case ESP_V4_FLOW:
868 case SCTP_V4_FLOW:
869 case AH_ESP_V6_FLOW:
870 case AH_V6_FLOW:
871 case ESP_V6_FLOW:
872 case SCTP_V6_FLOW:
873 if (!(nfc->data & RXH_IP_SRC) ||
874 !(nfc->data & RXH_IP_DST) ||
875 (nfc->data & RXH_L4_B_0_1) ||
876 (nfc->data & RXH_L4_B_2_3))
877 return -EINVAL;
878 break;
879 default:
880 return -EINVAL;
881 }
882
883 /* if we changed something we need to update flags */
884 if (flags != interface->flags) {
885 struct fm10k_hw *hw = &interface->hw;
886 u32 mrqc;
887
888 if ((flags & UDP_RSS_FLAGS) &&
889 !(interface->flags & UDP_RSS_FLAGS))
890 netif_warn(interface, drv, interface->netdev,
891 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
892
893 interface->flags = flags;
894
895 /* Perform hash on these packet types */
896 mrqc = FM10K_MRQC_IPV4 |
897 FM10K_MRQC_TCP_IPV4 |
898 FM10K_MRQC_IPV6 |
899 FM10K_MRQC_TCP_IPV6;
900
901 if (flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
902 mrqc |= FM10K_MRQC_UDP_IPV4;
903 if (flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
904 mrqc |= FM10K_MRQC_UDP_IPV6;
905
906 fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
907 }
908
909 return 0;
910}
911
912static int fm10k_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
913{
914 struct fm10k_intfc *interface = netdev_priv(dev);
915 int ret = -EOPNOTSUPP;
916
917 switch (cmd->cmd) {
918 case ETHTOOL_SRXFH:
919 ret = fm10k_set_rss_hash_opt(interface, cmd);
920 break;
921 default:
922 break;
923 }
924
925 return ret;
926}
927
Alexander Duyck5cb8db42014-09-20 19:51:40 -0400928static int fm10k_mbx_test(struct fm10k_intfc *interface, u64 *data)
929{
930 struct fm10k_hw *hw = &interface->hw;
931 struct fm10k_mbx_info *mbx = &hw->mbx;
932 u32 attr_flag, test_msg[6];
933 unsigned long timeout;
934 int err;
935
936 /* For now this is a VF only feature */
937 if (hw->mac.type != fm10k_mac_vf)
938 return 0;
939
940 /* loop through both nested and unnested attribute types */
941 for (attr_flag = (1 << FM10K_TEST_MSG_UNSET);
942 attr_flag < (1 << (2 * FM10K_TEST_MSG_NESTED));
943 attr_flag += attr_flag) {
944 /* generate message to be tested */
945 fm10k_tlv_msg_test_create(test_msg, attr_flag);
946
947 fm10k_mbx_lock(interface);
948 mbx->test_result = FM10K_NOT_IMPLEMENTED;
949 err = mbx->ops.enqueue_tx(hw, mbx, test_msg);
950 fm10k_mbx_unlock(interface);
951
952 /* wait up to 1 second for response */
953 timeout = jiffies + HZ;
954 do {
955 if (err < 0)
956 goto err_out;
957
958 usleep_range(500, 1000);
959
960 fm10k_mbx_lock(interface);
961 mbx->ops.process(hw, mbx);
962 fm10k_mbx_unlock(interface);
963
964 err = mbx->test_result;
965 if (!err)
966 break;
967 } while (time_is_after_jiffies(timeout));
968
969 /* reporting errors */
970 if (err)
971 goto err_out;
972 }
973
974err_out:
975 *data = err < 0 ? (attr_flag) : (err > 0);
976 return err;
977}
978
979static void fm10k_self_test(struct net_device *dev,
980 struct ethtool_test *eth_test, u64 *data)
981{
982 struct fm10k_intfc *interface = netdev_priv(dev);
983 struct fm10k_hw *hw = &interface->hw;
984
985 memset(data, 0, sizeof(*data) * FM10K_TEST_LEN);
986
987 if (FM10K_REMOVED(hw)) {
988 netif_err(interface, drv, dev,
989 "Interface removed - test blocked\n");
990 eth_test->flags |= ETH_TEST_FL_FAILED;
991 return;
992 }
993
994 if (fm10k_mbx_test(interface, &data[FM10K_TEST_MBX]))
995 eth_test->flags |= ETH_TEST_FL_FAILED;
996}
997
Jacob Keller80043f32015-07-01 17:38:36 -0700998static u32 fm10k_get_priv_flags(struct net_device *netdev)
999{
1000 struct fm10k_intfc *interface = netdev_priv(netdev);
1001 u32 priv_flags = 0;
1002
1003 if (interface->flags & FM10K_FLAG_DEBUG_STATS)
1004 priv_flags |= 1 << FM10K_PRV_FLAG_DEBUG_STATS;
1005
1006 return priv_flags;
1007}
1008
1009static int fm10k_set_priv_flags(struct net_device *netdev, u32 priv_flags)
1010{
1011 struct fm10k_intfc *interface = netdev_priv(netdev);
1012
1013 if (priv_flags >= (1 << FM10K_PRV_FLAG_LEN))
1014 return -EINVAL;
1015
1016 if (priv_flags & (1 << FM10K_PRV_FLAG_DEBUG_STATS))
1017 interface->flags |= FM10K_FLAG_DEBUG_STATS;
1018 else
1019 interface->flags &= ~FM10K_FLAG_DEBUG_STATS;
1020
1021 return 0;
1022}
1023
Jeff Kirsherde445192015-04-03 13:26:56 -07001024static u32 fm10k_get_reta_size(struct net_device __always_unused *netdev)
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001025{
1026 return FM10K_RETA_SIZE * FM10K_RETA_ENTRIES_PER_REG;
1027}
1028
1029static int fm10k_get_reta(struct net_device *netdev, u32 *indir)
1030{
1031 struct fm10k_intfc *interface = netdev_priv(netdev);
1032 int i;
1033
1034 if (!indir)
1035 return 0;
1036
1037 for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
1038 u32 reta = interface->reta[i];
1039
1040 indir[0] = (reta << 24) >> 24;
1041 indir[1] = (reta << 16) >> 24;
1042 indir[2] = (reta << 8) >> 24;
1043 indir[3] = (reta) >> 24;
1044 }
1045
1046 return 0;
1047}
1048
1049static int fm10k_set_reta(struct net_device *netdev, const u32 *indir)
1050{
1051 struct fm10k_intfc *interface = netdev_priv(netdev);
1052 struct fm10k_hw *hw = &interface->hw;
1053 int i;
1054 u16 rss_i;
1055
1056 if (!indir)
1057 return 0;
1058
1059 /* Verify user input. */
1060 rss_i = interface->ring_feature[RING_F_RSS].indices;
1061 for (i = fm10k_get_reta_size(netdev); i--;) {
1062 if (indir[i] < rss_i)
1063 continue;
1064 return -EINVAL;
1065 }
1066
1067 /* record entries to reta table */
1068 for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
1069 u32 reta = indir[0] |
1070 (indir[1] << 8) |
1071 (indir[2] << 16) |
1072 (indir[3] << 24);
1073
1074 if (interface->reta[i] == reta)
1075 continue;
1076
1077 interface->reta[i] = reta;
1078 fm10k_write_reg(hw, FM10K_RETA(0, i), reta);
1079 }
1080
1081 return 0;
1082}
1083
Jeff Kirsherde445192015-04-03 13:26:56 -07001084static u32 fm10k_get_rssrk_size(struct net_device __always_unused *netdev)
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001085{
1086 return FM10K_RSSRK_SIZE * FM10K_RSSRK_ENTRIES_PER_REG;
1087}
1088
Eyal Perry892311f2014-12-02 18:12:10 +02001089static int fm10k_get_rssh(struct net_device *netdev, u32 *indir, u8 *key,
1090 u8 *hfunc)
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001091{
1092 struct fm10k_intfc *interface = netdev_priv(netdev);
1093 int i, err;
1094
Eyal Perry892311f2014-12-02 18:12:10 +02001095 if (hfunc)
1096 *hfunc = ETH_RSS_HASH_TOP;
1097
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001098 err = fm10k_get_reta(netdev, indir);
1099 if (err || !key)
1100 return err;
1101
1102 for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4)
1103 *(__le32 *)key = cpu_to_le32(interface->rssrk[i]);
1104
1105 return 0;
1106}
1107
1108static int fm10k_set_rssh(struct net_device *netdev, const u32 *indir,
Eyal Perry892311f2014-12-02 18:12:10 +02001109 const u8 *key, const u8 hfunc)
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001110{
1111 struct fm10k_intfc *interface = netdev_priv(netdev);
1112 struct fm10k_hw *hw = &interface->hw;
1113 int i, err;
1114
Eyal Perry892311f2014-12-02 18:12:10 +02001115 /* We do not allow change in unsupported parameters */
1116 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1117 return -EOPNOTSUPP;
1118
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001119 err = fm10k_set_reta(netdev, indir);
1120 if (err || !key)
1121 return err;
1122
1123 for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4) {
1124 u32 rssrk = le32_to_cpu(*(__le32 *)key);
1125
1126 if (interface->rssrk[i] == rssrk)
1127 continue;
1128
1129 interface->rssrk[i] = rssrk;
1130 fm10k_write_reg(hw, FM10K_RSSRK(0, i), rssrk);
1131 }
1132
1133 return 0;
1134}
1135
Alexander Duyckaa3ac822014-09-20 19:50:42 -04001136static unsigned int fm10k_max_channels(struct net_device *dev)
1137{
1138 struct fm10k_intfc *interface = netdev_priv(dev);
1139 unsigned int max_combined = interface->hw.mac.max_queues;
1140 u8 tcs = netdev_get_num_tc(dev);
1141
1142 /* For QoS report channels per traffic class */
1143 if (tcs > 1)
1144 max_combined = 1 << (fls(max_combined / tcs) - 1);
1145
1146 return max_combined;
1147}
1148
1149static void fm10k_get_channels(struct net_device *dev,
1150 struct ethtool_channels *ch)
1151{
1152 struct fm10k_intfc *interface = netdev_priv(dev);
1153 struct fm10k_hw *hw = &interface->hw;
1154
1155 /* report maximum channels */
1156 ch->max_combined = fm10k_max_channels(dev);
1157
1158 /* report info for other vector */
1159 ch->max_other = NON_Q_VECTORS(hw);
1160 ch->other_count = ch->max_other;
1161
1162 /* record RSS queues */
1163 ch->combined_count = interface->ring_feature[RING_F_RSS].indices;
1164}
1165
1166static int fm10k_set_channels(struct net_device *dev,
1167 struct ethtool_channels *ch)
1168{
1169 struct fm10k_intfc *interface = netdev_priv(dev);
1170 unsigned int count = ch->combined_count;
1171 struct fm10k_hw *hw = &interface->hw;
1172
1173 /* verify they are not requesting separate vectors */
1174 if (!count || ch->rx_count || ch->tx_count)
1175 return -EINVAL;
1176
1177 /* verify other_count has not changed */
1178 if (ch->other_count != NON_Q_VECTORS(hw))
1179 return -EINVAL;
1180
1181 /* verify the number of channels does not exceed hardware limits */
1182 if (count > fm10k_max_channels(dev))
1183 return -EINVAL;
1184
1185 interface->ring_feature[RING_F_RSS].limit = count;
1186
1187 /* use setup TC to update any traffic class queue mapping */
1188 return fm10k_setup_tc(dev, netdev_get_num_tc(dev));
1189}
1190
Alexander Duycka211e012014-09-20 19:54:07 -04001191static int fm10k_get_ts_info(struct net_device *dev,
Matthew Vickeca32042015-01-31 02:23:05 +00001192 struct ethtool_ts_info *info)
Alexander Duycka211e012014-09-20 19:54:07 -04001193{
1194 struct fm10k_intfc *interface = netdev_priv(dev);
1195
1196 info->so_timestamping =
1197 SOF_TIMESTAMPING_TX_SOFTWARE |
1198 SOF_TIMESTAMPING_RX_SOFTWARE |
1199 SOF_TIMESTAMPING_SOFTWARE |
1200 SOF_TIMESTAMPING_TX_HARDWARE |
1201 SOF_TIMESTAMPING_RX_HARDWARE |
1202 SOF_TIMESTAMPING_RAW_HARDWARE;
1203
1204 if (interface->ptp_clock)
1205 info->phc_index = ptp_clock_index(interface->ptp_clock);
1206 else
1207 info->phc_index = -1;
1208
1209 info->tx_types = (1 << HWTSTAMP_TX_OFF) |
1210 (1 << HWTSTAMP_TX_ON);
1211
1212 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1213 (1 << HWTSTAMP_FILTER_ALL);
1214
1215 return 0;
1216}
1217
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001218static const struct ethtool_ops fm10k_ethtool_ops = {
1219 .get_strings = fm10k_get_strings,
1220 .get_sset_count = fm10k_get_sset_count,
1221 .get_ethtool_stats = fm10k_get_ethtool_stats,
1222 .get_drvinfo = fm10k_get_drvinfo,
1223 .get_link = ethtool_op_get_link,
1224 .get_pauseparam = fm10k_get_pauseparam,
1225 .set_pauseparam = fm10k_set_pauseparam,
1226 .get_msglevel = fm10k_get_msglevel,
1227 .set_msglevel = fm10k_set_msglevel,
1228 .get_ringparam = fm10k_get_ringparam,
1229 .set_ringparam = fm10k_set_ringparam,
1230 .get_coalesce = fm10k_get_coalesce,
1231 .set_coalesce = fm10k_set_coalesce,
1232 .get_rxnfc = fm10k_get_rxnfc,
1233 .set_rxnfc = fm10k_set_rxnfc,
1234 .get_regs = fm10k_get_regs,
1235 .get_regs_len = fm10k_get_regs_len,
Alexander Duyck5cb8db42014-09-20 19:51:40 -04001236 .self_test = fm10k_self_test,
Jacob Keller80043f32015-07-01 17:38:36 -07001237 .get_priv_flags = fm10k_get_priv_flags,
1238 .set_priv_flags = fm10k_set_priv_flags,
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001239 .get_rxfh_indir_size = fm10k_get_reta_size,
1240 .get_rxfh_key_size = fm10k_get_rssrk_size,
1241 .get_rxfh = fm10k_get_rssh,
1242 .set_rxfh = fm10k_set_rssh,
Alexander Duyckaa3ac822014-09-20 19:50:42 -04001243 .get_channels = fm10k_get_channels,
1244 .set_channels = fm10k_set_channels,
Alexander Duycka211e012014-09-20 19:54:07 -04001245 .get_ts_info = fm10k_get_ts_info,
Alexander Duyck82dd0f72014-09-20 19:50:15 -04001246};
1247
1248void fm10k_set_ethtool_ops(struct net_device *dev)
1249{
1250 dev->ethtool_ops = &fm10k_ethtool_ops;
1251}