1ae06c70bSJeff Kirsher // SPDX-License-Identifier: GPL-2.0
2a5c0d861SJacob Keller /* Copyright(c) 2013 - 2019 Intel Corporation. */
382dd0f7eSAlexander Duyck
4cc69837fSJakub Kicinski #include <linux/ethtool.h>
5eb51bbafSStephen Rothwell #include <linux/vmalloc.h>
6eb51bbafSStephen Rothwell
782dd0f7eSAlexander Duyck #include "fm10k.h"
882dd0f7eSAlexander Duyck
982dd0f7eSAlexander Duyck struct fm10k_stats {
10d63bb21aSJacob Keller /* The stat_string is expected to be a format string formatted using
11d63bb21aSJacob Keller * vsnprintf by fm10k_add_stat_strings. Every member of a stats array
12d63bb21aSJacob Keller * should use the same format specifiers as they will be formatted
13d63bb21aSJacob Keller * using the same variadic arguments.
14d63bb21aSJacob Keller */
1582dd0f7eSAlexander Duyck char stat_string[ETH_GSTRING_LEN];
1682dd0f7eSAlexander Duyck int sizeof_stat;
1782dd0f7eSAlexander Duyck int stat_offset;
1882dd0f7eSAlexander Duyck };
1982dd0f7eSAlexander Duyck
202ead8ae1SJacob Keller #define FM10K_STAT_FIELDS(_type, _name, _stat) { \
212ead8ae1SJacob Keller .stat_string = _name, \
22c593642cSPankaj Bharadiya .sizeof_stat = sizeof_field(_type, _stat), \
232ead8ae1SJacob Keller .stat_offset = offsetof(_type, _stat) \
2482dd0f7eSAlexander Duyck }
2582dd0f7eSAlexander Duyck
262ead8ae1SJacob Keller /* netdevice statistics */
272ead8ae1SJacob Keller #define FM10K_NETDEV_STAT(_net_stat) \
282ead8ae1SJacob Keller FM10K_STAT_FIELDS(struct net_device_stats, __stringify(_net_stat), \
292ead8ae1SJacob Keller _net_stat)
302ead8ae1SJacob Keller
3182dd0f7eSAlexander Duyck static const struct fm10k_stats fm10k_gstrings_net_stats[] = {
3282dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(tx_packets),
3382dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(tx_bytes),
3482dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(tx_errors),
3582dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(rx_packets),
3682dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(rx_bytes),
3782dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(rx_errors),
3882dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(rx_dropped),
3982dd0f7eSAlexander Duyck
4082dd0f7eSAlexander Duyck /* detailed Rx errors */
4182dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(rx_length_errors),
4282dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(rx_crc_errors),
4382dd0f7eSAlexander Duyck FM10K_NETDEV_STAT(rx_fifo_errors),
4482dd0f7eSAlexander Duyck };
4582dd0f7eSAlexander Duyck
4682dd0f7eSAlexander Duyck #define FM10K_NETDEV_STATS_LEN ARRAY_SIZE(fm10k_gstrings_net_stats)
4782dd0f7eSAlexander Duyck
482ead8ae1SJacob Keller /* General interface statistics */
492ead8ae1SJacob Keller #define FM10K_STAT(_name, _stat) \
502ead8ae1SJacob Keller FM10K_STAT_FIELDS(struct fm10k_intfc, _name, _stat)
5182dd0f7eSAlexander Duyck
52fbdb159fSJeff Kirsher static const struct fm10k_stats fm10k_gstrings_global_stats[] = {
5382dd0f7eSAlexander Duyck FM10K_STAT("tx_restart_queue", restart_queue),
5482dd0f7eSAlexander Duyck FM10K_STAT("tx_busy", tx_busy),
5582dd0f7eSAlexander Duyck FM10K_STAT("tx_csum_errors", tx_csum_errors),
5682dd0f7eSAlexander Duyck FM10K_STAT("rx_alloc_failed", alloc_failed),
5782dd0f7eSAlexander Duyck FM10K_STAT("rx_csum_errors", rx_csum_errors),
5882dd0f7eSAlexander Duyck
5982dd0f7eSAlexander Duyck FM10K_STAT("tx_packets_nic", tx_packets_nic),
6082dd0f7eSAlexander Duyck FM10K_STAT("tx_bytes_nic", tx_bytes_nic),
6182dd0f7eSAlexander Duyck FM10K_STAT("rx_packets_nic", rx_packets_nic),
6282dd0f7eSAlexander Duyck FM10K_STAT("rx_bytes_nic", rx_bytes_nic),
6382dd0f7eSAlexander Duyck FM10K_STAT("rx_drops_nic", rx_drops_nic),
6482dd0f7eSAlexander Duyck FM10K_STAT("rx_overrun_pf", rx_overrun_pf),
6582dd0f7eSAlexander Duyck FM10K_STAT("rx_overrun_vf", rx_overrun_vf),
6682dd0f7eSAlexander Duyck
6782dd0f7eSAlexander Duyck FM10K_STAT("swapi_status", hw.swapi.status),
6882dd0f7eSAlexander Duyck FM10K_STAT("mac_rules_used", hw.swapi.mac.used),
6982dd0f7eSAlexander Duyck FM10K_STAT("mac_rules_avail", hw.swapi.mac.avail),
7082dd0f7eSAlexander Duyck
71ce33624fSJacob Keller FM10K_STAT("reset_while_pending", hw.mac.reset_while_pending),
72ce33624fSJacob Keller
73e05546ecSJeff Kirsher FM10K_STAT("tx_hang_count", tx_timeout_count),
7482dd0f7eSAlexander Duyck };
7582dd0f7eSAlexander Duyck
76fbdb159fSJeff Kirsher static const struct fm10k_stats fm10k_gstrings_pf_stats[] = {
77fbdb159fSJeff Kirsher FM10K_STAT("timeout", stats.timeout.count),
78fbdb159fSJeff Kirsher FM10K_STAT("ur", stats.ur.count),
79fbdb159fSJeff Kirsher FM10K_STAT("ca", stats.ca.count),
80fbdb159fSJeff Kirsher FM10K_STAT("um", stats.um.count),
81fbdb159fSJeff Kirsher FM10K_STAT("xec", stats.xec.count),
82fbdb159fSJeff Kirsher FM10K_STAT("vlan_drop", stats.vlan_drop.count),
83fbdb159fSJeff Kirsher FM10K_STAT("loopback_drop", stats.loopback_drop.count),
84fbdb159fSJeff Kirsher FM10K_STAT("nodesc_drop", stats.nodesc_drop.count),
85fbdb159fSJeff Kirsher };
86fbdb159fSJeff Kirsher
872ead8ae1SJacob Keller /* mailbox statistics */
882ead8ae1SJacob Keller #define FM10K_MBX_STAT(_name, _stat) \
892ead8ae1SJacob Keller FM10K_STAT_FIELDS(struct fm10k_mbx_info, _name, _stat)
9080043f3bSJacob Keller
9180043f3bSJacob Keller static const struct fm10k_stats fm10k_gstrings_mbx_stats[] = {
9280043f3bSJacob Keller FM10K_MBX_STAT("mbx_tx_busy", tx_busy),
935680ea69SJacob Keller FM10K_MBX_STAT("mbx_tx_dropped", tx_dropped),
9480043f3bSJacob Keller FM10K_MBX_STAT("mbx_tx_messages", tx_messages),
9580043f3bSJacob Keller FM10K_MBX_STAT("mbx_tx_dwords", tx_dwords),
9617d39facSJacob Keller FM10K_MBX_STAT("mbx_tx_mbmem_pulled", tx_mbmem_pulled),
9780043f3bSJacob Keller FM10K_MBX_STAT("mbx_rx_messages", rx_messages),
9880043f3bSJacob Keller FM10K_MBX_STAT("mbx_rx_dwords", rx_dwords),
9980043f3bSJacob Keller FM10K_MBX_STAT("mbx_rx_parse_err", rx_parse_err),
10017d39facSJacob Keller FM10K_MBX_STAT("mbx_rx_mbmem_pushed", rx_mbmem_pushed),
10180043f3bSJacob Keller };
10280043f3bSJacob Keller
103d63bb21aSJacob Keller /* per-queue ring statistics */
104d63bb21aSJacob Keller #define FM10K_QUEUE_STAT(_name, _stat) \
105d63bb21aSJacob Keller FM10K_STAT_FIELDS(struct fm10k_ring, _name, _stat)
10609401ae2SJacob Keller
10709401ae2SJacob Keller static const struct fm10k_stats fm10k_gstrings_queue_stats[] = {
108d63bb21aSJacob Keller FM10K_QUEUE_STAT("%s_queue_%u_packets", stats.packets),
109d63bb21aSJacob Keller FM10K_QUEUE_STAT("%s_queue_%u_bytes", stats.bytes),
11009401ae2SJacob Keller };
11109401ae2SJacob Keller
112fbdb159fSJeff Kirsher #define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_global_stats)
113fbdb159fSJeff Kirsher #define FM10K_PF_STATS_LEN ARRAY_SIZE(fm10k_gstrings_pf_stats)
11480043f3bSJacob Keller #define FM10K_MBX_STATS_LEN ARRAY_SIZE(fm10k_gstrings_mbx_stats)
11509401ae2SJacob Keller #define FM10K_QUEUE_STATS_LEN ARRAY_SIZE(fm10k_gstrings_queue_stats)
11682dd0f7eSAlexander Duyck
117c0e61781SJeff Kirsher #define FM10K_STATIC_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
11880043f3bSJacob Keller FM10K_NETDEV_STATS_LEN + \
11980043f3bSJacob Keller FM10K_MBX_STATS_LEN)
12082dd0f7eSAlexander Duyck
1215cb8db4aSAlexander Duyck static const char fm10k_gstrings_test[][ETH_GSTRING_LEN] = {
1225cb8db4aSAlexander Duyck "Mailbox test (on/offline)"
1235cb8db4aSAlexander Duyck };
1245cb8db4aSAlexander Duyck
1255cb8db4aSAlexander Duyck #define FM10K_TEST_LEN (sizeof(fm10k_gstrings_test) / ETH_GSTRING_LEN)
1265cb8db4aSAlexander Duyck
1275cb8db4aSAlexander Duyck enum fm10k_self_test_types {
1285cb8db4aSAlexander Duyck FM10K_TEST_MBX,
1295cb8db4aSAlexander Duyck FM10K_TEST_MAX = FM10K_TEST_LEN
1305cb8db4aSAlexander Duyck };
1315cb8db4aSAlexander Duyck
13280043f3bSJacob Keller enum {
13380043f3bSJacob Keller FM10K_PRV_FLAG_LEN,
13480043f3bSJacob Keller };
13580043f3bSJacob Keller
13680043f3bSJacob Keller static const char fm10k_prv_flags[FM10K_PRV_FLAG_LEN][ETH_GSTRING_LEN] = {
13780043f3bSJacob Keller };
13880043f3bSJacob Keller
__fm10k_add_stat_strings(u8 ** p,const struct fm10k_stats stats[],const unsigned int size,...)13936592d6cSJacob Keller static void __fm10k_add_stat_strings(u8 **p, const struct fm10k_stats stats[],
140d63bb21aSJacob Keller const unsigned int size, ...)
141d2e0721bSJacob Keller {
142d2e0721bSJacob Keller unsigned int i;
143d2e0721bSJacob Keller
144d2e0721bSJacob Keller for (i = 0; i < size; i++) {
145d63bb21aSJacob Keller va_list args;
146d63bb21aSJacob Keller
147d63bb21aSJacob Keller va_start(args, size);
148d63bb21aSJacob Keller vsnprintf(*p, ETH_GSTRING_LEN, stats[i].stat_string, args);
149d2e0721bSJacob Keller *p += ETH_GSTRING_LEN;
150d63bb21aSJacob Keller va_end(args);
151d2e0721bSJacob Keller }
152d2e0721bSJacob Keller }
153d2e0721bSJacob Keller
15436592d6cSJacob Keller #define fm10k_add_stat_strings(p, stats, ...) \
15536592d6cSJacob Keller __fm10k_add_stat_strings(p, stats, ARRAY_SIZE(stats), ## __VA_ARGS__)
15636592d6cSJacob Keller
fm10k_get_stat_strings(struct net_device * dev,u8 * data)15780043f3bSJacob Keller static void fm10k_get_stat_strings(struct net_device *dev, u8 *data)
15882dd0f7eSAlexander Duyck {
15929a928eeSJeff Kirsher struct fm10k_intfc *interface = netdev_priv(dev);
160c0e58e93SJacob Keller unsigned int i;
16182dd0f7eSAlexander Duyck
16236592d6cSJacob Keller fm10k_add_stat_strings(&data, fm10k_gstrings_net_stats);
16380043f3bSJacob Keller
16436592d6cSJacob Keller fm10k_add_stat_strings(&data, fm10k_gstrings_global_stats);
165fbdb159fSJeff Kirsher
16636592d6cSJacob Keller fm10k_add_stat_strings(&data, fm10k_gstrings_mbx_stats);
16780043f3bSJacob Keller
168d2e0721bSJacob Keller if (interface->hw.mac.type != fm10k_mac_vf)
16936592d6cSJacob Keller fm10k_add_stat_strings(&data, fm10k_gstrings_pf_stats);
17082dd0f7eSAlexander Duyck
17129a928eeSJeff Kirsher for (i = 0; i < interface->hw.mac.max_queues; i++) {
172d63bb21aSJacob Keller fm10k_add_stat_strings(&data, fm10k_gstrings_queue_stats,
173d63bb21aSJacob Keller "tx", i);
17409401ae2SJacob Keller
175d63bb21aSJacob Keller fm10k_add_stat_strings(&data, fm10k_gstrings_queue_stats,
176d63bb21aSJacob Keller "rx", i);
17782dd0f7eSAlexander Duyck }
17880043f3bSJacob Keller }
17980043f3bSJacob Keller
fm10k_get_strings(struct net_device * dev,u32 stringset,u8 * data)18080043f3bSJacob Keller static void fm10k_get_strings(struct net_device *dev,
18180043f3bSJacob Keller u32 stringset, u8 *data)
18280043f3bSJacob Keller {
18380043f3bSJacob Keller switch (stringset) {
18480043f3bSJacob Keller case ETH_SS_TEST:
185aee24333SJacob Keller memcpy(data, fm10k_gstrings_test,
18680043f3bSJacob Keller FM10K_TEST_LEN * ETH_GSTRING_LEN);
18780043f3bSJacob Keller break;
18880043f3bSJacob Keller case ETH_SS_STATS:
18980043f3bSJacob Keller fm10k_get_stat_strings(dev, data);
19080043f3bSJacob Keller break;
19180043f3bSJacob Keller case ETH_SS_PRIV_FLAGS:
192aee24333SJacob Keller memcpy(data, fm10k_prv_flags,
19380043f3bSJacob Keller FM10K_PRV_FLAG_LEN * ETH_GSTRING_LEN);
19482dd0f7eSAlexander Duyck break;
19582dd0f7eSAlexander Duyck }
19682dd0f7eSAlexander Duyck }
19782dd0f7eSAlexander Duyck
fm10k_get_sset_count(struct net_device * dev,int sset)19882dd0f7eSAlexander Duyck static int fm10k_get_sset_count(struct net_device *dev, int sset)
19982dd0f7eSAlexander Duyck {
200c0e61781SJeff Kirsher struct fm10k_intfc *interface = netdev_priv(dev);
201c0e61781SJeff Kirsher struct fm10k_hw *hw = &interface->hw;
202c0e61781SJeff Kirsher int stats_len = FM10K_STATIC_STATS_LEN;
203c0e61781SJeff Kirsher
20482dd0f7eSAlexander Duyck switch (sset) {
2055cb8db4aSAlexander Duyck case ETH_SS_TEST:
2065cb8db4aSAlexander Duyck return FM10K_TEST_LEN;
20782dd0f7eSAlexander Duyck case ETH_SS_STATS:
20809401ae2SJacob Keller stats_len += hw->mac.max_queues * 2 * FM10K_QUEUE_STATS_LEN;
209fbdb159fSJeff Kirsher
210fbdb159fSJeff Kirsher if (hw->mac.type != fm10k_mac_vf)
211fbdb159fSJeff Kirsher stats_len += FM10K_PF_STATS_LEN;
212fbdb159fSJeff Kirsher
213c0e61781SJeff Kirsher return stats_len;
21480043f3bSJacob Keller case ETH_SS_PRIV_FLAGS:
21580043f3bSJacob Keller return FM10K_PRV_FLAG_LEN;
21682dd0f7eSAlexander Duyck default:
21782dd0f7eSAlexander Duyck return -EOPNOTSUPP;
21882dd0f7eSAlexander Duyck }
21982dd0f7eSAlexander Duyck }
22082dd0f7eSAlexander Duyck
__fm10k_add_ethtool_stats(u64 ** data,void * pointer,const struct fm10k_stats stats[],const unsigned int size)22136592d6cSJacob Keller static void __fm10k_add_ethtool_stats(u64 **data, void *pointer,
222d2e0721bSJacob Keller const struct fm10k_stats stats[],
223d2e0721bSJacob Keller const unsigned int size)
224d2e0721bSJacob Keller {
225d2e0721bSJacob Keller unsigned int i;
226d2e0721bSJacob Keller
227d2e0721bSJacob Keller if (!pointer) {
22809401ae2SJacob Keller /* memory is not zero allocated so we have to clear it */
22909401ae2SJacob Keller for (i = 0; i < size; i++)
23009401ae2SJacob Keller *((*data)++) = 0;
231d2e0721bSJacob Keller return;
232d2e0721bSJacob Keller }
233d2e0721bSJacob Keller
234d2e0721bSJacob Keller for (i = 0; i < size; i++) {
235a5c0d861SJacob Keller char *p = (char *)pointer + stats[i].stat_offset;
236d2e0721bSJacob Keller
237d2e0721bSJacob Keller switch (stats[i].sizeof_stat) {
238d2e0721bSJacob Keller case sizeof(u64):
239d2e0721bSJacob Keller *((*data)++) = *(u64 *)p;
240d2e0721bSJacob Keller break;
241d2e0721bSJacob Keller case sizeof(u32):
242d2e0721bSJacob Keller *((*data)++) = *(u32 *)p;
243d2e0721bSJacob Keller break;
244d2e0721bSJacob Keller case sizeof(u16):
245d2e0721bSJacob Keller *((*data)++) = *(u16 *)p;
246d2e0721bSJacob Keller break;
247d2e0721bSJacob Keller case sizeof(u8):
248d2e0721bSJacob Keller *((*data)++) = *(u8 *)p;
249d2e0721bSJacob Keller break;
250d2e0721bSJacob Keller default:
251454ca380SJacob Keller WARN_ONCE(1, "unexpected stat size for %s",
252454ca380SJacob Keller stats[i].stat_string);
253d2e0721bSJacob Keller *((*data)++) = 0;
254d2e0721bSJacob Keller }
255d2e0721bSJacob Keller }
256d2e0721bSJacob Keller }
257d2e0721bSJacob Keller
25836592d6cSJacob Keller #define fm10k_add_ethtool_stats(data, pointer, stats) \
25936592d6cSJacob Keller __fm10k_add_ethtool_stats(data, pointer, stats, ARRAY_SIZE(stats))
26036592d6cSJacob Keller
fm10k_get_ethtool_stats(struct net_device * netdev,struct ethtool_stats __always_unused * stats,u64 * data)26182dd0f7eSAlexander Duyck static void fm10k_get_ethtool_stats(struct net_device *netdev,
262de445199SJeff Kirsher struct ethtool_stats __always_unused *stats,
263de445199SJeff Kirsher u64 *data)
26482dd0f7eSAlexander Duyck {
26582dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
26682dd0f7eSAlexander Duyck struct net_device_stats *net_stats = &netdev->stats;
26709401ae2SJacob Keller int i;
26882dd0f7eSAlexander Duyck
26982dd0f7eSAlexander Duyck fm10k_update_stats(interface);
27082dd0f7eSAlexander Duyck
27136592d6cSJacob Keller fm10k_add_ethtool_stats(&data, net_stats, fm10k_gstrings_net_stats);
27282dd0f7eSAlexander Duyck
27336592d6cSJacob Keller fm10k_add_ethtool_stats(&data, interface, fm10k_gstrings_global_stats);
274fbdb159fSJeff Kirsher
275d2e0721bSJacob Keller fm10k_add_ethtool_stats(&data, &interface->hw.mbx,
27636592d6cSJacob Keller fm10k_gstrings_mbx_stats);
27780043f3bSJacob Keller
27880043f3bSJacob Keller if (interface->hw.mac.type != fm10k_mac_vf) {
279d2e0721bSJacob Keller fm10k_add_ethtool_stats(&data, interface,
28036592d6cSJacob Keller fm10k_gstrings_pf_stats);
28180043f3bSJacob Keller }
28280043f3bSJacob Keller
28329a928eeSJeff Kirsher for (i = 0; i < interface->hw.mac.max_queues; i++) {
28482dd0f7eSAlexander Duyck struct fm10k_ring *ring;
28582dd0f7eSAlexander Duyck
28682dd0f7eSAlexander Duyck ring = interface->tx_ring[i];
28709401ae2SJacob Keller fm10k_add_ethtool_stats(&data, ring,
28836592d6cSJacob Keller fm10k_gstrings_queue_stats);
28982dd0f7eSAlexander Duyck
29082dd0f7eSAlexander Duyck ring = interface->rx_ring[i];
29109401ae2SJacob Keller fm10k_add_ethtool_stats(&data, ring,
29236592d6cSJacob Keller fm10k_gstrings_queue_stats);
29382dd0f7eSAlexander Duyck }
29482dd0f7eSAlexander Duyck }
29582dd0f7eSAlexander Duyck
29682dd0f7eSAlexander Duyck /* If function below adds more registers this define needs to be updated */
29782dd0f7eSAlexander Duyck #define FM10K_REGS_LEN_Q 29
29882dd0f7eSAlexander Duyck
fm10k_get_reg_q(struct fm10k_hw * hw,u32 * buff,int i)29982dd0f7eSAlexander Duyck static void fm10k_get_reg_q(struct fm10k_hw *hw, u32 *buff, int i)
30082dd0f7eSAlexander Duyck {
30182dd0f7eSAlexander Duyck int idx = 0;
30282dd0f7eSAlexander Duyck
30382dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAL(i));
30482dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAH(i));
30582dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RDLEN(i));
30682dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_RXCTRL(i));
30782dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RDH(i));
30882dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RDT(i));
30982dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RXQCTL(i));
31082dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RXDCTL(i));
31182dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RXINT(i));
31282dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_SRRCTL(i));
31382dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_QPRC(i));
31482dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_QPRDC(i));
31582dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_L(i));
31682dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_H(i));
31782dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAL(i));
31882dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAH(i));
31982dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TDLEN(i));
32082dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_TXCTRL(i));
32182dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TDH(i));
32282dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TDT(i));
32382dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TXDCTL(i));
32482dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TXQCTL(i));
32582dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TXINT(i));
32682dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_QPTC(i));
32782dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_L(i));
32882dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_H(i));
32982dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TQDLOC(i));
33082dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_TX_SGLORT(i));
33182dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_PFVTCTL(i));
33282dd0f7eSAlexander Duyck
33382dd0f7eSAlexander Duyck BUG_ON(idx != FM10K_REGS_LEN_Q);
33482dd0f7eSAlexander Duyck }
33582dd0f7eSAlexander Duyck
33682dd0f7eSAlexander Duyck /* If function above adds more registers this define needs to be updated */
33782dd0f7eSAlexander Duyck #define FM10K_REGS_LEN_VSI 43
33882dd0f7eSAlexander Duyck
fm10k_get_reg_vsi(struct fm10k_hw * hw,u32 * buff,int i)33982dd0f7eSAlexander Duyck static void fm10k_get_reg_vsi(struct fm10k_hw *hw, u32 *buff, int i)
34082dd0f7eSAlexander Duyck {
34182dd0f7eSAlexander Duyck int idx = 0, j;
34282dd0f7eSAlexander Duyck
34382dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_MRQC(i));
34482dd0f7eSAlexander Duyck for (j = 0; j < 10; j++)
34582dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RSSRK(i, j));
34682dd0f7eSAlexander Duyck for (j = 0; j < 32; j++)
34782dd0f7eSAlexander Duyck buff[idx++] = fm10k_read_reg(hw, FM10K_RETA(i, j));
34882dd0f7eSAlexander Duyck
34982dd0f7eSAlexander Duyck BUG_ON(idx != FM10K_REGS_LEN_VSI);
35082dd0f7eSAlexander Duyck }
35182dd0f7eSAlexander Duyck
fm10k_get_regs(struct net_device * netdev,struct ethtool_regs * regs,void * p)35282dd0f7eSAlexander Duyck static void fm10k_get_regs(struct net_device *netdev,
35382dd0f7eSAlexander Duyck struct ethtool_regs *regs, void *p)
35482dd0f7eSAlexander Duyck {
35582dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
35682dd0f7eSAlexander Duyck struct fm10k_hw *hw = &interface->hw;
35782dd0f7eSAlexander Duyck u32 *buff = p;
35882dd0f7eSAlexander Duyck u16 i;
35982dd0f7eSAlexander Duyck
360fcdb0a99SBruce Allan regs->version = BIT(24) | (hw->revision_id << 16) | hw->device_id;
36182dd0f7eSAlexander Duyck
36282dd0f7eSAlexander Duyck switch (hw->mac.type) {
36382dd0f7eSAlexander Duyck case fm10k_mac_pf:
36482dd0f7eSAlexander Duyck /* General PF Registers */
36582dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_CTRL);
36682dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_CTRL_EXT);
36782dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_GCR);
36882dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_GCR_EXT);
36982dd0f7eSAlexander Duyck
37082dd0f7eSAlexander Duyck for (i = 0; i < 8; i++) {
37182dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTMAP(i));
37282dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTDEC(i));
37382dd0f7eSAlexander Duyck }
37482dd0f7eSAlexander Duyck
37582dd0f7eSAlexander Duyck for (i = 0; i < 65; i++) {
37682dd0f7eSAlexander Duyck fm10k_get_reg_vsi(hw, buff, i);
37782dd0f7eSAlexander Duyck buff += FM10K_REGS_LEN_VSI;
37882dd0f7eSAlexander Duyck }
37982dd0f7eSAlexander Duyck
38082dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL);
38182dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL2);
38282dd0f7eSAlexander Duyck
38382dd0f7eSAlexander Duyck for (i = 0; i < FM10K_MAX_QUEUES_PF; i++) {
38482dd0f7eSAlexander Duyck fm10k_get_reg_q(hw, buff, i);
38582dd0f7eSAlexander Duyck buff += FM10K_REGS_LEN_Q;
38682dd0f7eSAlexander Duyck }
38782dd0f7eSAlexander Duyck
38882dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_TPH_CTRL);
38982dd0f7eSAlexander Duyck
39082dd0f7eSAlexander Duyck for (i = 0; i < 8; i++)
39182dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_INT_MAP(i));
39282dd0f7eSAlexander Duyck
39382dd0f7eSAlexander Duyck /* Interrupt Throttling Registers */
39482dd0f7eSAlexander Duyck for (i = 0; i < 130; i++)
39582dd0f7eSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_ITR(i));
39682dd0f7eSAlexander Duyck
39782dd0f7eSAlexander Duyck break;
3985cb8db4aSAlexander Duyck case fm10k_mac_vf:
3995cb8db4aSAlexander Duyck /* General VF registers */
4005cb8db4aSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_VFCTRL);
4015cb8db4aSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_VFINT_MAP);
4025cb8db4aSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_VFSYSTIME);
4035cb8db4aSAlexander Duyck
4045cb8db4aSAlexander Duyck /* Interrupt Throttling Registers */
4055cb8db4aSAlexander Duyck for (i = 0; i < 8; i++)
4065cb8db4aSAlexander Duyck *(buff++) = fm10k_read_reg(hw, FM10K_VFITR(i));
4075cb8db4aSAlexander Duyck
4085cb8db4aSAlexander Duyck fm10k_get_reg_vsi(hw, buff, 0);
4095cb8db4aSAlexander Duyck buff += FM10K_REGS_LEN_VSI;
4105cb8db4aSAlexander Duyck
4115cb8db4aSAlexander Duyck for (i = 0; i < FM10K_MAX_QUEUES_POOL; i++) {
4125cb8db4aSAlexander Duyck if (i < hw->mac.max_queues)
4135cb8db4aSAlexander Duyck fm10k_get_reg_q(hw, buff, i);
4145cb8db4aSAlexander Duyck else
4155cb8db4aSAlexander Duyck memset(buff, 0, sizeof(u32) * FM10K_REGS_LEN_Q);
4165cb8db4aSAlexander Duyck buff += FM10K_REGS_LEN_Q;
4175cb8db4aSAlexander Duyck }
4185cb8db4aSAlexander Duyck
4195cb8db4aSAlexander Duyck break;
42082dd0f7eSAlexander Duyck default:
42182dd0f7eSAlexander Duyck return;
42282dd0f7eSAlexander Duyck }
42382dd0f7eSAlexander Duyck }
42482dd0f7eSAlexander Duyck
42582dd0f7eSAlexander Duyck /* If function above adds more registers these define need to be updated */
42682dd0f7eSAlexander Duyck #define FM10K_REGS_LEN_PF \
42782dd0f7eSAlexander Duyck (162 + (65 * FM10K_REGS_LEN_VSI) + (FM10K_MAX_QUEUES_PF * FM10K_REGS_LEN_Q))
4285cb8db4aSAlexander Duyck #define FM10K_REGS_LEN_VF \
4295cb8db4aSAlexander Duyck (11 + FM10K_REGS_LEN_VSI + (FM10K_MAX_QUEUES_POOL * FM10K_REGS_LEN_Q))
43082dd0f7eSAlexander Duyck
fm10k_get_regs_len(struct net_device * netdev)43182dd0f7eSAlexander Duyck static int fm10k_get_regs_len(struct net_device *netdev)
43282dd0f7eSAlexander Duyck {
43382dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
43482dd0f7eSAlexander Duyck struct fm10k_hw *hw = &interface->hw;
43582dd0f7eSAlexander Duyck
43682dd0f7eSAlexander Duyck switch (hw->mac.type) {
43782dd0f7eSAlexander Duyck case fm10k_mac_pf:
43882dd0f7eSAlexander Duyck return FM10K_REGS_LEN_PF * sizeof(u32);
4395cb8db4aSAlexander Duyck case fm10k_mac_vf:
4405cb8db4aSAlexander Duyck return FM10K_REGS_LEN_VF * sizeof(u32);
44182dd0f7eSAlexander Duyck default:
44282dd0f7eSAlexander Duyck return 0;
44382dd0f7eSAlexander Duyck }
44482dd0f7eSAlexander Duyck }
44582dd0f7eSAlexander Duyck
fm10k_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)44682dd0f7eSAlexander Duyck static void fm10k_get_drvinfo(struct net_device *dev,
44782dd0f7eSAlexander Duyck struct ethtool_drvinfo *info)
44882dd0f7eSAlexander Duyck {
44982dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
45082dd0f7eSAlexander Duyck
45182dd0f7eSAlexander Duyck strncpy(info->driver, fm10k_driver_name,
45282dd0f7eSAlexander Duyck sizeof(info->driver) - 1);
45382dd0f7eSAlexander Duyck strncpy(info->bus_info, pci_name(interface->pdev),
45482dd0f7eSAlexander Duyck sizeof(info->bus_info) - 1);
45582dd0f7eSAlexander Duyck }
45682dd0f7eSAlexander Duyck
fm10k_get_pauseparam(struct net_device * dev,struct ethtool_pauseparam * pause)45782dd0f7eSAlexander Duyck static void fm10k_get_pauseparam(struct net_device *dev,
45882dd0f7eSAlexander Duyck struct ethtool_pauseparam *pause)
45982dd0f7eSAlexander Duyck {
46082dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
46182dd0f7eSAlexander Duyck
46282dd0f7eSAlexander Duyck /* record fixed values for autoneg and tx pause */
46382dd0f7eSAlexander Duyck pause->autoneg = 0;
46482dd0f7eSAlexander Duyck pause->tx_pause = 1;
46582dd0f7eSAlexander Duyck
46682dd0f7eSAlexander Duyck pause->rx_pause = interface->rx_pause ? 1 : 0;
46782dd0f7eSAlexander Duyck }
46882dd0f7eSAlexander Duyck
fm10k_set_pauseparam(struct net_device * dev,struct ethtool_pauseparam * pause)46982dd0f7eSAlexander Duyck static int fm10k_set_pauseparam(struct net_device *dev,
47082dd0f7eSAlexander Duyck struct ethtool_pauseparam *pause)
47182dd0f7eSAlexander Duyck {
47282dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
47382dd0f7eSAlexander Duyck struct fm10k_hw *hw = &interface->hw;
47482dd0f7eSAlexander Duyck
47582dd0f7eSAlexander Duyck if (pause->autoneg || !pause->tx_pause)
47682dd0f7eSAlexander Duyck return -EINVAL;
47782dd0f7eSAlexander Duyck
47882dd0f7eSAlexander Duyck /* we can only support pause on the PF to avoid head-of-line blocking */
47982dd0f7eSAlexander Duyck if (hw->mac.type == fm10k_mac_pf)
48082dd0f7eSAlexander Duyck interface->rx_pause = pause->rx_pause ? ~0 : 0;
48182dd0f7eSAlexander Duyck else if (pause->rx_pause)
48282dd0f7eSAlexander Duyck return -EINVAL;
48382dd0f7eSAlexander Duyck
48482dd0f7eSAlexander Duyck if (netif_running(dev))
48582dd0f7eSAlexander Duyck fm10k_update_rx_drop_en(interface);
48682dd0f7eSAlexander Duyck
48782dd0f7eSAlexander Duyck return 0;
48882dd0f7eSAlexander Duyck }
48982dd0f7eSAlexander Duyck
fm10k_get_msglevel(struct net_device * netdev)49082dd0f7eSAlexander Duyck static u32 fm10k_get_msglevel(struct net_device *netdev)
49182dd0f7eSAlexander Duyck {
49282dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
49382dd0f7eSAlexander Duyck
49482dd0f7eSAlexander Duyck return interface->msg_enable;
49582dd0f7eSAlexander Duyck }
49682dd0f7eSAlexander Duyck
fm10k_set_msglevel(struct net_device * netdev,u32 data)49782dd0f7eSAlexander Duyck static void fm10k_set_msglevel(struct net_device *netdev, u32 data)
49882dd0f7eSAlexander Duyck {
49982dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
50082dd0f7eSAlexander Duyck
50182dd0f7eSAlexander Duyck interface->msg_enable = data;
50282dd0f7eSAlexander Duyck }
50382dd0f7eSAlexander Duyck
fm10k_get_ringparam(struct net_device * netdev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)50482dd0f7eSAlexander Duyck static void fm10k_get_ringparam(struct net_device *netdev,
505*74624944SHao Chen struct ethtool_ringparam *ring,
506*74624944SHao Chen struct kernel_ethtool_ringparam *kernel_ring,
507*74624944SHao Chen struct netlink_ext_ack *extack)
50882dd0f7eSAlexander Duyck {
50982dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
51082dd0f7eSAlexander Duyck
51182dd0f7eSAlexander Duyck ring->rx_max_pending = FM10K_MAX_RXD;
51282dd0f7eSAlexander Duyck ring->tx_max_pending = FM10K_MAX_TXD;
51382dd0f7eSAlexander Duyck ring->rx_mini_max_pending = 0;
51482dd0f7eSAlexander Duyck ring->rx_jumbo_max_pending = 0;
51582dd0f7eSAlexander Duyck ring->rx_pending = interface->rx_ring_count;
51682dd0f7eSAlexander Duyck ring->tx_pending = interface->tx_ring_count;
51782dd0f7eSAlexander Duyck ring->rx_mini_pending = 0;
51882dd0f7eSAlexander Duyck ring->rx_jumbo_pending = 0;
51982dd0f7eSAlexander Duyck }
52082dd0f7eSAlexander Duyck
fm10k_set_ringparam(struct net_device * netdev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)52182dd0f7eSAlexander Duyck static int fm10k_set_ringparam(struct net_device *netdev,
522*74624944SHao Chen struct ethtool_ringparam *ring,
523*74624944SHao Chen struct kernel_ethtool_ringparam *kernel_ring,
524*74624944SHao Chen struct netlink_ext_ack *extack)
52582dd0f7eSAlexander Duyck {
52682dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
52782dd0f7eSAlexander Duyck struct fm10k_ring *temp_ring;
52882dd0f7eSAlexander Duyck int i, err = 0;
52982dd0f7eSAlexander Duyck u32 new_rx_count, new_tx_count;
53082dd0f7eSAlexander Duyck
53182dd0f7eSAlexander Duyck if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
53282dd0f7eSAlexander Duyck return -EINVAL;
53382dd0f7eSAlexander Duyck
53482dd0f7eSAlexander Duyck new_tx_count = clamp_t(u32, ring->tx_pending,
53582dd0f7eSAlexander Duyck FM10K_MIN_TXD, FM10K_MAX_TXD);
53682dd0f7eSAlexander Duyck new_tx_count = ALIGN(new_tx_count, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE);
53782dd0f7eSAlexander Duyck
53882dd0f7eSAlexander Duyck new_rx_count = clamp_t(u32, ring->rx_pending,
53982dd0f7eSAlexander Duyck FM10K_MIN_RXD, FM10K_MAX_RXD);
54082dd0f7eSAlexander Duyck new_rx_count = ALIGN(new_rx_count, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE);
54182dd0f7eSAlexander Duyck
54282dd0f7eSAlexander Duyck if ((new_tx_count == interface->tx_ring_count) &&
54382dd0f7eSAlexander Duyck (new_rx_count == interface->rx_ring_count)) {
54482dd0f7eSAlexander Duyck /* nothing to do */
54582dd0f7eSAlexander Duyck return 0;
54682dd0f7eSAlexander Duyck }
54782dd0f7eSAlexander Duyck
54846929557SJacob Keller while (test_and_set_bit(__FM10K_RESETTING, interface->state))
54982dd0f7eSAlexander Duyck usleep_range(1000, 2000);
55082dd0f7eSAlexander Duyck
55182dd0f7eSAlexander Duyck if (!netif_running(interface->netdev)) {
55282dd0f7eSAlexander Duyck for (i = 0; i < interface->num_tx_queues; i++)
55382dd0f7eSAlexander Duyck interface->tx_ring[i]->count = new_tx_count;
55482dd0f7eSAlexander Duyck for (i = 0; i < interface->num_rx_queues; i++)
55582dd0f7eSAlexander Duyck interface->rx_ring[i]->count = new_rx_count;
55682dd0f7eSAlexander Duyck interface->tx_ring_count = new_tx_count;
55782dd0f7eSAlexander Duyck interface->rx_ring_count = new_rx_count;
55882dd0f7eSAlexander Duyck goto clear_reset;
55982dd0f7eSAlexander Duyck }
56082dd0f7eSAlexander Duyck
56182dd0f7eSAlexander Duyck /* allocate temporary buffer to store rings in */
56282dd0f7eSAlexander Duyck i = max_t(int, interface->num_tx_queues, interface->num_rx_queues);
56342bc47b3SKees Cook temp_ring = vmalloc(array_size(i, sizeof(struct fm10k_ring)));
56482dd0f7eSAlexander Duyck
56582dd0f7eSAlexander Duyck if (!temp_ring) {
56682dd0f7eSAlexander Duyck err = -ENOMEM;
56782dd0f7eSAlexander Duyck goto clear_reset;
56882dd0f7eSAlexander Duyck }
56982dd0f7eSAlexander Duyck
57082dd0f7eSAlexander Duyck fm10k_down(interface);
57182dd0f7eSAlexander Duyck
57282dd0f7eSAlexander Duyck /* Setup new Tx resources and free the old Tx resources in that order.
57382dd0f7eSAlexander Duyck * We can then assign the new resources to the rings via a memcpy.
57482dd0f7eSAlexander Duyck * The advantage to this approach is that we are guaranteed to still
57582dd0f7eSAlexander Duyck * have resources even in the case of an allocation failure.
57682dd0f7eSAlexander Duyck */
57782dd0f7eSAlexander Duyck if (new_tx_count != interface->tx_ring_count) {
57882dd0f7eSAlexander Duyck for (i = 0; i < interface->num_tx_queues; i++) {
57982dd0f7eSAlexander Duyck memcpy(&temp_ring[i], interface->tx_ring[i],
58082dd0f7eSAlexander Duyck sizeof(struct fm10k_ring));
58182dd0f7eSAlexander Duyck
58282dd0f7eSAlexander Duyck temp_ring[i].count = new_tx_count;
58382dd0f7eSAlexander Duyck err = fm10k_setup_tx_resources(&temp_ring[i]);
58482dd0f7eSAlexander Duyck if (err) {
58582dd0f7eSAlexander Duyck while (i) {
58682dd0f7eSAlexander Duyck i--;
58782dd0f7eSAlexander Duyck fm10k_free_tx_resources(&temp_ring[i]);
58882dd0f7eSAlexander Duyck }
58982dd0f7eSAlexander Duyck goto err_setup;
59082dd0f7eSAlexander Duyck }
59182dd0f7eSAlexander Duyck }
59282dd0f7eSAlexander Duyck
59382dd0f7eSAlexander Duyck for (i = 0; i < interface->num_tx_queues; i++) {
59482dd0f7eSAlexander Duyck fm10k_free_tx_resources(interface->tx_ring[i]);
59582dd0f7eSAlexander Duyck
59682dd0f7eSAlexander Duyck memcpy(interface->tx_ring[i], &temp_ring[i],
59782dd0f7eSAlexander Duyck sizeof(struct fm10k_ring));
59882dd0f7eSAlexander Duyck }
59982dd0f7eSAlexander Duyck
60082dd0f7eSAlexander Duyck interface->tx_ring_count = new_tx_count;
60182dd0f7eSAlexander Duyck }
60282dd0f7eSAlexander Duyck
60382dd0f7eSAlexander Duyck /* Repeat the process for the Rx rings if needed */
60482dd0f7eSAlexander Duyck if (new_rx_count != interface->rx_ring_count) {
60582dd0f7eSAlexander Duyck for (i = 0; i < interface->num_rx_queues; i++) {
60682dd0f7eSAlexander Duyck memcpy(&temp_ring[i], interface->rx_ring[i],
60782dd0f7eSAlexander Duyck sizeof(struct fm10k_ring));
60882dd0f7eSAlexander Duyck
60982dd0f7eSAlexander Duyck temp_ring[i].count = new_rx_count;
61082dd0f7eSAlexander Duyck err = fm10k_setup_rx_resources(&temp_ring[i]);
61182dd0f7eSAlexander Duyck if (err) {
61282dd0f7eSAlexander Duyck while (i) {
61382dd0f7eSAlexander Duyck i--;
61482dd0f7eSAlexander Duyck fm10k_free_rx_resources(&temp_ring[i]);
61582dd0f7eSAlexander Duyck }
61682dd0f7eSAlexander Duyck goto err_setup;
61782dd0f7eSAlexander Duyck }
61882dd0f7eSAlexander Duyck }
61982dd0f7eSAlexander Duyck
62082dd0f7eSAlexander Duyck for (i = 0; i < interface->num_rx_queues; i++) {
62182dd0f7eSAlexander Duyck fm10k_free_rx_resources(interface->rx_ring[i]);
62282dd0f7eSAlexander Duyck
62382dd0f7eSAlexander Duyck memcpy(interface->rx_ring[i], &temp_ring[i],
62482dd0f7eSAlexander Duyck sizeof(struct fm10k_ring));
62582dd0f7eSAlexander Duyck }
62682dd0f7eSAlexander Duyck
62782dd0f7eSAlexander Duyck interface->rx_ring_count = new_rx_count;
62882dd0f7eSAlexander Duyck }
62982dd0f7eSAlexander Duyck
63082dd0f7eSAlexander Duyck err_setup:
63182dd0f7eSAlexander Duyck fm10k_up(interface);
63282dd0f7eSAlexander Duyck vfree(temp_ring);
63382dd0f7eSAlexander Duyck clear_reset:
63446929557SJacob Keller clear_bit(__FM10K_RESETTING, interface->state);
63582dd0f7eSAlexander Duyck return err;
63682dd0f7eSAlexander Duyck }
63782dd0f7eSAlexander Duyck
fm10k_get_coalesce(struct net_device * dev,struct ethtool_coalesce * ec,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)63882dd0f7eSAlexander Duyck static int fm10k_get_coalesce(struct net_device *dev,
639f3ccfda1SYufeng Mo struct ethtool_coalesce *ec,
640f3ccfda1SYufeng Mo struct kernel_ethtool_coalesce *kernel_coal,
641f3ccfda1SYufeng Mo struct netlink_ext_ack *extack)
64282dd0f7eSAlexander Duyck {
64382dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
64482dd0f7eSAlexander Duyck
645584373f5SJacob Keller ec->use_adaptive_tx_coalesce = ITR_IS_ADAPTIVE(interface->tx_itr);
64682dd0f7eSAlexander Duyck ec->tx_coalesce_usecs = interface->tx_itr & ~FM10K_ITR_ADAPTIVE;
64782dd0f7eSAlexander Duyck
648584373f5SJacob Keller ec->use_adaptive_rx_coalesce = ITR_IS_ADAPTIVE(interface->rx_itr);
64982dd0f7eSAlexander Duyck ec->rx_coalesce_usecs = interface->rx_itr & ~FM10K_ITR_ADAPTIVE;
65082dd0f7eSAlexander Duyck
65182dd0f7eSAlexander Duyck return 0;
65282dd0f7eSAlexander Duyck }
65382dd0f7eSAlexander Duyck
fm10k_set_coalesce(struct net_device * dev,struct ethtool_coalesce * ec,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)65482dd0f7eSAlexander Duyck static int fm10k_set_coalesce(struct net_device *dev,
655f3ccfda1SYufeng Mo struct ethtool_coalesce *ec,
656f3ccfda1SYufeng Mo struct kernel_ethtool_coalesce *kernel_coal,
657f3ccfda1SYufeng Mo struct netlink_ext_ack *extack)
65882dd0f7eSAlexander Duyck {
65982dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
66082dd0f7eSAlexander Duyck u16 tx_itr, rx_itr;
66182dd0f7eSAlexander Duyck int i;
66282dd0f7eSAlexander Duyck
66382dd0f7eSAlexander Duyck /* verify limits */
66482dd0f7eSAlexander Duyck if ((ec->rx_coalesce_usecs > FM10K_ITR_MAX) ||
66582dd0f7eSAlexander Duyck (ec->tx_coalesce_usecs > FM10K_ITR_MAX))
66682dd0f7eSAlexander Duyck return -EINVAL;
66782dd0f7eSAlexander Duyck
66882dd0f7eSAlexander Duyck /* record settings */
66982dd0f7eSAlexander Duyck tx_itr = ec->tx_coalesce_usecs;
67082dd0f7eSAlexander Duyck rx_itr = ec->rx_coalesce_usecs;
67182dd0f7eSAlexander Duyck
67282dd0f7eSAlexander Duyck /* set initial values for adaptive ITR */
67382dd0f7eSAlexander Duyck if (ec->use_adaptive_tx_coalesce)
674436ea956SJacob Keller tx_itr = FM10K_ITR_ADAPTIVE | FM10K_TX_ITR_DEFAULT;
67582dd0f7eSAlexander Duyck
67682dd0f7eSAlexander Duyck if (ec->use_adaptive_rx_coalesce)
677436ea956SJacob Keller rx_itr = FM10K_ITR_ADAPTIVE | FM10K_RX_ITR_DEFAULT;
67882dd0f7eSAlexander Duyck
67982dd0f7eSAlexander Duyck /* update interface */
68082dd0f7eSAlexander Duyck interface->tx_itr = tx_itr;
68182dd0f7eSAlexander Duyck interface->rx_itr = rx_itr;
68282dd0f7eSAlexander Duyck
68382dd0f7eSAlexander Duyck /* update q_vectors */
68482dd0f7eSAlexander Duyck for (i = 0; i < interface->num_q_vectors; i++) {
6854f9e05fbSJacob Keller struct fm10k_q_vector *qv = interface->q_vector[i];
6864f9e05fbSJacob Keller
68782dd0f7eSAlexander Duyck qv->tx.itr = tx_itr;
68882dd0f7eSAlexander Duyck qv->rx.itr = rx_itr;
68982dd0f7eSAlexander Duyck }
69082dd0f7eSAlexander Duyck
69182dd0f7eSAlexander Duyck return 0;
69282dd0f7eSAlexander Duyck }
69382dd0f7eSAlexander Duyck
fm10k_get_rss_hash_opts(struct fm10k_intfc * interface,struct ethtool_rxnfc * cmd)69482dd0f7eSAlexander Duyck static int fm10k_get_rss_hash_opts(struct fm10k_intfc *interface,
69582dd0f7eSAlexander Duyck struct ethtool_rxnfc *cmd)
69682dd0f7eSAlexander Duyck {
69782dd0f7eSAlexander Duyck cmd->data = 0;
69882dd0f7eSAlexander Duyck
69982dd0f7eSAlexander Duyck /* Report default options for RSS on fm10k */
70082dd0f7eSAlexander Duyck switch (cmd->flow_type) {
70182dd0f7eSAlexander Duyck case TCP_V4_FLOW:
70282dd0f7eSAlexander Duyck case TCP_V6_FLOW:
70382dd0f7eSAlexander Duyck cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
7045463fce6SJeff Kirsher fallthrough;
70582dd0f7eSAlexander Duyck case UDP_V4_FLOW:
7063ee7b3a3SJacob Keller if (test_bit(FM10K_FLAG_RSS_FIELD_IPV4_UDP,
7073ee7b3a3SJacob Keller interface->flags))
70882dd0f7eSAlexander Duyck cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
7095463fce6SJeff Kirsher fallthrough;
71082dd0f7eSAlexander Duyck case SCTP_V4_FLOW:
71182dd0f7eSAlexander Duyck case SCTP_V6_FLOW:
71282dd0f7eSAlexander Duyck case AH_ESP_V4_FLOW:
71382dd0f7eSAlexander Duyck case AH_ESP_V6_FLOW:
71482dd0f7eSAlexander Duyck case AH_V4_FLOW:
71582dd0f7eSAlexander Duyck case AH_V6_FLOW:
71682dd0f7eSAlexander Duyck case ESP_V4_FLOW:
71782dd0f7eSAlexander Duyck case ESP_V6_FLOW:
71882dd0f7eSAlexander Duyck case IPV4_FLOW:
71982dd0f7eSAlexander Duyck case IPV6_FLOW:
72082dd0f7eSAlexander Duyck cmd->data |= RXH_IP_SRC | RXH_IP_DST;
72182dd0f7eSAlexander Duyck break;
72282dd0f7eSAlexander Duyck case UDP_V6_FLOW:
7233ee7b3a3SJacob Keller if (test_bit(FM10K_FLAG_RSS_FIELD_IPV6_UDP,
7243ee7b3a3SJacob Keller interface->flags))
72582dd0f7eSAlexander Duyck cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
72682dd0f7eSAlexander Duyck cmd->data |= RXH_IP_SRC | RXH_IP_DST;
72782dd0f7eSAlexander Duyck break;
72882dd0f7eSAlexander Duyck default:
72982dd0f7eSAlexander Duyck return -EINVAL;
73082dd0f7eSAlexander Duyck }
73182dd0f7eSAlexander Duyck
73282dd0f7eSAlexander Duyck return 0;
73382dd0f7eSAlexander Duyck }
73482dd0f7eSAlexander Duyck
fm10k_get_rxnfc(struct net_device * dev,struct ethtool_rxnfc * cmd,u32 __always_unused * rule_locs)73582dd0f7eSAlexander Duyck static int fm10k_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
736de445199SJeff Kirsher u32 __always_unused *rule_locs)
73782dd0f7eSAlexander Duyck {
73882dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
73982dd0f7eSAlexander Duyck int ret = -EOPNOTSUPP;
74082dd0f7eSAlexander Duyck
74182dd0f7eSAlexander Duyck switch (cmd->cmd) {
74282dd0f7eSAlexander Duyck case ETHTOOL_GRXRINGS:
74382dd0f7eSAlexander Duyck cmd->data = interface->num_rx_queues;
74482dd0f7eSAlexander Duyck ret = 0;
74582dd0f7eSAlexander Duyck break;
74682dd0f7eSAlexander Duyck case ETHTOOL_GRXFH:
74782dd0f7eSAlexander Duyck ret = fm10k_get_rss_hash_opts(interface, cmd);
74882dd0f7eSAlexander Duyck break;
74982dd0f7eSAlexander Duyck default:
75082dd0f7eSAlexander Duyck break;
75182dd0f7eSAlexander Duyck }
75282dd0f7eSAlexander Duyck
75382dd0f7eSAlexander Duyck return ret;
75482dd0f7eSAlexander Duyck }
75582dd0f7eSAlexander Duyck
fm10k_set_rss_hash_opt(struct fm10k_intfc * interface,struct ethtool_rxnfc * nfc)75682dd0f7eSAlexander Duyck static int fm10k_set_rss_hash_opt(struct fm10k_intfc *interface,
75782dd0f7eSAlexander Duyck struct ethtool_rxnfc *nfc)
75882dd0f7eSAlexander Duyck {
7593ee7b3a3SJacob Keller int rss_ipv4_udp = test_bit(FM10K_FLAG_RSS_FIELD_IPV4_UDP,
7603ee7b3a3SJacob Keller interface->flags);
7613ee7b3a3SJacob Keller int rss_ipv6_udp = test_bit(FM10K_FLAG_RSS_FIELD_IPV6_UDP,
7623ee7b3a3SJacob Keller interface->flags);
76382dd0f7eSAlexander Duyck
76482dd0f7eSAlexander Duyck /* RSS does not support anything other than hashing
76582dd0f7eSAlexander Duyck * to queues on src and dst IPs and ports
76682dd0f7eSAlexander Duyck */
76782dd0f7eSAlexander Duyck if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
76882dd0f7eSAlexander Duyck RXH_L4_B_0_1 | RXH_L4_B_2_3))
76982dd0f7eSAlexander Duyck return -EINVAL;
77082dd0f7eSAlexander Duyck
77182dd0f7eSAlexander Duyck switch (nfc->flow_type) {
77282dd0f7eSAlexander Duyck case TCP_V4_FLOW:
77382dd0f7eSAlexander Duyck case TCP_V6_FLOW:
77482dd0f7eSAlexander Duyck if (!(nfc->data & RXH_IP_SRC) ||
77582dd0f7eSAlexander Duyck !(nfc->data & RXH_IP_DST) ||
77682dd0f7eSAlexander Duyck !(nfc->data & RXH_L4_B_0_1) ||
77782dd0f7eSAlexander Duyck !(nfc->data & RXH_L4_B_2_3))
77882dd0f7eSAlexander Duyck return -EINVAL;
77982dd0f7eSAlexander Duyck break;
78082dd0f7eSAlexander Duyck case UDP_V4_FLOW:
78182dd0f7eSAlexander Duyck if (!(nfc->data & RXH_IP_SRC) ||
78282dd0f7eSAlexander Duyck !(nfc->data & RXH_IP_DST))
78382dd0f7eSAlexander Duyck return -EINVAL;
78482dd0f7eSAlexander Duyck switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
78582dd0f7eSAlexander Duyck case 0:
7863ee7b3a3SJacob Keller clear_bit(FM10K_FLAG_RSS_FIELD_IPV4_UDP,
7873ee7b3a3SJacob Keller interface->flags);
78882dd0f7eSAlexander Duyck break;
78982dd0f7eSAlexander Duyck case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
7903ee7b3a3SJacob Keller set_bit(FM10K_FLAG_RSS_FIELD_IPV4_UDP,
7913ee7b3a3SJacob Keller interface->flags);
79282dd0f7eSAlexander Duyck break;
79382dd0f7eSAlexander Duyck default:
79482dd0f7eSAlexander Duyck return -EINVAL;
79582dd0f7eSAlexander Duyck }
79682dd0f7eSAlexander Duyck break;
79782dd0f7eSAlexander Duyck case UDP_V6_FLOW:
79882dd0f7eSAlexander Duyck if (!(nfc->data & RXH_IP_SRC) ||
79982dd0f7eSAlexander Duyck !(nfc->data & RXH_IP_DST))
80082dd0f7eSAlexander Duyck return -EINVAL;
80182dd0f7eSAlexander Duyck switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
80282dd0f7eSAlexander Duyck case 0:
8033ee7b3a3SJacob Keller clear_bit(FM10K_FLAG_RSS_FIELD_IPV6_UDP,
8043ee7b3a3SJacob Keller interface->flags);
80582dd0f7eSAlexander Duyck break;
80682dd0f7eSAlexander Duyck case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
8073ee7b3a3SJacob Keller set_bit(FM10K_FLAG_RSS_FIELD_IPV6_UDP,
8083ee7b3a3SJacob Keller interface->flags);
80982dd0f7eSAlexander Duyck break;
81082dd0f7eSAlexander Duyck default:
81182dd0f7eSAlexander Duyck return -EINVAL;
81282dd0f7eSAlexander Duyck }
81382dd0f7eSAlexander Duyck break;
81482dd0f7eSAlexander Duyck case AH_ESP_V4_FLOW:
81582dd0f7eSAlexander Duyck case AH_V4_FLOW:
81682dd0f7eSAlexander Duyck case ESP_V4_FLOW:
81782dd0f7eSAlexander Duyck case SCTP_V4_FLOW:
81882dd0f7eSAlexander Duyck case AH_ESP_V6_FLOW:
81982dd0f7eSAlexander Duyck case AH_V6_FLOW:
82082dd0f7eSAlexander Duyck case ESP_V6_FLOW:
82182dd0f7eSAlexander Duyck case SCTP_V6_FLOW:
82282dd0f7eSAlexander Duyck if (!(nfc->data & RXH_IP_SRC) ||
82382dd0f7eSAlexander Duyck !(nfc->data & RXH_IP_DST) ||
82482dd0f7eSAlexander Duyck (nfc->data & RXH_L4_B_0_1) ||
82582dd0f7eSAlexander Duyck (nfc->data & RXH_L4_B_2_3))
82682dd0f7eSAlexander Duyck return -EINVAL;
82782dd0f7eSAlexander Duyck break;
82882dd0f7eSAlexander Duyck default:
82982dd0f7eSAlexander Duyck return -EINVAL;
83082dd0f7eSAlexander Duyck }
83182dd0f7eSAlexander Duyck
8323ee7b3a3SJacob Keller /* If something changed we need to update the MRQC register. Note that
8333ee7b3a3SJacob Keller * test_bit() is guaranteed to return strictly 0 or 1, so testing for
8343ee7b3a3SJacob Keller * equality is safe.
8353ee7b3a3SJacob Keller */
8363ee7b3a3SJacob Keller if ((rss_ipv4_udp != test_bit(FM10K_FLAG_RSS_FIELD_IPV4_UDP,
8373ee7b3a3SJacob Keller interface->flags)) ||
8383ee7b3a3SJacob Keller (rss_ipv6_udp != test_bit(FM10K_FLAG_RSS_FIELD_IPV6_UDP,
8393ee7b3a3SJacob Keller interface->flags))) {
84082dd0f7eSAlexander Duyck struct fm10k_hw *hw = &interface->hw;
8413ee7b3a3SJacob Keller bool warn = false;
84282dd0f7eSAlexander Duyck u32 mrqc;
84382dd0f7eSAlexander Duyck
84482dd0f7eSAlexander Duyck /* Perform hash on these packet types */
84582dd0f7eSAlexander Duyck mrqc = FM10K_MRQC_IPV4 |
84682dd0f7eSAlexander Duyck FM10K_MRQC_TCP_IPV4 |
84782dd0f7eSAlexander Duyck FM10K_MRQC_IPV6 |
84882dd0f7eSAlexander Duyck FM10K_MRQC_TCP_IPV6;
84982dd0f7eSAlexander Duyck
8503ee7b3a3SJacob Keller if (test_bit(FM10K_FLAG_RSS_FIELD_IPV4_UDP,
8513ee7b3a3SJacob Keller interface->flags)) {
85282dd0f7eSAlexander Duyck mrqc |= FM10K_MRQC_UDP_IPV4;
8533ee7b3a3SJacob Keller warn = true;
8543ee7b3a3SJacob Keller }
8553ee7b3a3SJacob Keller if (test_bit(FM10K_FLAG_RSS_FIELD_IPV6_UDP,
8563ee7b3a3SJacob Keller interface->flags)) {
85782dd0f7eSAlexander Duyck mrqc |= FM10K_MRQC_UDP_IPV6;
8583ee7b3a3SJacob Keller warn = true;
8593ee7b3a3SJacob Keller }
8603ee7b3a3SJacob Keller
8613ee7b3a3SJacob Keller /* If we enable UDP RSS display a warning that this may cause
8623ee7b3a3SJacob Keller * fragmented UDP packets to arrive out of order.
8633ee7b3a3SJacob Keller */
8643ee7b3a3SJacob Keller if (warn)
8653ee7b3a3SJacob Keller netif_warn(interface, drv, interface->netdev,
8663ee7b3a3SJacob Keller "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
86782dd0f7eSAlexander Duyck
86882dd0f7eSAlexander Duyck fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
86982dd0f7eSAlexander Duyck }
87082dd0f7eSAlexander Duyck
87182dd0f7eSAlexander Duyck return 0;
87282dd0f7eSAlexander Duyck }
87382dd0f7eSAlexander Duyck
fm10k_set_rxnfc(struct net_device * dev,struct ethtool_rxnfc * cmd)87482dd0f7eSAlexander Duyck static int fm10k_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
87582dd0f7eSAlexander Duyck {
87682dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
87782dd0f7eSAlexander Duyck int ret = -EOPNOTSUPP;
87882dd0f7eSAlexander Duyck
87982dd0f7eSAlexander Duyck switch (cmd->cmd) {
88082dd0f7eSAlexander Duyck case ETHTOOL_SRXFH:
88182dd0f7eSAlexander Duyck ret = fm10k_set_rss_hash_opt(interface, cmd);
88282dd0f7eSAlexander Duyck break;
88382dd0f7eSAlexander Duyck default:
88482dd0f7eSAlexander Duyck break;
88582dd0f7eSAlexander Duyck }
88682dd0f7eSAlexander Duyck
88782dd0f7eSAlexander Duyck return ret;
88882dd0f7eSAlexander Duyck }
88982dd0f7eSAlexander Duyck
fm10k_mbx_test(struct fm10k_intfc * interface,u64 * data)8905cb8db4aSAlexander Duyck static int fm10k_mbx_test(struct fm10k_intfc *interface, u64 *data)
8915cb8db4aSAlexander Duyck {
8925cb8db4aSAlexander Duyck struct fm10k_hw *hw = &interface->hw;
8935cb8db4aSAlexander Duyck struct fm10k_mbx_info *mbx = &hw->mbx;
8945cb8db4aSAlexander Duyck u32 attr_flag, test_msg[6];
8955cb8db4aSAlexander Duyck unsigned long timeout;
896c4114e3dSBruce Allan int err = -EINVAL;
8975cb8db4aSAlexander Duyck
8985cb8db4aSAlexander Duyck /* For now this is a VF only feature */
8995cb8db4aSAlexander Duyck if (hw->mac.type != fm10k_mac_vf)
9005cb8db4aSAlexander Duyck return 0;
9015cb8db4aSAlexander Duyck
9025cb8db4aSAlexander Duyck /* loop through both nested and unnested attribute types */
903fcdb0a99SBruce Allan for (attr_flag = BIT(FM10K_TEST_MSG_UNSET);
904fcdb0a99SBruce Allan attr_flag < BIT(2 * FM10K_TEST_MSG_NESTED);
9055cb8db4aSAlexander Duyck attr_flag += attr_flag) {
9065cb8db4aSAlexander Duyck /* generate message to be tested */
9075cb8db4aSAlexander Duyck fm10k_tlv_msg_test_create(test_msg, attr_flag);
9085cb8db4aSAlexander Duyck
9095cb8db4aSAlexander Duyck fm10k_mbx_lock(interface);
9105cb8db4aSAlexander Duyck mbx->test_result = FM10K_NOT_IMPLEMENTED;
9115cb8db4aSAlexander Duyck err = mbx->ops.enqueue_tx(hw, mbx, test_msg);
9125cb8db4aSAlexander Duyck fm10k_mbx_unlock(interface);
9135cb8db4aSAlexander Duyck
9145cb8db4aSAlexander Duyck /* wait up to 1 second for response */
9155cb8db4aSAlexander Duyck timeout = jiffies + HZ;
9165cb8db4aSAlexander Duyck do {
9175cb8db4aSAlexander Duyck if (err < 0)
9185cb8db4aSAlexander Duyck goto err_out;
9195cb8db4aSAlexander Duyck
9205cb8db4aSAlexander Duyck usleep_range(500, 1000);
9215cb8db4aSAlexander Duyck
9225cb8db4aSAlexander Duyck fm10k_mbx_lock(interface);
9235cb8db4aSAlexander Duyck mbx->ops.process(hw, mbx);
9245cb8db4aSAlexander Duyck fm10k_mbx_unlock(interface);
9255cb8db4aSAlexander Duyck
9265cb8db4aSAlexander Duyck err = mbx->test_result;
9275cb8db4aSAlexander Duyck if (!err)
9285cb8db4aSAlexander Duyck break;
9295cb8db4aSAlexander Duyck } while (time_is_after_jiffies(timeout));
9305cb8db4aSAlexander Duyck
9315cb8db4aSAlexander Duyck /* reporting errors */
9325cb8db4aSAlexander Duyck if (err)
9335cb8db4aSAlexander Duyck goto err_out;
9345cb8db4aSAlexander Duyck }
9355cb8db4aSAlexander Duyck
9365cb8db4aSAlexander Duyck err_out:
9375cb8db4aSAlexander Duyck *data = err < 0 ? (attr_flag) : (err > 0);
9385cb8db4aSAlexander Duyck return err;
9395cb8db4aSAlexander Duyck }
9405cb8db4aSAlexander Duyck
fm10k_self_test(struct net_device * dev,struct ethtool_test * eth_test,u64 * data)9415cb8db4aSAlexander Duyck static void fm10k_self_test(struct net_device *dev,
9425cb8db4aSAlexander Duyck struct ethtool_test *eth_test, u64 *data)
9435cb8db4aSAlexander Duyck {
9445cb8db4aSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
9455cb8db4aSAlexander Duyck struct fm10k_hw *hw = &interface->hw;
9465cb8db4aSAlexander Duyck
9475cb8db4aSAlexander Duyck memset(data, 0, sizeof(*data) * FM10K_TEST_LEN);
9485cb8db4aSAlexander Duyck
949540fca35SPhil Turnbull if (FM10K_REMOVED(hw->hw_addr)) {
9505cb8db4aSAlexander Duyck netif_err(interface, drv, dev,
9515cb8db4aSAlexander Duyck "Interface removed - test blocked\n");
9525cb8db4aSAlexander Duyck eth_test->flags |= ETH_TEST_FL_FAILED;
9535cb8db4aSAlexander Duyck return;
9545cb8db4aSAlexander Duyck }
9555cb8db4aSAlexander Duyck
9565cb8db4aSAlexander Duyck if (fm10k_mbx_test(interface, &data[FM10K_TEST_MBX]))
9575cb8db4aSAlexander Duyck eth_test->flags |= ETH_TEST_FL_FAILED;
9585cb8db4aSAlexander Duyck }
9595cb8db4aSAlexander Duyck
fm10k_get_priv_flags(struct net_device * netdev)96080043f3bSJacob Keller static u32 fm10k_get_priv_flags(struct net_device *netdev)
96180043f3bSJacob Keller {
9623ef2f563SJacob Keller return 0;
96380043f3bSJacob Keller }
96480043f3bSJacob Keller
fm10k_set_priv_flags(struct net_device * netdev,u32 priv_flags)96580043f3bSJacob Keller static int fm10k_set_priv_flags(struct net_device *netdev, u32 priv_flags)
96680043f3bSJacob Keller {
967fcdb0a99SBruce Allan if (priv_flags >= BIT(FM10K_PRV_FLAG_LEN))
96880043f3bSJacob Keller return -EINVAL;
96980043f3bSJacob Keller
97080043f3bSJacob Keller return 0;
97180043f3bSJacob Keller }
97280043f3bSJacob Keller
fm10k_get_reta_size(struct net_device __always_unused * netdev)97388cdcfecSJacob Keller static u32 fm10k_get_reta_size(struct net_device __always_unused *netdev)
97482dd0f7eSAlexander Duyck {
97582dd0f7eSAlexander Duyck return FM10K_RETA_SIZE * FM10K_RETA_ENTRIES_PER_REG;
97682dd0f7eSAlexander Duyck }
97782dd0f7eSAlexander Duyck
fm10k_write_reta(struct fm10k_intfc * interface,const u32 * indir)9780ea7fae4SJacob Keller void fm10k_write_reta(struct fm10k_intfc *interface, const u32 *indir)
9790ea7fae4SJacob Keller {
980540a5d85SJacob Keller u16 rss_i = interface->ring_feature[RING_F_RSS].indices;
9810ea7fae4SJacob Keller struct fm10k_hw *hw = &interface->hw;
982540a5d85SJacob Keller u32 table[4];
983540a5d85SJacob Keller int i, j;
9840ea7fae4SJacob Keller
9850ea7fae4SJacob Keller /* record entries to reta table */
986540a5d85SJacob Keller for (i = 0; i < FM10K_RETA_SIZE; i++) {
987540a5d85SJacob Keller u32 reta, n;
988540a5d85SJacob Keller
989540a5d85SJacob Keller /* generate a new table if we weren't given one */
990540a5d85SJacob Keller for (j = 0; j < 4; j++) {
991540a5d85SJacob Keller if (indir)
99234875887SJacob Keller n = indir[4 * i + j];
993540a5d85SJacob Keller else
99434875887SJacob Keller n = ethtool_rxfh_indir_default(4 * i + j,
99534875887SJacob Keller rss_i);
996540a5d85SJacob Keller
997540a5d85SJacob Keller table[j] = n;
998540a5d85SJacob Keller }
999540a5d85SJacob Keller
1000540a5d85SJacob Keller reta = table[0] |
1001540a5d85SJacob Keller (table[1] << 8) |
1002540a5d85SJacob Keller (table[2] << 16) |
1003540a5d85SJacob Keller (table[3] << 24);
10040ea7fae4SJacob Keller
10050ea7fae4SJacob Keller if (interface->reta[i] == reta)
10060ea7fae4SJacob Keller continue;
10070ea7fae4SJacob Keller
10080ea7fae4SJacob Keller interface->reta[i] = reta;
10090ea7fae4SJacob Keller fm10k_write_reg(hw, FM10K_RETA(0, i), reta);
10100ea7fae4SJacob Keller }
10110ea7fae4SJacob Keller }
10120ea7fae4SJacob Keller
fm10k_get_reta(struct net_device * netdev,u32 * indir)101382dd0f7eSAlexander Duyck static int fm10k_get_reta(struct net_device *netdev, u32 *indir)
101482dd0f7eSAlexander Duyck {
101582dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
101682dd0f7eSAlexander Duyck int i;
101782dd0f7eSAlexander Duyck
101882dd0f7eSAlexander Duyck if (!indir)
101982dd0f7eSAlexander Duyck return 0;
102082dd0f7eSAlexander Duyck
102182dd0f7eSAlexander Duyck for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
102282dd0f7eSAlexander Duyck u32 reta = interface->reta[i];
102382dd0f7eSAlexander Duyck
102482dd0f7eSAlexander Duyck indir[0] = (reta << 24) >> 24;
102582dd0f7eSAlexander Duyck indir[1] = (reta << 16) >> 24;
102682dd0f7eSAlexander Duyck indir[2] = (reta << 8) >> 24;
102782dd0f7eSAlexander Duyck indir[3] = (reta) >> 24;
102882dd0f7eSAlexander Duyck }
102982dd0f7eSAlexander Duyck
103082dd0f7eSAlexander Duyck return 0;
103182dd0f7eSAlexander Duyck }
103282dd0f7eSAlexander Duyck
fm10k_set_reta(struct net_device * netdev,const u32 * indir)103382dd0f7eSAlexander Duyck static int fm10k_set_reta(struct net_device *netdev, const u32 *indir)
103482dd0f7eSAlexander Duyck {
103582dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
103682dd0f7eSAlexander Duyck int i;
103782dd0f7eSAlexander Duyck u16 rss_i;
103882dd0f7eSAlexander Duyck
103982dd0f7eSAlexander Duyck if (!indir)
104082dd0f7eSAlexander Duyck return 0;
104182dd0f7eSAlexander Duyck
104282dd0f7eSAlexander Duyck /* Verify user input. */
104382dd0f7eSAlexander Duyck rss_i = interface->ring_feature[RING_F_RSS].indices;
104482dd0f7eSAlexander Duyck for (i = fm10k_get_reta_size(netdev); i--;) {
104582dd0f7eSAlexander Duyck if (indir[i] < rss_i)
104682dd0f7eSAlexander Duyck continue;
104782dd0f7eSAlexander Duyck return -EINVAL;
104882dd0f7eSAlexander Duyck }
104982dd0f7eSAlexander Duyck
10500ea7fae4SJacob Keller fm10k_write_reta(interface, indir);
105182dd0f7eSAlexander Duyck
105282dd0f7eSAlexander Duyck return 0;
105382dd0f7eSAlexander Duyck }
105482dd0f7eSAlexander Duyck
fm10k_get_rssrk_size(struct net_device __always_unused * netdev)1055de445199SJeff Kirsher static u32 fm10k_get_rssrk_size(struct net_device __always_unused *netdev)
105682dd0f7eSAlexander Duyck {
105782dd0f7eSAlexander Duyck return FM10K_RSSRK_SIZE * FM10K_RSSRK_ENTRIES_PER_REG;
105882dd0f7eSAlexander Duyck }
105982dd0f7eSAlexander Duyck
fm10k_get_rssh(struct net_device * netdev,u32 * indir,u8 * key,u8 * hfunc)1060892311f6SEyal Perry static int fm10k_get_rssh(struct net_device *netdev, u32 *indir, u8 *key,
1061892311f6SEyal Perry u8 *hfunc)
106282dd0f7eSAlexander Duyck {
106382dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
106482dd0f7eSAlexander Duyck int i, err;
106582dd0f7eSAlexander Duyck
1066892311f6SEyal Perry if (hfunc)
1067892311f6SEyal Perry *hfunc = ETH_RSS_HASH_TOP;
1068892311f6SEyal Perry
106982dd0f7eSAlexander Duyck err = fm10k_get_reta(netdev, indir);
107082dd0f7eSAlexander Duyck if (err || !key)
107182dd0f7eSAlexander Duyck return err;
107282dd0f7eSAlexander Duyck
107382dd0f7eSAlexander Duyck for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4)
107482dd0f7eSAlexander Duyck *(__le32 *)key = cpu_to_le32(interface->rssrk[i]);
107582dd0f7eSAlexander Duyck
107682dd0f7eSAlexander Duyck return 0;
107782dd0f7eSAlexander Duyck }
107882dd0f7eSAlexander Duyck
fm10k_set_rssh(struct net_device * netdev,const u32 * indir,const u8 * key,const u8 hfunc)107982dd0f7eSAlexander Duyck static int fm10k_set_rssh(struct net_device *netdev, const u32 *indir,
1080892311f6SEyal Perry const u8 *key, const u8 hfunc)
108182dd0f7eSAlexander Duyck {
108282dd0f7eSAlexander Duyck struct fm10k_intfc *interface = netdev_priv(netdev);
108382dd0f7eSAlexander Duyck struct fm10k_hw *hw = &interface->hw;
108482dd0f7eSAlexander Duyck int i, err;
108582dd0f7eSAlexander Duyck
1086892311f6SEyal Perry /* We do not allow change in unsupported parameters */
1087892311f6SEyal Perry if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
1088892311f6SEyal Perry return -EOPNOTSUPP;
1089892311f6SEyal Perry
109082dd0f7eSAlexander Duyck err = fm10k_set_reta(netdev, indir);
109182dd0f7eSAlexander Duyck if (err || !key)
109282dd0f7eSAlexander Duyck return err;
109382dd0f7eSAlexander Duyck
109482dd0f7eSAlexander Duyck for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4) {
109582dd0f7eSAlexander Duyck u32 rssrk = le32_to_cpu(*(__le32 *)key);
109682dd0f7eSAlexander Duyck
109782dd0f7eSAlexander Duyck if (interface->rssrk[i] == rssrk)
109882dd0f7eSAlexander Duyck continue;
109982dd0f7eSAlexander Duyck
110082dd0f7eSAlexander Duyck interface->rssrk[i] = rssrk;
110182dd0f7eSAlexander Duyck fm10k_write_reg(hw, FM10K_RSSRK(0, i), rssrk);
110282dd0f7eSAlexander Duyck }
110382dd0f7eSAlexander Duyck
110482dd0f7eSAlexander Duyck return 0;
110582dd0f7eSAlexander Duyck }
110682dd0f7eSAlexander Duyck
fm10k_max_channels(struct net_device * dev)1107aa3ac822SAlexander Duyck static unsigned int fm10k_max_channels(struct net_device *dev)
1108aa3ac822SAlexander Duyck {
1109aa3ac822SAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
1110aa3ac822SAlexander Duyck unsigned int max_combined = interface->hw.mac.max_queues;
1111aa3ac822SAlexander Duyck u8 tcs = netdev_get_num_tc(dev);
1112aa3ac822SAlexander Duyck
1113aa3ac822SAlexander Duyck /* For QoS report channels per traffic class */
1114aa3ac822SAlexander Duyck if (tcs > 1)
1115fcdb0a99SBruce Allan max_combined = BIT((fls(max_combined / tcs) - 1));
1116aa3ac822SAlexander Duyck
1117aa3ac822SAlexander Duyck return max_combined;
1118aa3ac822SAlexander Duyck }
1119aa3ac822SAlexander Duyck
fm10k_get_channels(struct net_device * dev,struct ethtool_channels * ch)1120aa3ac822SAlexander Duyck static void fm10k_get_channels(struct net_device *dev,
1121aa3ac822SAlexander Duyck struct ethtool_channels *ch)
1122aa3ac822SAlexander Duyck {
1123aa3ac822SAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
1124aa3ac822SAlexander Duyck
1125aa3ac822SAlexander Duyck /* report maximum channels */
1126aa3ac822SAlexander Duyck ch->max_combined = fm10k_max_channels(dev);
1127aa3ac822SAlexander Duyck
1128aa3ac822SAlexander Duyck /* report info for other vector */
1129a3ffeaf7SJacob Keller ch->max_other = NON_Q_VECTORS;
1130aa3ac822SAlexander Duyck ch->other_count = ch->max_other;
1131aa3ac822SAlexander Duyck
1132aa3ac822SAlexander Duyck /* record RSS queues */
1133aa3ac822SAlexander Duyck ch->combined_count = interface->ring_feature[RING_F_RSS].indices;
1134aa3ac822SAlexander Duyck }
1135aa3ac822SAlexander Duyck
fm10k_set_channels(struct net_device * dev,struct ethtool_channels * ch)1136aa3ac822SAlexander Duyck static int fm10k_set_channels(struct net_device *dev,
1137aa3ac822SAlexander Duyck struct ethtool_channels *ch)
1138aa3ac822SAlexander Duyck {
1139aa3ac822SAlexander Duyck struct fm10k_intfc *interface = netdev_priv(dev);
1140aa3ac822SAlexander Duyck unsigned int count = ch->combined_count;
1141aa3ac822SAlexander Duyck
1142aa3ac822SAlexander Duyck /* verify they are not requesting separate vectors */
1143aa3ac822SAlexander Duyck if (!count || ch->rx_count || ch->tx_count)
1144aa3ac822SAlexander Duyck return -EINVAL;
1145aa3ac822SAlexander Duyck
1146aa3ac822SAlexander Duyck /* verify other_count has not changed */
1147a3ffeaf7SJacob Keller if (ch->other_count != NON_Q_VECTORS)
1148aa3ac822SAlexander Duyck return -EINVAL;
1149aa3ac822SAlexander Duyck
1150aa3ac822SAlexander Duyck /* verify the number of channels does not exceed hardware limits */
1151aa3ac822SAlexander Duyck if (count > fm10k_max_channels(dev))
1152aa3ac822SAlexander Duyck return -EINVAL;
1153aa3ac822SAlexander Duyck
1154aa3ac822SAlexander Duyck interface->ring_feature[RING_F_RSS].limit = count;
1155aa3ac822SAlexander Duyck
1156aa3ac822SAlexander Duyck /* use setup TC to update any traffic class queue mapping */
1157aa3ac822SAlexander Duyck return fm10k_setup_tc(dev, netdev_get_num_tc(dev));
1158aa3ac822SAlexander Duyck }
1159aa3ac822SAlexander Duyck
116082dd0f7eSAlexander Duyck static const struct ethtool_ops fm10k_ethtool_ops = {
1161194219a7SJakub Kicinski .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1162194219a7SJakub Kicinski ETHTOOL_COALESCE_USE_ADAPTIVE,
116382dd0f7eSAlexander Duyck .get_strings = fm10k_get_strings,
116482dd0f7eSAlexander Duyck .get_sset_count = fm10k_get_sset_count,
116582dd0f7eSAlexander Duyck .get_ethtool_stats = fm10k_get_ethtool_stats,
116682dd0f7eSAlexander Duyck .get_drvinfo = fm10k_get_drvinfo,
116782dd0f7eSAlexander Duyck .get_link = ethtool_op_get_link,
116882dd0f7eSAlexander Duyck .get_pauseparam = fm10k_get_pauseparam,
116982dd0f7eSAlexander Duyck .set_pauseparam = fm10k_set_pauseparam,
117082dd0f7eSAlexander Duyck .get_msglevel = fm10k_get_msglevel,
117182dd0f7eSAlexander Duyck .set_msglevel = fm10k_set_msglevel,
117282dd0f7eSAlexander Duyck .get_ringparam = fm10k_get_ringparam,
117382dd0f7eSAlexander Duyck .set_ringparam = fm10k_set_ringparam,
117482dd0f7eSAlexander Duyck .get_coalesce = fm10k_get_coalesce,
117582dd0f7eSAlexander Duyck .set_coalesce = fm10k_set_coalesce,
117682dd0f7eSAlexander Duyck .get_rxnfc = fm10k_get_rxnfc,
117782dd0f7eSAlexander Duyck .set_rxnfc = fm10k_set_rxnfc,
117882dd0f7eSAlexander Duyck .get_regs = fm10k_get_regs,
117982dd0f7eSAlexander Duyck .get_regs_len = fm10k_get_regs_len,
11805cb8db4aSAlexander Duyck .self_test = fm10k_self_test,
118180043f3bSJacob Keller .get_priv_flags = fm10k_get_priv_flags,
118280043f3bSJacob Keller .set_priv_flags = fm10k_set_priv_flags,
118382dd0f7eSAlexander Duyck .get_rxfh_indir_size = fm10k_get_reta_size,
118482dd0f7eSAlexander Duyck .get_rxfh_key_size = fm10k_get_rssrk_size,
118582dd0f7eSAlexander Duyck .get_rxfh = fm10k_get_rssh,
118682dd0f7eSAlexander Duyck .set_rxfh = fm10k_set_rssh,
1187aa3ac822SAlexander Duyck .get_channels = fm10k_get_channels,
1188aa3ac822SAlexander Duyck .set_channels = fm10k_set_channels,
1189bab02a69SJacob Keller .get_ts_info = ethtool_op_get_ts_info,
119082dd0f7eSAlexander Duyck };
119182dd0f7eSAlexander Duyck
fm10k_set_ethtool_ops(struct net_device * dev)119282dd0f7eSAlexander Duyck void fm10k_set_ethtool_ops(struct net_device *dev)
119382dd0f7eSAlexander Duyck {
119482dd0f7eSAlexander Duyck dev->ethtool_ops = &fm10k_ethtool_ops;
119582dd0f7eSAlexander Duyck }
1196