net/cnxk: integrate BPF count get mailbox
authorRakesh Kudurumalla <rkudurumalla@marvell.com>
Tue, 2 Nov 2021 06:41:36 +0000 (12:11 +0530)
committerJerin Jacob <jerinj@marvell.com>
Wed, 3 Nov 2021 15:15:08 +0000 (16:15 +0100)
Bandwidth profile count is updated in meter capabilities during device
initialization using mbox interface.

Signed-off-by: Rakesh Kudurumalla <rkudurumalla@marvell.com>
Acked-by: Jerin Jacob <jerinj@marvell.com>
drivers/net/cnxk/cn10k_rte_flow.c
drivers/net/cnxk/cn9k_ethdev.c
drivers/net/cnxk/cnxk_ethdev.c
drivers/net/cnxk/cnxk_ethdev.h
drivers/net/cnxk/cnxk_ethdev_mtr.c

index dff4c77..b830abe 100644 (file)
@@ -249,7 +249,7 @@ cn10k_flow_destroy(struct rte_eth_dev *eth_dev, struct rte_flow *rte_flow,
 
        mtr_id = flow->mtr_id;
        rc = cnxk_flow_destroy(eth_dev, flow, error);
-       if (!rc) {
+       if (!rc && mtr_id != ROC_NIX_MTR_ID_INVALID) {
                rc = cn10k_mtr_destroy(eth_dev, mtr_id);
                if (rc) {
                        rte_flow_error_set(error, ENXIO,
index 2fdc10a..f8f3d38 100644 (file)
@@ -486,6 +486,7 @@ nix_eth_dev_ops_override(void)
        cnxk_eth_dev_ops.dev_ptypes_set = cn9k_nix_ptypes_set;
        cnxk_eth_dev_ops.timesync_enable = cn9k_nix_timesync_enable;
        cnxk_eth_dev_ops.timesync_disable = cn9k_nix_timesync_disable;
+       cnxk_eth_dev_ops.mtr_ops_get = NULL;
 }
 
 static void
index a62ded6..74f6255 100644 (file)
@@ -765,11 +765,17 @@ nix_free_queue_mem(struct cnxk_eth_dev *dev)
 static int
 nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
 {
+       struct rte_eth_dev *eth_dev = dev->eth_dev;
+       int rc = 0;
+
        TAILQ_INIT(&dev->mtr_profiles);
        TAILQ_INIT(&dev->mtr_policy);
        TAILQ_INIT(&dev->mtr);
 
-       return 0;
+       if (eth_dev->dev_ops->mtr_ops_get == NULL)
+               return rc;
+
+       return nix_mtr_capabilities_init(eth_dev);
 }
 
 static int
index 7cbd9f1..5bfda3d 100644 (file)
@@ -597,6 +597,7 @@ struct cnxk_meter_node *nix_get_mtr(struct rte_eth_dev *eth_dev,
                                    uint32_t cur_id);
 int nix_mtr_level_update(struct rte_eth_dev *eth_dev, uint32_t id,
                         uint32_t level);
+int nix_mtr_capabilities_init(struct rte_eth_dev *eth_dev);
 int nix_mtr_configure(struct rte_eth_dev *eth_dev, uint32_t id);
 int nix_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t id);
 int nix_mtr_destroy(struct rte_eth_dev *eth_dev, uint32_t id,
index 22c8533..39d8563 100644 (file)
@@ -28,7 +28,6 @@ static const enum roc_nix_bpf_level_flag lvl_map[] = {ROC_NIX_BPF_LEVEL_F_LEAF,
                                                      ROC_NIX_BPF_LEVEL_F_TOP};
 
 static struct rte_mtr_capabilities mtr_capa = {
-       .n_max = NIX_MTR_COUNT_MAX,
        .n_shared_max = NIX_MTR_COUNT_PER_FLOW,
        /* .identical = , */
        .shared_identical = true,
@@ -36,11 +35,7 @@ static struct rte_mtr_capabilities mtr_capa = {
        .chaining_n_mtrs_per_flow_max = NIX_MTR_COUNT_PER_FLOW,
        .chaining_use_prev_mtr_color_supported = true,
        .chaining_use_prev_mtr_color_enforced = true,
-       .meter_srtcm_rfc2697_n_max = NIX_MTR_COUNT_MAX,
-       .meter_trtcm_rfc2698_n_max = NIX_MTR_COUNT_MAX,
-       .meter_trtcm_rfc4115_n_max = NIX_MTR_COUNT_MAX,
        .meter_rate_max = NIX_BPF_RATE_MAX / 8, /* Bytes per second */
-       .meter_policy_n_max = NIX_MTR_COUNT_MAX,
        .color_aware_srtcm_rfc2697_supported = true,
        .color_aware_trtcm_rfc2698_supported = true,
        .color_aware_trtcm_rfc4115_supported = true,
@@ -185,12 +180,33 @@ cnxk_nix_mtr_capabilities_get(struct rte_eth_dev *dev,
                              struct rte_mtr_capabilities *capa,
                              struct rte_mtr_error *error)
 {
+       struct cnxk_eth_dev *eth_dev = cnxk_eth_pmd_priv(dev);
+       uint16_t count[ROC_NIX_BPF_LEVEL_MAX] = {0};
+       uint8_t lvl_mask = ROC_NIX_BPF_LEVEL_F_LEAF | ROC_NIX_BPF_LEVEL_F_MID |
+                          ROC_NIX_BPF_LEVEL_F_TOP;
+       struct roc_nix *nix = &eth_dev->nix;
+       int rc;
+       int i;
+
        RTE_SET_USED(dev);
 
        if (!capa)
                return -rte_mtr_error_set(error, EINVAL,
-                                         RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
-                                         "NULL input parameter");
+                               RTE_MTR_ERROR_TYPE_MTR_PARAMS, NULL,
+                               "NULL input parameter");
+
+       rc = roc_nix_bpf_count_get(nix, lvl_mask, count);
+       if (rc)
+               return rc;
+
+       for (i = 0; i < ROC_NIX_BPF_LEVEL_MAX; i++)
+               mtr_capa.n_max += count[i];
+
+       mtr_capa.meter_srtcm_rfc2697_n_max = mtr_capa.n_max;
+       mtr_capa.meter_trtcm_rfc2698_n_max = mtr_capa.n_max;
+       mtr_capa.meter_trtcm_rfc4115_n_max = mtr_capa.n_max;
+       mtr_capa.meter_policy_n_max = mtr_capa.n_max;
+
        *capa = mtr_capa;
        return 0;
 }
@@ -1339,3 +1355,12 @@ nix_mtr_color_action_validate(struct rte_eth_dev *eth_dev, uint32_t id,
 
        return 0;
 }
+
+int
+nix_mtr_capabilities_init(struct rte_eth_dev *eth_dev)
+{
+       struct rte_mtr_capabilities capa;
+       struct rte_mtr_error error;
+
+       return cnxk_nix_mtr_capabilities_get(eth_dev, &capa, &error);
+}