diff mbox series

[RFC,net-next,1/3] sock: Definition and general functions for dev_and_queue structure

Message ID 20201021194743.781583-2-harshitha.ramamurthy@intel.com
State RFC
Delegated to: David Miller
Headers show
Series sock: Fix sock queue mapping to include device | expand

Checks

Context Check Description
jkicinski/cover_letter success Link
jkicinski/fixes_present success Link
jkicinski/patch_count success Link
jkicinski/tree_selection success Clearly marked for net-next
jkicinski/subject_prefix success Link
jkicinski/source_inline success Was 0 now: 0
jkicinski/verify_signedoff success Link
jkicinski/module_param success Was 0 now: 0
jkicinski/build_32bit success Errors and warnings before: 4895 this patch: 4895
jkicinski/kdoc success Errors and warnings before: 0 this patch: 0
jkicinski/verify_fixes success Link
jkicinski/checkpatch warning CHECK: Alignment should match open parenthesis
jkicinski/build_allmodconfig_warn success Errors and warnings before: 5273 this patch: 5273
jkicinski/header_inline success Link
jkicinski/stable success Stable not CCed

Commit Message

Harshitha Ramamurthy Oct. 21, 2020, 7:47 p.m. UTC
From: Tom Herbert <tom@herbertland.com>

Add struct dev_and_queue which holds and ifindex and queue pair. Add
generic functions to get the queue for the ifindex held as well as
functions to set, clear the pair in a structure.

Signed-off-by: Tom Herbert <tom@herbertland.com>
Signed-off-by: Harshitha Ramamurthy <harshitha.ramamurthy@intel.com>
---
 include/net/sock.h | 52 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/include/net/sock.h b/include/net/sock.h
index a5c6ae78df77..9755a6cab1a1 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -107,6 +107,16 @@  typedef struct {
 #endif
 } socket_lock_t;
 
+struct dev_and_queue {
+	union {
+		struct {
+			int ifindex;
+			u16 queue;
+		};
+		u64 val64;
+	};
+};
+
 struct sock;
 struct proto;
 struct net;
@@ -1791,6 +1801,46 @@  static inline int sk_receive_skb(struct sock *sk, struct sk_buff *skb,
 	return __sk_receive_skb(sk, skb, nested, 1, true);
 }
 
+#define NO_QUEUE_MAPPING	USHRT_MAX
+
+static inline int __dev_and_queue_get(const struct dev_and_queue *idandq,
+				       int ifindex)
+{
+	struct dev_and_queue dandq;
+
+	dandq.val64 = idandq->val64;
+
+	if (dandq.ifindex == ifindex && dandq.queue != NO_QUEUE_MAPPING)
+		return dandq.queue;
+
+	return -1;
+}
+
+static inline void __dev_and_queue_set(struct dev_and_queue *odandq,
+				       int ifindex, int queue)
+{
+	struct dev_and_queue dandq;
+
+	/* queue_mapping accept only upto a 16-bit value */
+	if (WARN_ON_ONCE((unsigned short)queue >= USHRT_MAX))
+		return;
+
+	dandq.ifindex = ifindex;
+	dandq.queue = queue;
+
+	odandq->val64 = dandq.val64;
+}
+
+static inline void __dev_and_queue_clear(struct dev_and_queue *odandq)
+{
+	struct dev_and_queue dandq;
+
+	dandq.ifindex = -1;
+	dandq.queue = NO_QUEUE_MAPPING;
+
+	odandq->val64 = dandq.val64;
+}
+
 static inline void sk_tx_queue_set(struct sock *sk, int tx_queue)
 {
 	/* sk_tx_queue_mapping accept only upto a 16-bit value */
@@ -1799,8 +1849,6 @@  static inline void sk_tx_queue_set(struct sock *sk, int tx_queue)
 	sk->sk_tx_queue_mapping = tx_queue;
 }
 
-#define NO_QUEUE_MAPPING	USHRT_MAX
-
 static inline void sk_tx_queue_clear(struct sock *sk)
 {
 	sk->sk_tx_queue_mapping = NO_QUEUE_MAPPING;