+static int
+flow_program_vtag_action(struct rte_eth_dev *eth_dev,
+ const struct rte_flow_action actions[],
+ struct rte_flow *flow)
+{
+ uint16_t vlan_id = 0, vlan_ethtype = RTE_ETHER_TYPE_VLAN;
+ struct otx2_eth_dev *dev = eth_dev->data->dev_private;
+ union {
+ uint64_t reg;
+ struct nix_tx_vtag_action_s act;
+ } tx_vtag_action;
+ struct otx2_mbox *mbox = dev->mbox;
+ struct nix_vtag_config *vtag_cfg;
+ struct nix_vtag_config_rsp *rsp;
+ bool vlan_insert_action = false;
+ uint64_t rx_vtag_action = 0;
+ uint8_t vlan_pcp = 0;
+ int rc;
+
+ for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
+ if (actions->type == RTE_FLOW_ACTION_TYPE_OF_POP_VLAN) {
+ if (dev->npc_flow.vtag_actions == 1) {
+ vtag_cfg =
+ otx2_mbox_alloc_msg_nix_vtag_cfg(mbox);
+ vtag_cfg->cfg_type = VTAG_RX;
+ vtag_cfg->rx.strip_vtag = 1;
+ /* Always capture */
+ vtag_cfg->rx.capture_vtag = 1;
+ vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
+ vtag_cfg->rx.vtag_type = 0;
+
+ rc = otx2_mbox_process(mbox);
+ if (rc)
+ return rc;
+ }
+
+ rx_vtag_action |= (NIX_RX_VTAGACTION_VTAG_VALID << 15);
+ rx_vtag_action |= (NPC_LID_LB << 8);
+ rx_vtag_action |= NIX_RX_VTAGACTION_VTAG0_RELPTR;
+ flow->vtag_action = rx_vtag_action;
+ } else if (actions->type ==
+ RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID) {
+ const struct rte_flow_action_of_set_vlan_vid *vtag =
+ (const struct rte_flow_action_of_set_vlan_vid *)
+ actions->conf;
+ vlan_id = rte_be_to_cpu_16(vtag->vlan_vid);
+ if (vlan_id > 0xfff) {
+ otx2_err("Invalid vlan_id for set vlan action");
+ return -EINVAL;
+ }
+ vlan_insert_action = true;
+ } else if (actions->type == RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN) {
+ const struct rte_flow_action_of_push_vlan *ethtype =
+ (const struct rte_flow_action_of_push_vlan *)
+ actions->conf;
+ vlan_ethtype = rte_be_to_cpu_16(ethtype->ethertype);
+ if (vlan_ethtype != RTE_ETHER_TYPE_VLAN &&
+ vlan_ethtype != RTE_ETHER_TYPE_QINQ) {
+ otx2_err("Invalid ethtype specified for push"
+ " vlan action");
+ return -EINVAL;
+ }
+ vlan_insert_action = true;
+ } else if (actions->type ==
+ RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP) {
+ const struct rte_flow_action_of_set_vlan_pcp *pcp =
+ (const struct rte_flow_action_of_set_vlan_pcp *)
+ actions->conf;
+ vlan_pcp = pcp->vlan_pcp;
+ if (vlan_pcp > 0x7) {
+ otx2_err("Invalid PCP value for pcp action");
+ return -EINVAL;
+ }
+ vlan_insert_action = true;
+ }
+ }
+
+ if (vlan_insert_action) {
+ vtag_cfg = otx2_mbox_alloc_msg_nix_vtag_cfg(mbox);
+ vtag_cfg->cfg_type = VTAG_TX;
+ vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
+ vtag_cfg->tx.vtag0 =
+ ((vlan_ethtype << 16) | (vlan_pcp << 13) | vlan_id);
+ vtag_cfg->tx.cfg_vtag0 = 1;
+ rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
+ if (rc)
+ return rc;
+
+ tx_vtag_action.reg = 0;
+ tx_vtag_action.act.vtag0_def = rsp->vtag0_idx;
+ if (tx_vtag_action.act.vtag0_def < 0) {
+ otx2_err("Failed to config TX VTAG action");
+ return -EINVAL;
+ }
+ tx_vtag_action.act.vtag0_lid = NPC_LID_LA;
+ tx_vtag_action.act.vtag0_op = NIX_TX_VTAGOP_INSERT;
+ tx_vtag_action.act.vtag0_relptr =
+ NIX_TX_VTAGACTION_VTAG0_RELPTR;
+ flow->vtag_action = tx_vtag_action.reg;
+ }
+ return 0;
+}
+