Create linux/netqueue.h to hold generic network queue definitions. Define NO_QUEUE to replace NO_QUEUE_MAPPING in net/sock.h. NO_QUEUE can generally be used to indicate that a 16 bit queue index does not refer to a queue.
Also, define net_queue_pair which will be used as a generic way to store a transmit/receive pair of network queues. --- include/linux/netdevice.h | 1 + include/linux/netqueue.h | 25 +++++++++++++++++++++++++ include/net/sock.h | 12 +++++------- net/core/filter.c | 4 ++-- 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 include/linux/netqueue.h diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 6fc613ed8eae..bf5f2a85da97 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -32,6 +32,7 @@ #include <linux/percpu.h> #include <linux/rculist.h> #include <linux/workqueue.h> +#include <linux/netqueue.h> #include <linux/dynamic_queue_limits.h> #include <linux/ethtool.h> diff --git a/include/linux/netqueue.h b/include/linux/netqueue.h new file mode 100644 index 000000000000..5a4d39821ada --- /dev/null +++ b/include/linux/netqueue.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Network queue identifier definitions + * + * Copyright (c) 2020 Tom Herbert <t...@herbertland.com> + */ + +#ifndef _LINUX_NETQUEUE_H +#define _LINUX_NETQUEUE_H + +/* Indicates no network queue is present in 16 bit queue number */ +#define NO_QUEUE USHRT_MAX + +struct net_queue_pair { + unsigned short txq_id; + unsigned short rxq_id; +}; + +static inline void init_net_queue_pair(struct net_queue_pair *qpair) +{ + qpair->rxq_id = NO_QUEUE; + qpair->txq_id = NO_QUEUE; +} + +#endif /* _LINUX_NETQUEUE_H */ diff --git a/include/net/sock.h b/include/net/sock.h index c53cc42b5ab9..acb76cfaae1b 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1800,16 +1800,14 @@ 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; + sk->sk_tx_queue_mapping = NO_QUEUE; } static inline int sk_tx_queue_get(const struct sock *sk) { - if (sk && sk->sk_tx_queue_mapping != NO_QUEUE_MAPPING) + if (sk && sk->sk_tx_queue_mapping != NO_QUEUE) return sk->sk_tx_queue_mapping; return -1; @@ -1821,7 +1819,7 @@ static inline void sk_rx_queue_set(struct sock *sk, const struct sk_buff *skb) if (skb_rx_queue_recorded(skb)) { u16 rx_queue = skb_get_rx_queue(skb); - if (WARN_ON_ONCE(rx_queue == NO_QUEUE_MAPPING)) + if (WARN_ON_ONCE(rx_queue == NO_QUEUE)) return; sk->sk_rx_queue_mapping = rx_queue; @@ -1832,14 +1830,14 @@ static inline void sk_rx_queue_set(struct sock *sk, const struct sk_buff *skb) static inline void sk_rx_queue_clear(struct sock *sk) { #ifdef CONFIG_XPS - sk->sk_rx_queue_mapping = NO_QUEUE_MAPPING; + sk->sk_rx_queue_mapping = NO_QUEUE; #endif } #ifdef CONFIG_XPS static inline int sk_rx_queue_get(const struct sock *sk) { - if (sk && sk->sk_rx_queue_mapping != NO_QUEUE_MAPPING) + if (sk && sk->sk_rx_queue_mapping != NO_QUEUE) return sk->sk_rx_queue_mapping; return -1; diff --git a/net/core/filter.c b/net/core/filter.c index 73395384afe2..d696aaabe3af 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -7544,7 +7544,7 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type, case offsetof(struct __sk_buff, queue_mapping): if (type == BPF_WRITE) { - *insn++ = BPF_JMP_IMM(BPF_JGE, si->src_reg, NO_QUEUE_MAPPING, 1); + *insn++ = BPF_JMP_IMM(BPF_JGE, si->src_reg, NO_QUEUE, 1); *insn++ = BPF_STX_MEM(BPF_H, si->dst_reg, si->src_reg, bpf_target_off(struct sk_buff, queue_mapping, @@ -7981,7 +7981,7 @@ u32 bpf_sock_convert_ctx_access(enum bpf_access_type type, sizeof_field(struct sock, sk_rx_queue_mapping), target_size)); - *insn++ = BPF_JMP_IMM(BPF_JNE, si->dst_reg, NO_QUEUE_MAPPING, + *insn++ = BPF_JMP_IMM(BPF_JNE, si->dst_reg, NO_QUEUE, 1); *insn++ = BPF_MOV64_IMM(si->dst_reg, -1); #else -- 2.25.1