Commit 4b24dd80 authored by David S. Miller's avatar David S. Miller

Merge branch 'nfp-flower-repr-link-state'

Jakub Kicinski says:

====================
nfp: flower: repr link state

Dirk says:

This series provides two updates towards the link state of reprs in
the flower nfp app.

Patch #1 improves the way link state is reported for reprs. Instead of
starting with an assumed 'UP' state, always assume the link state is
'DOWN' and then modify this only on events received from firmware.

Patch #2 adds a new nfp_app hook, repr_preclean. This callback is
executed before reprs are removed from the app context and is executed
per repr.

Patch #3 implements the new REIFY control message, used to indicate
when reprs are created and destroyed. Firmware uses these messages
to prevent communication about any particular port when the driver
doesn't know about the repr yet or anymore.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents ee7e16b6 d2c2928d
...@@ -125,6 +125,27 @@ int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok) ...@@ -125,6 +125,27 @@ int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok)
return 0; return 0;
} }
int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists)
{
struct nfp_flower_cmsg_portreify *msg;
struct sk_buff *skb;
skb = nfp_flower_cmsg_alloc(repr->app, sizeof(*msg),
NFP_FLOWER_CMSG_TYPE_PORT_REIFY,
GFP_KERNEL);
if (!skb)
return -ENOMEM;
msg = nfp_flower_cmsg_get_data(skb);
msg->portnum = cpu_to_be32(repr->dst->u.port_info.port_id);
msg->reserved = 0;
msg->info = cpu_to_be16(exists);
nfp_ctrl_tx(repr->app->ctrl, skb);
return 0;
}
static void static void
nfp_flower_cmsg_portmod_rx(struct nfp_app *app, struct sk_buff *skb) nfp_flower_cmsg_portmod_rx(struct nfp_app *app, struct sk_buff *skb)
{ {
...@@ -160,6 +181,28 @@ nfp_flower_cmsg_portmod_rx(struct nfp_app *app, struct sk_buff *skb) ...@@ -160,6 +181,28 @@ nfp_flower_cmsg_portmod_rx(struct nfp_app *app, struct sk_buff *skb)
rtnl_unlock(); rtnl_unlock();
} }
static void
nfp_flower_cmsg_portreify_rx(struct nfp_app *app, struct sk_buff *skb)
{
struct nfp_flower_priv *priv = app->priv;
struct nfp_flower_cmsg_portreify *msg;
bool exists;
msg = nfp_flower_cmsg_get_data(skb);
rcu_read_lock();
exists = !!nfp_app_repr_get(app, be32_to_cpu(msg->portnum));
rcu_read_unlock();
if (!exists) {
nfp_flower_cmsg_warn(app, "ctrl msg for unknown port 0x%08x\n",
be32_to_cpu(msg->portnum));
return;
}
atomic_inc(&priv->reify_replies);
wake_up_interruptible(&priv->reify_wait_queue);
}
static void static void
nfp_flower_cmsg_process_one_rx(struct nfp_app *app, struct sk_buff *skb) nfp_flower_cmsg_process_one_rx(struct nfp_app *app, struct sk_buff *skb)
{ {
...@@ -176,6 +219,9 @@ nfp_flower_cmsg_process_one_rx(struct nfp_app *app, struct sk_buff *skb) ...@@ -176,6 +219,9 @@ nfp_flower_cmsg_process_one_rx(struct nfp_app *app, struct sk_buff *skb)
type = cmsg_hdr->type; type = cmsg_hdr->type;
switch (type) { switch (type) {
case NFP_FLOWER_CMSG_TYPE_PORT_REIFY:
nfp_flower_cmsg_portreify_rx(app, skb);
break;
case NFP_FLOWER_CMSG_TYPE_PORT_MOD: case NFP_FLOWER_CMSG_TYPE_PORT_MOD:
nfp_flower_cmsg_portmod_rx(app, skb); nfp_flower_cmsg_portmod_rx(app, skb);
break; break;
......
...@@ -350,6 +350,7 @@ struct nfp_flower_cmsg_hdr { ...@@ -350,6 +350,7 @@ struct nfp_flower_cmsg_hdr {
enum nfp_flower_cmsg_type_port { enum nfp_flower_cmsg_type_port {
NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0, NFP_FLOWER_CMSG_TYPE_FLOW_ADD = 0,
NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2, NFP_FLOWER_CMSG_TYPE_FLOW_DEL = 2,
NFP_FLOWER_CMSG_TYPE_PORT_REIFY = 6,
NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7, NFP_FLOWER_CMSG_TYPE_MAC_REPR = 7,
NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8, NFP_FLOWER_CMSG_TYPE_PORT_MOD = 8,
NFP_FLOWER_CMSG_TYPE_NO_NEIGH = 10, NFP_FLOWER_CMSG_TYPE_NO_NEIGH = 10,
...@@ -386,6 +387,15 @@ struct nfp_flower_cmsg_portmod { ...@@ -386,6 +387,15 @@ struct nfp_flower_cmsg_portmod {
#define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0) #define NFP_FLOWER_CMSG_PORTMOD_INFO_LINK BIT(0)
/* NFP_FLOWER_CMSG_TYPE_PORT_REIFY */
struct nfp_flower_cmsg_portreify {
__be32 portnum;
u16 reserved;
__be16 info;
};
#define NFP_FLOWER_CMSG_PORTREIFY_INFO_EXIST BIT(0)
enum nfp_flower_cmsg_port_type { enum nfp_flower_cmsg_port_type {
NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0, NFP_FLOWER_CMSG_PORT_TYPE_UNSPEC = 0x0,
NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1, NFP_FLOWER_CMSG_PORT_TYPE_PHYS_PORT = 0x1,
...@@ -444,6 +454,7 @@ nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx, ...@@ -444,6 +454,7 @@ nfp_flower_cmsg_mac_repr_add(struct sk_buff *skb, unsigned int idx,
unsigned int nbi, unsigned int nbi_port, unsigned int nbi, unsigned int nbi_port,
unsigned int phys_port); unsigned int phys_port);
int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok); int nfp_flower_cmsg_portmod(struct nfp_repr *repr, bool carrier_ok);
int nfp_flower_cmsg_portreify(struct nfp_repr *repr, bool exists);
void nfp_flower_cmsg_process_rx(struct work_struct *work); void nfp_flower_cmsg_process_rx(struct work_struct *work);
void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb); void nfp_flower_cmsg_rx(struct nfp_app *app, struct sk_buff *skb);
struct sk_buff * struct sk_buff *
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
*/ */
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/lockdep.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
...@@ -101,6 +102,52 @@ nfp_flower_repr_get(struct nfp_app *app, u32 port_id) ...@@ -101,6 +102,52 @@ nfp_flower_repr_get(struct nfp_app *app, u32 port_id)
return reprs->reprs[port]; return reprs->reprs[port];
} }
static int
nfp_flower_reprs_reify(struct nfp_app *app, enum nfp_repr_type type,
bool exists)
{
struct nfp_reprs *reprs;
int i, err, count = 0;
reprs = rcu_dereference_protected(app->reprs[type],
lockdep_is_held(&app->pf->lock));
if (!reprs)
return 0;
for (i = 0; i < reprs->num_reprs; i++)
if (reprs->reprs[i]) {
struct nfp_repr *repr = netdev_priv(reprs->reprs[i]);
err = nfp_flower_cmsg_portreify(repr, exists);
if (err)
return err;
count++;
}
return count;
}
static int
nfp_flower_wait_repr_reify(struct nfp_app *app, atomic_t *replies, int tot_repl)
{
struct nfp_flower_priv *priv = app->priv;
int err;
if (!tot_repl)
return 0;
lockdep_assert_held(&app->pf->lock);
err = wait_event_interruptible_timeout(priv->reify_wait_queue,
atomic_read(replies) >= tot_repl,
msecs_to_jiffies(10));
if (err <= 0) {
nfp_warn(app->cpp, "Not all reprs responded to reify\n");
return -EIO;
}
return 0;
}
static int static int
nfp_flower_repr_netdev_open(struct nfp_app *app, struct nfp_repr *repr) nfp_flower_repr_netdev_open(struct nfp_app *app, struct nfp_repr *repr)
{ {
...@@ -110,7 +157,6 @@ nfp_flower_repr_netdev_open(struct nfp_app *app, struct nfp_repr *repr) ...@@ -110,7 +157,6 @@ nfp_flower_repr_netdev_open(struct nfp_app *app, struct nfp_repr *repr)
if (err) if (err)
return err; return err;
netif_carrier_on(repr->netdev);
netif_tx_wake_all_queues(repr->netdev); netif_tx_wake_all_queues(repr->netdev);
return 0; return 0;
...@@ -119,7 +165,6 @@ nfp_flower_repr_netdev_open(struct nfp_app *app, struct nfp_repr *repr) ...@@ -119,7 +165,6 @@ nfp_flower_repr_netdev_open(struct nfp_app *app, struct nfp_repr *repr)
static int static int
nfp_flower_repr_netdev_stop(struct nfp_app *app, struct nfp_repr *repr) nfp_flower_repr_netdev_stop(struct nfp_app *app, struct nfp_repr *repr)
{ {
netif_carrier_off(repr->netdev);
netif_tx_disable(repr->netdev); netif_tx_disable(repr->netdev);
return nfp_flower_cmsg_portmod(repr, false); return nfp_flower_cmsg_portmod(repr, false);
...@@ -140,6 +185,24 @@ nfp_flower_repr_netdev_clean(struct nfp_app *app, struct net_device *netdev) ...@@ -140,6 +185,24 @@ nfp_flower_repr_netdev_clean(struct nfp_app *app, struct net_device *netdev)
netdev_priv(netdev)); netdev_priv(netdev));
} }
static void
nfp_flower_repr_netdev_preclean(struct nfp_app *app, struct net_device *netdev)
{
struct nfp_repr *repr = netdev_priv(netdev);
struct nfp_flower_priv *priv = app->priv;
atomic_t *replies = &priv->reify_replies;
int err;
atomic_set(replies, 0);
err = nfp_flower_cmsg_portreify(repr, false);
if (err) {
nfp_warn(app->cpp, "Failed to notify firmware about repr destruction\n");
return;
}
nfp_flower_wait_repr_reify(app, replies, 1);
}
static void nfp_flower_sriov_disable(struct nfp_app *app) static void nfp_flower_sriov_disable(struct nfp_app *app)
{ {
struct nfp_flower_priv *priv = app->priv; struct nfp_flower_priv *priv = app->priv;
...@@ -157,10 +220,11 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app, ...@@ -157,10 +220,11 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app,
{ {
u8 nfp_pcie = nfp_cppcore_pcie_unit(app->pf->cpp); u8 nfp_pcie = nfp_cppcore_pcie_unit(app->pf->cpp);
struct nfp_flower_priv *priv = app->priv; struct nfp_flower_priv *priv = app->priv;
atomic_t *replies = &priv->reify_replies;
enum nfp_port_type port_type; enum nfp_port_type port_type;
struct nfp_reprs *reprs; struct nfp_reprs *reprs;
int i, err, reify_cnt;
const u8 queue = 0; const u8 queue = 0;
int i, err;
port_type = repr_type == NFP_REPR_TYPE_PF ? NFP_PORT_PF_PORT : port_type = repr_type == NFP_REPR_TYPE_PF ? NFP_PORT_PF_PORT :
NFP_PORT_VF_PORT; NFP_PORT_VF_PORT;
...@@ -211,7 +275,21 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app, ...@@ -211,7 +275,21 @@ nfp_flower_spawn_vnic_reprs(struct nfp_app *app,
nfp_app_reprs_set(app, repr_type, reprs); nfp_app_reprs_set(app, repr_type, reprs);
atomic_set(replies, 0);
reify_cnt = nfp_flower_reprs_reify(app, repr_type, true);
if (reify_cnt < 0) {
err = reify_cnt;
nfp_warn(app->cpp, "Failed to notify firmware about repr creation\n");
goto err_reprs_remove;
}
err = nfp_flower_wait_repr_reify(app, replies, reify_cnt);
if (err)
goto err_reprs_remove;
return 0; return 0;
err_reprs_remove:
reprs = nfp_app_reprs_set(app, repr_type, NULL);
err_reprs_clean: err_reprs_clean:
nfp_reprs_clean_and_free(reprs); nfp_reprs_clean_and_free(reprs);
return err; return err;
...@@ -233,10 +311,11 @@ static int ...@@ -233,10 +311,11 @@ static int
nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv) nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv)
{ {
struct nfp_eth_table *eth_tbl = app->pf->eth_tbl; struct nfp_eth_table *eth_tbl = app->pf->eth_tbl;
atomic_t *replies = &priv->reify_replies;
struct sk_buff *ctrl_skb; struct sk_buff *ctrl_skb;
struct nfp_reprs *reprs; struct nfp_reprs *reprs;
int err, reify_cnt;
unsigned int i; unsigned int i;
int err;
ctrl_skb = nfp_flower_cmsg_mac_repr_start(app, eth_tbl->count); ctrl_skb = nfp_flower_cmsg_mac_repr_start(app, eth_tbl->count);
if (!ctrl_skb) if (!ctrl_skb)
...@@ -293,16 +372,30 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv) ...@@ -293,16 +372,30 @@ nfp_flower_spawn_phy_reprs(struct nfp_app *app, struct nfp_flower_priv *priv)
nfp_app_reprs_set(app, NFP_REPR_TYPE_PHYS_PORT, reprs); nfp_app_reprs_set(app, NFP_REPR_TYPE_PHYS_PORT, reprs);
/* The MAC_REPR control message should be sent after the MAC /* The REIFY/MAC_REPR control messages should be sent after the MAC
* representors are registered using nfp_app_reprs_set(). This is * representors are registered using nfp_app_reprs_set(). This is
* because the firmware may respond with control messages for the * because the firmware may respond with control messages for the
* MAC representors, f.e. to provide the driver with information * MAC representors, f.e. to provide the driver with information
* about their state, and without registration the driver will drop * about their state, and without registration the driver will drop
* any such messages. * any such messages.
*/ */
atomic_set(replies, 0);
reify_cnt = nfp_flower_reprs_reify(app, NFP_REPR_TYPE_PHYS_PORT, true);
if (reify_cnt < 0) {
err = reify_cnt;
nfp_warn(app->cpp, "Failed to notify firmware about repr creation\n");
goto err_reprs_remove;
}
err = nfp_flower_wait_repr_reify(app, replies, reify_cnt);
if (err)
goto err_reprs_remove;
nfp_ctrl_tx(app->ctrl, ctrl_skb); nfp_ctrl_tx(app->ctrl, ctrl_skb);
return 0; return 0;
err_reprs_remove:
reprs = nfp_app_reprs_set(app, NFP_REPR_TYPE_PHYS_PORT, NULL);
err_reprs_clean: err_reprs_clean:
nfp_reprs_clean_and_free(reprs); nfp_reprs_clean_and_free(reprs);
err_free_ctrl_skb: err_free_ctrl_skb:
...@@ -419,6 +512,7 @@ static int nfp_flower_init(struct nfp_app *app) ...@@ -419,6 +512,7 @@ static int nfp_flower_init(struct nfp_app *app)
app_priv->app = app; app_priv->app = app;
skb_queue_head_init(&app_priv->cmsg_skbs); skb_queue_head_init(&app_priv->cmsg_skbs);
INIT_WORK(&app_priv->cmsg_work, nfp_flower_cmsg_process_rx); INIT_WORK(&app_priv->cmsg_work, nfp_flower_cmsg_process_rx);
init_waitqueue_head(&app_priv->reify_wait_queue);
err = nfp_flower_metadata_init(app); err = nfp_flower_metadata_init(app);
if (err) if (err)
...@@ -476,6 +570,7 @@ const struct nfp_app_type app_flower = { ...@@ -476,6 +570,7 @@ const struct nfp_app_type app_flower = {
.vnic_clean = nfp_flower_vnic_clean, .vnic_clean = nfp_flower_vnic_clean,
.repr_init = nfp_flower_repr_netdev_init, .repr_init = nfp_flower_repr_netdev_init,
.repr_preclean = nfp_flower_repr_netdev_preclean,
.repr_clean = nfp_flower_repr_netdev_clean, .repr_clean = nfp_flower_repr_netdev_clean,
.repr_open = nfp_flower_repr_netdev_open, .repr_open = nfp_flower_repr_netdev_open,
......
...@@ -102,6 +102,9 @@ struct nfp_fl_stats_id { ...@@ -102,6 +102,9 @@ struct nfp_fl_stats_id {
* @nfp_mac_off_count: Number of MACs in address list * @nfp_mac_off_count: Number of MACs in address list
* @nfp_tun_mac_nb: Notifier to monitor link state * @nfp_tun_mac_nb: Notifier to monitor link state
* @nfp_tun_neigh_nb: Notifier to monitor neighbour state * @nfp_tun_neigh_nb: Notifier to monitor neighbour state
* @reify_replies: atomically stores the number of replies received
* from firmware for repr reify
* @reify_wait_queue: wait queue for repr reify response counting
*/ */
struct nfp_flower_priv { struct nfp_flower_priv {
struct nfp_app *app; struct nfp_app *app;
...@@ -127,6 +130,8 @@ struct nfp_flower_priv { ...@@ -127,6 +130,8 @@ struct nfp_flower_priv {
int nfp_mac_off_count; int nfp_mac_off_count;
struct notifier_block nfp_tun_mac_nb; struct notifier_block nfp_tun_mac_nb;
struct notifier_block nfp_tun_neigh_nb; struct notifier_block nfp_tun_neigh_nb;
atomic_t reify_replies;
wait_queue_head_t reify_wait_queue;
}; };
struct nfp_fl_key_ls { struct nfp_fl_key_ls {
......
...@@ -77,6 +77,8 @@ extern const struct nfp_app_type app_flower; ...@@ -77,6 +77,8 @@ extern const struct nfp_app_type app_flower;
* @vnic_init: vNIC netdev was registered * @vnic_init: vNIC netdev was registered
* @vnic_clean: vNIC netdev about to be unregistered * @vnic_clean: vNIC netdev about to be unregistered
* @repr_init: representor about to be registered * @repr_init: representor about to be registered
* @repr_preclean: representor about to unregistered, executed before app
* reference to the it is removed
* @repr_clean: representor about to be unregistered * @repr_clean: representor about to be unregistered
* @repr_open: representor netdev open callback * @repr_open: representor netdev open callback
* @repr_stop: representor netdev stop callback * @repr_stop: representor netdev stop callback
...@@ -112,6 +114,7 @@ struct nfp_app_type { ...@@ -112,6 +114,7 @@ struct nfp_app_type {
void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn); void (*vnic_clean)(struct nfp_app *app, struct nfp_net *nn);
int (*repr_init)(struct nfp_app *app, struct net_device *netdev); int (*repr_init)(struct nfp_app *app, struct net_device *netdev);
void (*repr_preclean)(struct nfp_app *app, struct net_device *netdev);
void (*repr_clean)(struct nfp_app *app, struct net_device *netdev); void (*repr_clean)(struct nfp_app *app, struct net_device *netdev);
int (*repr_open)(struct nfp_app *app, struct nfp_repr *repr); int (*repr_open)(struct nfp_app *app, struct nfp_repr *repr);
...@@ -225,6 +228,13 @@ nfp_app_repr_init(struct nfp_app *app, struct net_device *netdev) ...@@ -225,6 +228,13 @@ nfp_app_repr_init(struct nfp_app *app, struct net_device *netdev)
return app->type->repr_init(app, netdev); return app->type->repr_init(app, netdev);
} }
static inline void
nfp_app_repr_preclean(struct nfp_app *app, struct net_device *netdev)
{
if (app->type->repr_preclean)
app->type->repr_preclean(app, netdev);
}
static inline void static inline void
nfp_app_repr_clean(struct nfp_app *app, struct net_device *netdev) nfp_app_repr_clean(struct nfp_app *app, struct net_device *netdev)
{ {
......
...@@ -336,6 +336,8 @@ struct net_device *nfp_repr_alloc(struct nfp_app *app) ...@@ -336,6 +336,8 @@ struct net_device *nfp_repr_alloc(struct nfp_app *app)
if (!netdev) if (!netdev)
return NULL; return NULL;
netif_carrier_off(netdev);
repr = netdev_priv(netdev); repr = netdev_priv(netdev);
repr->netdev = netdev; repr->netdev = netdev;
repr->app = app; repr->app = app;
...@@ -375,11 +377,22 @@ nfp_reprs_clean_and_free_by_type(struct nfp_app *app, ...@@ -375,11 +377,22 @@ nfp_reprs_clean_and_free_by_type(struct nfp_app *app,
enum nfp_repr_type type) enum nfp_repr_type type)
{ {
struct nfp_reprs *reprs; struct nfp_reprs *reprs;
int i;
reprs = nfp_app_reprs_set(app, type, NULL); reprs = rcu_dereference_protected(app->reprs[type],
lockdep_is_held(&app->pf->lock));
if (!reprs) if (!reprs)
return; return;
/* Preclean must happen before we remove the reprs reference from the
* app below.
*/
for (i = 0; i < reprs->num_reprs; i++)
if (reprs->reprs[i])
nfp_app_repr_preclean(app, reprs->reprs[i]);
reprs = nfp_app_reprs_set(app, type, NULL);
synchronize_rcu(); synchronize_rcu();
nfp_reprs_clean_and_free(reprs); nfp_reprs_clean_and_free(reprs);
} }
...@@ -418,8 +431,10 @@ int nfp_reprs_resync_phys_ports(struct nfp_app *app) ...@@ -418,8 +431,10 @@ int nfp_reprs_resync_phys_ports(struct nfp_app *app)
continue; continue;
repr = netdev_priv(old_reprs->reprs[i]); repr = netdev_priv(old_reprs->reprs[i]);
if (repr->port->type == NFP_PORT_INVALID) if (repr->port->type == NFP_PORT_INVALID) {
nfp_app_repr_preclean(app, old_reprs->reprs[i]);
continue; continue;
}
reprs->reprs[i] = old_reprs->reprs[i]; reprs->reprs[i] = old_reprs->reprs[i];
} }
...@@ -436,7 +451,6 @@ int nfp_reprs_resync_phys_ports(struct nfp_app *app) ...@@ -436,7 +451,6 @@ int nfp_reprs_resync_phys_ports(struct nfp_app *app)
if (repr->port->type != NFP_PORT_INVALID) if (repr->port->type != NFP_PORT_INVALID)
continue; continue;
nfp_app_repr_stop(app, repr);
nfp_repr_clean(repr); nfp_repr_clean(repr);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment