3 * Copyright (c) 2017 Jesper Dangaard Brouer, Red Hat Inc.
4 * Released under terms in GPL version 2. See COPYING.
6 #include <linux/types.h>
11 #define REG_STATE_NEW 0x0
12 #define REG_STATE_REGISTERED 0x1
13 #define REG_STATE_UNREGISTERED 0x2
14 #define REG_STATE_UNUSED 0x3
16 void xdp_rxq_info_unreg(struct xdp_rxq_info
*xdp_rxq
)
18 /* Simplify driver cleanup code paths, allow unreg "unused" */
19 if (xdp_rxq
->reg_state
== REG_STATE_UNUSED
)
22 WARN(!(xdp_rxq
->reg_state
== REG_STATE_REGISTERED
), "Driver BUG");
24 xdp_rxq
->reg_state
= REG_STATE_UNREGISTERED
;
27 EXPORT_SYMBOL_GPL(xdp_rxq_info_unreg
);
29 static void xdp_rxq_info_init(struct xdp_rxq_info
*xdp_rxq
)
31 memset(xdp_rxq
, 0, sizeof(*xdp_rxq
));
34 /* Returns 0 on success, negative on failure */
35 int xdp_rxq_info_reg(struct xdp_rxq_info
*xdp_rxq
,
36 struct net_device
*dev
, u32 queue_index
)
38 if (xdp_rxq
->reg_state
== REG_STATE_UNUSED
) {
39 WARN(1, "Driver promised not to register this");
43 if (xdp_rxq
->reg_state
== REG_STATE_REGISTERED
) {
44 WARN(1, "Missing unregister, handled but fix driver");
45 xdp_rxq_info_unreg(xdp_rxq
);
49 WARN(1, "Missing net_device from driver");
53 /* State either UNREGISTERED or NEW */
54 xdp_rxq_info_init(xdp_rxq
);
56 xdp_rxq
->queue_index
= queue_index
;
58 xdp_rxq
->reg_state
= REG_STATE_REGISTERED
;
61 EXPORT_SYMBOL_GPL(xdp_rxq_info_reg
);
63 void xdp_rxq_info_unused(struct xdp_rxq_info
*xdp_rxq
)
65 xdp_rxq
->reg_state
= REG_STATE_UNUSED
;
67 EXPORT_SYMBOL_GPL(xdp_rxq_info_unused
);
69 bool xdp_rxq_info_is_reg(struct xdp_rxq_info
*xdp_rxq
)
71 return (xdp_rxq
->reg_state
== REG_STATE_REGISTERED
);
73 EXPORT_SYMBOL_GPL(xdp_rxq_info_is_reg
);