common/cnxk: add lower bound check for SSO resources
[dpdk.git] / drivers / common / cnxk / roc_npc.c
index 0a7966b..da5b962 100644 (file)
@@ -74,6 +74,14 @@ roc_npc_mcam_alloc_entries(struct roc_npc *roc_npc, int ref_entry,
                                      priority, resp_count);
 }
 
+int
+roc_npc_mcam_enable_all_entries(struct roc_npc *roc_npc, bool enable)
+{
+       struct npc *npc = roc_npc_to_npc_priv(roc_npc);
+
+       return npc_flow_enable_all_entries(npc, enable);
+}
+
 int
 roc_npc_mcam_alloc_entry(struct roc_npc *roc_npc, struct roc_npc_flow *mcam,
                         struct roc_npc_flow *ref_mcam, int prio,
@@ -166,8 +174,6 @@ roc_npc_init(struct roc_npc *roc_npc)
        roc_npc->kex_capability = npc_get_kex_capability(npc);
        roc_npc->rx_parse_nibble = npc->keyx_supp_nmask[NPC_MCAM_RX];
 
-       npc->mark_actions = 0;
-
        npc->mcam_entries = npc_mcam_tot_entries() >> npc->keyw[NPC_MCAM_RX];
 
        /* Free, free_rev, live and live_rev entries */
@@ -287,6 +293,48 @@ roc_npc_validate_portid_action(struct roc_npc *roc_npc_src,
        return 0;
 }
 
+static int
+npc_parse_msns_action(struct roc_npc *roc_npc, const struct roc_npc_action *act,
+                     struct roc_npc_flow *flow, uint8_t *has_msns_action)
+{
+       const struct roc_npc_sec_action *sec_action;
+       union {
+               uint64_t reg;
+               union nix_rx_vtag_action_u act;
+       } vtag_act;
+
+       if (roc_npc->roc_nix->custom_sa_action == 0 ||
+           roc_model_is_cn9k() == 1 || act->conf == NULL)
+               return 0;
+
+       *has_msns_action = true;
+       sec_action = act->conf;
+
+       vtag_act.reg = 0;
+       vtag_act.act.sa_xor = sec_action->sa_xor;
+       vtag_act.act.sa_hi = sec_action->sa_hi;
+       vtag_act.act.sa_lo = sec_action->sa_lo;
+
+       switch (sec_action->alg) {
+       case ROC_NPC_SEC_ACTION_ALG0:
+               break;
+       case ROC_NPC_SEC_ACTION_ALG1:
+               vtag_act.act.vtag1_valid = false;
+               vtag_act.act.vtag1_lid = ROC_NPC_SEC_ACTION_ALG1;
+               break;
+       case ROC_NPC_SEC_ACTION_ALG2:
+               vtag_act.act.vtag1_valid = false;
+               vtag_act.act.vtag1_lid = ROC_NPC_SEC_ACTION_ALG2;
+               break;
+       default:
+               return -1;
+       }
+
+       flow->vtag_action = vtag_act.reg;
+
+       return 0;
+}
+
 static int
 npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
                  const struct roc_npc_action actions[],
@@ -299,14 +347,18 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
        const struct roc_npc_action_queue *act_q;
        const struct roc_npc_action_vf *vf_act;
        bool vlan_insert_action = false;
+       uint8_t has_msns_act = 0;
        int sel_act, req_act = 0;
        uint16_t pf_func, vf_id;
+       struct roc_nix *roc_nix;
        int errcode = 0;
        int mark = 0;
        int rq = 0;
+       int rc = 0;
 
        /* Initialize actions */
        flow->ctr_id = NPC_COUNTER_NONE;
+       flow->mtr_id = ROC_NIX_MTR_ID_INVALID;
        pf_func = npc->pf_func;
 
        for (; actions->type != ROC_NPC_ACTION_TYPE_END; actions++) {
@@ -322,13 +374,11 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
                        }
                        mark = act_mark->id + 1;
                        req_act |= ROC_NPC_ACTION_TYPE_MARK;
-                       npc->mark_actions += 1;
                        break;
 
                case ROC_NPC_ACTION_TYPE_FLAG:
                        mark = NPC_FLOW_FLAG_VAL;
                        req_act |= ROC_NPC_ACTION_TYPE_FLAG;
-                       npc->mark_actions += 1;
                        break;
 
                case ROC_NPC_ACTION_TYPE_COUNT:
@@ -387,13 +437,27 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
                         */
                        req_act |= ROC_NPC_ACTION_TYPE_SEC;
                        rq = 0;
+                       roc_nix = roc_npc->roc_nix;
 
                        /* Special processing when with inline device */
-                       if (roc_nix_inb_is_with_inl_dev(roc_npc->roc_nix) &&
+                       if (roc_nix_inb_is_with_inl_dev(roc_nix) &&
                            roc_nix_inl_dev_is_probed()) {
-                               rq = 0;
+                               struct roc_nix_rq *inl_rq;
+
+                               inl_rq = roc_nix_inl_dev_rq(roc_nix);
+                               if (!inl_rq) {
+                                       errcode = NPC_ERR_INTERNAL;
+                                       goto err_exit;
+                               }
+                               rq = inl_rq->qid;
                                pf_func = nix_inl_dev_pffunc_get();
                        }
+                       rc = npc_parse_msns_action(roc_npc, actions, flow,
+                                                  &has_msns_act);
+                       if (rc) {
+                               errcode = NPC_ERR_ACTION_NOTSUP;
+                               goto err_exit;
+                       }
                        break;
                case ROC_NPC_ACTION_TYPE_VLAN_STRIP:
                        req_act |= ROC_NPC_ACTION_TYPE_VLAN_STRIP;
@@ -433,6 +497,14 @@ npc_parse_actions(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
                goto err_exit;
        }
 
+       if (has_msns_act && (vlan_insert_action ||
+                            (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP))) {
+               plt_err("Both MSNS and VLAN insert/strip action can't be supported"
+                       " together");
+               errcode = NPC_ERR_ACTION_NOTSUP;
+               goto err_exit;
+       }
+
        /* Both STRIP and INSERT actions are not supported */
        if (vlan_insert_action && (req_act & ROC_NPC_ACTION_TYPE_VLAN_STRIP)) {
                errcode = NPC_ERR_ACTION_NOTSUP;
@@ -565,10 +637,11 @@ npc_parse_pattern(struct npc *npc, const struct roc_npc_item_info pattern[],
                  struct roc_npc_flow *flow, struct npc_parse_state *pst)
 {
        npc_parse_stage_func_t parse_stage_funcs[] = {
-               npc_parse_meta_items, npc_parse_cpt_hdr, npc_parse_higig2_hdr,
-               npc_parse_la,         npc_parse_lb,      npc_parse_lc,
-               npc_parse_ld,         npc_parse_le,      npc_parse_lf,
-               npc_parse_lg,         npc_parse_lh,
+               npc_parse_meta_items, npc_parse_mark_item,  npc_parse_pre_l2,
+               npc_parse_cpt_hdr,    npc_parse_higig2_hdr, npc_parse_la,
+               npc_parse_lb,         npc_parse_lc,         npc_parse_ld,
+               npc_parse_le,         npc_parse_lf,         npc_parse_lg,
+               npc_parse_lh,
        };
        uint8_t layer = 0;
        int key_offset;
@@ -811,23 +884,6 @@ npc_rss_action_program(struct roc_npc *roc_npc,
        return 0;
 }
 
-int
-roc_npc_mark_actions_get(struct roc_npc *roc_npc)
-{
-       struct npc *npc = roc_npc_to_npc_priv(roc_npc);
-
-       return npc->mark_actions;
-}
-
-int
-roc_npc_mark_actions_sub_return(struct roc_npc *roc_npc, uint32_t count)
-{
-       struct npc *npc = roc_npc_to_npc_priv(roc_npc);
-
-       npc->mark_actions -= count;
-       return npc->mark_actions;
-}
-
 static int
 npc_vtag_cfg_delete(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
 {
@@ -968,14 +1024,14 @@ npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
        vtag_cfg->cfg_type = VTAG_TX;
        vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
        vtag_cfg->tx.vtag0 =
-               ((vlan_info[0].vlan_ethtype << 16) |
+               (((uint32_t)vlan_info[0].vlan_ethtype << 16) |
                 (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
 
        vtag_cfg->tx.cfg_vtag0 = 1;
 
        if (flow->vtag_insert_count == 2) {
                vtag_cfg->tx.vtag1 =
-                       ((vlan_info[1].vlan_ethtype << 16) |
+                       (((uint32_t)vlan_info[1].vlan_ethtype << 16) |
                         (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
 
                vtag_cfg->tx.cfg_vtag1 = 1;
@@ -1151,6 +1207,19 @@ roc_npc_flow_create(struct roc_npc *roc_npc, const struct roc_npc_attr *attr,
        int rc;
 
        npc->channel = roc_npc->channel;
+       npc->is_sdp_link = roc_nix_is_sdp(roc_npc->roc_nix);
+       if (npc->is_sdp_link) {
+               if (roc_npc->is_sdp_mask_set) {
+                       npc->sdp_channel = roc_npc->sdp_channel;
+                       npc->sdp_channel_mask = roc_npc->sdp_channel_mask;
+               } else {
+                       /* By default set the channel and mask to cover
+                        * the whole SDP channel range.
+                        */
+                       npc->sdp_channel = (uint16_t)NIX_CHAN_SDP_CH_START;
+                       npc->sdp_channel_mask = (uint16_t)NIX_CHAN_SDP_CH_START;
+               }
+       }
 
        flow = plt_zmalloc(sizeof(*flow), 0);
        if (flow == NULL) {
@@ -1245,6 +1314,16 @@ roc_npc_flow_destroy(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
                        return rc;
        }
 
+       if (flow->ctr_id != NPC_COUNTER_NONE) {
+               rc = roc_npc_mcam_clear_counter(roc_npc, flow->ctr_id);
+               if (rc != 0)
+                       return rc;
+
+               rc = npc_mcam_free_counter(npc, flow->ctr_id);
+               if (rc != 0)
+                       return rc;
+       }
+
        rc = npc_mcam_free_entry(npc, flow->mcam_id);
        if (rc != 0)
                return rc;