diff mbox

[rdma-core,07/11] verbs: Add counters flow_spec

Message ID 1526553577-32273-8-git-send-email-yishaih@mellanox.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Yishai Hadas May 17, 2018, 10:39 a.m. UTC
From: Raed Salem <raeds@mellanox.com>

The flow counter specification is used to bind an ibv_counters
to a new flow.

This feature allows an application to request to add an action
to count events that match this flow rule.

The ibv_counters object used must be created beforehand.

Signed-off-by: Raed Salem <raeds@mellanox.com>
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
---
 libibverbs/cmd.c                 | 9 +++++++++
 libibverbs/kern-abi.h            | 1 +
 libibverbs/man/ibv_create_flow.3 | 1 +
 libibverbs/verbs.h               | 8 ++++++++
 4 files changed, 19 insertions(+)
diff mbox

Patch

diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c
index 9cd1ba5..bb07af5 100644
--- a/libibverbs/cmd.c
+++ b/libibverbs/cmd.c
@@ -1795,6 +1795,15 @@  static int ib_spec_to_kern_spec(struct ibv_flow_spec *ib_spec,
 		kern_spec->handle.handle = vaction->handle;
 		break;
 	}
+	case IBV_FLOW_SPEC_ACTION_COUNT: {
+		const struct verbs_counters *vcounters =
+			container_of(ib_spec->flow_count.counters,
+				     const struct verbs_counters, counters);
+		kern_spec->flow_count.size =
+			sizeof(struct ib_uverbs_flow_spec_action_count);
+		kern_spec->flow_count.handle = vcounters->handle;
+		break;
+	}
 	default:
 		return EINVAL;
 	}
diff --git a/libibverbs/kern-abi.h b/libibverbs/kern-abi.h
index 23dd104..3b9e7e5 100644
--- a/libibverbs/kern-abi.h
+++ b/libibverbs/kern-abi.h
@@ -271,6 +271,7 @@  struct ibv_kern_spec {
 		struct ib_uverbs_flow_spec_action_tag flow_tag;
 		struct ib_uverbs_flow_spec_action_drop drop;
 		struct ib_uverbs_flow_spec_action_handle handle;
+		struct ib_uverbs_flow_spec_action_count flow_count;
 	};
 };
 
diff --git a/libibverbs/man/ibv_create_flow.3 b/libibverbs/man/ibv_create_flow.3
index 65de08b..efa145c 100644
--- a/libibverbs/man/ibv_create_flow.3
+++ b/libibverbs/man/ibv_create_flow.3
@@ -73,6 +73,7 @@  IBV_FLOW_SPEC_INNER                    	= 0x100,  /* Flag making L2/L3/L4 specif
 IBV_FLOW_SPEC_ACTION_TAG                = 0x1000, /* Action tagging matched packet */
 IBV_FLOW_SPEC_ACTION_DROP               = 0x1001, /* Action dropping matched packet */
 IBV_FLOW_SPEC_ACTION_HANDLE             = 0x1002, /* Carry out an action created by ibv_create_flow_action_xxxx verb */
+IBV_FLOW_SPEC_ACTION_COUNT              = 0x1003, /* Action count matched packet with a ibv_counters handle */
 .in -8
 };
 .br
diff --git a/libibverbs/verbs.h b/libibverbs/verbs.h
index bcb1af0..4175347 100644
--- a/libibverbs/verbs.h
+++ b/libibverbs/verbs.h
@@ -1404,6 +1404,7 @@  enum ibv_flow_spec_type {
 	IBV_FLOW_SPEC_ACTION_TAG	= 0x1000,
 	IBV_FLOW_SPEC_ACTION_DROP	= 0x1001,
 	IBV_FLOW_SPEC_ACTION_HANDLE	= 0x1002,
+	IBV_FLOW_SPEC_ACTION_COUNT	= 0x1003,
 };
 
 struct ibv_flow_eth_filter {
@@ -1519,6 +1520,12 @@  struct ibv_flow_spec_action_handle {
 	const struct ibv_flow_action *action;
 };
 
+struct ibv_flow_spec_counter_action {
+	enum ibv_flow_spec_type  type;
+	uint16_t  size;
+	struct ibv_counters *counters;
+};
+
 struct ibv_flow_spec {
 	union {
 		struct {
@@ -1535,6 +1542,7 @@  struct ibv_flow_spec {
 		struct ibv_flow_spec_action_tag flow_tag;
 		struct ibv_flow_spec_action_drop drop;
 		struct ibv_flow_spec_action_handle handle;
+		struct ibv_flow_spec_counter_action flow_count;
 	};
 };