diff mbox series

[RFC,10/24] netdevice: added XDP_{UN,}REGISTER_XSK command to ndo_bpf

Message ID 20180131135356.19134-11-bjorn.topel@gmail.com
State RFC, archived
Delegated to: David Miller
Headers show
Series Introducing AF_XDP support | expand

Commit Message

Björn Töpel Jan. 31, 2018, 1:53 p.m. UTC
From: Magnus Karlsson <magnus.karlsson@intel.com>

Here, ndo_bpf is extended with two sub-commands: XDP_REGISTER_XSK and
XDP_UNREGISTER_XSK. They are used to support zero copy allocators with
XDP sockets.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
---
 include/linux/netdevice.h | 17 +++++++++++++++++
 include/net/xdp_sock.h    | 30 +++++++++++++++++++++++++++++-
 2 files changed, 46 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 36cc7e92bd8e..a997649dd5cc 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -810,10 +810,18 @@  enum bpf_netdev_command {
 	BPF_OFFLOAD_DESTROY,
 	BPF_OFFLOAD_MAP_ALLOC,
 	BPF_OFFLOAD_MAP_FREE,
+	/* Registers callbacks with the driver that is used to support
+	 * AF_XDP sockets in zero copy mode.
+	 */
+	XDP_REGISTER_XSK,
+	/* Unregisters and AF_XDP socket in zero copy mode. */
+	XDP_UNREGISTER_XSK,
 };
 
 struct bpf_prog_offload_ops;
 struct netlink_ext_ack;
+struct xsk_tx_parms;
+struct xsk_rx_parms;
 
 struct netdev_bpf {
 	enum bpf_netdev_command command;
@@ -844,6 +852,15 @@  struct netdev_bpf {
 		struct {
 			struct bpf_offloaded_map *offmap;
 		};
+		/* XDP_REGISTER_XSK, XDP_UNREGISTER_XSK
+		 * All fields used for XDP_REGISTER_XSK.
+		 * queue_id the only field used for XDP_UNREGISTER_XSK.
+		 */
+		struct {
+			struct xsk_tx_parms *tx_parms;
+			struct xsk_rx_parms *rx_parms;
+			u32 queue_id;
+		} xsk;
 	};
 };
 
diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h
index 132489fe0e70..866ea7191217 100644
--- a/include/net/xdp_sock.h
+++ b/include/net/xdp_sock.h
@@ -1,8 +1,36 @@ 
 #ifndef _LINUX_AF_XDP_SOCK_H
 #define _LINUX_AF_XDP_SOCK_H
 
-struct xdp_sock;
+#include <linux/dma-direction.h>
+
+struct buff_pool;
+struct net_device;
 struct xdp_buff;
+struct xdp_sock;
+
+/* These two functions have to be called from the same serializing conext,
+ * for example the same NAPI context.
+ * They should not be called for the XDP_SKB path, only XDP_DRV.
+ */
+
+struct xsk_tx_parms {
+	void (*tx_completion)(u32 start, u32 npackets,
+			      unsigned long ctx1, unsigned long ctx2);
+	unsigned long ctx1;
+	unsigned long ctx2;
+	int (*get_tx_packet)(struct net_device *dev, u32 queue_id,
+			     dma_addr_t *dma, void **data, u32 *len,
+			     u32 *offset);
+};
+
+struct xsk_rx_parms {
+	struct buff_pool *buff_pool;
+	int (*dma_map)(struct buff_pool *bp, struct device *dev,
+		       enum dma_data_direction dir,
+		       unsigned long attr);
+	void *error_report_ctx;
+	void (*error_report)(void *ctx, int errno);
+};
 
 #ifdef CONFIG_XDP_SOCKETS
 int xsk_generic_rcv(struct xdp_buff *xdp);