octeontx2-pf: Add support for offload tc with skbedit mark action
authorGeetha sowjanya <gakula@marvell.com>
Sat, 20 Apr 2024 09:35:05 +0000 (15:05 +0530)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 Apr 2024 09:14:14 +0000 (10:14 +0100)
Support offloading of skbedit mark action.

For example, to mark with 0x0008, with dest ip 60.60.60.2 on eth2
interface:

 # tc qdisc add dev eth2 ingress
 # tc filter add dev eth2 ingress protocol ip flower \
      dst_ip 60.60.60.2 action skbedit mark 0x0008 skip_sw

Signed-off-by: Geetha sowjanya <gakula@marvell.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc_fs.c
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h
drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.h

index c181e7aa9eb67d969ecdea4e513694ac59f613e5..150635de2bd5a1b86f51c33ac4bd14513e144355 100644 (file)
@@ -1187,6 +1187,8 @@ static int npc_update_rx_entry(struct rvu *rvu, struct rvu_pfvf *pfvf,
                        action.pf_func = target;
                        action.op = NIX_RX_ACTIONOP_UCAST;
                }
+               if (req->match_id)
+                       action.match_id = req->match_id;
        }
 
        entry->action = *(u64 *)&action;
index c5de3ba33e2f0e363fb2d2944fa401a944fc8848..24fbbef265a61a4e7624f869e25d966e77597dde 100644 (file)
@@ -363,6 +363,7 @@ struct otx2_flow_config {
        struct list_head        flow_list;
        u32                     dmacflt_max_flows;
        u16                     max_flows;
+       refcount_t              mark_flows;
        struct list_head        flow_list_tc;
        bool                    ntuple;
 };
@@ -465,6 +466,7 @@ struct otx2_nic {
 #define OTX2_FLAG_DMACFLTR_SUPPORT             BIT_ULL(14)
 #define OTX2_FLAG_PTP_ONESTEP_SYNC             BIT_ULL(15)
 #define OTX2_FLAG_ADPTV_INT_COAL_ENABLED BIT_ULL(16)
+#define OTX2_FLAG_TC_MARK_ENABLED              BIT_ULL(17)
        u64                     flags;
        u64                     *cq_op_addr;
 
index 97a71e9b856372b95edd964e31fdc0b1156b8454..bc5819237ed711bbec50820ae6274462ad6df7b3 100644 (file)
@@ -252,6 +252,7 @@ static int otx2_mcam_entry_init(struct otx2_nic *pfvf)
 
        pfvf->flags |= OTX2_FLAG_TC_FLOWER_SUPPORT;
 
+       refcount_set(&flow_cfg->mark_flows, 1);
        return 0;
 }
 
index f4655a8c0705d70b3a4aff580ccb1e437069ca64..6d4ce2ece8d022d659583b939e24e6ba515e6c77 100644 (file)
@@ -511,7 +511,15 @@ static int otx2_tc_parse_actions(struct otx2_nic *nic,
                        nr_police++;
                        break;
                case FLOW_ACTION_MARK:
+                       if (act->mark & ~OTX2_RX_MATCH_ID_MASK) {
+                               NL_SET_ERR_MSG_MOD(extack, "Bad flow mark, only 16 bit supported");
+                               return -EOPNOTSUPP;
+                       }
                        mark = act->mark;
+                       req->match_id = mark & OTX2_RX_MATCH_ID_MASK;
+                       req->op = NIX_RX_ACTION_DEFAULT;
+                       nic->flags |= OTX2_FLAG_TC_MARK_ENABLED;
+                       refcount_inc(&nic->flow_cfg->mark_flows);
                        break;
 
                case FLOW_ACTION_RX_QUEUE_MAPPING:
@@ -1187,6 +1195,11 @@ static int otx2_tc_del_flow(struct otx2_nic *nic,
                return -EINVAL;
        }
 
+       /* Disable TC MARK flag if they are no rules with skbedit mark action */
+       if (flow_node->req.match_id)
+               if (!refcount_dec_and_test(&flow_cfg->mark_flows))
+                       nic->flags &= ~OTX2_FLAG_TC_MARK_ENABLED;
+
        if (flow_node->is_act_police) {
                __clear_bit(flow_node->rq, &nic->rq_bmap);
 
index f828d32737af02f6a1492e015a1a3d77a732e732..a16e9f244117bda8fd4c1bc6c9f7fdc3239830dd 100644 (file)
@@ -380,6 +380,9 @@ static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
        if (pfvf->netdev->features & NETIF_F_RXCSUM)
                skb->ip_summed = CHECKSUM_UNNECESSARY;
 
+       if (pfvf->flags & OTX2_FLAG_TC_MARK_ENABLED)
+               skb->mark = parse->match_id;
+
        skb_mark_for_recycle(skb);
 
        napi_gro_frags(napi);
index a82ffca8ce1b1bcf9b9fc0b9d0707da79d3ac3e1..3f1d2655ff777cb94ce7d10e975ba7c7978f3ed2 100644 (file)
@@ -62,6 +62,9 @@
 #define CQ_OP_STAT_OP_ERR       63
 #define CQ_OP_STAT_CQ_ERR       46
 
+/* Packet mark mask */
+#define OTX2_RX_MATCH_ID_MASK 0x0000ffff
+
 struct queue_stats {
        u64     bytes;
        u64     pkts;