From 6d397cf1747a5e16a8041d85bc6cb0ee6457bfc8 Mon Sep 17 00:00:00 2001 From: coolsnowwolf Date: Tue, 20 Dec 2022 01:18:50 +0800 Subject: [PATCH] generic: backport API from linux 6.10 for mac80211 v6.1-rc8 --- .../900-v6.10-backport-stddef.patch | 169 +++++++++++++++++ .../901-v6.10-backport-net-device-path.patch | 73 ++++++++ .../902-v6.10-backport-minmax.patch | 172 ++++++++++++++++++ .../903-v6.10-backport-genl-small-ops.patch | 46 +++++ 4 files changed, 460 insertions(+) create mode 100644 target/linux/generic/backport-5.4/900-v6.10-backport-stddef.patch create mode 100644 target/linux/generic/backport-5.4/901-v6.10-backport-net-device-path.patch create mode 100644 target/linux/generic/backport-5.4/902-v6.10-backport-minmax.patch create mode 100644 target/linux/generic/backport-5.4/903-v6.10-backport-genl-small-ops.patch diff --git a/target/linux/generic/backport-5.4/900-v6.10-backport-stddef.patch b/target/linux/generic/backport-5.4/900-v6.10-backport-stddef.patch new file mode 100644 index 000000000..7f45c3bf2 --- /dev/null +++ b/target/linux/generic/backport-5.4/900-v6.10-backport-stddef.patch @@ -0,0 +1,169 @@ +--- a/include/linux/stddef.h ++++ b/include/linux/stddef.h +@@ -35,5 +35,66 @@ + */ + #define offsetofend(TYPE, MEMBER) \ + (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER)) ++ ++/** ++ * struct_group() - Wrap a set of declarations in a mirrored struct ++ * ++ * @NAME: The identifier name of the mirrored sub-struct ++ * @MEMBERS: The member declarations for the mirrored structs ++ * ++ * Used to create an anonymous union of two structs with identical ++ * layout and size: one anonymous and one named. The former can be ++ * used normally without sub-struct naming, and the latter can be ++ * used to reason about the start, end, and size of the group of ++ * struct members. ++ */ ++#define struct_group(NAME, MEMBERS...) \ ++ __struct_group(/* no tag */, NAME, /* no attrs */, MEMBERS) ++ ++/** ++ * struct_group_attr() - Create a struct_group() with trailing attributes ++ * ++ * @NAME: The identifier name of the mirrored sub-struct ++ * @ATTRS: Any struct attributes to apply ++ * @MEMBERS: The member declarations for the mirrored structs ++ * ++ * Used to create an anonymous union of two structs with identical ++ * layout and size: one anonymous and one named. The former can be ++ * used normally without sub-struct naming, and the latter can be ++ * used to reason about the start, end, and size of the group of ++ * struct members. Includes structure attributes argument. ++ */ ++#define struct_group_attr(NAME, ATTRS, MEMBERS...) \ ++ __struct_group(/* no tag */, NAME, ATTRS, MEMBERS) ++ ++/** ++ * struct_group_tagged() - Create a struct_group with a reusable tag ++ * ++ * @TAG: The tag name for the named sub-struct ++ * @NAME: The identifier name of the mirrored sub-struct ++ * @MEMBERS: The member declarations for the mirrored structs ++ * ++ * Used to create an anonymous union of two structs with identical ++ * layout and size: one anonymous and one named. The former can be ++ * used normally without sub-struct naming, and the latter can be ++ * used to reason about the start, end, and size of the group of ++ * struct members. Includes struct tag argument for the named copy, ++ * so the specified layout can be reused later. ++ */ ++#define struct_group_tagged(TAG, NAME, MEMBERS...) \ ++ __struct_group(TAG, NAME, /* no attrs */, MEMBERS) ++ ++/** ++ * DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union ++ * ++ * @TYPE: The type of each flexible array element ++ * @NAME: The name of the flexible array member ++ * ++ * In order to have a flexible array member in a union or alone in a ++ * struct, it needs to be wrapped in an anonymous struct with at least 1 ++ * named member, but that member can be empty. ++ */ ++#define DECLARE_FLEX_ARRAY(TYPE, NAME) \ ++ __DECLARE_FLEX_ARRAY(TYPE, NAME) + + #endif +--- a/dev/null ++++ b/tools/include/uapi/linux/stddef.h +@@ -0,0 +1,47 @@ ++/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ ++#ifndef _LINUX_STDDEF_H ++#define _LINUX_STDDEF_H ++ ++ ++ ++#ifndef __always_inline ++#define __always_inline __inline__ ++#endif ++ ++/** ++ * __struct_group() - Create a mirrored named and anonyomous struct ++ * ++ * @TAG: The tag name for the named sub-struct (usually empty) ++ * @NAME: The identifier name of the mirrored sub-struct ++ * @ATTRS: Any struct attributes (usually empty) ++ * @MEMBERS: The member declarations for the mirrored structs ++ * ++ * Used to create an anonymous union of two structs with identical layout ++ * and size: one anonymous and one named. The former's members can be used ++ * normally without sub-struct naming, and the latter can be used to ++ * reason about the start, end, and size of the group of struct members. ++ * The named struct can also be explicitly tagged for layer reuse, as well ++ * as both having struct attributes appended. ++ */ ++#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \ ++ union { \ ++ struct { MEMBERS } ATTRS; \ ++ struct TAG { MEMBERS } ATTRS NAME; \ ++ } ++ ++/** ++ * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union ++ * ++ * @TYPE: The type of each flexible array element ++ * @NAME: The name of the flexible array member ++ * ++ * In order to have a flexible array member in a union or alone in a ++ * struct, it needs to be wrapped in an anonymous struct with at least 1 ++ * named member, but that member can be empty. ++ */ ++#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \ ++ struct { \ ++ struct { } __empty_ ## NAME; \ ++ TYPE NAME[]; \ ++ } ++#endif +--- a/dev/null ++++ b/include/uapi/linux/stddef.h +@@ -0,0 +1,47 @@ ++/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ ++#ifndef _UAPI_LINUX_STDDEF_H ++#define _UAPI_LINUX_STDDEF_H ++ ++#include ++ ++#ifndef __always_inline ++#define __always_inline inline ++#endif ++ ++/** ++ * __struct_group() - Create a mirrored named and anonyomous struct ++ * ++ * @TAG: The tag name for the named sub-struct (usually empty) ++ * @NAME: The identifier name of the mirrored sub-struct ++ * @ATTRS: Any struct attributes (usually empty) ++ * @MEMBERS: The member declarations for the mirrored structs ++ * ++ * Used to create an anonymous union of two structs with identical layout ++ * and size: one anonymous and one named. The former's members can be used ++ * normally without sub-struct naming, and the latter can be used to ++ * reason about the start, end, and size of the group of struct members. ++ * The named struct can also be explicitly tagged for layer reuse, as well ++ * as both having struct attributes appended. ++ */ ++#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \ ++ union { \ ++ struct { MEMBERS } ATTRS; \ ++ struct TAG { MEMBERS } ATTRS NAME; \ ++ } ++ ++/** ++ * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union ++ * ++ * @TYPE: The type of each flexible array element ++ * @NAME: The name of the flexible array member ++ * ++ * In order to have a flexible array member in a union or alone in a ++ * struct, it needs to be wrapped in an anonymous struct with at least 1 ++ * named member, but that member can be empty. ++ */ ++#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \ ++ struct { \ ++ struct { } __empty_ ## NAME; \ ++ TYPE NAME[]; \ ++ } ++#endif diff --git a/target/linux/generic/backport-5.4/901-v6.10-backport-net-device-path.patch b/target/linux/generic/backport-5.4/901-v6.10-backport-net-device-path.patch new file mode 100644 index 000000000..4afea2782 --- /dev/null +++ b/target/linux/generic/backport-5.4/901-v6.10-backport-net-device-path.patch @@ -0,0 +1,73 @@ +--- a/include/linux/netdevice.h ++++ b/include/linux/netdevice.h +@@ -838,6 +838,61 @@ + struct sk_buff *skb, + struct net_device *sb_dev); + ++enum net_device_path_type { ++ DEV_PATH_ETHERNET = 0, ++ DEV_PATH_VLAN, ++ DEV_PATH_BRIDGE, ++ DEV_PATH_PPPOE, ++ DEV_PATH_DSA, ++ DEV_PATH_MTK_WDMA, ++}; ++ ++struct net_device_path { ++ enum net_device_path_type type; ++ const struct net_device *dev; ++ union { ++ struct { ++ u16 id; ++ __be16 proto; ++ u8 h_dest[ETH_ALEN]; ++ } encap; ++ struct { ++ enum { ++ DEV_PATH_BR_VLAN_KEEP, ++ DEV_PATH_BR_VLAN_TAG, ++ DEV_PATH_BR_VLAN_UNTAG, ++ DEV_PATH_BR_VLAN_UNTAG_HW, ++ } vlan_mode; ++ u16 vlan_id; ++ __be16 vlan_proto; ++ } bridge; ++ struct { ++ int port; ++ u16 proto; ++ } dsa; ++ struct { ++ u8 wdma_idx; ++ u8 queue; ++ u16 wcid; ++ u8 bss; ++ } mtk_wdma; ++ }; ++}; ++ ++#define NET_DEVICE_PATH_STACK_MAX 5 ++#define NET_DEVICE_PATH_VLAN_MAX 2 ++ ++struct net_device_path_ctx { ++ const struct net_device *dev; ++ u8 daddr[ETH_ALEN]; ++ ++ int num_vlans; ++ struct { ++ u16 id; ++ __be16 proto; ++ } vlan[NET_DEVICE_PATH_VLAN_MAX]; ++}; ++ + enum tc_setup_type { + TC_SETUP_QDISC_MQPRIO, + TC_SETUP_CLSU32, +@@ -1468,6 +1523,8 @@ + u32 flags); + int (*ndo_xsk_wakeup)(struct net_device *dev, + u32 queue_id, u32 flags); ++ int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, ++ struct net_device_path *path); + struct devlink_port * (*ndo_get_devlink_port)(struct net_device *dev); + }; + diff --git a/target/linux/generic/backport-5.4/902-v6.10-backport-minmax.patch b/target/linux/generic/backport-5.4/902-v6.10-backport-minmax.patch new file mode 100644 index 000000000..1a393b1d7 --- /dev/null +++ b/target/linux/generic/backport-5.4/902-v6.10-backport-minmax.patch @@ -0,0 +1,172 @@ +--- a/dev/null ++++ b/include/linux/minmax.h +@@ -0,0 +1,169 @@ ++/* SPDX-License-Identifier: GPL-2.0 */ ++#ifndef _LINUX_MINMAX_H ++#define _LINUX_MINMAX_H ++ ++#include ++ ++/* ++ * min()/max()/clamp() macros must accomplish three things: ++ * ++ * - avoid multiple evaluations of the arguments (so side-effects like ++ * "x++" happen only once) when non-constant. ++ * - perform strict type-checking (to generate warnings instead of ++ * nasty runtime surprises). See the "unnecessary" pointer comparison ++ * in __typecheck(). ++ * - retain result as a constant expressions when called with only ++ * constant expressions (to avoid tripping VLA warnings in stack ++ * allocation usage). ++ */ ++#define __typecheck(x, y) \ ++ (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) ++ ++#define __no_side_effects(x, y) \ ++ (__is_constexpr(x) && __is_constexpr(y)) ++ ++#define __safe_cmp(x, y) \ ++ (__typecheck(x, y) && __no_side_effects(x, y)) ++ ++#define __cmp(x, y, op) ((x) op (y) ? (x) : (y)) ++ ++#define __cmp_once(x, y, unique_x, unique_y, op) ({ \ ++ typeof(x) unique_x = (x); \ ++ typeof(y) unique_y = (y); \ ++ __cmp(unique_x, unique_y, op); }) ++ ++#define __careful_cmp(x, y, op) \ ++ __builtin_choose_expr(__safe_cmp(x, y), \ ++ __cmp(x, y, op), \ ++ __cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op)) ++ ++#define __clamp(val, lo, hi) \ ++ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) ++ ++#define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({ \ ++ typeof(val) unique_val = (val); \ ++ typeof(lo) unique_lo = (lo); \ ++ typeof(hi) unique_hi = (hi); \ ++ __clamp(unique_val, unique_lo, unique_hi); }) ++ ++#define __clamp_input_check(lo, hi) \ ++ (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \ ++ __is_constexpr((lo) > (hi)), (lo) > (hi), false))) ++ ++#define __careful_clamp(val, lo, hi) ({ \ ++ __clamp_input_check(lo, hi) + \ ++ __builtin_choose_expr(__typecheck(val, lo) && __typecheck(val, hi) && \ ++ __typecheck(hi, lo) && __is_constexpr(val) && \ ++ __is_constexpr(lo) && __is_constexpr(hi), \ ++ __clamp(val, lo, hi), \ ++ __clamp_once(val, lo, hi, __UNIQUE_ID(__val), \ ++ __UNIQUE_ID(__lo), __UNIQUE_ID(__hi))); }) ++ ++/** ++ * min - return minimum of two values of the same or compatible types ++ * @x: first value ++ * @y: second value ++ */ ++#define min(x, y) __careful_cmp(x, y, <) ++ ++/** ++ * max - return maximum of two values of the same or compatible types ++ * @x: first value ++ * @y: second value ++ */ ++#define max(x, y) __careful_cmp(x, y, >) ++ ++/** ++ * min3 - return minimum of three values ++ * @x: first value ++ * @y: second value ++ * @z: third value ++ */ ++#define min3(x, y, z) min((typeof(x))min(x, y), z) ++ ++/** ++ * max3 - return maximum of three values ++ * @x: first value ++ * @y: second value ++ * @z: third value ++ */ ++#define max3(x, y, z) max((typeof(x))max(x, y), z) ++ ++/** ++ * min_not_zero - return the minimum that is _not_ zero, unless both are zero ++ * @x: value1 ++ * @y: value2 ++ */ ++#define min_not_zero(x, y) ({ \ ++ typeof(x) __x = (x); \ ++ typeof(y) __y = (y); \ ++ __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) ++ ++/** ++ * clamp - return a value clamped to a given range with strict typechecking ++ * @val: current value ++ * @lo: lowest allowable value ++ * @hi: highest allowable value ++ * ++ * This macro does strict typechecking of @lo/@hi to make sure they are of the ++ * same type as @val. See the unnecessary pointer comparisons. ++ */ ++#define clamp(val, lo, hi) __careful_clamp(val, lo, hi) ++ ++/* ++ * ..and if you can't take the strict ++ * types, you can specify one yourself. ++ * ++ * Or not use min/max/clamp at all, of course. ++ */ ++ ++/** ++ * min_t - return minimum of two values, using the specified type ++ * @type: data type to use ++ * @x: first value ++ * @y: second value ++ */ ++#define min_t(type, x, y) __careful_cmp((type)(x), (type)(y), <) ++ ++/** ++ * max_t - return maximum of two values, using the specified type ++ * @type: data type to use ++ * @x: first value ++ * @y: second value ++ */ ++#define max_t(type, x, y) __careful_cmp((type)(x), (type)(y), >) ++ ++/** ++ * clamp_t - return a value clamped to a given range using a given type ++ * @type: the type of variable to use ++ * @val: current value ++ * @lo: minimum allowable value ++ * @hi: maximum allowable value ++ * ++ * This macro does no typechecking and uses temporary variables of type ++ * @type to make all the comparisons. ++ */ ++#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) ++ ++/** ++ * clamp_val - return a value clamped to a given range using val's type ++ * @val: current value ++ * @lo: minimum allowable value ++ * @hi: maximum allowable value ++ * ++ * This macro does no typechecking and uses temporary variables of whatever ++ * type the input argument @val is. This is useful when @val is an unsigned ++ * type and @lo and @hi are literals that will otherwise be assigned a signed ++ * integer type. ++ */ ++#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) ++ ++/** ++ * swap - swap values of @a and @b ++ * @a: first value ++ * @b: second value ++ */ ++#define swap(a, b) \ ++ do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) ++ ++#endif /* _LINUX_MINMAX_H */ diff --git a/target/linux/generic/backport-5.4/903-v6.10-backport-genl-small-ops.patch b/target/linux/generic/backport-5.4/903-v6.10-backport-genl-small-ops.patch new file mode 100644 index 000000000..3be3147af --- /dev/null +++ b/target/linux/generic/backport-5.4/903-v6.10-backport-genl-small-ops.patch @@ -0,0 +1,46 @@ +--- a/include/net/genetlink.h ++++ b/include/net/genetlink.h +@@ -51,6 +51,7 @@ + unsigned int maxattr; + bool netnsok; + bool parallel_ops; ++ u8 n_small_ops; + const struct nla_policy *policy; + int (*pre_doit)(const struct genl_ops *ops, + struct sk_buff *skb, +@@ -60,6 +61,7 @@ + struct genl_info *info); + struct nlattr ** attrbuf; /* private */ + const struct genl_ops * ops; ++ const struct genl_small_ops *small_ops; + const struct genl_multicast_group *mcgrps; + unsigned int n_ops; + unsigned int n_mcgrps; +@@ -117,6 +119,27 @@ + GENL_DONT_VALIDATE_STRICT = BIT(0), + GENL_DONT_VALIDATE_DUMP = BIT(1), + GENL_DONT_VALIDATE_DUMP_STRICT = BIT(2), ++}; ++ ++/** ++ * struct genl_small_ops - generic netlink operations (small version) ++ * @cmd: command identifier ++ * @internal_flags: flags used by the family ++ * @flags: GENL_* flags (%GENL_ADMIN_PERM or %GENL_UNS_ADMIN_PERM) ++ * @validate: validation flags from enum genl_validate_flags ++ * @doit: standard command callback ++ * @dumpit: callback for dumpers ++ * ++ * This is a cut-down version of struct genl_ops for users who don't need ++ * most of the ancillary infra and want to save space. ++ */ ++struct genl_small_ops { ++ int (*doit)(struct sk_buff *skb, struct genl_info *info); ++ int (*dumpit)(struct sk_buff *skb, struct netlink_callback *cb); ++ u8 cmd; ++ u8 internal_flags; ++ u8 flags; ++ u8 validate; + }; + + /**