Commit 6133e78f authored by David S. Miller's avatar David S. Miller

Merge branch 'gred-add-offload-support'

Jakub Kicinski says:

====================
gred: add offload support

This series adds support for GRED offload in the nfp driver.  So
far we have only supported the RED Qdisc offload, but we need a
way to differentiate traffic types e.g. based on DSCP marking.

It may seem like PRIO+RED is a good match for this job, however,
(a) we don't need strict priority behaviour of PRIO, and (b) PRIO
uses the legacy way of mapping ToS fields to bands, which is quite
awkward and limitting.

The less commonly used GRED Qdisc is a better much for the scenario,
it allows multiple sets of RED parameters and queue lengths to be
maintained with a single FIFO queue.  This is exactly how nfp offload
behaves.  We use a trivial u32 classifier to assign packets to virtual
queues.

There is also the minor advantage that GRED can't have its child
changed, therefore limitting ways in which the configuration of SW
path can diverge from HW offload.

Last patch of the series adds support for (G)RED in non-ECN mode,
where packets are dropped instead of marked.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents e432abfb 340a4864
...@@ -56,6 +56,7 @@ endif ...@@ -56,6 +56,7 @@ endif
ifeq ($(CONFIG_NFP_APP_ABM_NIC),y) ifeq ($(CONFIG_NFP_APP_ABM_NIC),y)
nfp-objs += \ nfp-objs += \
abm/cls.o \
abm/ctrl.o \ abm/ctrl.o \
abm/qdisc.o \ abm/qdisc.o \
abm/main.o abm/main.o
......
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright (C) 2018 Netronome Systems, Inc. */
#include <linux/bitfield.h>
#include <net/pkt_cls.h>
#include "../nfpcore/nfp_cpp.h"
#include "../nfp_app.h"
#include "../nfp_net_repr.h"
#include "main.h"
struct nfp_abm_u32_match {
u32 handle;
u32 band;
u8 mask;
u8 val;
struct list_head list;
};
static bool
nfp_abm_u32_check_knode(struct nfp_abm *abm, struct tc_cls_u32_knode *knode,
__be16 proto, struct netlink_ext_ack *extack)
{
struct tc_u32_key *k;
unsigned int tos_off;
if (knode->exts && tcf_exts_has_actions(knode->exts)) {
NL_SET_ERR_MSG_MOD(extack, "action offload not supported");
return false;
}
if (knode->link_handle) {
NL_SET_ERR_MSG_MOD(extack, "linking not supported");
return false;
}
if (knode->sel->flags != TC_U32_TERMINAL) {
NL_SET_ERR_MSG_MOD(extack,
"flags must be equal to TC_U32_TERMINAL");
return false;
}
if (knode->sel->off || knode->sel->offshift || knode->sel->offmask ||
knode->sel->offoff || knode->fshift) {
NL_SET_ERR_MSG_MOD(extack, "variable offseting not supported");
return false;
}
if (knode->sel->hoff || knode->sel->hmask) {
NL_SET_ERR_MSG_MOD(extack, "hashing not supported");
return false;
}
if (knode->val || knode->mask) {
NL_SET_ERR_MSG_MOD(extack, "matching on mark not supported");
return false;
}
if (knode->res && knode->res->class) {
NL_SET_ERR_MSG_MOD(extack, "setting non-0 class not supported");
return false;
}
if (knode->res && knode->res->classid >= abm->num_bands) {
NL_SET_ERR_MSG_MOD(extack,
"classid higher than number of bands");
return false;
}
if (knode->sel->nkeys != 1) {
NL_SET_ERR_MSG_MOD(extack, "exactly one key required");
return false;
}
switch (proto) {
case htons(ETH_P_IP):
tos_off = 16;
break;
case htons(ETH_P_IPV6):
tos_off = 20;
break;
default:
NL_SET_ERR_MSG_MOD(extack, "only IP and IPv6 supported as filter protocol");
return false;
}
k = &knode->sel->keys[0];
if (k->offmask) {
NL_SET_ERR_MSG_MOD(extack, "offset mask - variable offseting not supported");
return false;
}
if (k->off) {
NL_SET_ERR_MSG_MOD(extack, "only DSCP fields can be matched");
return false;
}
if (k->val & ~k->mask) {
NL_SET_ERR_MSG_MOD(extack, "mask does not cover the key");
return false;
}
if (be32_to_cpu(k->mask) >> tos_off & ~abm->dscp_mask) {
NL_SET_ERR_MSG_MOD(extack, "only high DSCP class selector bits can be used");
nfp_err(abm->app->cpp,
"u32 offload: requested mask %x FW can support only %x\n",
be32_to_cpu(k->mask) >> tos_off, abm->dscp_mask);
return false;
}
return true;
}
/* This filter list -> map conversion is O(n * m), we expect single digit or
* low double digit number of prios and likewise for the filters. Also u32
* doesn't report stats, so it's really only setup time cost.
*/
static unsigned int
nfp_abm_find_band_for_prio(struct nfp_abm_link *alink, unsigned int prio)
{
struct nfp_abm_u32_match *iter;
list_for_each_entry(iter, &alink->dscp_map, list)
if ((prio & iter->mask) == iter->val)
return iter->band;
return alink->def_band;
}
static int nfp_abm_update_band_map(struct nfp_abm_link *alink)
{
unsigned int i, bits_per_prio, prios_per_word, base_shift;
struct nfp_abm *abm = alink->abm;
u32 field_mask;
alink->has_prio = !list_empty(&alink->dscp_map);
bits_per_prio = roundup_pow_of_two(order_base_2(abm->num_bands));
field_mask = (1 << bits_per_prio) - 1;
prios_per_word = sizeof(u32) * BITS_PER_BYTE / bits_per_prio;
/* FW mask applies from top bits */
base_shift = 8 - order_base_2(abm->num_prios);
for (i = 0; i < abm->num_prios; i++) {
unsigned int offset;
u32 *word;
u8 band;
word = &alink->prio_map[i / prios_per_word];
offset = (i % prios_per_word) * bits_per_prio;
band = nfp_abm_find_band_for_prio(alink, i << base_shift);
*word &= ~(field_mask << offset);
*word |= band << offset;
}
/* Qdisc offload status may change if has_prio changed */
nfp_abm_qdisc_offload_update(alink);
return nfp_abm_ctrl_prio_map_update(alink, alink->prio_map);
}
static void
nfp_abm_u32_knode_delete(struct nfp_abm_link *alink,
struct tc_cls_u32_knode *knode)
{
struct nfp_abm_u32_match *iter;
list_for_each_entry(iter, &alink->dscp_map, list)
if (iter->handle == knode->handle) {
list_del(&iter->list);
kfree(iter);
nfp_abm_update_band_map(alink);
return;
}
}
static int
nfp_abm_u32_knode_replace(struct nfp_abm_link *alink,
struct tc_cls_u32_knode *knode,
__be16 proto, struct netlink_ext_ack *extack)
{
struct nfp_abm_u32_match *match = NULL, *iter;
unsigned int tos_off;
u8 mask, val;
int err;
if (!nfp_abm_u32_check_knode(alink->abm, knode, proto, extack))
goto err_delete;
tos_off = proto == htons(ETH_P_IP) ? 16 : 20;
/* Extract the DSCP Class Selector bits */
val = be32_to_cpu(knode->sel->keys[0].val) >> tos_off & 0xff;
mask = be32_to_cpu(knode->sel->keys[0].mask) >> tos_off & 0xff;
/* Check if there is no conflicting mapping and find match by handle */
list_for_each_entry(iter, &alink->dscp_map, list) {
u32 cmask;
if (iter->handle == knode->handle) {
match = iter;
continue;
}
cmask = iter->mask & mask;
if ((iter->val & cmask) == (val & cmask) &&
iter->band != knode->res->classid) {
NL_SET_ERR_MSG_MOD(extack, "conflict with already offloaded filter");
goto err_delete;
}
}
if (!match) {
match = kzalloc(sizeof(*match), GFP_KERNEL);
if (!match)
return -ENOMEM;
list_add(&match->list, &alink->dscp_map);
}
match->handle = knode->handle;
match->band = knode->res->classid;
match->mask = mask;
match->val = val;
err = nfp_abm_update_band_map(alink);
if (err)
goto err_delete;
return 0;
err_delete:
nfp_abm_u32_knode_delete(alink, knode);
return -EOPNOTSUPP;
}
static int nfp_abm_setup_tc_block_cb(enum tc_setup_type type,
void *type_data, void *cb_priv)
{
struct tc_cls_u32_offload *cls_u32 = type_data;
struct nfp_repr *repr = cb_priv;
struct nfp_abm_link *alink;
alink = repr->app_priv;
if (type != TC_SETUP_CLSU32) {
NL_SET_ERR_MSG_MOD(cls_u32->common.extack,
"only offload of u32 classifier supported");
return -EOPNOTSUPP;
}
if (!tc_cls_can_offload_and_chain0(repr->netdev, &cls_u32->common))
return -EOPNOTSUPP;
if (cls_u32->common.protocol != htons(ETH_P_IP) &&
cls_u32->common.protocol != htons(ETH_P_IPV6)) {
NL_SET_ERR_MSG_MOD(cls_u32->common.extack,
"only IP and IPv6 supported as filter protocol");
return -EOPNOTSUPP;
}
switch (cls_u32->command) {
case TC_CLSU32_NEW_KNODE:
case TC_CLSU32_REPLACE_KNODE:
return nfp_abm_u32_knode_replace(alink, &cls_u32->knode,
cls_u32->common.protocol,
cls_u32->common.extack);
case TC_CLSU32_DELETE_KNODE:
nfp_abm_u32_knode_delete(alink, &cls_u32->knode);
return 0;
default:
return -EOPNOTSUPP;
}
}
int nfp_abm_setup_cls_block(struct net_device *netdev, struct nfp_repr *repr,
struct tc_block_offload *f)
{
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS)
return -EOPNOTSUPP;
switch (f->command) {
case TC_BLOCK_BIND:
return tcf_block_cb_register(f->block,
nfp_abm_setup_tc_block_cb,
repr, repr, f->extack);
case TC_BLOCK_UNBIND:
tcf_block_cb_unregister(f->block, nfp_abm_setup_tc_block_cb,
repr);
return 0;
default:
return -EOPNOTSUPP;
}
}
...@@ -44,6 +44,10 @@ nfp_abm_setup_tc(struct nfp_app *app, struct net_device *netdev, ...@@ -44,6 +44,10 @@ nfp_abm_setup_tc(struct nfp_app *app, struct net_device *netdev,
return nfp_abm_setup_tc_mq(netdev, repr->app_priv, type_data); return nfp_abm_setup_tc_mq(netdev, repr->app_priv, type_data);
case TC_SETUP_QDISC_RED: case TC_SETUP_QDISC_RED:
return nfp_abm_setup_tc_red(netdev, repr->app_priv, type_data); return nfp_abm_setup_tc_red(netdev, repr->app_priv, type_data);
case TC_SETUP_QDISC_GRED:
return nfp_abm_setup_tc_gred(netdev, repr->app_priv, type_data);
case TC_SETUP_BLOCK:
return nfp_abm_setup_cls_block(netdev, repr, type_data);
default: default:
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -313,21 +317,32 @@ nfp_abm_vnic_alloc(struct nfp_app *app, struct nfp_net *nn, unsigned int id) ...@@ -313,21 +317,32 @@ nfp_abm_vnic_alloc(struct nfp_app *app, struct nfp_net *nn, unsigned int id)
alink->id = id; alink->id = id;
alink->total_queues = alink->vnic->max_rx_rings; alink->total_queues = alink->vnic->max_rx_rings;
INIT_LIST_HEAD(&alink->dscp_map);
err = nfp_abm_ctrl_read_params(alink);
if (err)
goto err_free_alink;
alink->prio_map = kzalloc(abm->prio_map_len, GFP_KERNEL);
if (!alink->prio_map)
goto err_free_alink;
/* This is a multi-host app, make sure MAC/PHY is up, but don't /* This is a multi-host app, make sure MAC/PHY is up, but don't
* make the MAC/PHY state follow the state of any of the ports. * make the MAC/PHY state follow the state of any of the ports.
*/ */
err = nfp_eth_set_configured(app->cpp, eth_port->index, true); err = nfp_eth_set_configured(app->cpp, eth_port->index, true);
if (err < 0) if (err < 0)
goto err_free_alink; goto err_free_priomap;
netif_keep_dst(nn->dp.netdev); netif_keep_dst(nn->dp.netdev);
nfp_abm_vnic_set_mac(app->pf, abm, nn, id); nfp_abm_vnic_set_mac(app->pf, abm, nn, id);
nfp_abm_ctrl_read_params(alink);
INIT_RADIX_TREE(&alink->qdiscs, GFP_KERNEL); INIT_RADIX_TREE(&alink->qdiscs, GFP_KERNEL);
return 0; return 0;
err_free_priomap:
kfree(alink->prio_map);
err_free_alink: err_free_alink:
kfree(alink); kfree(alink);
return err; return err;
...@@ -339,9 +354,19 @@ static void nfp_abm_vnic_free(struct nfp_app *app, struct nfp_net *nn) ...@@ -339,9 +354,19 @@ static void nfp_abm_vnic_free(struct nfp_app *app, struct nfp_net *nn)
nfp_abm_kill_reprs(alink->abm, alink); nfp_abm_kill_reprs(alink->abm, alink);
WARN(!radix_tree_empty(&alink->qdiscs), "left over qdiscs\n"); WARN(!radix_tree_empty(&alink->qdiscs), "left over qdiscs\n");
kfree(alink->prio_map);
kfree(alink); kfree(alink);
} }
static int nfp_abm_vnic_init(struct nfp_app *app, struct nfp_net *nn)
{
struct nfp_abm_link *alink = nn->app_priv;
if (nfp_abm_has_prio(alink->abm))
return nfp_abm_ctrl_prio_map_update(alink, alink->prio_map);
return 0;
}
static u64 * static u64 *
nfp_abm_port_get_stats(struct nfp_app *app, struct nfp_port *port, u64 *data) nfp_abm_port_get_stats(struct nfp_app *app, struct nfp_port *port, u64 *data)
{ {
...@@ -422,7 +447,7 @@ static int nfp_abm_init(struct nfp_app *app) ...@@ -422,7 +447,7 @@ static int nfp_abm_init(struct nfp_app *app)
goto err_free_abm; goto err_free_abm;
err = -ENOMEM; err = -ENOMEM;
abm->num_thresholds = NFP_NET_MAX_RX_RINGS; abm->num_thresholds = array_size(abm->num_bands, NFP_NET_MAX_RX_RINGS);
abm->threshold_undef = bitmap_zalloc(abm->num_thresholds, GFP_KERNEL); abm->threshold_undef = bitmap_zalloc(abm->num_thresholds, GFP_KERNEL);
if (!abm->threshold_undef) if (!abm->threshold_undef)
goto err_free_abm; goto err_free_abm;
...@@ -431,18 +456,25 @@ static int nfp_abm_init(struct nfp_app *app) ...@@ -431,18 +456,25 @@ static int nfp_abm_init(struct nfp_app *app)
sizeof(*abm->thresholds), GFP_KERNEL); sizeof(*abm->thresholds), GFP_KERNEL);
if (!abm->thresholds) if (!abm->thresholds)
goto err_free_thresh_umap; goto err_free_thresh_umap;
for (i = 0; i < NFP_NET_MAX_RX_RINGS; i++) for (i = 0; i < abm->num_bands * NFP_NET_MAX_RX_RINGS; i++)
__nfp_abm_ctrl_set_q_lvl(abm, i, NFP_ABM_LVL_INFINITY); __nfp_abm_ctrl_set_q_lvl(abm, i, NFP_ABM_LVL_INFINITY);
abm->actions = kvcalloc(abm->num_thresholds, sizeof(*abm->actions),
GFP_KERNEL);
if (!abm->actions)
goto err_free_thresh;
for (i = 0; i < abm->num_bands * NFP_NET_MAX_RX_RINGS; i++)
__nfp_abm_ctrl_set_q_act(abm, i, NFP_ABM_ACT_DROP);
/* 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_thresh; goto err_free_act;
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_thresh; goto err_free_act;
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);
...@@ -454,6 +486,8 @@ static int nfp_abm_init(struct nfp_app *app) ...@@ -454,6 +486,8 @@ 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_act:
kvfree(abm->actions);
err_free_thresh: err_free_thresh:
kvfree(abm->thresholds); kvfree(abm->thresholds);
err_free_thresh_umap: err_free_thresh_umap:
...@@ -472,6 +506,7 @@ static void nfp_abm_clean(struct nfp_app *app) ...@@ -472,6 +506,7 @@ static void nfp_abm_clean(struct nfp_app *app)
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); bitmap_free(abm->threshold_undef);
kvfree(abm->actions);
kvfree(abm->thresholds); kvfree(abm->thresholds);
kfree(abm); kfree(abm);
app->priv = NULL; app->priv = NULL;
...@@ -486,6 +521,7 @@ const struct nfp_app_type app_abm = { ...@@ -486,6 +521,7 @@ const struct nfp_app_type app_abm = {
.vnic_alloc = nfp_abm_vnic_alloc, .vnic_alloc = nfp_abm_vnic_alloc,
.vnic_free = nfp_abm_vnic_free, .vnic_free = nfp_abm_vnic_free,
.vnic_init = nfp_abm_vnic_init,
.port_get_stats = nfp_abm_port_get_stats, .port_get_stats = nfp_abm_port_get_stats,
.port_get_stats_count = nfp_abm_port_get_stats_count, .port_get_stats_count = nfp_abm_port_get_stats_count,
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
#define __NFP_ABM_H__ 1 #define __NFP_ABM_H__ 1
#include <linux/bits.h> #include <linux/bits.h>
#include <linux/list.h>
#include <linux/radix-tree.h> #include <linux/radix-tree.h>
#include <net/devlink.h> #include <net/devlink.h>
#include <net/pkt_cls.h> #include <net/pkt_cls.h>
#include <net/pkt_sched.h>
/* Dump of 64 PRIOs and 256 REDs seems to take 850us on Xeon v4 @ 2.20GHz; /* Dump of 64 PRIOs and 256 REDs seems to take 850us on Xeon v4 @ 2.20GHz;
* 2.5ms / 400Hz seems more than sufficient for stats resolution. * 2.5ms / 400Hz seems more than sufficient for stats resolution.
...@@ -22,31 +24,62 @@ struct nfp_net; ...@@ -22,31 +24,62 @@ struct nfp_net;
#define NFP_ABM_PORTID_TYPE GENMASK(23, 16) #define NFP_ABM_PORTID_TYPE GENMASK(23, 16)
#define NFP_ABM_PORTID_ID GENMASK(7, 0) #define NFP_ABM_PORTID_ID GENMASK(7, 0)
/* The possible actions if thresholds are exceeded */
enum nfp_abm_q_action {
/* mark if ECN capable, otherwise drop */
NFP_ABM_ACT_MARK_DROP = 0,
/* mark if ECN capable, otherwise goto QM */
NFP_ABM_ACT_MARK_QUEUE = 1,
NFP_ABM_ACT_DROP = 2,
NFP_ABM_ACT_QUEUE = 3,
NFP_ABM_ACT_NOQUEUE = 4,
};
/** /**
* 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
* *
* @num_prios: number of supported DSCP priorities
* @num_bands: number of supported DSCP priority bands
* @action_mask: bitmask of supported actions
*
* @thresholds: current threshold configuration * @thresholds: current threshold configuration
* @threshold_undef: bitmap of thresholds which have not been set * @threshold_undef: bitmap of thresholds which have not been set
* @actions: current FW action configuration
* @num_thresholds: number of @thresholds and bits in @threshold_undef * @num_thresholds: number of @thresholds and bits in @threshold_undef
* *
* @prio_map_len: computed length of FW priority map (in bytes)
* @dscp_mask: mask FW will apply on DSCP field
*
* @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
* @qm_stats: queue statistics symbol * @qm_stats: queue statistics symbol
* @q_stats: basic queue statistics (only in per-band case)
*/ */
struct nfp_abm { struct nfp_abm {
struct nfp_app *app; struct nfp_app *app;
unsigned int pf_id; unsigned int pf_id;
unsigned int num_prios;
unsigned int num_bands;
unsigned int action_mask;
u32 *thresholds; u32 *thresholds;
unsigned long *threshold_undef; unsigned long *threshold_undef;
u8 *actions;
size_t num_thresholds; size_t num_thresholds;
unsigned int prio_map_len;
u8 dscp_mask;
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;
const struct nfp_rtsym *q_stats;
}; };
/** /**
...@@ -81,6 +114,7 @@ enum nfp_qdisc_type { ...@@ -81,6 +114,7 @@ enum nfp_qdisc_type {
NFP_QDISC_NONE = 0, NFP_QDISC_NONE = 0,
NFP_QDISC_MQ, NFP_QDISC_MQ,
NFP_QDISC_RED, NFP_QDISC_RED,
NFP_QDISC_GRED,
}; };
#define NFP_QDISC_UNTRACKED ((struct nfp_qdisc *)1UL) #define NFP_QDISC_UNTRACKED ((struct nfp_qdisc *)1UL)
...@@ -104,11 +138,14 @@ enum nfp_qdisc_type { ...@@ -104,11 +138,14 @@ enum nfp_qdisc_type {
* @mq.prev_stats: previously reported @mq.stats * @mq.prev_stats: previously reported @mq.stats
* *
* @red: RED Qdisc specific parameters and state * @red: RED Qdisc specific parameters and state
* @red.threshold: ECN marking threshold * @red.num_bands: Number of valid entries in the @red.band table
* @red.stats: current stats of the RED Qdisc * @red.band: Per-band array of RED instances
* @red.prev_stats: previously reported @red.stats * @red.band.ecn: ECN marking is enabled (rather than drop)
* @red.xstats: extended stats for RED - current * @red.band.threshold: ECN marking threshold
* @red.prev_xstats: extended stats for RED - previously reported * @red.band.stats: current stats of the RED Qdisc
* @red.band.prev_stats: previously reported @red.stats
* @red.band.xstats: extended stats for RED - current
* @red.band.prev_xstats: extended stats for RED - previously reported
*/ */
struct nfp_qdisc { struct nfp_qdisc {
struct net_device *netdev; struct net_device *netdev;
...@@ -129,13 +166,18 @@ struct nfp_qdisc { ...@@ -129,13 +166,18 @@ struct nfp_qdisc {
struct nfp_alink_stats stats; struct nfp_alink_stats stats;
struct nfp_alink_stats prev_stats; struct nfp_alink_stats prev_stats;
} mq; } mq;
/* TC_SETUP_QDISC_RED */ /* TC_SETUP_QDISC_RED, TC_SETUP_QDISC_GRED */
struct { struct {
u32 threshold; unsigned int num_bands;
struct nfp_alink_stats stats;
struct nfp_alink_stats prev_stats; struct {
struct nfp_alink_xstats xstats; bool ecn;
struct nfp_alink_xstats prev_xstats; u32 threshold;
struct nfp_alink_stats stats;
struct nfp_alink_stats prev_stats;
struct nfp_alink_xstats xstats;
struct nfp_alink_xstats prev_xstats;
} band[MAX_DPs];
} red; } red;
}; };
}; };
...@@ -150,6 +192,12 @@ struct nfp_qdisc { ...@@ -150,6 +192,12 @@ struct nfp_qdisc {
* *
* @last_stats_update: ktime of last stats update * @last_stats_update: ktime of last stats update
* *
* @prio_map: current map of priorities
* @has_prio: @prio_map is valid
*
* @def_band: default band to use
* @dscp_map: list of DSCP to band mappings
*
* @root_qdisc: pointer to the current root of the Qdisc hierarchy * @root_qdisc: pointer to the current root of the Qdisc hierarchy
* @qdiscs: all qdiscs recorded by major part of the handle * @qdiscs: all qdiscs recorded by major part of the handle
*/ */
...@@ -162,10 +210,31 @@ struct nfp_abm_link { ...@@ -162,10 +210,31 @@ struct nfp_abm_link {
u64 last_stats_update; u64 last_stats_update;
u32 *prio_map;
bool has_prio;
u8 def_band;
struct list_head dscp_map;
struct nfp_qdisc *root_qdisc; struct nfp_qdisc *root_qdisc;
struct radix_tree_root qdiscs; struct radix_tree_root qdiscs;
}; };
static inline bool nfp_abm_has_prio(struct nfp_abm *abm)
{
return abm->num_bands > 1;
}
static inline bool nfp_abm_has_drop(struct nfp_abm *abm)
{
return abm->action_mask & BIT(NFP_ABM_ACT_DROP);
}
static inline bool nfp_abm_has_mark(struct nfp_abm *abm)
{
return abm->action_mask & BIT(NFP_ABM_ACT_MARK_DROP);
}
void nfp_abm_qdisc_offload_update(struct nfp_abm_link *alink); void nfp_abm_qdisc_offload_update(struct nfp_abm_link *alink);
int nfp_abm_setup_root(struct net_device *netdev, struct nfp_abm_link *alink, int nfp_abm_setup_root(struct net_device *netdev, struct nfp_abm_link *alink,
struct tc_root_qopt_offload *opt); struct tc_root_qopt_offload *opt);
...@@ -173,18 +242,30 @@ int nfp_abm_setup_tc_red(struct net_device *netdev, struct nfp_abm_link *alink, ...@@ -173,18 +242,30 @@ int nfp_abm_setup_tc_red(struct net_device *netdev, struct nfp_abm_link *alink,
struct tc_red_qopt_offload *opt); struct tc_red_qopt_offload *opt);
int nfp_abm_setup_tc_mq(struct net_device *netdev, struct nfp_abm_link *alink, int nfp_abm_setup_tc_mq(struct net_device *netdev, struct nfp_abm_link *alink,
struct tc_mq_qopt_offload *opt); struct tc_mq_qopt_offload *opt);
int nfp_abm_setup_tc_gred(struct net_device *netdev, struct nfp_abm_link *alink,
struct tc_gred_qopt_offload *opt);
int nfp_abm_setup_cls_block(struct net_device *netdev, struct nfp_repr *repr,
struct tc_block_offload *opt);
void nfp_abm_ctrl_read_params(struct nfp_abm_link *alink); int 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_q_lvl(struct nfp_abm *abm, unsigned int id, 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 queue, int nfp_abm_ctrl_set_q_lvl(struct nfp_abm_link *alink, unsigned int band,
u32 val); unsigned int queue, u32 val);
int nfp_abm_ctrl_read_q_stats(struct nfp_abm_link *alink, unsigned int i, int __nfp_abm_ctrl_set_q_act(struct nfp_abm *abm, unsigned int id,
enum nfp_abm_q_action act);
int nfp_abm_ctrl_set_q_act(struct nfp_abm_link *alink, unsigned int band,
unsigned int queue, enum nfp_abm_q_action act);
int nfp_abm_ctrl_read_q_stats(struct nfp_abm_link *alink,
unsigned int band, unsigned int queue,
struct nfp_alink_stats *stats); struct nfp_alink_stats *stats);
int nfp_abm_ctrl_read_q_xstats(struct nfp_abm_link *alink, unsigned int i, int nfp_abm_ctrl_read_q_xstats(struct nfp_abm_link *alink,
unsigned int band, unsigned int queue,
struct nfp_alink_xstats *xstats); struct nfp_alink_xstats *xstats);
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);
u64 nfp_abm_ctrl_stat_sto(struct nfp_abm_link *alink, unsigned int i); u64 nfp_abm_ctrl_stat_sto(struct nfp_abm_link *alink, unsigned int i);
int nfp_abm_ctrl_qm_enable(struct nfp_abm *abm); int nfp_abm_ctrl_qm_enable(struct nfp_abm *abm);
int nfp_abm_ctrl_qm_disable(struct nfp_abm *abm); int nfp_abm_ctrl_qm_disable(struct nfp_abm *abm);
void nfp_abm_prio_map_update(struct nfp_abm *abm);
int nfp_abm_ctrl_prio_map_update(struct nfp_abm_link *alink, u32 *packed);
#endif #endif
...@@ -868,6 +868,7 @@ unsigned int nfp_net_rss_key_sz(struct nfp_net *nn); ...@@ -868,6 +868,7 @@ unsigned int nfp_net_rss_key_sz(struct nfp_net *nn);
void nfp_net_rss_write_itbl(struct nfp_net *nn); void nfp_net_rss_write_itbl(struct nfp_net *nn);
void nfp_net_rss_write_key(struct nfp_net *nn); void nfp_net_rss_write_key(struct nfp_net *nn);
void nfp_net_coalesce_write_cfg(struct nfp_net *nn); void nfp_net_coalesce_write_cfg(struct nfp_net *nn);
int nfp_net_reconfig_mbox(struct nfp_net *nn, u32 mbox_cmd);
unsigned int unsigned int
nfp_net_irqs_alloc(struct pci_dev *pdev, struct msix_entry *irq_entries, nfp_net_irqs_alloc(struct pci_dev *pdev, struct msix_entry *irq_entries,
......
...@@ -279,7 +279,7 @@ int nfp_net_reconfig(struct nfp_net *nn, u32 update) ...@@ -279,7 +279,7 @@ int nfp_net_reconfig(struct nfp_net *nn, u32 update)
* *
* Return: Negative errno on error, 0 on success * Return: Negative errno on error, 0 on success
*/ */
static int nfp_net_reconfig_mbox(struct nfp_net *nn, u32 mbox_cmd) int nfp_net_reconfig_mbox(struct nfp_net *nn, u32 mbox_cmd)
{ {
u32 mbox = nn->tlv_caps.mbox_off; u32 mbox = nn->tlv_caps.mbox_off;
int ret; int ret;
......
...@@ -397,6 +397,8 @@ ...@@ -397,6 +397,8 @@
#define NFP_NET_CFG_MBOX_CMD_CTAG_FILTER_ADD 1 #define NFP_NET_CFG_MBOX_CMD_CTAG_FILTER_ADD 1
#define NFP_NET_CFG_MBOX_CMD_CTAG_FILTER_KILL 2 #define NFP_NET_CFG_MBOX_CMD_CTAG_FILTER_KILL 2
#define NFP_NET_CFG_MBOX_CMD_PCI_DSCP_PRIOMAP_SET 5
/** /**
* VLAN filtering using general use mailbox * VLAN filtering using general use mailbox
* %NFP_NET_CFG_VLAN_FILTER: Base address of VLAN filter mailbox * %NFP_NET_CFG_VLAN_FILTER: Base address of VLAN filter mailbox
......
...@@ -846,6 +846,7 @@ enum tc_setup_type { ...@@ -846,6 +846,7 @@ enum tc_setup_type {
TC_SETUP_QDISC_MQ, TC_SETUP_QDISC_MQ,
TC_SETUP_QDISC_ETF, TC_SETUP_QDISC_ETF,
TC_SETUP_ROOT_QDISC, TC_SETUP_ROOT_QDISC,
TC_SETUP_QDISC_GRED,
}; };
/* These structures hold the attributes of bpf state that are being passed /* These structures hold the attributes of bpf state that are being passed
......
...@@ -643,6 +643,7 @@ struct tc_cls_common_offload { ...@@ -643,6 +643,7 @@ struct tc_cls_common_offload {
struct tc_cls_u32_knode { struct tc_cls_u32_knode {
struct tcf_exts *exts; struct tcf_exts *exts;
struct tcf_result *res;
struct tc_u32_sel *sel; struct tc_u32_sel *sel;
u32 handle; u32 handle;
u32 val; u32 val;
...@@ -868,6 +869,50 @@ struct tc_red_qopt_offload { ...@@ -868,6 +869,50 @@ struct tc_red_qopt_offload {
}; };
}; };
enum tc_gred_command {
TC_GRED_REPLACE,
TC_GRED_DESTROY,
TC_GRED_STATS,
};
struct tc_gred_vq_qopt_offload_params {
bool present;
u32 limit;
u32 prio;
u32 min;
u32 max;
bool is_ecn;
bool is_harddrop;
u32 probability;
/* Only need backlog, see struct tc_prio_qopt_offload_params */
u32 *backlog;
};
struct tc_gred_qopt_offload_params {
bool grio_on;
bool wred_on;
unsigned int dp_cnt;
unsigned int dp_def;
struct gnet_stats_queue *qstats;
struct tc_gred_vq_qopt_offload_params tab[MAX_DPs];
};
struct tc_gred_qopt_offload_stats {
struct gnet_stats_basic_packed bstats[MAX_DPs];
struct gnet_stats_queue qstats[MAX_DPs];
struct red_stats *xstats[MAX_DPs];
};
struct tc_gred_qopt_offload {
enum tc_gred_command command;
u32 handle;
u32 parent;
union {
struct tc_gred_qopt_offload_params set;
struct tc_gred_qopt_offload_stats stats;
};
};
enum tc_prio_command { enum tc_prio_command {
TC_PRIO_REPLACE, TC_PRIO_REPLACE,
TC_PRIO_DESTROY, TC_PRIO_DESTROY,
......
...@@ -558,6 +558,7 @@ static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n, ...@@ -558,6 +558,7 @@ static int u32_replace_hw_knode(struct tcf_proto *tp, struct tc_u_knode *n,
cls_u32.knode.mask = 0; cls_u32.knode.mask = 0;
#endif #endif
cls_u32.knode.sel = &n->sel; cls_u32.knode.sel = &n->sel;
cls_u32.knode.res = &n->res;
cls_u32.knode.exts = &n->exts; cls_u32.knode.exts = &n->exts;
if (n->ht_down) if (n->ht_down)
cls_u32.knode.link_handle = ht->handle; cls_u32.knode.link_handle = ht->handle;
...@@ -1206,6 +1207,7 @@ static int u32_reoffload_knode(struct tcf_proto *tp, struct tc_u_knode *n, ...@@ -1206,6 +1207,7 @@ static int u32_reoffload_knode(struct tcf_proto *tp, struct tc_u_knode *n,
cls_u32.knode.mask = 0; cls_u32.knode.mask = 0;
#endif #endif
cls_u32.knode.sel = &n->sel; cls_u32.knode.sel = &n->sel;
cls_u32.knode.res = &n->res;
cls_u32.knode.exts = &n->exts; cls_u32.knode.exts = &n->exts;
if (n->ht_down) if (n->ht_down)
cls_u32.knode.link_handle = ht->handle; cls_u32.knode.link_handle = ht->handle;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <net/pkt_cls.h>
#include <net/pkt_sched.h> #include <net/pkt_sched.h>
#include <net/red.h> #include <net/red.h>
...@@ -311,6 +312,92 @@ static void gred_reset(struct Qdisc *sch) ...@@ -311,6 +312,92 @@ static void gred_reset(struct Qdisc *sch)
} }
} }
static void gred_offload(struct Qdisc *sch, enum tc_gred_command command)
{
struct gred_sched *table = qdisc_priv(sch);
struct net_device *dev = qdisc_dev(sch);
struct tc_gred_qopt_offload opt = {
.command = command,
.handle = sch->handle,
.parent = sch->parent,
};
if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
return;
if (command == TC_GRED_REPLACE) {
unsigned int i;
opt.set.grio_on = gred_rio_mode(table);
opt.set.wred_on = gred_wred_mode(table);
opt.set.dp_cnt = table->DPs;
opt.set.dp_def = table->def;
for (i = 0; i < table->DPs; i++) {
struct gred_sched_data *q = table->tab[i];
if (!q)
continue;
opt.set.tab[i].present = true;
opt.set.tab[i].limit = q->limit;
opt.set.tab[i].prio = q->prio;
opt.set.tab[i].min = q->parms.qth_min >> q->parms.Wlog;
opt.set.tab[i].max = q->parms.qth_max >> q->parms.Wlog;
opt.set.tab[i].is_ecn = gred_use_ecn(q);
opt.set.tab[i].is_harddrop = gred_use_harddrop(q);
opt.set.tab[i].probability = q->parms.max_P;
opt.set.tab[i].backlog = &q->backlog;
}
opt.set.qstats = &sch->qstats;
}
dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_QDISC_GRED, &opt);
}
static int gred_offload_dump_stats(struct Qdisc *sch)
{
struct gred_sched *table = qdisc_priv(sch);
struct tc_gred_qopt_offload *hw_stats;
unsigned int i;
int ret;
hw_stats = kzalloc(sizeof(*hw_stats), GFP_KERNEL);
if (!hw_stats)
return -ENOMEM;
hw_stats->command = TC_GRED_STATS;
hw_stats->handle = sch->handle;
hw_stats->parent = sch->parent;
for (i = 0; i < MAX_DPs; i++)
if (table->tab[i])
hw_stats->stats.xstats[i] = &table->tab[i]->stats;
ret = qdisc_offload_dump_helper(sch, TC_SETUP_QDISC_GRED, hw_stats);
/* Even if driver returns failure adjust the stats - in case offload
* ended but driver still wants to adjust the values.
*/
for (i = 0; i < MAX_DPs; i++) {
if (!table->tab[i])
continue;
table->tab[i]->packetsin += hw_stats->stats.bstats[i].packets;
table->tab[i]->bytesin += hw_stats->stats.bstats[i].bytes;
table->tab[i]->backlog += hw_stats->stats.qstats[i].backlog;
_bstats_update(&sch->bstats,
hw_stats->stats.bstats[i].bytes,
hw_stats->stats.bstats[i].packets);
sch->qstats.qlen += hw_stats->stats.qstats[i].qlen;
sch->qstats.backlog += hw_stats->stats.qstats[i].backlog;
sch->qstats.drops += hw_stats->stats.qstats[i].drops;
sch->qstats.requeues += hw_stats->stats.qstats[i].requeues;
sch->qstats.overlimits += hw_stats->stats.qstats[i].overlimits;
}
kfree(hw_stats);
return ret;
}
static inline void gred_destroy_vq(struct gred_sched_data *q) static inline void gred_destroy_vq(struct gred_sched_data *q)
{ {
kfree(q); kfree(q);
...@@ -385,6 +472,7 @@ static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps, ...@@ -385,6 +472,7 @@ static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps,
} }
} }
gred_offload(sch, TC_GRED_REPLACE);
return 0; return 0;
} }
...@@ -630,6 +718,8 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt, ...@@ -630,6 +718,8 @@ static int gred_change(struct Qdisc *sch, struct nlattr *opt,
sch_tree_unlock(sch); sch_tree_unlock(sch);
kfree(prealloc); kfree(prealloc);
gred_offload(sch, TC_GRED_REPLACE);
return 0; return 0;
err_unlock_free: err_unlock_free:
...@@ -679,6 +769,9 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb) ...@@ -679,6 +769,9 @@ static int gred_dump(struct Qdisc *sch, struct sk_buff *skb)
.flags = table->red_flags, .flags = table->red_flags,
}; };
if (gred_offload_dump_stats(sch))
goto nla_put_failure;
opts = nla_nest_start(skb, TCA_OPTIONS); opts = nla_nest_start(skb, TCA_OPTIONS);
if (opts == NULL) if (opts == NULL)
goto nla_put_failure; goto nla_put_failure;
...@@ -815,6 +908,7 @@ static void gred_destroy(struct Qdisc *sch) ...@@ -815,6 +908,7 @@ static void gred_destroy(struct Qdisc *sch)
if (table->tab[i]) if (table->tab[i])
gred_destroy_vq(table->tab[i]); gred_destroy_vq(table->tab[i]);
} }
gred_offload(sch, TC_GRED_DESTROY);
} }
static struct Qdisc_ops gred_qdisc_ops __read_mostly = { static struct Qdisc_ops gred_qdisc_ops __read_mostly = {
......
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