Skip to content

Commit a4b7c07

Browse files
committed
Merge branch 'nfp-ksettings'
Jakub Kicinski says: ==================== nfp: ethtool link settings This series adds support for getting and setting link settings via the (moderately) new ethtool ksettings ops. First patch introduces minimal speed and duplex reporting using the information directly provided in PCI BAR0 memory. Next few changes deal with the need to refresh port state read from the service process and patch 6 finally uses that information to provide link speed and duplex. Patches 7 and 8 add auto negotiation and port type reporting. Remaining changes provide the set support for speed and auto negotiation. An upcoming series will also add port splitting support via devlink. Quite a bit of churn in this series is caused by the fact that currently port speed and split changes will usually require a reboot to take effect. Current service process code is not capable of performing MAC reinitialization after chip has been passing traffic. To make sure user is aware of this limitation we refuse the configuration unless netdev is down, print warning to the logs and if configuration was performed but did take effect we unregister the netdev. Service process has a "reboot needed" sticky bit, so reloading the driver will not bring the netdev back. Note that there is a helper in patch 13 which is marked as __always_inline, because the FIELD_* macros require the parameters to be known at compilation time. I hope that is OK. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 18148f0 + 7c69873 commit a4b7c07

11 files changed

Lines changed: 754 additions & 128 deletions

File tree

‎drivers/net/ethernet/netronome/nfp/nfp_main.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#include "nfpcore/nfp.h"
4949
#include "nfpcore/nfp_cpp.h"
5050
#include "nfpcore/nfp_nffw.h"
51-
#include "nfpcore/nfp_nsp_eth.h"
51+
#include "nfpcore/nfp_nsp.h"
5252

5353
#include "nfpcore/nfp6000_pcie.h"
5454

@@ -385,8 +385,7 @@ static void nfp_pci_remove(struct pci_dev *pdev)
385385
{
386386
struct nfp_pf *pf = pci_get_drvdata(pdev);
387387

388-
if (!list_empty(&pf->ports))
389-
nfp_net_pci_remove(pf);
388+
nfp_net_pci_remove(pf);
390389

391390
nfp_pcie_sriov_disable(pdev);
392391

‎drivers/net/ethernet/netronome/nfp/nfp_main.h‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
#include <linux/list.h>
4343
#include <linux/types.h>
4444
#include <linux/msi.h>
45+
#include <linux/mutex.h>
4546
#include <linux/pci.h>
47+
#include <linux/workqueue.h>
4648

4749
struct dentry;
4850
struct pci_dev;
@@ -64,8 +66,11 @@ struct nfp_eth_table;
6466
* @fw_loaded: Is the firmware loaded?
6567
* @eth_tbl: NSP ETH table
6668
* @ddir: Per-device debugfs directory
67-
* @num_ports: Number of adapter ports
69+
* @num_ports: Number of adapter ports app firmware supports
70+
* @num_netdevs: Number of netdevs spawned
6871
* @ports: Linked list of port structures (struct nfp_net)
72+
* @port_lock: Protects @ports, @num_ports, @num_netdevs
73+
* @port_refresh_work: Work entry for taking netdevs out
6974
*/
7075
struct nfp_pf {
7176
struct pci_dev *pdev;
@@ -88,7 +93,11 @@ struct nfp_pf {
8893
struct dentry *ddir;
8994

9095
unsigned int num_ports;
96+
unsigned int num_netdevs;
97+
9198
struct list_head ports;
99+
struct work_struct port_refresh_work;
100+
struct mutex port_lock;
92101
};
93102

94103
extern struct pci_driver nfp_netvf_pci_driver;

‎drivers/net/ethernet/netronome/nfp/nfp_net.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ struct nfp_net_dp {
523523
* @reconfig_sync_present: Some thread is performing synchronous reconfig
524524
* @reconfig_timer: Timer for async reading of reconfig results
525525
* @link_up: Is the link up?
526-
* @link_status_lock: Protects @link_up and ensures atomicity with BAR reading
526+
* @link_changed: Has link state changes since last port refresh?
527+
* @link_status_lock: Protects @link_* and ensures atomicity with BAR reading
527528
* @rx_coalesce_usecs: RX interrupt moderation usecs delay parameter
528529
* @rx_coalesce_max_frames: RX interrupt moderation frame count parameter
529530
* @tx_coalesce_usecs: TX interrupt moderation usecs delay parameter
@@ -580,6 +581,7 @@ struct nfp_net {
580581
u32 me_freq_mhz;
581582

582583
bool link_up;
584+
bool link_changed;
583585
spinlock_t link_status_lock;
584586

585587
spinlock_t reconfig_lock;
@@ -810,6 +812,9 @@ nfp_net_irqs_assign(struct nfp_net *nn, struct msix_entry *irq_entries,
810812
struct nfp_net_dp *nfp_net_clone_dp(struct nfp_net *nn);
811813
int nfp_net_ring_reconfig(struct nfp_net *nn, struct nfp_net_dp *new);
812814

815+
bool nfp_net_link_changed_read_clear(struct nfp_net *nn);
816+
void nfp_net_refresh_port_config(struct nfp_net *nn);
817+
813818
#ifdef CONFIG_NFP_DEBUG
814819
void nfp_net_debugfs_create(void);
815820
void nfp_net_debugfs_destroy(void);

‎drivers/net/ethernet/netronome/nfp/nfp_net_common.c‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
#include <net/pkt_cls.h>
6868
#include <net/vxlan.h>
6969

70-
#include "nfpcore/nfp_nsp_eth.h"
70+
#include "nfpcore/nfp_nsp.h"
7171
#include "nfp_net_ctrl.h"
7272
#include "nfp_net.h"
7373

@@ -376,6 +376,19 @@ static irqreturn_t nfp_net_irq_rxtx(int irq, void *data)
376376
return IRQ_HANDLED;
377377
}
378378

379+
bool nfp_net_link_changed_read_clear(struct nfp_net *nn)
380+
{
381+
unsigned long flags;
382+
bool ret;
383+
384+
spin_lock_irqsave(&nn->link_status_lock, flags);
385+
ret = nn->link_changed;
386+
nn->link_changed = false;
387+
spin_unlock_irqrestore(&nn->link_status_lock, flags);
388+
389+
return ret;
390+
}
391+
379392
/**
380393
* nfp_net_read_link_status() - Reread link status from control BAR
381394
* @nn: NFP Network structure
@@ -395,6 +408,7 @@ static void nfp_net_read_link_status(struct nfp_net *nn)
395408
goto out;
396409

397410
nn->link_up = link_up;
411+
nn->link_changed = true;
398412

399413
if (nn->link_up) {
400414
netif_carrier_on(nn->dp.netdev);

‎drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,19 @@
177177
#define NFP_NET_CFG_VERSION_MINOR(x) (((x) & 0xff) << 0)
178178
#define NFP_NET_CFG_STS 0x0034
179179
#define NFP_NET_CFG_STS_LINK (0x1 << 0) /* Link up or down */
180+
/* Link rate */
181+
#define NFP_NET_CFG_STS_LINK_RATE_SHIFT 1
182+
#define NFP_NET_CFG_STS_LINK_RATE_MASK 0xF
183+
#define NFP_NET_CFG_STS_LINK_RATE \
184+
(NFP_NET_CFG_STS_LINK_RATE_MASK << NFP_NET_CFG_STS_LINK_RATE_SHIFT)
185+
#define NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED 0
186+
#define NFP_NET_CFG_STS_LINK_RATE_UNKNOWN 1
187+
#define NFP_NET_CFG_STS_LINK_RATE_1G 2
188+
#define NFP_NET_CFG_STS_LINK_RATE_10G 3
189+
#define NFP_NET_CFG_STS_LINK_RATE_25G 4
190+
#define NFP_NET_CFG_STS_LINK_RATE_40G 5
191+
#define NFP_NET_CFG_STS_LINK_RATE_50G 6
192+
#define NFP_NET_CFG_STS_LINK_RATE_100G 7
180193
#define NFP_NET_CFG_CAP 0x0038
181194
#define NFP_NET_CFG_MAX_TXRINGS 0x003c
182195
#define NFP_NET_CFG_MAX_RXRINGS 0x0040

‎drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <linux/ethtool.h>
5050

5151
#include "nfpcore/nfp.h"
52+
#include "nfpcore/nfp_nsp.h"
5253
#include "nfp_net_ctrl.h"
5354
#include "nfp_net.h"
5455

@@ -173,6 +174,114 @@ static void nfp_net_get_drvinfo(struct net_device *netdev,
173174
drvinfo->regdump_len = NFP_NET_CFG_BAR_SZ;
174175
}
175176

177+
/**
178+
* nfp_net_get_link_ksettings - Get Link Speed settings
179+
* @netdev: network interface device structure
180+
* @cmd: ethtool command
181+
*
182+
* Reports speed settings based on info in the BAR provided by the fw.
183+
*/
184+
static int
185+
nfp_net_get_link_ksettings(struct net_device *netdev,
186+
struct ethtool_link_ksettings *cmd)
187+
{
188+
static const u32 ls_to_ethtool[] = {
189+
[NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED] = 0,
190+
[NFP_NET_CFG_STS_LINK_RATE_UNKNOWN] = SPEED_UNKNOWN,
191+
[NFP_NET_CFG_STS_LINK_RATE_1G] = SPEED_1000,
192+
[NFP_NET_CFG_STS_LINK_RATE_10G] = SPEED_10000,
193+
[NFP_NET_CFG_STS_LINK_RATE_25G] = SPEED_25000,
194+
[NFP_NET_CFG_STS_LINK_RATE_40G] = SPEED_40000,
195+
[NFP_NET_CFG_STS_LINK_RATE_50G] = SPEED_50000,
196+
[NFP_NET_CFG_STS_LINK_RATE_100G] = SPEED_100000,
197+
};
198+
struct nfp_net *nn = netdev_priv(netdev);
199+
u32 sts, ls;
200+
201+
ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
202+
cmd->base.port = PORT_OTHER;
203+
cmd->base.speed = SPEED_UNKNOWN;
204+
cmd->base.duplex = DUPLEX_UNKNOWN;
205+
206+
if (nn->eth_port)
207+
cmd->base.autoneg = nn->eth_port->aneg != NFP_ANEG_DISABLED ?
208+
AUTONEG_ENABLE : AUTONEG_DISABLE;
209+
210+
if (!netif_carrier_ok(netdev))
211+
return 0;
212+
213+
/* Use link speed from ETH table if available, otherwise try the BAR */
214+
if (nn->eth_port && nfp_net_link_changed_read_clear(nn))
215+
nfp_net_refresh_port_config(nn);
216+
/* Separate if - on FW error the port could've disappeared from table */
217+
if (nn->eth_port) {
218+
cmd->base.port = nn->eth_port->port_type;
219+
cmd->base.speed = nn->eth_port->speed;
220+
cmd->base.duplex = DUPLEX_FULL;
221+
return 0;
222+
}
223+
224+
sts = nn_readl(nn, NFP_NET_CFG_STS);
225+
226+
ls = FIELD_GET(NFP_NET_CFG_STS_LINK_RATE, sts);
227+
if (ls == NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED)
228+
return -EOPNOTSUPP;
229+
230+
if (ls == NFP_NET_CFG_STS_LINK_RATE_UNKNOWN ||
231+
ls >= ARRAY_SIZE(ls_to_ethtool))
232+
return 0;
233+
234+
cmd->base.speed = ls_to_ethtool[sts];
235+
cmd->base.duplex = DUPLEX_FULL;
236+
237+
return 0;
238+
}
239+
240+
static int
241+
nfp_net_set_link_ksettings(struct net_device *netdev,
242+
const struct ethtool_link_ksettings *cmd)
243+
{
244+
struct nfp_net *nn = netdev_priv(netdev);
245+
struct nfp_nsp *nsp;
246+
int err;
247+
248+
if (!nn->eth_port)
249+
return -EOPNOTSUPP;
250+
251+
if (netif_running(netdev)) {
252+
nn_warn(nn, "Changing settings not allowed on an active interface. It may cause the port to be disabled until reboot.\n");
253+
return -EBUSY;
254+
}
255+
256+
nsp = nfp_eth_config_start(nn->cpp, nn->eth_port->index);
257+
if (IS_ERR(nsp))
258+
return PTR_ERR(nsp);
259+
260+
err = __nfp_eth_set_aneg(nsp, cmd->base.autoneg == AUTONEG_ENABLE ?
261+
NFP_ANEG_AUTO : NFP_ANEG_DISABLED);
262+
if (err)
263+
goto err_bad_set;
264+
if (cmd->base.speed != SPEED_UNKNOWN) {
265+
u32 speed = cmd->base.speed / nn->eth_port->lanes;
266+
267+
err = __nfp_eth_set_speed(nsp, speed);
268+
if (err)
269+
goto err_bad_set;
270+
}
271+
272+
err = nfp_eth_config_commit_end(nsp);
273+
if (err > 0)
274+
return 0; /* no change */
275+
276+
nfp_net_refresh_port_config(nn);
277+
278+
return err;
279+
280+
err_bad_set:
281+
nfp_eth_config_cleanup_end(nsp);
282+
return err;
283+
}
284+
176285
static void nfp_net_get_ringparam(struct net_device *netdev,
177286
struct ethtool_ringparam *ring)
178287
{
@@ -814,6 +923,8 @@ static const struct ethtool_ops nfp_net_ethtool_ops = {
814923
.set_coalesce = nfp_net_set_coalesce,
815924
.get_channels = nfp_net_get_channels,
816925
.set_channels = nfp_net_set_channels,
926+
.get_link_ksettings = nfp_net_get_link_ksettings,
927+
.set_link_ksettings = nfp_net_set_link_ksettings,
817928
};
818929

819930
void nfp_net_set_ethtool_ops(struct net_device *netdev)

0 commit comments

Comments
 (0)