From: Tom Herbert <tom@herbertland.com>
To: netdev@vger.kernel.org, amritha.nambiar@intel.com
Cc: Tom Herbert <tom@herbertland.com>
Subject: [RFC PATCH net-next 1/3] sock: Definition and general functions for dev_and_queue structure
Date: Fri, 24 Jul 2020 13:14:10 -0700 [thread overview]
Message-ID: <20200724201412.599398-2-tom@herbertland.com> (raw)
In-Reply-To: <20200724201412.599398-1-tom@herbertland.com>
Add struct dev_and_queue which holds and ifindex and queue pair. Add
generic functions to set, get, and clear the pair in a structure.
---
include/net/sock.h | 56 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 54 insertions(+), 2 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 62e18fc8ac9f..b4919e603648 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -106,6 +106,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;
@@ -1788,6 +1798,50 @@ 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 void __dev_and_queue_get(const struct dev_and_queue *idandq,
+ int *ifindex, int *queue)
+{
+ struct dev_and_queue dandq;
+
+ dandq.val64 = idandq->val64;
+
+ if (dandq.ifindex >= 0 && dandq.queue != NO_QUEUE_MAPPING) {
+ *ifindex = dandq.ifindex;
+ *queue = dandq.queue;
+ return;
+ }
+
+ *ifindex = -1;
+ *queue = -1;
+}
+
+static inline void __dev_and_queue_set(struct dev_and_queue *odandq,
+ struct net_device *dev, 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 = dev->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 */
@@ -1796,8 +1850,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;
--
2.25.1
next prev parent reply other threads:[~2020-07-24 20:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-24 20:14 [RFC PATCH net-next 0/3] sock: Fix sock queue mapping to include device Tom Herbert
2020-07-24 20:14 ` Tom Herbert [this message]
2020-07-24 20:14 ` [RFC PATCH net-next 2/3] sock: Use dev_and_queue structure for TX queue mapping in sock Tom Herbert
2020-07-24 20:14 ` [RFC PATCH net-next 3/3] sock: Use dev_and_queue structure for RX " Tom Herbert
-- strict thread matches above, loose matches on Subject: below --
2020-10-21 19:47 [RFC PATCH net-next 0/3] sock: Fix sock queue mapping to include device Harshitha Ramamurthy
2020-10-21 19:47 ` [RFC PATCH net-next 1/3] sock: Definition and general functions for dev_and_queue structure Harshitha Ramamurthy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200724201412.599398-2-tom@herbertland.com \
--to=tom@herbertland.com \
--cc=amritha.nambiar@intel.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).