Commit 6666f545 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

nfp: abm: keep track of all RED thresholds

Instead of writing the threshold out when Qdisc is configured
and not remembering it move to a scheme where we remember all
thresholds.  When configuration changes parse the offloaded
Qdiscs and set thresholds appropriately.

This will help future extensions.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarJohn Hurley <john.hurley@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 08990494
...@@ -71,35 +71,37 @@ nfp_abm_ctrl_stat_all(struct nfp_abm_link *alink, const struct nfp_rtsym *sym, ...@@ -71,35 +71,37 @@ nfp_abm_ctrl_stat_all(struct nfp_abm_link *alink, const struct nfp_rtsym *sym,
return 0; return 0;
} }
int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link *alink, unsigned int i, u32 val) int __nfp_abm_ctrl_set_q_lvl(struct nfp_abm *abm, unsigned int id, u32 val)
{ {
struct nfp_cpp *cpp = alink->abm->app->cpp; struct nfp_cpp *cpp = abm->app->cpp;
u64 sym_offset; u64 sym_offset;
int err; int err;
sym_offset = (alink->queue_base + i) * NFP_QLVL_STRIDE + NFP_QLVL_THRS; __clear_bit(id, abm->threshold_undef);
err = __nfp_rtsym_writel(cpp, alink->abm->q_lvls, 4, 0, if (abm->thresholds[id] == val)
sym_offset, val); return 0;
sym_offset = id * NFP_QLVL_STRIDE + NFP_QLVL_THRS;
err = __nfp_rtsym_writel(cpp, abm->q_lvls, 4, 0, sym_offset, val);
if (err) { if (err) {
nfp_err(cpp, "RED offload setting level failed on vNIC %d queue %d\n", nfp_err(cpp,
alink->id, i); "RED offload setting level failed on subqueue %d\n",
id);
return err; return err;
} }
abm->thresholds[id] = val;
return 0; return 0;
} }
int nfp_abm_ctrl_set_all_q_lvls(struct nfp_abm_link *alink, u32 val) int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link *alink, unsigned int queue,
u32 val)
{ {
int i, err; unsigned int threshold;
for (i = 0; i < alink->vnic->max_rx_rings; i++) { threshold = alink->queue_base + queue;
err = nfp_abm_ctrl_set_q_lvl(alink, i, val);
if (err)
return err;
}
return 0; return __nfp_abm_ctrl_set_q_lvl(alink->abm, threshold, val);
} }
u64 nfp_abm_ctrl_stat_non_sto(struct nfp_abm_link *alink, unsigned int i) u64 nfp_abm_ctrl_stat_non_sto(struct nfp_abm_link *alink, unsigned int i)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
/* Copyright (C) 2018 Netronome Systems, Inc. */ /* Copyright (C) 2018 Netronome Systems, Inc. */
#include <linux/bitfield.h> #include <linux/bitfield.h>
#include <linux/bitmap.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/lockdep.h> #include <linux/lockdep.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
...@@ -399,6 +400,7 @@ static int nfp_abm_init(struct nfp_app *app) ...@@ -399,6 +400,7 @@ static int nfp_abm_init(struct nfp_app *app)
struct nfp_pf *pf = app->pf; struct nfp_pf *pf = app->pf;
struct nfp_reprs *reprs; struct nfp_reprs *reprs;
struct nfp_abm *abm; struct nfp_abm *abm;
unsigned int i;
int err; int err;
if (!pf->eth_tbl) { if (!pf->eth_tbl) {
...@@ -425,15 +427,28 @@ static int nfp_abm_init(struct nfp_app *app) ...@@ -425,15 +427,28 @@ static int nfp_abm_init(struct nfp_app *app)
if (err) if (err)
goto err_free_abm; goto err_free_abm;
err = -ENOMEM;
abm->num_thresholds = NFP_NET_MAX_RX_RINGS;
abm->threshold_undef = bitmap_zalloc(abm->num_thresholds, GFP_KERNEL);
if (!abm->threshold_undef)
goto err_free_abm;
abm->thresholds = kvcalloc(abm->num_thresholds,
sizeof(*abm->thresholds), GFP_KERNEL);
if (!abm->thresholds)
goto err_free_thresh_umap;
for (i = 0; i < NFP_NET_MAX_RX_RINGS; i++)
__nfp_abm_ctrl_set_q_lvl(abm, i, NFP_ABM_LVL_INFINITY);
/* We start in legacy mode, make sure advanced queuing is disabled */ /* We start in legacy mode, make sure advanced queuing is disabled */
err = nfp_abm_ctrl_qm_disable(abm); err = nfp_abm_ctrl_qm_disable(abm);
if (err) if (err)
goto err_free_abm; goto err_free_thresh;
err = -ENOMEM; err = -ENOMEM;
reprs = nfp_reprs_alloc(pf->max_data_vnics); reprs = nfp_reprs_alloc(pf->max_data_vnics);
if (!reprs) if (!reprs)
goto err_free_abm; goto err_free_thresh;
RCU_INIT_POINTER(app->reprs[NFP_REPR_TYPE_PHYS_PORT], reprs); RCU_INIT_POINTER(app->reprs[NFP_REPR_TYPE_PHYS_PORT], reprs);
reprs = nfp_reprs_alloc(pf->max_data_vnics); reprs = nfp_reprs_alloc(pf->max_data_vnics);
...@@ -445,6 +460,10 @@ static int nfp_abm_init(struct nfp_app *app) ...@@ -445,6 +460,10 @@ static int nfp_abm_init(struct nfp_app *app)
err_free_phys: err_free_phys:
nfp_reprs_clean_and_free_by_type(app, NFP_REPR_TYPE_PHYS_PORT); nfp_reprs_clean_and_free_by_type(app, NFP_REPR_TYPE_PHYS_PORT);
err_free_thresh:
kvfree(abm->thresholds);
err_free_thresh_umap:
bitmap_free(abm->threshold_undef);
err_free_abm: err_free_abm:
kfree(abm); kfree(abm);
app->priv = NULL; app->priv = NULL;
...@@ -458,6 +477,8 @@ static void nfp_abm_clean(struct nfp_app *app) ...@@ -458,6 +477,8 @@ static void nfp_abm_clean(struct nfp_app *app)
nfp_abm_eswitch_clean_up(abm); nfp_abm_eswitch_clean_up(abm);
nfp_reprs_clean_and_free_by_type(app, NFP_REPR_TYPE_PF); nfp_reprs_clean_and_free_by_type(app, NFP_REPR_TYPE_PF);
nfp_reprs_clean_and_free_by_type(app, NFP_REPR_TYPE_PHYS_PORT); nfp_reprs_clean_and_free_by_type(app, NFP_REPR_TYPE_PHYS_PORT);
bitmap_free(abm->threshold_undef);
kvfree(abm->thresholds);
kfree(abm); kfree(abm);
app->priv = NULL; app->priv = NULL;
} }
......
...@@ -20,6 +20,11 @@ struct nfp_net; ...@@ -20,6 +20,11 @@ struct nfp_net;
* struct nfp_abm - ABM NIC app structure * struct nfp_abm - ABM NIC app structure
* @app: back pointer to nfp_app * @app: back pointer to nfp_app
* @pf_id: ID of our PF link * @pf_id: ID of our PF link
*
* @thresholds: current threshold configuration
* @threshold_undef: bitmap of thresholds which have not been set
* @num_thresholds: number of @thresholds and bits in @threshold_undef
*
* @eswitch_mode: devlink eswitch mode, advanced functions only visible * @eswitch_mode: devlink eswitch mode, advanced functions only visible
* in switchdev mode * in switchdev mode
* @q_lvls: queue level control area * @q_lvls: queue level control area
...@@ -28,6 +33,11 @@ struct nfp_net; ...@@ -28,6 +33,11 @@ struct nfp_net;
struct nfp_abm { struct nfp_abm {
struct nfp_app *app; struct nfp_app *app;
unsigned int pf_id; unsigned int pf_id;
u32 *thresholds;
unsigned long *threshold_undef;
size_t num_thresholds;
enum devlink_eswitch_mode eswitch_mode; enum devlink_eswitch_mode eswitch_mode;
const struct nfp_rtsym *q_lvls; const struct nfp_rtsym *q_lvls;
const struct nfp_rtsym *qm_stats; const struct nfp_rtsym *qm_stats;
...@@ -64,11 +74,13 @@ struct nfp_alink_xstats { ...@@ -64,11 +74,13 @@ struct nfp_alink_xstats {
/** /**
* struct nfp_red_qdisc - representation of single RED Qdisc * struct nfp_red_qdisc - representation of single RED Qdisc
* @handle: handle of currently offloaded RED Qdisc * @handle: handle of currently offloaded RED Qdisc
* @threshold: marking threshold of this Qdisc
* @stats: statistics from last refresh * @stats: statistics from last refresh
* @xstats: base of extended statistics * @xstats: base of extended statistics
*/ */
struct nfp_red_qdisc { struct nfp_red_qdisc {
u32 handle; u32 handle;
u32 threshold;
struct nfp_alink_stats stats; struct nfp_alink_stats stats;
struct nfp_alink_xstats xstats; struct nfp_alink_xstats xstats;
}; };
...@@ -102,8 +114,8 @@ int nfp_abm_setup_tc_mq(struct net_device *netdev, struct nfp_abm_link *alink, ...@@ -102,8 +114,8 @@ int nfp_abm_setup_tc_mq(struct net_device *netdev, struct nfp_abm_link *alink,
void nfp_abm_ctrl_read_params(struct nfp_abm_link *alink); void nfp_abm_ctrl_read_params(struct nfp_abm_link *alink);
int nfp_abm_ctrl_find_addrs(struct nfp_abm *abm); int nfp_abm_ctrl_find_addrs(struct nfp_abm *abm);
int nfp_abm_ctrl_set_all_q_lvls(struct nfp_abm_link *alink, u32 val); int __nfp_abm_ctrl_set_q_lvl(struct nfp_abm *abm, unsigned int id, u32 val);
int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link *alink, unsigned int i, int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link *alink, unsigned int queue,
u32 val); u32 val);
int nfp_abm_ctrl_read_stats(struct nfp_abm_link *alink, int nfp_abm_ctrl_read_stats(struct nfp_abm_link *alink,
struct nfp_alink_stats *stats); struct nfp_alink_stats *stats);
......
...@@ -7,25 +7,73 @@ ...@@ -7,25 +7,73 @@
#include "../nfpcore/nfp_cpp.h" #include "../nfpcore/nfp_cpp.h"
#include "../nfp_app.h" #include "../nfp_app.h"
#include "../nfp_main.h"
#include "../nfp_net.h"
#include "../nfp_port.h" #include "../nfp_port.h"
#include "main.h" #include "main.h"
static int static void
nfp_abm_offload_compile_red(struct nfp_abm_link *alink,
struct nfp_red_qdisc *qdisc, unsigned int queue)
{
if (!qdisc->handle)
return;
nfp_abm_ctrl_set_q_lvl(alink, queue, qdisc->threshold);
}
static void nfp_abm_offload_compile_one(struct nfp_abm_link *alink)
{
unsigned int i;
bool is_mq;
is_mq = alink->num_qdiscs > 1;
for (i = 0; i < alink->total_queues; i++) {
struct nfp_red_qdisc *next;
if (is_mq && !alink->red_qdiscs[i].handle)
continue;
next = is_mq ? &alink->red_qdiscs[i] : &alink->red_qdiscs[0];
nfp_abm_offload_compile_red(alink, next, i);
}
}
static void nfp_abm_offload_update(struct nfp_abm *abm)
{
struct nfp_abm_link *alink = NULL;
struct nfp_pf *pf = abm->app->pf;
struct nfp_net *nn;
size_t i;
/* Mark all thresholds as unconfigured */
__bitmap_set(abm->threshold_undef, 0, abm->num_thresholds);
/* Configure all offloads */
list_for_each_entry(nn, &pf->vnics, vnic_list) {
alink = nn->app_priv;
nfp_abm_offload_compile_one(alink);
}
/* Reset the unconfigured thresholds */
for (i = 0; i < abm->num_thresholds; i++)
if (test_bit(i, abm->threshold_undef))
__nfp_abm_ctrl_set_q_lvl(abm, i, NFP_ABM_LVL_INFINITY);
}
static void
__nfp_abm_reset_root(struct net_device *netdev, struct nfp_abm_link *alink, __nfp_abm_reset_root(struct net_device *netdev, struct nfp_abm_link *alink,
u32 handle, unsigned int qs, u32 init_val) u32 handle, unsigned int qs, u32 init_val)
{ {
struct nfp_port *port = nfp_port_from_netdev(netdev); struct nfp_port *port = nfp_port_from_netdev(netdev);
int ret;
ret = nfp_abm_ctrl_set_all_q_lvls(alink, init_val);
memset(alink->red_qdiscs, 0, memset(alink->red_qdiscs, 0,
sizeof(*alink->red_qdiscs) * alink->num_qdiscs); sizeof(*alink->red_qdiscs) * alink->num_qdiscs);
alink->parent = handle; alink->parent = handle;
alink->num_qdiscs = qs; alink->num_qdiscs = qs;
port->tc_offload_cnt = qs; port->tc_offload_cnt = qs;
return ret;
} }
static void static void
...@@ -66,12 +114,12 @@ nfp_abm_red_destroy(struct net_device *netdev, struct nfp_abm_link *alink, ...@@ -66,12 +114,12 @@ nfp_abm_red_destroy(struct net_device *netdev, struct nfp_abm_link *alink,
if (i == alink->num_qdiscs) if (i == alink->num_qdiscs)
return; return;
if (alink->parent == TC_H_ROOT) { if (alink->parent == TC_H_ROOT)
nfp_abm_reset_root(netdev, alink, TC_H_ROOT, 0); nfp_abm_reset_root(netdev, alink, TC_H_ROOT, 0);
} else { else
nfp_abm_ctrl_set_q_lvl(alink, i, NFP_ABM_LVL_INFINITY);
memset(&alink->red_qdiscs[i], 0, sizeof(*alink->red_qdiscs)); memset(&alink->red_qdiscs[i], 0, sizeof(*alink->red_qdiscs));
}
nfp_abm_offload_update(alink->abm);
} }
static bool static bool
...@@ -121,29 +169,19 @@ nfp_abm_red_replace(struct net_device *netdev, struct nfp_abm_link *alink, ...@@ -121,29 +169,19 @@ nfp_abm_red_replace(struct net_device *netdev, struct nfp_abm_link *alink,
} }
if (existing) { if (existing) {
if (alink->parent == TC_H_ROOT) nfp_abm_offload_update(alink->abm);
err = nfp_abm_ctrl_set_all_q_lvls(alink, opt->set.min);
else
err = nfp_abm_ctrl_set_q_lvl(alink, i, opt->set.min);
if (err)
goto err_destroy;
return 0; return 0;
} }
if (opt->parent == TC_H_ROOT) { if (opt->parent == TC_H_ROOT) {
i = 0; i = 0;
err = __nfp_abm_reset_root(netdev, alink, TC_H_ROOT, 1, __nfp_abm_reset_root(netdev, alink, TC_H_ROOT, 1, opt->set.min);
opt->set.min);
} else if (TC_H_MAJ(alink->parent) == TC_H_MAJ(opt->parent)) { } else if (TC_H_MAJ(alink->parent) == TC_H_MAJ(opt->parent)) {
i = TC_H_MIN(opt->parent) - 1; i = TC_H_MIN(opt->parent) - 1;
err = nfp_abm_ctrl_set_q_lvl(alink, i, opt->set.min);
} else { } else {
return -EINVAL; return -EINVAL;
} }
/* Set the handle to try full clean up, in case IO failed */
alink->red_qdiscs[i].handle = opt->handle; alink->red_qdiscs[i].handle = opt->handle;
if (err)
goto err_destroy;
if (opt->parent == TC_H_ROOT) if (opt->parent == TC_H_ROOT)
err = nfp_abm_ctrl_read_stats(alink, err = nfp_abm_ctrl_read_stats(alink,
...@@ -163,9 +201,12 @@ nfp_abm_red_replace(struct net_device *netdev, struct nfp_abm_link *alink, ...@@ -163,9 +201,12 @@ nfp_abm_red_replace(struct net_device *netdev, struct nfp_abm_link *alink,
if (err) if (err)
goto err_destroy; goto err_destroy;
alink->red_qdiscs[i].threshold = opt->set.min;
alink->red_qdiscs[i].stats.backlog_pkts = 0; alink->red_qdiscs[i].stats.backlog_pkts = 0;
alink->red_qdiscs[i].stats.backlog_bytes = 0; alink->red_qdiscs[i].stats.backlog_bytes = 0;
nfp_abm_offload_update(alink->abm);
return 0; return 0;
err_destroy: err_destroy:
/* If the qdisc keeps on living, but we can't offload undo changes */ /* If the qdisc keeps on living, but we can't offload undo changes */
...@@ -292,10 +333,13 @@ int nfp_abm_setup_tc_mq(struct net_device *netdev, struct nfp_abm_link *alink, ...@@ -292,10 +333,13 @@ int nfp_abm_setup_tc_mq(struct net_device *netdev, struct nfp_abm_link *alink,
case TC_MQ_CREATE: case TC_MQ_CREATE:
nfp_abm_reset_root(netdev, alink, opt->handle, nfp_abm_reset_root(netdev, alink, opt->handle,
alink->total_queues); alink->total_queues);
nfp_abm_offload_update(alink->abm);
return 0; return 0;
case TC_MQ_DESTROY: case TC_MQ_DESTROY:
if (opt->handle == alink->parent) if (opt->handle == alink->parent) {
nfp_abm_reset_root(netdev, alink, TC_H_ROOT, 0); nfp_abm_reset_root(netdev, alink, TC_H_ROOT, 0);
nfp_abm_offload_update(alink->abm);
}
return 0; return 0;
case TC_MQ_STATS: case TC_MQ_STATS:
return nfp_abm_mq_stats(alink, opt); return nfp_abm_mq_stats(alink, opt);
......
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