nfp: abm: map per-band symbols
authorJakub Kicinski <jakub.kicinski@netronome.com>
Mon, 19 Nov 2018 23:21:37 +0000 (15:21 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 20 Nov 2018 02:53:45 +0000 (18:53 -0800)
In preparation for multi-band RED offload if FW is capable map
the extended symbols which will allow us to set per-band parameters
and read stats.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: John Hurley <john.hurley@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/abm/ctrl.c
drivers/net/ethernet/netronome/nfp/abm/main.h

index 1629b07f727b8e0451c28b16868febc9972206fa..d9c5fff975476d7adadcb33a6f86dae5d457735d 100644 (file)
@@ -2,6 +2,7 @@
 /* Copyright (C) 2018 Netronome Systems, Inc. */
 
 #include <linux/kernel.h>
+#include <linux/log2.h>
 
 #include "../nfpcore/nfp_cpp.h"
 #include "../nfpcore/nfp_nffw.h"
 #include "../nfp_net.h"
 #include "main.h"
 
-#define NFP_QLVL_SYM_NAME      "_abi_nfd_out_q_lvls_%u"
+#define NFP_NUM_PRIOS_SYM_NAME "_abi_pci_dscp_num_prio_%u"
+#define NFP_NUM_BANDS_SYM_NAME "_abi_pci_dscp_num_band_%u"
+
+#define NFP_QLVL_SYM_NAME      "_abi_nfd_out_q_lvls_%u%s"
 #define NFP_QLVL_STRIDE                16
 #define NFP_QLVL_BLOG_BYTES    0
 #define NFP_QLVL_BLOG_PKTS     4
 #define NFP_QLVL_THRS          8
 
-#define NFP_QMSTAT_SYM_NAME    "_abi_nfdqm%u_stats"
+#define NFP_QMSTAT_SYM_NAME    "_abi_nfdqm%u_stats%s"
 #define NFP_QMSTAT_STRIDE      32
 #define NFP_QMSTAT_NON_STO     0
 #define NFP_QMSTAT_STO         8
@@ -189,30 +193,56 @@ nfp_abm_ctrl_find_rtsym(struct nfp_pf *pf, const char *name, unsigned int size)
 }
 
 static const struct nfp_rtsym *
-nfp_abm_ctrl_find_q_rtsym(struct nfp_pf *pf, const char *name,
-                         unsigned int size)
+nfp_abm_ctrl_find_q_rtsym(struct nfp_abm *abm, const char *name_fmt,
+                         size_t size)
 {
-       return nfp_abm_ctrl_find_rtsym(pf, name, size * NFP_NET_MAX_RX_RINGS);
+       char pf_symbol[64];
+
+       size = array3_size(size, abm->num_bands, NFP_NET_MAX_RX_RINGS);
+       snprintf(pf_symbol, sizeof(pf_symbol), name_fmt,
+                abm->pf_id, nfp_abm_has_prio(abm) ? "_per_band" : "");
+
+       return nfp_abm_ctrl_find_rtsym(abm->app->pf, pf_symbol, size);
 }
 
 int nfp_abm_ctrl_find_addrs(struct nfp_abm *abm)
 {
        struct nfp_pf *pf = abm->app->pf;
        const struct nfp_rtsym *sym;
-       unsigned int pf_id;
-       char pf_symbol[64];
+       int res;
 
-       pf_id = nfp_cppcore_pcie_unit(pf->cpp);
-       abm->pf_id = pf_id;
+       abm->pf_id = nfp_cppcore_pcie_unit(pf->cpp);
+
+       /* Read count of prios and prio bands */
+       res = nfp_pf_rtsym_read_optional(pf, NFP_NUM_BANDS_SYM_NAME, 1);
+       if (res < 0)
+               return res;
+       abm->num_bands = res;
+
+       res = nfp_pf_rtsym_read_optional(pf, NFP_NUM_PRIOS_SYM_NAME, 1);
+       if (res < 0)
+               return res;
+       abm->num_prios = res;
+
+       /* Check values are sane, U16_MAX is arbitrarily chosen as max */
+       if (!is_power_of_2(abm->num_bands) || !is_power_of_2(abm->num_prios) ||
+           abm->num_bands > U16_MAX || abm->num_prios > U16_MAX ||
+           (abm->num_bands == 1) != (abm->num_prios == 1)) {
+               nfp_err(pf->cpp,
+                       "invalid priomap description num bands: %u and num prios: %u\n",
+                       abm->num_bands, abm->num_prios);
+               return -EINVAL;
+       }
 
-       snprintf(pf_symbol, sizeof(pf_symbol), NFP_QLVL_SYM_NAME, pf_id);
-       sym = nfp_abm_ctrl_find_q_rtsym(pf, pf_symbol, NFP_QLVL_STRIDE);
+       /* Find level and stat symbols */
+       sym = nfp_abm_ctrl_find_q_rtsym(abm, NFP_QLVL_SYM_NAME,
+                                       NFP_QLVL_STRIDE);
        if (IS_ERR(sym))
                return PTR_ERR(sym);
        abm->q_lvls = sym;
 
-       snprintf(pf_symbol, sizeof(pf_symbol), NFP_QMSTAT_SYM_NAME, pf_id);
-       sym = nfp_abm_ctrl_find_q_rtsym(pf, pf_symbol, NFP_QMSTAT_STRIDE);
+       sym = nfp_abm_ctrl_find_q_rtsym(abm, NFP_QMSTAT_SYM_NAME,
+                                       NFP_QMSTAT_STRIDE);
        if (IS_ERR(sym))
                return PTR_ERR(sym);
        abm->qm_stats = sym;
index 240e2c8683fe81823c0f73583c7f4290c9bf7206..b10c067b15c84d18d1285998d098c8bf68fd6061 100644 (file)
@@ -27,6 +27,9 @@ struct nfp_net;
  * @app:       back pointer to nfp_app
  * @pf_id:     ID of our PF link
  *
+ * @num_prios: number of supported DSCP priorities
+ * @num_bands: number of supported DSCP priority bands
+ *
  * @thresholds:                current threshold configuration
  * @threshold_undef:   bitmap of thresholds which have not been set
  * @num_thresholds:    number of @thresholds and bits in @threshold_undef
@@ -40,6 +43,9 @@ struct nfp_abm {
        struct nfp_app *app;
        unsigned int pf_id;
 
+       unsigned int num_prios;
+       unsigned int num_bands;
+
        u32 *thresholds;
        unsigned long *threshold_undef;
        size_t num_thresholds;
@@ -166,6 +172,11 @@ struct nfp_abm_link {
        struct radix_tree_root qdiscs;
 };
 
+static inline bool nfp_abm_has_prio(struct nfp_abm *abm)
+{
+       return abm->num_bands > 1;
+}
+
 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,
                       struct tc_root_qopt_offload *opt);